diff options
| author | Jonathan Bradley <jcb@pikum.xyz> | 2025-04-21 15:46:46 -0400 |
|---|---|---|
| committer | Jonathan Bradley <jcb@pikum.xyz> | 2025-04-21 15:46:46 -0400 |
| commit | ef37d054dfe5812efa9eefb4b9b18621fdabac25 (patch) | |
| tree | 713042c875004da0058bf5813c4b2b736b6c4ed3 /src/font.cpp | |
| parent | a066448effaa9a56c049136067a73ba0156f65d3 (diff) | |
pke: first-pass serializing ui and font renders
Diffstat (limited to 'src/font.cpp')
| -rw-r--r-- | src/font.cpp | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/src/font.cpp b/src/font.cpp index 9c8f1bc..c94890b 100644 --- a/src/font.cpp +++ b/src/font.cpp @@ -7,6 +7,7 @@ #include "static-plane.hpp" #include "vendor-stb-image-include.h" #include "game-settings.hpp" +#include "ecs.hpp" #include <vulkan/vulkan_core.h> @@ -734,7 +735,7 @@ void FontType_Unload(FontTypeIndex idx) { // However, the new buffer is exactly the length it needs to be and no greater. // Consider using a heuristic to allocate a buffer larger than needed. // At the time of writing, the only way to do this is to un-register text. -FontRenderHandle FontType_AddStringRender(FontTypeIndex idx_ft, const pk_str str, FontRenderSettings *settings) { +FontRenderHandle FontType_AddStringRender(FontTypeIndex idx_ft, const pk_cstr &&str, FontRenderSettings *settings, Entity_Base *parent) { assert(settings != nullptr); PKVK_TmpBufferDetails tmpBufferDetails{}; VkDeviceSize byteCount; @@ -755,9 +756,12 @@ FontRenderHandle FontType_AddStringRender(FontTypeIndex idx_ft, const pk_str str ft->renders = arr; } fr = &ft->renders[(FontRenderIndex_T)idx_fr]; - fr->handle.index_ft = idx_ft; - fr->handle.index_fr = idx_fr; + *fr = {}; + ECS_CreateEntity(fr, parent); + fr->fr_handle.index_ft = idx_ft; + fr->fr_handle.index_fr = idx_fr; fr->settings = *settings; + fr->text = str; // insert new characters into tmp buffer { @@ -940,7 +944,7 @@ FontRenderHandle FontType_AddStringRender(FontTypeIndex idx_ft, const pk_str str } PKVK_EndBuffer(tmpBufferDetails); - return fr->handle; + return fr->fr_handle; } void FontType_UpdateStringRender(FontRenderHandle frh, FontRenderSettings *settings) { @@ -968,4 +972,11 @@ void FontType_RemoveStringRender(FontRenderHandle handle) { fr->buffer_start_index = buffer_start_index; buffer_start_index += fr->n_glyphs; } + if (fr->text.reserved > 0) { + // 2025-04-16 - JCB + // not passing a specific bucket because pk_cstr doesn't store it. + // font.cpp assumes the user has already cloned the string if necessary - only assigns the value. + pk_delete<char>(fr->text.val, fr->text.reserved); + } + ECS_MarkForRemoval(fr); } |
