diff --git a/src/gx/font/CGxString.cpp b/src/gx/font/CGxString.cpp index fd95b57..f87163b 100644 --- a/src/gx/font/CGxString.cpp +++ b/src/gx/font/CGxString.cpp @@ -12,20 +12,37 @@ #include #include -TEXTLINETEXTURE* TEXTLINETEXTURE::NewTextLineTexture() { - // TODO - // Allocate off of TEXTLINETEXTURE::s_freeTextLineTextures +STORM_LIST(TEXTLINETEXTURE) TEXTLINETEXTURE::s_freeTextLineTextures; +uint32_t TEXTLINETEXTURE::s_recycledBytes; - auto m = SMemAlloc(sizeof(TEXTLINETEXTURE), __FILE__, __LINE__, 0x0); - return new (m) TEXTLINETEXTURE(); +TEXTLINETEXTURE* TEXTLINETEXTURE::NewTextLineTexture() { + auto line = TEXTLINETEXTURE::s_freeTextLineTextures.Head(); + + if (!line) { + return STORM_NEW(TEXTLINETEXTURE); + } + + // TODO Likely TSBaseArray::Bytes() + TEXTLINETEXTURE::s_recycledBytes -= (sizeof(VERT) * line->m_vert.m_alloc) + (sizeof(CImVector) * line->m_colors.m_alloc); + + line->Unlink(); + + return line; } -void TEXTLINETEXTURE::Recycle(TEXTLINETEXTURE* ptr) { - // TODO if (TEXTLINETEXTURE::s_recycledBytes <= 0x80000) - - if (ptr) { - delete ptr; +void TEXTLINETEXTURE::Recycle(TEXTLINETEXTURE* line) { + if (TEXTLINETEXTURE::s_recycledBytes > 0x80000) { + delete line; + return; } + + line->m_vert.SetCount(0); + line->m_colors.SetCount(0); + + // TODO Likely TSBaseArray::Bytes() + TEXTLINETEXTURE::s_recycledBytes += (sizeof(VERT) * line->m_vert.m_alloc) + (sizeof(CImVector) * line->m_colors.m_alloc); + + TEXTLINETEXTURE::s_freeTextLineTextures.LinkToTail(line); } void TEXTLINETEXTURE::WriteGeometry(CGxVertexPCT* buffer, const CImVector& fontColor, const C2Vector& shadowOffset, const CImVector& shadowColor, const C3Vector& viewTranslation, bool hasShadow, bool a8, int32_t vertexOffset, int32_t vertexCount) { diff --git a/src/gx/font/CGxString.hpp b/src/gx/font/CGxString.hpp index e4d2619..06112ae 100644 --- a/src/gx/font/CGxString.hpp +++ b/src/gx/font/CGxString.hpp @@ -16,8 +16,12 @@ struct VERT { C2Vector tc; }; -class TEXTLINETEXTURE { +class TEXTLINETEXTURE : public TSLinkedNode { public: + // Static variables + static STORM_LIST(TEXTLINETEXTURE) s_freeTextLineTextures; + static uint32_t s_recycledBytes; + // Static functions static TEXTLINETEXTURE* NewTextLineTexture(); static void Recycle(TEXTLINETEXTURE* ptr);