diff options
| author | Jonathan Bradley <jcb@pikum.xyz> | 2025-05-21 14:05:03 -0400 |
|---|---|---|
| committer | Jonathan Bradley <jcb@pikum.xyz> | 2025-05-21 14:05:03 -0400 |
| commit | 104a579c9e3bce425bcb4a857083f84ca1f1a3e0 (patch) | |
| tree | f6dc0e713a6ef9d566b8e525a2ee81d0abe36a54 /src/window.cpp | |
| parent | 672a63dff6f313abe8e9ae6376ab6c09db9e8ac3 (diff) | |
pke: window DynArray to pk_arr_t
Diffstat (limited to 'src/window.cpp')
| -rw-r--r-- | src/window.cpp | 46 |
1 files changed, 21 insertions, 25 deletions
diff --git a/src/window.cpp b/src/window.cpp index a099984..acbe00e 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -8,7 +8,6 @@ #include "asset-manager.hpp" #include "camera.hpp" -#include "dynamic-array.hpp" #include "ecs.hpp" #include "font.hpp" #include "game-settings.hpp" @@ -29,7 +28,7 @@ struct pke_vkAllocData { void *data; std::size_t size; }; -DynArray<pke_vkAllocData> *vulkanAllocs = nullptr; +pk_arr_t<pke_vkAllocData> vulkanAllocs{}; #define NELEMS(x) (sizeof(x) / sizeof((x)[0])) @@ -665,11 +664,11 @@ void PKE_vkFreeFunction(void *pUserData, void *pMemory) { (void)pUserData; if (pMemory == nullptr) return; pke_vkAllocData *chunk = nullptr; - size_t index = -1; - int64_t count = vulkanAllocs->Count(); - for (int64_t i = 0; i < count; ++i) { - if ((*vulkanAllocs)[i].data == pMemory) { - chunk = &(*vulkanAllocs)[i]; + uint32_t index, i, count; + count = vulkanAllocs.next; + for (i = 0; i < count; ++i) { + if (vulkanAllocs[i].data == pMemory) { + chunk = &vulkanAllocs[i]; index = i; break; } @@ -677,7 +676,7 @@ void PKE_vkFreeFunction(void *pUserData, void *pMemory) { if (chunk != nullptr) { assert(chunk != nullptr); pk_delete_bkt(chunk->data, chunk->size, MemBkt_Vulkan); - vulkanAllocs->Remove(index); + pk_arr_remove_at(&vulkanAllocs, index); } else { fprintf(stderr, "%s\n", "PKE_vkFreeFunction - untracked pointer"); } @@ -690,7 +689,7 @@ void *PKE_vkAllocateFunction(void *pUserData, size_t size, size_t alignment, VkS return nullptr; } void *ptr = pk_new_bkt(size, alignment, MemBkt_Vulkan); - vulkanAllocs->Push({ + pk_arr_append_t(&vulkanAllocs, { .data = ptr, .size = size, }); @@ -707,11 +706,11 @@ void *PKE_vkReallocationFunction(void *pUserData, void *pOriginal, size_t size, return nullptr; } pke_vkAllocData *chunk = nullptr; - size_t index = -1; - int64_t count = vulkanAllocs->Count(); - for (int64_t i = 0; i < count; ++i) { - if ((*vulkanAllocs)[i].data == pOriginal) { - chunk = &((*vulkanAllocs)[i]); + uint32_t index, i, count; + count = vulkanAllocs.next; + for (i = 0; i < count; ++i) { + if (vulkanAllocs[i].data == pOriginal) { + chunk = &(vulkanAllocs[i]); index = i; break; } @@ -725,7 +724,7 @@ void *PKE_vkReallocationFunction(void *pUserData, void *pOriginal, size_t size, if (chunk != nullptr) { memcpy(newPtr, chunk->data, (chunk->size < size ? chunk->size : size) - 1); pk_delete_bkt(chunk->data, chunk->size, MemBkt_Vulkan); - vulkanAllocs->Remove(index); + pk_arr_remove_at(&vulkanAllocs, index); } else { } @@ -3318,7 +3317,7 @@ void RecordCommandBuffer(VkCommandBuffer commandBuffer, uint32_t imageIndex) { // ImGui bool any = false; - for (long i = 0; i < LoadedPkePlugins.next; ++i) { + for (uint32_t i = 0; i < LoadedPkePlugins.next; ++i) { if (LoadedPkePlugins[i].OnImGuiRender != nullptr) { any = true; break; @@ -3329,7 +3328,7 @@ void RecordCommandBuffer(VkCommandBuffer commandBuffer, uint32_t imageIndex) { ImGui_ImplVulkan_NewFrame(); ImGui_ImplGlfw_NewFrame(); ImGui::NewFrame(); - for (long i = 0; i < LoadedPkePlugins.next; ++i) { + for (uint32_t i = 0; i < LoadedPkePlugins.next; ++i) { if (LoadedPkePlugins[i].OnImGuiRender != nullptr) { LoadedPkePlugins[i].OnImGuiRender(); } @@ -3574,9 +3573,8 @@ void CreateWindow(PKEWindowProperties wp) { pke_ev_mgr_id_window = pk_ev_create_mgr(); pke_ev_id_framebuffer_length_changed = pk_ev_register_ev(pke_ev_mgr_id_window, NULL); MemBkt_Vulkan = pk_bucket_create("vulkan", PK_DEFAULT_BUCKET_SIZE, false); - vulkanAllocs = pk_new<DynArray<pke_vkAllocData>>(MemBkt_Vulkan); - new (vulkanAllocs) DynArray<pke_vkAllocData>(MemBkt_Vulkan); - vulkanAllocs->Reserve(2048); + vulkanAllocs.bkt = MemBkt_Vulkan; + pk_arr_reserve(&vulkanAllocs, 2048); glfwInit(); glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); window = glfwCreateWindow(wp.width, wp.height, "Pikul", nullptr, nullptr); @@ -3673,12 +3671,10 @@ void DestroyWindow() { glfwDestroyWindow(window); glfwTerminate(); - if (vulkanAllocs->Count() > 0) { - fprintf(stderr, "VkAllocator has '%ld' outstanding allocations!", vulkanAllocs->Count()); + if (vulkanAllocs.next > 0) { + fprintf(stderr, "VkAllocator has '%u' outstanding allocations!", vulkanAllocs.next); } - vulkanAllocs->~DynArray(); - pk_delete<DynArray<pke_vkAllocData>>(vulkanAllocs, MemBkt_Vulkan); - vulkanAllocs = CAFE_BABE(DynArray<pke_vkAllocData>); + pk_arr_reset(&vulkanAllocs); // TODO there's un-freed vulkan stuff in the bucket // comment this out to see it in the debug printout pk_bucket_destroy(MemBkt_Vulkan); |
