From 9537b88060a2518577df94d6c79c8d0c7f5780b5 Mon Sep 17 00:00:00 2001 From: Mathew Benson Date: Wed, 30 Sep 2026 18:04:00 +0300 Subject: [PATCH] refactor(memory): Move Memory Management Macros to C++ Template Functions - This change targets the macros in the `ZEngineDef.h` header. - Refactored the Memory Management Macros to make them use C++ Template Based Functions instead. - This will make the code easier to read, especially when there is an issue(error messag) as tracking down what is going on with macros can be quite difficult. - The functions have also been made inline so there should be less binary code repetition, which should lead to a smaller binary. --- Obelisk/EntryPoint.cpp | 2 +- .../Controllers/EditorCameraController.cpp | 2 +- Tetragrama/Editor.cpp | 14 +- Tetragrama/Panels/AssetImporterPanel.cpp | 8 +- Tetragrama/Panels/HierarchyPanel.cpp | 8 +- Tetragrama/Panels/ProjectViewPanel.cpp | 2 +- .../Applications/AppRenderPipeline.cpp | 6 +- .../ZEngine/Applications/GameApplication.cpp | 4 +- ZEngine/ZEngine/Core/Containers/Array.h | 4 +- .../ZEngine/Core/Containers/InitializerList.h | 4 +- ZEngine/ZEngine/Core/Containers/Strings.h | 4 +- .../Core/VFS/Platform/VFSRDCWatcher.cpp | 2 +- .../Core/VFS/Registry/DependencyGraph.cpp | 4 +- ZEngine/ZEngine/Core/VFS/VFSContext.cpp | 8 +- ZEngine/ZEngine/Core/VFS/VFSDiskBackend.cpp | 2 +- ZEngine/ZEngine/Core/VFS/VFSMemoryBackend.cpp | 4 +- ZEngine/ZEngine/Core/VFS/VFSZipBackend.cpp | 2 +- ZEngine/ZEngine/ECS/Actor.h | 5 +- ZEngine/ZEngine/ECS/ActorManager.cpp | 2 +- ZEngine/ZEngine/ECS/ActorManager.h | 2 +- ZEngine/ZEngine/ECS/Scene.h | 2 +- ZEngine/ZEngine/Engine.cpp | 22 +-- .../Hardwares/CommandBufferManager.cpp | 34 ++-- ZEngine/ZEngine/Hardwares/DeviceSwapchain.cpp | 10 +- ZEngine/ZEngine/Hardwares/VulkanDevice.cpp | 17 +- ZEngine/ZEngine/Input/InputManager.cpp | 2 +- ZEngine/ZEngine/Logging/Logger.cpp | 2 +- ZEngine/ZEngine/Managers/AssetManager.cpp | 2 +- .../Rendering/RenderResourceManager.cpp | 12 +- .../Rendering/Renderers/Base/RenderPass.cpp | 8 +- .../Rendering/Renderers/GraphicRenderer.cpp | 40 ++-- .../Rendering/Renderers/RenderGraph.cpp | 12 +- .../ZEngine/Rendering/Renderers/ZUIPass.cpp | 4 +- .../Rendering/Shaders/ShaderReader.cpp | 6 +- ZEngine/ZEngine/UI/ZUIContext.cpp | 4 +- ZEngine/ZEngine/UI/ZUIDockSerial.cpp | 2 +- ZEngine/ZEngine/UI/ZUIDockspace.cpp | 4 +- ZEngine/ZEngine/UI/ZUIDrawList.cpp | 18 +- ZEngine/ZEngine/UI/ZUIFont.cpp | 16 +- ZEngine/ZEngine/UI/ZUIInteraction.cpp | 2 +- ZEngine/ZEngine/UI/ZUILayout.cpp | 4 +- ZEngine/ZEngine/UI/ZUIWidgets.cpp | 8 +- ZEngine/ZEngine/Windows/GameWindow.cpp | 4 +- ZEngine/ZEngine/Windows/Inputs/IDevice.h | 2 +- ZEngine/ZEngine/ZEngineDef.h | 177 ++++++++++++++---- ZEngine/tests/Memory/allocator_test.cpp | 12 +- .../tests/Rendering/MaterialSystemTest.cpp | 2 +- ZEngine/tests/Rendering/PSOCacheTest.cpp | 2 +- 48 files changed, 306 insertions(+), 213 deletions(-) diff --git a/Obelisk/EntryPoint.cpp b/Obelisk/EntryPoint.cpp index ce957004c..fd6cf6b69 100644 --- a/Obelisk/EntryPoint.cpp +++ b/Obelisk/EntryPoint.cpp @@ -56,7 +56,7 @@ int applicationEntryPoint(int argc, char* argv[]) if (launch_editor) { - app = ZPushStructCtor(arena, Tetragrama::Editor); + app = ZPushStructCtor(arena); app->EnableRenderOverlay = true; } diff --git a/Tetragrama/Controllers/EditorCameraController.cpp b/Tetragrama/Controllers/EditorCameraController.cpp index a2e4b2151..6d406fe38 100644 --- a/Tetragrama/Controllers/EditorCameraController.cpp +++ b/Tetragrama/Controllers/EditorCameraController.cpp @@ -123,7 +123,7 @@ namespace Tetragrama::Controllers settings.MinOrbitDistance = 0.5f; settings.MaxOrbitDistance = 10000.0f; - m_camera = ZPushStructCtorArgs(arena, FlyCamera, logicalW / logicalH, settings); + m_camera = ZPushStructCtorArgs(arena, std::source_location::current(), logicalW / logicalH, settings); m_camera->SetViewportSize(logicalW, logicalH); m_camera->Hooks.Context = app; diff --git a/Tetragrama/Editor.cpp b/Tetragrama/Editor.cpp index 3bed10d46..48e7ebe4b 100644 --- a/Tetragrama/Editor.cpp +++ b/Tetragrama/Editor.cpp @@ -28,7 +28,7 @@ namespace Tetragrama // Reserve the editor owner before creating configuration and workspace // state. EditorScene will later carve its 200 MiB local arena from here. Memory->CreateBudgetedArena(Memory->Budget.EditorContext, &EditorArena); - Configuration = ZPushStructCtor(&EditorArena, EditorConfiguration); + Configuration = ZPushStructCtor(&EditorArena); if (ZEngine::Helpers::secure_strlen(ConfigFile)) { @@ -61,26 +61,26 @@ namespace Tetragrama void Editor::OnInitialized() { - auto editor_scene = ZPushStructCtor(&EditorArena, EditorScene); - auto editor_cam_controller = ZPushStructCtor(&EditorArena, Controllers::EditorCameraController); - ZUIUILayer = ZPushStructCtor(&EditorArena, ZUILayer); + auto editor_scene = ZPushStructCtor(&EditorArena); + auto editor_cam_controller = ZPushStructCtor(&EditorArena); + ZUIUILayer = ZPushStructCtor(&EditorArena); ZUIUILayer->Initialize(&EditorArena, this); // Single panel-manager component replaces all old per-panel components. // It owns the dock tree, tab bars, and all panel views. - auto* pm = ZPushStructCtor(&EditorArena, Tetragrama::Panels::ZUIPanelManagerComponent); + auto* pm = ZPushStructCtor(&EditorArena); pm->Initialize(ZUIUILayer, "PanelManager"); ZUIUILayer->AddComponent(pm); // Editor shell: menu bar + floating overlays (settings, etc.) // Registered after PanelManager so it renders on top. - auto* shell = ZPushStructCtor(&EditorArena, Tetragrama::Components::ZUIDockspaceComponent); + auto* shell = ZPushStructCtor(&EditorArena); shell->Initialize(ZUIUILayer, "EditorShell"); shell->ShellPanelManager = &pm->Manager; ZUIUILayer->AddComponent(shell); - auto* sbar = ZPushStructCtor(&EditorArena, Tetragrama::Components::ZUIStatusBarComponent); + auto* sbar = ZPushStructCtor(&EditorArena); sbar->ShellPanelManager = &pm->Manager; sbar->Initialize(ZUIUILayer, "StatusBar"); ZUIUILayer->AddComponent(sbar); diff --git a/Tetragrama/Panels/AssetImporterPanel.cpp b/Tetragrama/Panels/AssetImporterPanel.cpp index bb21cf487..ffaf0c0f5 100644 --- a/Tetragrama/Panels/AssetImporterPanel.cpp +++ b/Tetragrama/Panels/AssetImporterPanel.cpp @@ -48,9 +48,9 @@ namespace Tetragrama::Panels import_arena->CreateSubArena(ZMega(64), &m_gltf_importer_arena, "ImportPipeline/EditorGltfImporter"); import_arena->CreateSubArena(ZMega(128), &m_assimp_importer_arena, "ImportPipeline/EditorAssimpImporter"); - m_gltf_importer = ZPushStructCtor(import_arena, ZEngine::Importers::GltfImporter); - m_fbx_importer = ZPushStructCtor(import_arena, ZEngine::Importers::FbxImporter); - m_assimp_importer = ZPushStructCtor(import_arena, ZEngine::Importers::AssimpImporter); + m_gltf_importer = ZPushStructCtor(import_arena); + m_fbx_importer = ZPushStructCtor(import_arena); + m_assimp_importer = ZPushStructCtor(import_arena); m_gltf_importer->Initialize(&m_gltf_importer_arena); m_fbx_importer->Initialize(import_arena); @@ -615,7 +615,7 @@ namespace Tetragrama::Panels m_local_arena.Clear(); - auto* config = ZPushStruct(&m_local_arena, ZEngine::Importers::AssetCodec::ImportConfiguration); + auto* config = ZPushStruct(&m_local_arena); const auto& cfg = *app->Configuration; config->OutputWorkingSpacePath.init(&m_local_arena, cfg.WorkingSpacePath.c_str()); config->OutputTextureFilesPath.init(&m_local_arena, cfg.TexturePath.c_str()); diff --git a/Tetragrama/Panels/HierarchyPanel.cpp b/Tetragrama/Panels/HierarchyPanel.cpp index c644d6bd8..0bdba1e3a 100644 --- a/Tetragrama/Panels/HierarchyPanel.cpp +++ b/Tetragrama/Panels/HierarchyPanel.cpp @@ -157,9 +157,9 @@ namespace Tetragrama::Panels EntityID EID; EntityID Parent; }; - OutlinerNode* nodes = ZPushArray(&ctx->FrameArena, OutlinerNode, cap); - uint32_t* first_child = ZPushArray(&ctx->FrameArena, uint32_t, cap); - uint32_t* next_sib = ZPushArray(&ctx->FrameArena, uint32_t, cap); + OutlinerNode* nodes = ZPushArray(&ctx->FrameArena, cap); + uint32_t* first_child = ZPushArray(&ctx->FrameArena, cap); + uint32_t* next_sib = ZPushArray(&ctx->FrameArena, cap); uint32_t node_count = 0; for (uint32_t i = 0; i < cap; ++i) @@ -196,7 +196,7 @@ namespace Tetragrama::Panels uint32_t idx; int depth; }; - DFSEntry* stk = ZPushArray(&ctx->FrameArena, DFSEntry, node_count * 2 + 2); + DFSEntry* stk = ZPushArray(&ctx->FrameArena, node_count * 2 + 2); int sp = 0; for (int i = (int) node_count - 1; i >= 0; --i) if (nodes[i].Parent == INVALID_ENTITY) diff --git a/Tetragrama/Panels/ProjectViewPanel.cpp b/Tetragrama/Panels/ProjectViewPanel.cpp index 385714200..d3abf0c9a 100644 --- a/Tetragrama/Panels/ProjectViewPanel.cpp +++ b/Tetragrama/Panels/ProjectViewPanel.cpp @@ -395,7 +395,7 @@ namespace Tetragrama::Panels int depth; }; static constexpr int kMaxStack = 512; - StackEntry* stk = ZPushArray(&ctx->FrameArena, StackEntry, kMaxStack); + StackEntry* stk = ZPushArray(&ctx->FrameArena, kMaxStack); int sp = 0; // Seed the stack with top-level directories (pushed in reverse for L-to-R order) diff --git a/ZEngine/ZEngine/Applications/AppRenderPipeline.cpp b/ZEngine/ZEngine/Applications/AppRenderPipeline.cpp index 866ad1e38..55dcc50e3 100644 --- a/ZEngine/ZEngine/Applications/AppRenderPipeline.cpp +++ b/ZEngine/ZEngine/Applications/AppRenderPipeline.cpp @@ -62,8 +62,8 @@ namespace ZEngine::Applications { Device = device; RenderWorkerThreadCount = Device->CommandBufferMgr->TotalThreadCount > 0u ? Device->CommandBufferMgr->TotalThreadCount - 1u : 0u; - SceneRenderer = ZPushStructCtor(Device->Arena, Rendering::Renderers::GraphicRenderer); - ZUIRenderPass = ZPushStructCtor(Device->Arena, Rendering::Renderers::ZUIPass); + SceneRenderer = ZPushStructCtor(Device->Arena); + ZUIRenderPass = ZPushStructCtor(Device->Arena); ZUIRenderPass->Initialize(Device); SceneRenderer->Initialize(Device); @@ -87,7 +87,7 @@ namespace ZEngine::Applications // UIContext arena: created by Engine::Initialize via MemoryBudgetConfig::Editor().UIContext // (128 MB budgeted, ~60 MB committed: FrameArena 32 MB · PersistentArena 1 MB · ZUIPayloadArenas 9 MB × 3) auto* ui_arena = &Engine::GetContext()->UIContextArena; - ZUICtx = ZPushStructCtor(ui_arena, ZEngine::UI::ZUIContext); + ZUICtx = ZPushStructCtor(ui_arena); ZEngine::UI::ZUIContextInit(ZUICtx, ui_arena, ZMega(32), ZMega(1), 8192, 8192); for (uint32_t i = 0; i < MaxOverlayBufferCount; ++i) { diff --git a/ZEngine/ZEngine/Applications/GameApplication.cpp b/ZEngine/ZEngine/Applications/GameApplication.cpp index 09e6fa1b0..5d554502c 100644 --- a/ZEngine/ZEngine/Applications/GameApplication.cpp +++ b/ZEngine/ZEngine/Applications/GameApplication.cpp @@ -12,7 +12,7 @@ namespace ZEngine::Applications { Memory = memory; - State = ZPushStructCtor(&Memory->BootstrapArena, ApplicationState); + State = ZPushStructCtor(&Memory->BootstrapArena); OnInitializing(); OverrideWindowConfiguration(); @@ -34,7 +34,7 @@ namespace ZEngine::Applications } } - RenderPipeline = ZPushStructCtor(&Memory->BootstrapArena, AppRenderPipeline); + RenderPipeline = ZPushStructCtor(&Memory->BootstrapArena); RenderPipeline->Initialize(Engine::GetContext()->Device); OnInitialized(); diff --git a/ZEngine/ZEngine/Core/Containers/Array.h b/ZEngine/ZEngine/Core/Containers/Array.h index e2a3c63aa..f4a7f42c4 100644 --- a/ZEngine/ZEngine/Core/Containers/Array.h +++ b/ZEngine/ZEngine/Core/Containers/Array.h @@ -284,7 +284,7 @@ namespace ZEngine::Core::Containers if (m_slab) m_data = static_cast(m_slab->Realloc(m_data, new_alloc_size)); else - m_data = static_cast(ZResize(m_allocator, m_data, old_alloc_size, new_alloc_size, ZAlignof(value_type))); + m_data = static_cast(ZResize(m_allocator, m_data, old_alloc_size, new_alloc_size, ZAlignof())); m_capacity = new_capacity; } @@ -339,4 +339,4 @@ namespace ZEngine::Core::Containers T* m_data; size_t m_size; }; -} // namespace ZEngine::Core::Containers \ No newline at end of file +} // namespace ZEngine::Core::Containers diff --git a/ZEngine/ZEngine/Core/Containers/InitializerList.h b/ZEngine/ZEngine/Core/Containers/InitializerList.h index c4b8a4862..8d3560638 100644 --- a/ZEngine/ZEngine/Core/Containers/InitializerList.h +++ b/ZEngine/ZEngine/Core/Containers/InitializerList.h @@ -69,7 +69,7 @@ namespace ZEngine::Core::Containers { size_t count = sizeof...(args) + 1; - T* buffer = static_cast(ZAlloc(allocator, count * sizeof(T), ZAlignof(T))); + T* buffer = static_cast(ZAlloc(allocator, count * sizeof(T), ZAlignof())); buffer[0] = first; @@ -79,4 +79,4 @@ namespace ZEngine::Core::Containers return InitializerList(buffer, count); } -} // namespace ZEngine::Core::Containers \ No newline at end of file +} // namespace ZEngine::Core::Containers diff --git a/ZEngine/ZEngine/Core/Containers/Strings.h b/ZEngine/ZEngine/Core/Containers/Strings.h index fadfb7742..7011e4039 100644 --- a/ZEngine/ZEngine/Core/Containers/Strings.h +++ b/ZEngine/ZEngine/Core/Containers/Strings.h @@ -205,7 +205,7 @@ namespace ZEngine::Core::Containers size_t old_alloc_size = m_capacity * sizeof(char); size_t new_alloc_size = new_capacity * sizeof(char); - m_data = static_cast(ZResize(m_allocator, m_data, old_alloc_size, new_alloc_size, ZAlignof(value_type))); + m_data = static_cast(ZResize(m_allocator, m_data, old_alloc_size, new_alloc_size, ZAlignof())); m_capacity = new_capacity; } @@ -285,4 +285,4 @@ namespace ZEngine::Core::Containers size_type m_size; }; -} // namespace ZEngine::Core::Containers \ No newline at end of file +} // namespace ZEngine::Core::Containers diff --git a/ZEngine/ZEngine/Core/VFS/Platform/VFSRDCWatcher.cpp b/ZEngine/ZEngine/Core/VFS/Platform/VFSRDCWatcher.cpp index 69fc450b2..10e4459b2 100644 --- a/ZEngine/ZEngine/Core/VFS/Platform/VFSRDCWatcher.cpp +++ b/ZEngine/ZEngine/Core/VFS/Platform/VFSRDCWatcher.cpp @@ -124,7 +124,7 @@ namespace ZEngine::Core::VFS std::lock_guard lock(m_watch_mutex); - void* storage = ZAlloc(m_arena, sizeof(WatchEntry), ZAlignof(WatchEntry)); + void* storage = ZAlloc(m_arena, sizeof(WatchEntry), ZAlignof()); if (!storage) { CloseHandle(dir); diff --git a/ZEngine/ZEngine/Core/VFS/Registry/DependencyGraph.cpp b/ZEngine/ZEngine/Core/VFS/Registry/DependencyGraph.cpp index 78a2f1c58..b65d79938 100644 --- a/ZEngine/ZEngine/Core/VFS/Registry/DependencyGraph.cpp +++ b/ZEngine/ZEngine/Core/VFS/Registry/DependencyGraph.cpp @@ -185,12 +185,12 @@ namespace ZEngine::Core::VFS // Inline open-addressing visited set backed by scratch arena. uint32_t visited_cap = 256; uint32_t visited_count = 0; - uuids::uuid* visited = ZPushArray(scratch, uuids::uuid, visited_cap); + uuids::uuid* visited = ZPushArray(scratch, visited_cap); std::memset(visited, 0, visited_cap * sizeof(uuids::uuid)); auto visited_rehash = [&]() { uint32_t new_cap = visited_cap * 2; - uuids::uuid* new_table = ZPushArray(scratch, uuids::uuid, new_cap); + uuids::uuid* new_table = ZPushArray(scratch, new_cap); std::memset(new_table, 0, new_cap * sizeof(uuids::uuid)); for (uint32_t i = 0; i < visited_cap; ++i) { diff --git a/ZEngine/ZEngine/Core/VFS/VFSContext.cpp b/ZEngine/ZEngine/Core/VFS/VFSContext.cpp index f694c4c63..480906aad 100644 --- a/ZEngine/ZEngine/Core/VFS/VFSContext.cpp +++ b/ZEngine/ZEngine/Core/VFS/VFSContext.cpp @@ -47,7 +47,7 @@ namespace ZEngine::Core::VFS #if defined(__APPLE__) { - void* storage = ZAlloc(m_arena, sizeof(VFSFSEventsWatcher), ZAlignof(VFSFSEventsWatcher)); + void* storage = ZAlloc(m_arena, sizeof(VFSFSEventsWatcher), ZAlignof()); if (!storage) { ZENGINE_LOG_VFS_ERR("InitWatcher: arena allocation failed for VFSFSEventsWatcher"); @@ -65,7 +65,7 @@ namespace ZEngine::Core::VFS } #elif defined(__linux__) { - void* storage = ZAlloc(m_arena, sizeof(VFSInotifyWatcher), ZAlignof(VFSInotifyWatcher)); + void* storage = ZAlloc(m_arena, sizeof(VFSInotifyWatcher), ZAlignof()); if (!storage) { ZENGINE_LOG_VFS_ERR("InitWatcher: arena allocation failed for VFSInotifyWatcher"); @@ -83,7 +83,7 @@ namespace ZEngine::Core::VFS } #elif defined(_WIN32) { - void* storage = ZAlloc(m_arena, sizeof(VFSRDCWatcher), ZAlignof(VFSRDCWatcher)); + void* storage = ZAlloc(m_arena, sizeof(VFSRDCWatcher), ZAlignof()); if (!storage) { ZENGINE_LOG_VFS_ERR("InitWatcher: arena allocation failed for VFSRDCWatcher"); @@ -104,7 +104,7 @@ namespace ZEngine::Core::VFS return; #endif - void* fw_storage = ZAlloc(m_arena, sizeof(VFSFileWatcher), ZAlignof(VFSFileWatcher)); + void* fw_storage = ZAlloc(m_arena, sizeof(VFSFileWatcher), ZAlignof()); if (!fw_storage) { ZENGINE_LOG_VFS_ERR("InitWatcher: arena allocation failed for VFSFileWatcher"); diff --git a/ZEngine/ZEngine/Core/VFS/VFSDiskBackend.cpp b/ZEngine/ZEngine/Core/VFS/VFSDiskBackend.cpp index 42c3d3ece..2fffbe8e4 100644 --- a/ZEngine/ZEngine/Core/VFS/VFSDiskBackend.cpp +++ b/ZEngine/ZEngine/Core/VFS/VFSDiskBackend.cpp @@ -309,7 +309,7 @@ namespace ZEngine::Core::VFS { return VFSResult::Fail(VFSError::OutOfMemory); } - VFSDiskFile* file = ZConstruct(mem, VFSDiskFile); + VFSDiskFile* file = ZConstruct(mem); file->Owner = this; file->m_path = relative_path; file->m_writable = wants_write; diff --git a/ZEngine/ZEngine/Core/VFS/VFSMemoryBackend.cpp b/ZEngine/ZEngine/Core/VFS/VFSMemoryBackend.cpp index 8e7588030..5a34b1a2c 100644 --- a/ZEngine/ZEngine/Core/VFS/VFSMemoryBackend.cpp +++ b/ZEngine/ZEngine/Core/VFS/VFSMemoryBackend.cpp @@ -184,7 +184,7 @@ namespace ZEngine::Core::VFS MemNode* VFSMemoryBackend::CreateNode(const VFSPath& path, MemNode::Kind kind) { - MemNode* node = ZPushStructCtor(m_arena, MemNode); + MemNode* node = ZPushStructCtor(m_arena); node->NodeKind = kind; node->Path = path; m_nodes.insert(node->Path.CStr(), node); @@ -199,7 +199,7 @@ namespace ZEngine::Core::VFS { return nullptr; } - return ZConstruct(mem, VFSMemoryFile); + return ZConstruct(mem); } void VFSMemoryBackend::FreeFile(IVFSFile* file) diff --git a/ZEngine/ZEngine/Core/VFS/VFSZipBackend.cpp b/ZEngine/ZEngine/Core/VFS/VFSZipBackend.cpp index fa7b47116..45026b918 100644 --- a/ZEngine/ZEngine/Core/VFS/VFSZipBackend.cpp +++ b/ZEngine/ZEngine/Core/VFS/VFSZipBackend.cpp @@ -302,7 +302,7 @@ namespace ZEngine::Core::VFS { return VFSResult::Fail(VFSError::OutOfMemory); } - VFSZipFile* file = ZConstruct(mem, VFSZipFile); + VFSZipFile* file = ZConstruct(mem); file->Owner = this; file->m_entry = entry; file->m_backend = this; diff --git a/ZEngine/ZEngine/ECS/Actor.h b/ZEngine/ZEngine/ECS/Actor.h index a1d5e4435..ea95293be 100644 --- a/ZEngine/ZEngine/ECS/Actor.h +++ b/ZEngine/ZEngine/ECS/Actor.h @@ -1,6 +1,7 @@ #pragma once #include #include +#include namespace ZEngine::ECS { @@ -9,6 +10,7 @@ namespace ZEngine::ECS class Actor { public: + Actor() = default; virtual ~Actor() = default; [[nodiscard]] EntityID GetEntityID() const @@ -67,9 +69,6 @@ namespace ZEngine::ECS virtual void OnDestroy() {} virtual void OnTick(float dt) {} - protected: - Actor() = default; - private: friend class ActorManager; diff --git a/ZEngine/ZEngine/ECS/ActorManager.cpp b/ZEngine/ZEngine/ECS/ActorManager.cpp index e1dfa76d8..2614e3f4e 100644 --- a/ZEngine/ZEngine/ECS/ActorManager.cpp +++ b/ZEngine/ZEngine/ECS/ActorManager.cpp @@ -85,7 +85,7 @@ namespace ZEngine::ECS ActorHandle ActorManager::CreateWithExistingEntityID(EntityID id) { ZENGINE_VALIDATE_ASSERT(m_arena != nullptr, "ActorManager::CreateWithExistingEntityID: not initialized") - Actor* actor = ZPushStructCtor(m_arena, Actor); + Actor* actor = ZPushStructCtor(m_arena); actor->m_entity_id = id; actor->m_scene = m_scene; AssertUniqueEntityID(actor->m_entity_id); diff --git a/ZEngine/ZEngine/ECS/ActorManager.h b/ZEngine/ZEngine/ECS/ActorManager.h index 210f4a643..5e1bc19af 100644 --- a/ZEngine/ZEngine/ECS/ActorManager.h +++ b/ZEngine/ZEngine/ECS/ActorManager.h @@ -28,7 +28,7 @@ namespace ZEngine::ECS ZENGINE_VALIDATE_ASSERT(m_arena != nullptr, "ActorManager::Create: not initialized") - T* actor = ZPushStructCtor(m_arena, T); + T* actor = ZPushStructCtor(m_arena); actor->m_entity_id = m_scene->CreateEntity(); actor->m_scene = m_scene; diff --git a/ZEngine/ZEngine/ECS/Scene.h b/ZEngine/ZEngine/ECS/Scene.h index b1ad70b05..fb258bbb3 100644 --- a/ZEngine/ZEngine/ECS/Scene.h +++ b/ZEngine/ZEngine/ECS/Scene.h @@ -121,7 +121,7 @@ namespace ZEngine::ECS return *static_cast*>(*existing); // Arena-allocate the storage object - auto* storage = ZPushStructCtor(m_arena, ComponentStorage); + auto* storage = ZPushStructCtor>(m_arena); storage->Initialize(m_arena, EntityRegistry::MAX_ENTITIES); auto* iface = static_cast(storage); m_storages.insert(type_id, iface); diff --git a/ZEngine/ZEngine/Engine.cpp b/ZEngine/ZEngine/Engine.cpp index 07c71204b..a016b7e6a 100644 --- a/ZEngine/ZEngine/Engine.cpp +++ b/ZEngine/ZEngine/Engine.cpp @@ -121,9 +121,9 @@ namespace ZEngine auto& arena = memory->BootstrapArena; - g_engine_ctx = ZPushStructCtor(&arena, EngineContext); + g_engine_ctx = ZPushStructCtor(&arena); - auto window = ZPushStructCtor(&arena, Windows::GameWindow); + auto window = ZPushStructCtor(&arena); window->SetCallbackFunction(std::bind(&Applications::GameApplication::ProcessEvent, app, std::placeholders::_1)); window->Initialize(&arena, *window_cfg_ptr); g_engine_ctx->Window = window; @@ -132,12 +132,12 @@ namespace ZEngine // swapchain state) must consume the declared VulkanDevice budget rather // than silently taking unbounded capacity from the bootstrap owner. memory->CreateBudgetedArena(memory->Budget.VulkanDevice, &g_engine_ctx->VulkanDeviceArena); - g_engine_ctx->Device = ZPushStructCtor(&g_engine_ctx->VulkanDeviceArena, Hardwares::VulkanDevice); + g_engine_ctx->Device = ZPushStructCtor(&g_engine_ctx->VulkanDeviceArena); uint32_t worker_thread_count = std::max(1u, (uint32_t) (Helpers::ThreadPoolHelper::Pool->MaxThreadCount / 2u)); g_engine_ctx->Device->Initialize(&g_engine_ctx->VulkanDeviceArena, window, worker_thread_count); memory->CreateBudgetedArena(memory->Budget.VirtualFS, &g_engine_ctx->VFSArena); - auto vfs_ctx = ZPushStructCtor(&g_engine_ctx->VFSArena, Core::VFS::VFSContext); + auto vfs_ctx = ZPushStructCtor(&g_engine_ctx->VFSArena); vfs_ctx->Initialize(&g_engine_ctx->VFSArena); g_engine_ctx->VFS = vfs_ctx; @@ -176,17 +176,17 @@ namespace ZEngine Managers::AssetManager::Initialize(&g_engine_ctx->AssetArena, g_engine_ctx->Device, app->WorkingSpacePath); memory->CreateBudgetedArena(memory->Budget.Input, &g_engine_ctx->InputArena); - g_engine_ctx->InputManager = ZPushStructCtor(&arena, Input::InputManager); + g_engine_ctx->InputManager = ZPushStructCtor(&arena); g_engine_ctx->InputManager->Initialize(&g_engine_ctx->InputArena); memory->CreateBudgetedArena(memory->Budget.ECSScene, &g_engine_ctx->ECSArena); - g_engine_ctx->Scene = ZPushStructCtor(&g_engine_ctx->ECSArena, ECS::Scene); + g_engine_ctx->Scene = ZPushStructCtor(&g_engine_ctx->ECSArena); g_engine_ctx->Scene->Initialize(&g_engine_ctx->ECSArena); - g_engine_ctx->ActorManager = ZPushStructCtor(&g_engine_ctx->ECSArena, ECS::ActorManager); + g_engine_ctx->ActorManager = ZPushStructCtor(&g_engine_ctx->ECSArena); g_engine_ctx->ActorManager->Initialize(&g_engine_ctx->ECSArena, *g_engine_ctx->Scene); - g_engine_ctx->WorldCommands = ZPushStructCtor(&g_engine_ctx->ECSArena, ECS::WorldCommands); + g_engine_ctx->WorldCommands = ZPushStructCtor(&g_engine_ctx->ECSArena); g_engine_ctx->WorldCommands->Initialize(&g_engine_ctx->ECSArena); - g_engine_ctx->WorldTick = ZPushStructCtor(&g_engine_ctx->ECSArena, ECS::WorldTick); + g_engine_ctx->WorldTick = ZPushStructCtor(&g_engine_ctx->ECSArena); g_engine_ctx->WorldTick->Initialize(&g_engine_ctx->ECSArena); ECS::ComponentReflectionRegistry::Get().Initialize(&g_engine_ctx->ECSArena); @@ -201,7 +201,7 @@ namespace ZEngine memory->CreateBudgetedArena(memory->Budget.EditorSceneLoadA, &g_engine_ctx->EditorSceneLoadArenaA); if (memory->Budget.EditorSceneLoadB.SizeBytes > 0) memory->CreateBudgetedArena(memory->Budget.EditorSceneLoadB, &g_engine_ctx->EditorSceneLoadArenaB); - g_engine_ctx->ImportCoordinator = ZPushStructCtor(&g_engine_ctx->AssetArena, Importers::ImportCoordinator); + g_engine_ctx->ImportCoordinator = ZPushStructCtor(&g_engine_ctx->AssetArena); g_engine_ctx->ImportCoordinator->Initialize(&g_engine_ctx->AssetArena, g_engine_ctx->VFS, Managers::AssetManager::Instance()->Registry); g_engine_ctx->GltfImporter.Initialize(&g_engine_ctx->ImportPipelineArena); @@ -223,7 +223,7 @@ namespace ZEngine g_engine_ctx->Device->EnvironmentLightingMemoryBudget = ReadEnvironmentLightingMemoryBudget(app->ConfigFile); // RenderResourceManager — GPU lifetime authority, bridges asset layer and VulkanDevice - g_engine_ctx->RenderResourceManager = ZPushStructCtor(&g_engine_ctx->AssetArena, Rendering::RenderResourceManager); + g_engine_ctx->RenderResourceManager = ZPushStructCtor(&g_engine_ctx->AssetArena); g_engine_ctx->RenderResourceManager->Initialize(g_engine_ctx->Device, Managers::AssetManager::Instance()->Registry, &g_engine_ctx->ImportPipelineArena); g_engine_ctx->Device->RRM = g_engine_ctx->RenderResourceManager; diff --git a/ZEngine/ZEngine/Hardwares/CommandBufferManager.cpp b/ZEngine/ZEngine/Hardwares/CommandBufferManager.cpp index bf5123ebd..280f35359 100644 --- a/ZEngine/ZEngine/Hardwares/CommandBufferManager.cpp +++ b/ZEngine/ZEngine/Hardwares/CommandBufferManager.cpp @@ -45,23 +45,23 @@ namespace ZEngine::Hardwares for (uint32_t i = 0; i < TotalPoolCount; ++i) { - InstantGraphicsPools[i] = ZPushStructCtorArgs(Device->Arena, Rendering::Pools::CommandPool, Device, QueueType::GRAPHIC_QUEUE); + InstantGraphicsPools[i] = ZPushStructCtorArgs(Device->Arena, std::source_location::current(), Device, QueueType::GRAPHIC_QUEUE); for (uint32_t buf_idx = 0; buf_idx < (MaxBufferPerPool * MaxBufferPerPool); ++buf_idx) { uint32_t buffer_idx = (i * (MaxBufferPerPool * MaxBufferPerPool)) + buf_idx; - InstantGraphicsCommandBuffers[buffer_idx] = ZPushStructCtorArgs(Device->Arena, CommandBuffer, Device, InstantGraphicsPools[i]->Handle, InstantGraphicsPools[i]->QueueType, true); + InstantGraphicsCommandBuffers[buffer_idx] = ZPushStructCtorArgs(Device->Arena, std::source_location::current(), Device, InstantGraphicsPools[i]->Handle, InstantGraphicsPools[i]->QueueType, true); } } for (uint32_t i = 0; i < TotalPoolCount; ++i) { - CommandPools[i] = ZPushStructCtorArgs(Device->Arena, Rendering::Pools::CommandPool, Device, QueueType::GRAPHIC_QUEUE); + CommandPools[i] = ZPushStructCtorArgs(Device->Arena, std::source_location::current(), Device, QueueType::GRAPHIC_QUEUE); for (uint32_t buf_idx = 0; buf_idx < MaxBufferPerPool; ++buf_idx) { uint32_t buffer_idx = (i * MaxBufferPerPool) + buf_idx; bool is_primary = (buffer_idx % 2) == 0; - CommandBuffers[buffer_idx] = ZPushStructCtorArgs(Device->Arena, CommandBuffer, Device, CommandPools[i]->Handle, CommandPools[i]->QueueType, is_primary); + CommandBuffers[buffer_idx] = ZPushStructCtorArgs(Device->Arena, std::source_location::current(), Device, CommandPools[i]->Handle, CommandPools[i]->QueueType, is_primary); } } @@ -79,7 +79,7 @@ namespace ZEngine::Hardwares for (uint32_t i = 0; i < TotalPoolCount; ++i) { auto& worker_pool = WorkerSecondaryGraphics[i]; - worker_pool.Pool = ZPushStructCtorArgs(Device->Arena, Rendering::Pools::CommandPool, Device, QueueType::GRAPHIC_QUEUE); + worker_pool.Pool = ZPushStructCtorArgs(Device->Arena, std::source_location::current(), Device, QueueType::GRAPHIC_QUEUE); worker_pool.Buffers.init(&m_render_graph_command_buffer_arena, 4); } @@ -92,20 +92,20 @@ namespace ZEngine::Hardwares for (uint32_t i = 0; i < TotalPoolCount; ++i) { - InstantTransferPools[i] = ZPushStructCtorArgs(Device->Arena, Rendering::Pools::CommandPool, Device, Rendering::QueueType::TRANSFER_QUEUE); + InstantTransferPools[i] = ZPushStructCtorArgs(Device->Arena, std::source_location::current(), Device, Rendering::QueueType::TRANSFER_QUEUE); for (uint32_t buf_idx = 0; buf_idx < (MaxBufferPerPool * MaxBufferPerPool); ++buf_idx) { uint32_t buffer_idx = (i * (MaxBufferPerPool * MaxBufferPerPool)) + buf_idx; - InstantTransferCommandBuffers[buffer_idx] = ZPushStructCtorArgs(Device->Arena, CommandBuffer, Device, InstantTransferPools[i]->Handle, InstantTransferPools[i]->QueueType, true); + InstantTransferCommandBuffers[buffer_idx] = ZPushStructCtorArgs(Device->Arena, std::source_location::current(), Device, InstantTransferPools[i]->Handle, InstantTransferPools[i]->QueueType, true); } } for (uint32_t i = 0; i < TotalPoolCount; ++i) { - TransferCommandPools[i] = ZPushStructCtorArgs(Device->Arena, Rendering::Pools::CommandPool, Device, Rendering::QueueType::TRANSFER_QUEUE); + TransferCommandPools[i] = ZPushStructCtorArgs(Device->Arena, std::source_location::current(), Device, Rendering::QueueType::TRANSFER_QUEUE); for (uint32_t buf_idx = 0; buf_idx < MaxBufferPerPool; ++buf_idx) { uint32_t buffer_idx = (i * MaxBufferPerPool) + buf_idx; - TransferCommandBuffers[buffer_idx] = ZPushStructCtorArgs(Device->Arena, CommandBuffer, Device, TransferCommandPools[i]->Handle, TransferCommandPools[i]->QueueType, true); + TransferCommandBuffers[buffer_idx] = ZPushStructCtorArgs(Device->Arena, std::source_location::current(), Device, TransferCommandPools[i]->Handle, TransferCommandPools[i]->QueueType, true); } } GraphTransferCommandBuffers.init(Device->Arena, TotalGraphCommandBufferCount, TotalGraphCommandBufferCount); @@ -117,7 +117,7 @@ namespace ZEngine::Hardwares for (uint32_t i = 0; i < TotalPoolCount; ++i) { auto& worker_pool = WorkerSecondaryTransfers[i]; - worker_pool.Pool = ZPushStructCtorArgs(Device->Arena, Rendering::Pools::CommandPool, Device, QueueType::TRANSFER_QUEUE); + worker_pool.Pool = ZPushStructCtorArgs(Device->Arena, std::source_location::current(), Device, QueueType::TRANSFER_QUEUE); worker_pool.Buffers.init(&m_render_graph_command_buffer_arena, 4); } } @@ -131,18 +131,18 @@ namespace ZEngine::Hardwares for (uint32_t i = 0; i < TotalPoolCount; ++i) { - InstantComputePools[i] = ZPushStructCtorArgs(Device->Arena, Rendering::Pools::CommandPool, Device, Rendering::QueueType::COMPUTE_QUEUE); + InstantComputePools[i] = ZPushStructCtorArgs(Device->Arena, std::source_location::current(), Device, Rendering::QueueType::COMPUTE_QUEUE); for (uint32_t buf_idx = 0; buf_idx < (MaxBufferPerPool * MaxBufferPerPool); ++buf_idx) { uint32_t buffer_idx = (i * (MaxBufferPerPool * MaxBufferPerPool)) + buf_idx; - InstantComputeCommandBuffers[buffer_idx] = ZPushStructCtorArgs(Device->Arena, CommandBuffer, Device, InstantComputePools[i]->Handle, InstantComputePools[i]->QueueType, true); + InstantComputeCommandBuffers[buffer_idx] = ZPushStructCtorArgs(Device->Arena, std::source_location::current(), Device, InstantComputePools[i]->Handle, InstantComputePools[i]->QueueType, true); } - ComputeCommandPools[i] = ZPushStructCtorArgs(Device->Arena, Rendering::Pools::CommandPool, Device, Rendering::QueueType::COMPUTE_QUEUE); + ComputeCommandPools[i] = ZPushStructCtorArgs(Device->Arena, std::source_location::current(), Device, Rendering::QueueType::COMPUTE_QUEUE); for (uint32_t buf_idx = 0; buf_idx < MaxBufferPerPool; ++buf_idx) { uint32_t buffer_idx = (i * MaxBufferPerPool) + buf_idx; - ComputeCommandBuffers[buffer_idx] = ZPushStructCtorArgs(Device->Arena, CommandBuffer, Device, ComputeCommandPools[i]->Handle, ComputeCommandPools[i]->QueueType, true); + ComputeCommandBuffers[buffer_idx] = ZPushStructCtorArgs(Device->Arena, std::source_location::current(), Device, ComputeCommandPools[i]->Handle, ComputeCommandPools[i]->QueueType, true); } } GraphComputeCommandBuffers.init(Device->Arena, TotalGraphCommandBufferCount, TotalGraphCommandBufferCount); @@ -154,7 +154,7 @@ namespace ZEngine::Hardwares for (uint32_t i = 0; i < TotalPoolCount; ++i) { auto& worker_pool = WorkerSecondaryComputes[i]; - worker_pool.Pool = ZPushStructCtorArgs(Device->Arena, Rendering::Pools::CommandPool, Device, QueueType::COMPUTE_QUEUE); + worker_pool.Pool = ZPushStructCtorArgs(Device->Arena, std::source_location::current(), Device, QueueType::COMPUTE_QUEUE); worker_pool.Buffers.init(&m_render_graph_command_buffer_arena, 4); } } @@ -269,7 +269,7 @@ namespace ZEngine::Hardwares } if (!*slot) - *slot = ZPushStructCtorArgs(&m_render_graph_command_buffer_arena, CommandBuffer, Device, command_pool, resolved_type, true, &m_render_graph_command_buffer_arena); + *slot = ZPushStructCtorArgs(&m_render_graph_command_buffer_arena, std::source_location::current(), Device, command_pool, resolved_type, true, &m_render_graph_command_buffer_arena); CommandBuffer* buffer = *slot; if (begin) { @@ -302,7 +302,7 @@ namespace ZEngine::Hardwares WorkerSecondaryPool& pool = ResolveWorkerSecondaryPool(this, type, frame_index * TotalThreadCount + worker_index); while (pool.Buffers.size() < count) { - CommandBuffer* buffer = ZPushStructCtorArgs(&m_render_graph_command_buffer_arena, CommandBuffer, Device, pool.Pool->Handle, pool.Pool->QueueType, false, &m_render_graph_command_buffer_arena); + CommandBuffer* buffer = ZPushStructCtorArgs(&m_render_graph_command_buffer_arena, std::source_location::current(), Device, pool.Pool->Handle, pool.Pool->QueueType, false, &m_render_graph_command_buffer_arena); pool.Buffers.push(buffer); } } diff --git a/ZEngine/ZEngine/Hardwares/DeviceSwapchain.cpp b/ZEngine/ZEngine/Hardwares/DeviceSwapchain.cpp index a939b60a2..9a8c3d1d6 100644 --- a/ZEngine/ZEngine/Hardwares/DeviceSwapchain.cpp +++ b/ZEngine/ZEngine/Hardwares/DeviceSwapchain.cpp @@ -23,7 +23,7 @@ namespace ZEngine::Hardwares BufferredFrameCount = buffered_frame_size; FrameContextPoolSize = BufferredFrameCount * FrameContextPoolSizeFactor; - RenderTimeline = ZPushStructCtorArgs(&Arena, Primitives::Semaphore, Device, true); + RenderTimeline = ZPushStructCtorArgs(&Arena, std::source_location::current(), Device, true); Specifications::AttachmentSpecification attachment_specification = {.BindPoint = Specifications::PipelineBindPoint::GRAPHIC}; attachment_specification.ColorsMap.init(&Arena, 2); @@ -34,7 +34,7 @@ namespace ZEngine::Hardwares attachment_specification.ColorsMap[0].Initial = ImageLayout::UNDEFINED; attachment_specification.ColorsMap[0].Final = ImageLayout::PRESENT_SRC; attachment_specification.ColorsMap[0].ReferenceLayout = ImageLayout::COLOR_ATTACHMENT_OPTIMAL; - SwapchainAttachment = ZPushStructCtorArgs(&Arena, RenderPasses::Attachment, Device, std::move(attachment_specification)); + SwapchainAttachment = ZPushStructCtorArgs(&Arena, std::source_location::current(), Device, std::move(attachment_specification)); IdleFrameThreshold = (BufferredFrameCount * 3 * 3 * 3); FrameContexts.init(&Arena, FrameContextPoolSize, FrameContextPoolSize); @@ -46,8 +46,8 @@ namespace ZEngine::Hardwares auto& frame = FrameContexts[i]; frame.Index = (i % BufferredFrameCount); - frame.Acquired = ZPushStructCtorArgs(&Arena, Primitives::Semaphore, Device); - frame.Fence = ZPushStructCtorArgs(&Arena, Primitives::Fence, Device, true); + frame.Acquired = ZPushStructCtorArgs(&Arena, std::source_location::current(), Device); + frame.Fence = ZPushStructCtorArgs(&Arena, std::source_location::current(), Device, true); } Create(); @@ -165,7 +165,7 @@ namespace ZEngine::Hardwares for (uint32_t i = 0; i < SwapchainImageCount; ++i) { ImageInFlights.push(nullptr); - RenderCompletes.push(ZPushStructCtorArgs(&Arena, Primitives::Semaphore, Device)); + RenderCompletes.push(ZPushStructCtorArgs(&Arena, std::source_location::current(), Device)); } } diff --git a/ZEngine/ZEngine/Hardwares/VulkanDevice.cpp b/ZEngine/ZEngine/Hardwares/VulkanDevice.cpp index e8f33d601..9f41d73c6 100644 --- a/ZEngine/ZEngine/Hardwares/VulkanDevice.cpp +++ b/ZEngine/ZEngine/Hardwares/VulkanDevice.cpp @@ -12,7 +12,6 @@ #include #include #include -#include #include using namespace std::chrono_literals; @@ -41,7 +40,7 @@ namespace ZEngine::Hardwares void AsyncGPUOperation::Initialize(VulkanDevice* device, uint32_t total_buffer_count) { NextValue = 0; - Timeline = ZPushStructCtorArgs(device->Arena, Semaphore, device, true); + Timeline = ZPushStructCtorArgs(device->Arena, std::source_location::current(), device, true); RetireValues.init(device->Arena, total_buffer_count, total_buffer_count); } @@ -53,8 +52,8 @@ namespace ZEngine::Hardwares BindlessTextureSlotRequests.init(Arena, 64); ShaderReservedBindingSets.init(Arena, 4); ShaderReservedBindingSets.insert(1); - CommandBufferMgr = ZPushStructCtor(Arena, CommandBufferManager); - SwapchainPtr = ZPushStructCtor(Arena, DeviceSwapchain); + CommandBufferMgr = ZPushStructCtor(Arena); + SwapchainPtr = ZPushStructCtor(Arena); DefaultDepthFormats.init(Arena, 3); DefaultDepthFormats.push(VK_FORMAT_D32_SFLOAT); @@ -239,13 +238,13 @@ namespace ZEngine::Hardwares if (result == VK_ERROR_INCOMPATIBLE_DRIVER) { ZENGINE_CORE_CRITICAL("Failed to create Vulkan Instance. Incompatible driver") - ZENGINE_EXIT_FAILURE() + ZENGINE_EXIT_FAILURE(); } if (result == VK_INCOMPLETE) { ZENGINE_CORE_CRITICAL("Failed to create Vulkan Instance. Confugration incomplete!") - ZENGINE_EXIT_FAILURE() + ZENGINE_EXIT_FAILURE(); } /*Create Message Callback*/ @@ -811,7 +810,7 @@ namespace ZEngine::Hardwares FrameHeaps[i].Initialize(&GpuMem, name); } - PipelineStateCache = ZPushStructCtor(Arena, Rendering::Renderers::Pipelines::PSOCache); + PipelineStateCache = ZPushStructCtor(Arena); PipelineStateCache->Initialize(this); /* @@ -3048,11 +3047,11 @@ namespace ZEngine::Hardwares { if (spec.Type == Rendering::Specifications::RenderPassType::COMPUTE) { - auto pass = ZPushStructCtorArgs(Arena, Rendering::Renderers::RenderPasses::ComputePass); + auto pass = ZPushStructCtor(Arena); pass->Initialize(this, std::move(spec)); return pass; } - auto pass = ZPushStructCtorArgs(Arena, Rendering::Renderers::RenderPasses::GraphicPass); + auto pass = ZPushStructCtor(Arena); pass->Initialize(this, std::move(spec)); return pass; } diff --git a/ZEngine/ZEngine/Input/InputManager.cpp b/ZEngine/ZEngine/Input/InputManager.cpp index a28036499..7f819777b 100644 --- a/ZEngine/ZEngine/Input/InputManager.cpp +++ b/ZEngine/ZEngine/Input/InputManager.cpp @@ -24,7 +24,7 @@ namespace ZEngine::Input m_max_actions = max_actions; m_action_count = 0; - m_actions = ZPushArray(arena, InputAction, max_actions); + m_actions = ZPushArray(arena, max_actions); memset(m_actions, 0, sizeof(InputAction) * max_actions); memset(m_scroll_scale, 0, sizeof(m_scroll_scale)); m_current = {}; diff --git a/ZEngine/ZEngine/Logging/Logger.cpp b/ZEngine/ZEngine/Logging/Logger.cpp index c41ec1f5b..d47b13a89 100644 --- a/ZEngine/ZEngine/Logging/Logger.cpp +++ b/ZEngine/ZEngine/Logging/Logger.cpp @@ -74,7 +74,7 @@ namespace ZEngine::Logging if (!dir_created) { ZENGINE_CORE_CRITICAL("Failed to create log directory at : {}", log_directory_path.string()) - ZENGINE_EXIT_FAILURE() + ZENGINE_EXIT_FAILURE(); } } diff --git a/ZEngine/ZEngine/Managers/AssetManager.cpp b/ZEngine/ZEngine/Managers/AssetManager.cpp index b0c176a83..a17ff5abc 100644 --- a/ZEngine/ZEngine/Managers/AssetManager.cpp +++ b/ZEngine/ZEngine/Managers/AssetManager.cpp @@ -37,7 +37,7 @@ namespace ZEngine::Managers void AssetManager::Initialize(Core::Memory::ArenaAllocator* arena, Hardwares::VulkanDevice* device, cstring working_space_path) { - s_Instance = ZPushStructCtor(arena, AssetManager); + s_Instance = ZPushStructCtor(arena); s_Instance->Arena = arena; s_Instance->Device = device; diff --git a/ZEngine/ZEngine/Rendering/RenderResourceManager.cpp b/ZEngine/ZEngine/Rendering/RenderResourceManager.cpp index 103900f06..f685f5007 100644 --- a/ZEngine/ZEngine/Rendering/RenderResourceManager.cpp +++ b/ZEngine/ZEngine/Rendering/RenderResourceManager.cpp @@ -234,10 +234,10 @@ namespace ZEngine::Rendering { // Pre-signaled so the first Wait() before a submit returns immediately. uint32_t frame_count = m_device->SwapchainPtr->BufferredFrameCount; - m_sync_upload_fence = ZPushStructCtorArgs(m_device->Arena, Rendering::Primitives::Fence, m_device, true); + m_sync_upload_fence = ZPushStructCtorArgs(m_device->Arena, std::source_location::current(), m_device, true); // LastSignal == 0 means "never used yet" for a given frame index. - m_batch_timeline = ZPushStructCtorArgs(m_device->Arena, Rendering::Primitives::Semaphore, m_device, true); + m_batch_timeline = ZPushStructCtorArgs(m_device->Arena, std::source_location::current(), m_device, true); m_batch_frames.init(m_device->Arena, frame_count, frame_count); for (uint32_t i = 0; i < frame_count; ++i) m_batch_frames[i] = BatchFrameState{}; @@ -246,7 +246,7 @@ namespace ZEngine::Rendering // command buffers instead of resetting and resubmitting the same one every call (see // issue #764 follow-up: reusing a single command buffer across many upload cycles was // suspected as a factor in an otherwise-unexplained GPU stall). - m_upload_cmd_mgr = ZPushStructCtor(m_device->Arena, CommandBufferManager); + m_upload_cmd_mgr = ZPushStructCtor(m_device->Arena); m_upload_cmd_mgr->Initialize(m_device, m_device->SwapchainPtr->BufferredFrameCount, 1); m_async_uploads.Initialize(m_device); @@ -1167,7 +1167,7 @@ namespace ZEngine::Rendering for (uint32_t i = 0; i < total_pool_count; ++i) { - m_tex_timelines[i] = ZPushStructCtorArgs(m_device->Arena, Rendering::Primitives::Semaphore, m_device, true); + m_tex_timelines[i] = ZPushStructCtorArgs(m_device->Arena, std::source_location::current(), m_device, true); m_tex_retire_values[i].init(m_device->Arena, m_tex_total_cmd_count, m_tex_total_cmd_count); m_tex_retire_staging[i].init(m_device->Arena, m_tex_total_cmd_count, m_tex_total_cmd_count); m_tex_next_values[i].store(1, std::memory_order_release); @@ -1182,7 +1182,7 @@ namespace ZEngine::Rendering for (uint32_t i = 0; i < total_pool_count; ++i) { - m_tex_transfer_timelines[i] = ZPushStructCtorArgs(m_device->Arena, Rendering::Primitives::Semaphore, m_device, true); + m_tex_transfer_timelines[i] = ZPushStructCtorArgs(m_device->Arena, std::source_location::current(), m_device, true); m_tex_transfer_retire[i].init(m_device->Arena, m_tex_total_cmd_count, m_tex_total_cmd_count); m_tex_transfer_staging[i].init(m_device->Arena, m_tex_total_cmd_count, m_tex_total_cmd_count); m_tex_transfer_next_values[i].store(1, std::memory_order_release); @@ -1905,7 +1905,7 @@ namespace ZEngine::Rendering } auto* task = static_cast(m_texture_task_slab.Alloc(sizeof(TextureDecodeTask))); - ZConstruct(task, TextureDecodeTask); + ZConstruct(task); task->Owner = this; task->Specification = spec; task->Texture = tex_handle; diff --git a/ZEngine/ZEngine/Rendering/Renderers/Base/RenderPass.cpp b/ZEngine/ZEngine/Rendering/Renderers/Base/RenderPass.cpp index 82227f8f3..da3a54099 100644 --- a/ZEngine/ZEngine/Rendering/Renderers/Base/RenderPass.cpp +++ b/ZEngine/ZEngine/Rendering/Renderers/Base/RenderPass.cpp @@ -163,7 +163,7 @@ namespace ZEngine::Rendering::Renderers::RenderPasses if (Specification.SwapchainAsRenderTarget) { Attachment = m_device->SwapchainPtr->SwapchainAttachment; - Pipeline = ZPushStructCtorArgs(m_device->Arena, Pipelines::GraphicPipeline); + Pipeline = ZPushStructCtor(m_device->Arena, std::source_location::current()); Pipeline->Initialize(m_device, std::move(Specification.PipelineDescription), Attachment); } else @@ -216,8 +216,8 @@ namespace ZEngine::Rendering::Renderers::RenderPasses color_map_index++; } - Attachment = ZPushStructCtorArgs(m_device->Arena, RenderPasses::Attachment, m_device, std::move(attachment_specification)); - Pipeline = ZPushStructCtorArgs(m_device->Arena, Pipelines::GraphicPipeline); + Attachment = ZPushStructCtorArgs(m_device->Arena, std::source_location::current(), m_device, std::move(attachment_specification)); + Pipeline = ZPushStructCtor(m_device->Arena); Pipeline->Initialize(m_device, std::move(Specification.PipelineDescription), Attachment); UpdateRenderTargets(); @@ -793,7 +793,7 @@ namespace ZEngine::Rendering::Renderers::RenderPasses Specification = std::move(specification); InitializeDescriptorBindings(device); - Pipeline = ZPushStructCtorArgs(m_device->Arena, Pipelines::ComputePipeline); + Pipeline = ZPushStructCtor(m_device->Arena, std::source_location::current()); Pipeline->Initialize(m_device, Specification.ComputeShaderName, Specification.ComputePushConstantSize); Pipeline->ReplayDescriptors = &DescriptorBoundPass::ReplayDescriptorBindings; Pipeline->DescriptorReplayContext = static_cast(this); diff --git a/ZEngine/ZEngine/Rendering/Renderers/GraphicRenderer.cpp b/ZEngine/ZEngine/Rendering/Renderers/GraphicRenderer.cpp index fc905a5de..78aa33a0a 100644 --- a/ZEngine/ZEngine/Rendering/Renderers/GraphicRenderer.cpp +++ b/ZEngine/ZEngine/Rendering/Renderers/GraphicRenderer.cpp @@ -110,8 +110,8 @@ namespace ZEngine::Rendering::Renderers void GraphicRenderer::Initialize(Hardwares::VulkanDevicePtr device) { Device = device; - RenderGraph = ZPushStructCtorArgs(Device->Arena, Renderers::RenderGraph); - RenderSceneData = ZPushStructCtor(Device->Arena, Scenes::SceneData); + RenderGraph = ZPushStructCtor(Device->Arena); + RenderSceneData = ZPushStructCtor(Device->Arena); ZENGINE_VALIDATE_ASSERT(Device->SwapchainPtr->BufferredFrameCount <= Scenes::SceneData::MAX_FRAMES_IN_FLIGHT, "SceneData buffers must cover every buffered frame") constexpr const char* transform_names[Scenes::SceneData::MAX_FRAMES_IN_FLIGHT] = {"TransformStorageBuffer[0]", "TransformStorageBuffer[1]", "TransformStorageBuffer[2]"}; constexpr const char* render_data_names[Scenes::SceneData::MAX_FRAMES_IN_FLIGHT] = {"RenderDataStorageBuffer[0]", "RenderDataStorageBuffer[1]", "RenderDataStorageBuffer[2]"}; @@ -134,17 +134,17 @@ namespace ZEngine::Rendering::Renderers /* * Renderer Passes */ - auto scene_depth_prepass = ZPushStructCtor(Device->Arena, DepthPrePass); - auto frustum_culling_pass = ZPushStructCtor(Device->Arena, FrustumCullingPass); - auto gbuffer_pass = ZPushStructCtor(Device->Arena, GbufferPass); - auto lighting_pass = ZPushStructCtor(Device->Arena, LightingPass); - auto environment_background_pass = ZPushStructCtor(Device->Arena, EnvironmentBackgroundPass); - auto sky_sphere_pass = ZPushStructCtor(Device->Arena, SkySpherePass); - auto sky_view_lut_pass = ZPushStructCtor(Device->Arena, SkyViewLutPass); - auto aerial_pass = ZPushStructCtor(Device->Arena, AerialPerspectivePass); - auto sky_composite_pass = ZPushStructCtor(Device->Arena, SkyCompositePass); - auto grid_pass = ZPushStructCtor(Device->Arena, GridPass); - auto tone_mapping_pass = ZPushStructCtor(Device->Arena, ToneMappingPass); + auto scene_depth_prepass = ZPushStructCtor(Device->Arena); + auto frustum_culling_pass = ZPushStructCtor(Device->Arena); + auto gbuffer_pass = ZPushStructCtor(Device->Arena); + auto lighting_pass = ZPushStructCtor(Device->Arena); + auto environment_background_pass = ZPushStructCtor(Device->Arena); + auto sky_sphere_pass = ZPushStructCtor(Device->Arena); + auto sky_view_lut_pass = ZPushStructCtor(Device->Arena); + auto aerial_pass = ZPushStructCtor(Device->Arena); + auto sky_composite_pass = ZPushStructCtor(Device->Arena); + auto grid_pass = ZPushStructCtor(Device->Arena); + auto tone_mapping_pass = ZPushStructCtor(Device->Arena); RenderGraph->Initialize(Device, RenderSceneData); RenderGraph->ImportBuffer(RendererBufferName::Transform, &RenderSceneData->TransformBuffers[0]); @@ -182,13 +182,13 @@ namespace ZEngine::Rendering::Renderers ZENGINE_CORE_WARN("[SkyEnvironment] Atmosphere baking is disabled: {}", m_atmosphere_bake_unavailable_reason) if (!m_atmosphere_view_resources_supported) ZENGINE_CORE_WARN("[SkyEnvironment] Per-view atmosphere composition is disabled: {}", m_atmosphere_view_unavailable_reason) - m_sky_atmosphere_transmittance_pass = ZPushStructCtorArgs(Device->Arena, SkyAtmosphereTransmittancePass, &m_sky_environment); - m_sky_atmosphere_multiscattering_pass = ZPushStructCtorArgs(Device->Arena, SkyAtmosphereMultiscatteringPass, &m_sky_environment); - m_sky_atmosphere_source_radiance_pass = ZPushStructCtorArgs(Device->Arena, SkyAtmosphereSourceRadiancePass, &m_sky_environment); - m_sky_hdri_mip_generation_pass = ZPushStructCtorArgs(Device->Arena, SkyEnvironmentMipGenerationPass, &m_sky_environment, "sky_environment_mip_generation", false); - m_sky_atmosphere_mip_generation_pass = ZPushStructCtorArgs(Device->Arena, SkyEnvironmentMipGenerationPass, &m_sky_environment, "sky_atmosphere_mip_generation", true); - m_sky_diffuse_irradiance_pass = ZPushStructCtorArgs(Device->Arena, SkyEnvironmentDiffuseIrradiancePass, &m_sky_environment); - m_sky_specular_prefilter_pass = ZPushStructCtorArgs(Device->Arena, SkyEnvironmentSpecularPrefilterPass, &m_sky_environment); + m_sky_atmosphere_transmittance_pass = ZPushStructCtorArgs(Device->Arena, std::source_location::current(), &m_sky_environment); + m_sky_atmosphere_multiscattering_pass = ZPushStructCtorArgs(Device->Arena, std::source_location::current(), &m_sky_environment); + m_sky_atmosphere_source_radiance_pass = ZPushStructCtorArgs(Device->Arena, std::source_location::current(), &m_sky_environment); + m_sky_hdri_mip_generation_pass = ZPushStructCtorArgs(Device->Arena, std::source_location::current(), &m_sky_environment, "sky_environment_mip_generation", false); + m_sky_atmosphere_mip_generation_pass = ZPushStructCtorArgs(Device->Arena, std::source_location::current(), &m_sky_environment, "sky_atmosphere_mip_generation", true); + m_sky_diffuse_irradiance_pass = ZPushStructCtorArgs(Device->Arena, std::source_location::current(), &m_sky_environment); + m_sky_specular_prefilter_pass = ZPushStructCtorArgs(Device->Arena, std::source_location::current(), &m_sky_environment); m_lighting_pass->SetEnvironmentLighting(fallback_lighting, m_sky_environment.GetPresentationConfig()); m_environment_background_pass->SetEnvironment(fallback_environment, m_sky_environment.GetPresentationConfig()); RenderGraph->ImportBuffer(RendererBufferName::GlobalVertex, rrm->GetGlobalVertexBuffer()); diff --git a/ZEngine/ZEngine/Rendering/Renderers/RenderGraph.cpp b/ZEngine/ZEngine/Rendering/Renderers/RenderGraph.cpp index 8ab7b17d6..8824d04da 100644 --- a/ZEngine/ZEngine/Rendering/Renderers/RenderGraph.cpp +++ b/ZEngine/ZEngine/Rendering/Renderers/RenderGraph.cpp @@ -1290,10 +1290,10 @@ namespace ZEngine::Rendering::Renderers InitializeTimestampFrames(); for (uint32_t i = 0; i < QueueTimelineCount; ++i) - QueueTimelines[i] = ZPushStructCtorArgs(Device->Arena, Rendering::Primitives::Semaphore, Device, true); + QueueTimelines[i] = ZPushStructCtorArgs(Device->Arena, std::source_location::current(), Device, true); - ResourceBuilder = ZPushStruct(Device->Arena, RenderGraphResourceBuilder); - ResourceInspector = ZPushStruct(Device->Arena, RenderGraphResourceInspector); + ResourceBuilder = ZPushStruct(Device->Arena); + ResourceInspector = ZPushStruct(Device->Arena); ResourceBuilder->Initialize(this); ResourceInspector->Initialize(this); @@ -1737,7 +1737,7 @@ namespace ZEngine::Rendering::Renderers // The countdown is frame-scratch owned. The render thread waits // for every submitted worker before this scratch scope ends. - auto* completion = ZPushStructCtor(scratch.Arena, PaddedAtomic); + auto* completion = ZPushStructCtor>(scratch.Arena); completion->value.store(task_count, std::memory_order_relaxed); RenderGraphSecondaryRecordTask tasks[Helpers::ThreadPool::MAX_WORKERS] = {}; bool record_on_render_thread[Helpers::ThreadPool::MAX_WORKERS] = {}; @@ -3197,7 +3197,7 @@ namespace ZEngine::Rendering::Renderers } else { - auto* buffer = ZPushStruct(Device->Arena, Core::Memory::BufferView); + auto* buffer = ZPushStruct(Device->Arena); if (auto* backing = TransientBufferPool.FindAliasingSlot(res.BufferSize, res.BufferUsage, res.FirstPassIndex, res.LastPassIndex)) { *buffer = Device->CreateAliasingBuffer(*backing->Buffer, res.BufferSize, res.BufferUsage, res.Name); @@ -4503,7 +4503,7 @@ namespace ZEngine::Rendering::Renderers } if (!pass.Framebuffer) - pass.Framebuffer = ZPushStructCtorArgs(Device->Arena, Buffers::FramebufferVNext, Device); + pass.Framebuffer = ZPushStructCtorArgs(Device->Arena, std::source_location::current(), Device); else pass.Framebuffer->Dispose(); pass.Framebuffer->Reset(vk_fb, w, h); diff --git a/ZEngine/ZEngine/Rendering/Renderers/ZUIPass.cpp b/ZEngine/ZEngine/Rendering/Renderers/ZUIPass.cpp index 47a910827..2e971b815 100644 --- a/ZEngine/ZEngine/Rendering/Renderers/ZUIPass.cpp +++ b/ZEngine/ZEngine/Rendering/Renderers/ZUIPass.cpp @@ -212,8 +212,8 @@ namespace ZEngine::Rendering::Renderers // DFS walk (identical traversal order to old PreparePayload) // HOT PATH — runs every frame, no heap allocation allowed. - ZUIBox** nodes = ZPushArray(&ctx->FrameArena, ZUIBox*, max_boxes); - ZUIBox** dfs_stack = ZPushArray(&ctx->FrameArena, ZUIBox*, max_boxes); + ZUIBox** nodes = ZPushArray(&ctx->FrameArena, max_boxes); + ZUIBox** dfs_stack = ZPushArray(&ctx->FrameArena, max_boxes); uint32_t node_count = 0, stack_top = 0; dfs_stack[stack_top++] = ctx->Root; diff --git a/ZEngine/ZEngine/Rendering/Shaders/ShaderReader.cpp b/ZEngine/ZEngine/Rendering/Shaders/ShaderReader.cpp index 3f612b5f3..a4a8643f6 100644 --- a/ZEngine/ZEngine/Rendering/Shaders/ShaderReader.cpp +++ b/ZEngine/ZEngine/Rendering/Shaders/ShaderReader.cpp @@ -27,14 +27,14 @@ namespace ZEngine::Rendering::Shaders if (path_res.Failed()) { ZENGINE_CORE_ERROR("====== Shader file : {} — invalid VFS path ======", filename) - ZENGINE_EXIT_FAILURE() + ZENGINE_EXIT_FAILURE(); } auto file_res = vfs->Open(path_res.Value(), Core::VFS::VFSOpenFlags::Read); if (file_res.Failed()) { ZENGINE_CORE_ERROR("====== Shader file : {} cannot be opened ======", filename) - ZENGINE_EXIT_FAILURE() + ZENGINE_EXIT_FAILURE(); } auto* file = file_res.Value(); @@ -43,7 +43,7 @@ namespace ZEngine::Rendering::Shaders { vfs->Close(file); ZENGINE_CORE_ERROR("====== Shader file : {} cannot get size ======", filename) - ZENGINE_EXIT_FAILURE() + ZENGINE_EXIT_FAILURE(); } const uint64_t byte_size = size_res.Value(); diff --git a/ZEngine/ZEngine/UI/ZUIContext.cpp b/ZEngine/ZEngine/UI/ZUIContext.cpp index 337375710..1e0732a6e 100644 --- a/ZEngine/ZEngine/UI/ZUIContext.cpp +++ b/ZEngine/ZEngine/UI/ZUIContext.cpp @@ -14,7 +14,7 @@ namespace ZEngine::UI parent->CreateSubArena(FrameArenaBytes, &ctx->FrameArena, "UIContext/Frame"); parent->CreateSubArena(PersistentArenaBytes, &ctx->PersistentArena, "UIContext/Persistent"); - ctx->StateStore.Slots = ZPushArray(&ctx->PersistentArena, ZUIPersistentSlot, StateCapacity); + ctx->StateStore.Slots = ZPushArray(&ctx->PersistentArena, StateCapacity); ctx->StateStore.Capacity = StateCapacity; ctx->StateStore.Count = 0; ctx->MaxBoxesPerFrame = MaxBoxesPerFrame; @@ -200,7 +200,7 @@ namespace ZEngine::UI ZUIBox* ZUIPushBox(ZUIContext* ctx, const char* key, uint32_t key_len, ZUIBoxFlags flags) { - ZUIBox* box = ZPushStructCtor(&ctx->FrameArena, ZUIBox); + ZUIBox* box = ZPushStructCtor(&ctx->FrameArena); ZENGINE_VALIDATE_ASSERT(box != nullptr, "ZUI FrameArena exhausted — increase FrameArenaBytes"); box->Flags = flags; diff --git a/ZEngine/ZEngine/UI/ZUIDockSerial.cpp b/ZEngine/ZEngine/UI/ZUIDockSerial.cpp index d158f3a18..82e79323e 100644 --- a/ZEngine/ZEngine/UI/ZUIDockSerial.cpp +++ b/ZEngine/ZEngine/UI/ZUIDockSerial.cpp @@ -224,7 +224,7 @@ namespace ZEngine::UI ZUIDockNode* new_nodes[kMaxSerialNodes] = {}; for (uint32_t i = 0; i < node_count; ++i) { - new_nodes[i] = ZPushStructCtor(arena, ZUIDockNode); + new_nodes[i] = ZPushStructCtor(arena); if (!new_nodes[i]) { return false; diff --git a/ZEngine/ZEngine/UI/ZUIDockspace.cpp b/ZEngine/ZEngine/UI/ZUIDockspace.cpp index 2efbb8104..b8d764fb3 100644 --- a/ZEngine/ZEngine/UI/ZUIDockspace.cpp +++ b/ZEngine/ZEngine/UI/ZUIDockspace.cpp @@ -9,7 +9,7 @@ namespace ZEngine::UI static ZUIDockNode* AllocNode(ZUIDockTree* tree) { - return ZPushStructCtor(tree->Arena, ZUIDockNode); + return ZPushStructCtor(tree->Arena); } static void AppendChild(ZUIDockNode* parent, ZUIDockNode* child) @@ -96,7 +96,7 @@ namespace ZEngine::UI ZUIDockTree* ZUIDockTreeCreate(ArenaAllocator* persistent_arena) { - auto* tree = ZPushStructCtor(persistent_arena, ZUIDockTree); + auto* tree = ZPushStructCtor(persistent_arena); tree->Arena = persistent_arena; tree->Root = AllocNode(tree); tree->Root->PctOfParent = 1.f; diff --git a/ZEngine/ZEngine/UI/ZUIDrawList.cpp b/ZEngine/ZEngine/UI/ZUIDrawList.cpp index 55d3fff13..c0b702818 100644 --- a/ZEngine/ZEngine/UI/ZUIDrawList.cpp +++ b/ZEngine/ZEngine/UI/ZUIDrawList.cpp @@ -52,7 +52,7 @@ namespace ZEngine::UI uint32_t new_cap = dl->VtxCapacity ? dl->VtxCapacity * 2 : 4096; while (new_cap < dl->VtxCount + needed) new_cap *= 2; - ZUIDrawVtx* nb = ZPushArray(arena, ZUIDrawVtx, new_cap); + ZUIDrawVtx* nb = ZPushArray(arena, new_cap); if (dl->Vtx) memcpy(nb, dl->Vtx, dl->VtxCount * sizeof(ZUIDrawVtx)); dl->Vtx = nb; @@ -66,7 +66,7 @@ namespace ZEngine::UI uint32_t new_cap = dl->IdxCapacity ? dl->IdxCapacity * 2 : 8192; while (new_cap < dl->IdxCount + needed) new_cap *= 2; - uint16_t* nb = ZPushArray(arena, uint16_t, new_cap); + uint16_t* nb = ZPushArray(arena, new_cap); if (dl->Idx) memcpy(nb, dl->Idx, dl->IdxCount * sizeof(uint16_t)); dl->Idx = nb; @@ -80,8 +80,8 @@ namespace ZEngine::UI uint32_t new_cap = dl->PathCap ? dl->PathCap * 2 : 256; while (new_cap < dl->PathCount + needed) new_cap *= 2; - float* nx = ZPushArray(arena, float, new_cap); - float* ny = ZPushArray(arena, float, new_cap); + float* nx = ZPushArray(arena, new_cap); + float* ny = ZPushArray(arena, new_cap); if (dl->PathX) { memcpy(nx, dl->PathX, dl->PathCount * sizeof(float)); @@ -104,13 +104,13 @@ namespace ZEngine::UI s_Arena = frame_arena; dl->VtxCapacity = vtx_cap; dl->IdxCapacity = idx_cap; - dl->Vtx = vtx_cap ? ZPushArray(frame_arena, ZUIDrawVtx, vtx_cap) : nullptr; - dl->Idx = idx_cap ? ZPushArray(frame_arena, uint16_t, idx_cap) : nullptr; + dl->Vtx = vtx_cap ? ZPushArray(frame_arena, vtx_cap) : nullptr; + dl->Idx = idx_cap ? ZPushArray(frame_arena, idx_cap) : nullptr; dl->CmdCapacity = 512; - dl->Cmds = ZPushArray(frame_arena, ZUIDrawListCmd, dl->CmdCapacity); + dl->Cmds = ZPushArray(frame_arena, dl->CmdCapacity); dl->PathCap = 256; - dl->PathX = ZPushArray(frame_arena, float, dl->PathCap); - dl->PathY = ZPushArray(frame_arena, float, dl->PathCap); + dl->PathX = ZPushArray(frame_arena, dl->PathCap); + dl->PathY = ZPushArray(frame_arena, dl->PathCap); dl->WhiteU = white_u; dl->WhiteV = white_v; dl->AtlasTexIdx = atlas_idx; diff --git a/ZEngine/ZEngine/UI/ZUIFont.cpp b/ZEngine/ZEngine/UI/ZUIFont.cpp index 2480f8c7b..aeb7d1592 100644 --- a/ZEngine/ZEngine/UI/ZUIFont.cpp +++ b/ZEngine/ZEngine/UI/ZUIFont.cpp @@ -39,7 +39,7 @@ namespace ZEngine::UI } uint64_t sz = size_res.Value(); - uint8_t* data = ZPushArray(temp_arena, uint8_t, (uint32_t) sz); + uint8_t* data = ZPushArray(temp_arena, (uint32_t) sz); ArrayView view{data, sz}; file->ReadAll(view); vfs->Close(file); @@ -87,7 +87,7 @@ namespace ZEngine::UI // Pass A: render each glyph to measure its bitmap dimensions. // Pass B: render again into the atlas at stb_rect_pack positions. const uint32_t kTotalGlyphs = 3 * codepoint_count; - stbrp_rect* rects = ZPushArray(temp_arena, stbrp_rect, kTotalGlyphs); + stbrp_rect* rects = ZPushArray(temp_arena, kTotalGlyphs); // Pass A — measure for (int fi = 0; fi < 3; ++fi) @@ -112,12 +112,12 @@ namespace ZEngine::UI const uint32_t kAtlasW = 1024; const uint32_t kAtlasH = 2048; stbrp_context pack_ctx = {}; - stbrp_node* pack_nodes = ZPushArray(temp_arena, stbrp_node, kAtlasW); + stbrp_node* pack_nodes = ZPushArray(temp_arena, kAtlasW); stbrp_init_target(&pack_ctx, (int) kAtlasW, (int) kAtlasH, pack_nodes, (int) kAtlasW); stbrp_pack_rects(&pack_ctx, rects, (int) kTotalGlyphs); // Pass B — render into atlas - uint8_t* atlas_px = ZPushArray(temp_arena, uint8_t, kAtlasW* kAtlasH); + uint8_t* atlas_px = ZPushArray(temp_arena, kAtlasW * kAtlasH); // White texel at (0,0) — used by solid-color draws atlas_px[0] = 255u; @@ -150,7 +150,7 @@ namespace ZEngine::UI } // 4. Expand single-channel → RGBA8 (white text, alpha-masked) - uint8_t* rgba = ZPushArray(temp_arena, uint8_t, kAtlasW * kAtlasH * 4); + uint8_t* rgba = ZPushArray(temp_arena, kAtlasW * kAtlasH * 4); for (uint32_t i = 0; i < kAtlasW * kAtlasH; ++i) { rgba[i * 4 + 0] = 255; @@ -169,7 +169,7 @@ namespace ZEngine::UI device->RequestDescriptorUpdate(gpu_handle); // 6. Build ZUIFontAtlas - ZUIFontAtlas* atlas = ZPushStruct(persistent_arena, ZUIFontAtlas); + ZUIFontAtlas* atlas = ZPushStruct(persistent_arena); atlas->Handle = gpu_handle; atlas->Width = kAtlasW; atlas->Height = kAtlasH; @@ -185,8 +185,8 @@ namespace ZEngine::UI { FT_Set_Pixel_Sizes(kFaces[fi], 0, (FT_UInt) kSizes[fi]); - ZUIFont* font = ZPushStruct(persistent_arena, ZUIFont); - font->Glyphs = ZPushArray(persistent_arena, ZUIGlyph, codepoint_count); + ZUIFont* font = ZPushStruct(persistent_arena); + font->Glyphs = ZPushArray(persistent_arena, codepoint_count); font->GlyphCount = codepoint_count; font->FirstCodepoint = first_codepoint; font->FontSize = kSizes[fi]; diff --git a/ZEngine/ZEngine/UI/ZUIInteraction.cpp b/ZEngine/ZEngine/UI/ZUIInteraction.cpp index 2e9a0fcfc..7e7a59e81 100644 --- a/ZEngine/ZEngine/UI/ZUIInteraction.cpp +++ b/ZEngine/ZEngine/UI/ZUIInteraction.cpp @@ -18,7 +18,7 @@ namespace ZEngine::UI uint32_t max = ctx->MaxBoxesPerFrame; auto scratch = ZGetScratch(&ctx->FrameArena); - ZUIBox** stack = ZPushArray(&ctx->FrameArena, ZUIBox*, max); + ZUIBox** stack = ZPushArray(&ctx->FrameArena, max); uint32_t stack_top = 0; uint64_t new_hot = 0; diff --git a/ZEngine/ZEngine/UI/ZUILayout.cpp b/ZEngine/ZEngine/UI/ZUILayout.cpp index c818d3436..75240c7f9 100644 --- a/ZEngine/ZEngine/UI/ZUILayout.cpp +++ b/ZEngine/ZEngine/UI/ZUILayout.cpp @@ -22,8 +22,8 @@ namespace ZEngine::UI uint32_t max = ctx->MaxBoxesPerFrame; - ZUIBox** nodes = ZPushArray(&ctx->FrameArena, ZUIBox*, max); - ZUIBox** dfs_stack = ZPushArray(&ctx->FrameArena, ZUIBox*, max); + ZUIBox** nodes = ZPushArray(&ctx->FrameArena, max); + ZUIBox** dfs_stack = ZPushArray(&ctx->FrameArena, max); uint32_t node_count = 0; uint32_t stack_top = 0; diff --git a/ZEngine/ZEngine/UI/ZUIWidgets.cpp b/ZEngine/ZEngine/UI/ZUIWidgets.cpp index 94292330f..8531ae4ce 100644 --- a/ZEngine/ZEngine/UI/ZUIWidgets.cpp +++ b/ZEngine/ZEngine/UI/ZUIWidgets.cpp @@ -1340,7 +1340,7 @@ namespace ZEngine::UI ctx->TableRowBox = nullptr; // Allocate per-column widths in FrameArena - ctx->TableColWidths = ZPushArray(&ctx->FrameArena, float, columns); + ctx->TableColWidths = ZPushArray(&ctx->FrameArena, columns); for (int i = 0; i < columns; ++i) ctx->TableColWidths[i] = widths ? widths[i] : 0.f; @@ -3316,7 +3316,7 @@ namespace ZEngine::UI } // Copy values to FrameArena so they survive until PreparePayload - float* data = ZPushArray(&ctx->FrameArena, float, (uint32_t) count); + float* data = ZPushArray(&ctx->FrameArena, (uint32_t) count); for (int i = 0; i < count; ++i) data[i] = values[i]; @@ -3663,7 +3663,7 @@ namespace ZEngine::UI // sum changes when the panel resizes. Compare with the last stored total // and scale all stored widths by the same ratio to keep user resize ratios. static constexpr uint64_t kTotalWSuffix = 0x544F54574944ULL; - ctx->DT_ColWidths = ZPushArray(&ctx->FrameArena, float, col_count); + ctx->DT_ColWidths = ZPushArray(&ctx->FrameArena, col_count); float total_init = 0.f; for (int i = 0; i < col_count; ++i) @@ -3728,7 +3728,7 @@ namespace ZEngine::UI // Store cols in FrameArena for HeadersRow if (cols) { - auto* copy = ZPushArray(&ctx->FrameArena, ZUIDataTableColumn, col_count); + auto* copy = ZPushArray(&ctx->FrameArena, col_count); for (int i = 0; i < col_count; ++i) copy[i] = cols[i]; ctx->DT_Cols = copy; diff --git a/ZEngine/ZEngine/Windows/GameWindow.cpp b/ZEngine/ZEngine/Windows/GameWindow.cpp index 638e4f492..846bf94a9 100644 --- a/ZEngine/ZEngine/Windows/GameWindow.cpp +++ b/ZEngine/ZEngine/Windows/GameWindow.cpp @@ -121,7 +121,7 @@ namespace ZEngine::Windows glfwSetErrorCallback([](int error, const char* description) { ZENGINE_CORE_CRITICAL("{}", description) - ZENGINE_EXIT_FAILURE() + ZENGINE_EXIT_FAILURE(); }); m_native_window = glfwCreateWindow(m_property.Width, m_property.Height, m_property.Title, NULL, NULL); @@ -129,7 +129,7 @@ namespace ZEngine::Windows if (!m_native_window) { ZENGINE_CORE_CRITICAL("Failed to create GLFW Window") - ZENGINE_EXIT_FAILURE() + ZENGINE_EXIT_FAILURE(); } { diff --git a/ZEngine/ZEngine/Windows/Inputs/IDevice.h b/ZEngine/ZEngine/Windows/Inputs/IDevice.h index 5317bfcb7..84fb04f21 100644 --- a/ZEngine/ZEngine/Windows/Inputs/IDevice.h +++ b/ZEngine/ZEngine/Windows/Inputs/IDevice.h @@ -32,7 +32,7 @@ namespace ZEngine::Windows::Inputs return reinterpret_cast(it->second); } - IDevice* device = ZPushStructCtor(Arena, T); + IDevice* device = ZPushStructCtor(Arena); auto pair = Devices.emplace(std::make_pair(type.name(), device)); return reinterpret_cast(pair.first->second); } diff --git a/ZEngine/ZEngine/ZEngineDef.h b/ZEngine/ZEngine/ZEngineDef.h index 4221f470b..f32292c90 100644 --- a/ZEngine/ZEngine/ZEngineDef.h +++ b/ZEngine/ZEngine/ZEngineDef.h @@ -1,11 +1,20 @@ #pragma once #include #include +#include +#include -#define BIT(x) (1 << (x)) -#define ZENGINE_EXIT_FAILURE() exit(EXIT_FAILURE); +inline constexpr auto BIT(auto x) +{ + return 1 << x; +} + +inline void ZENGINE_EXIT_FAILURE() +{ + exit(EXIT_FAILURE); +} -#define ZENGINE_KEYCODE ZEngine::Windows::Inputs::GlfwKeyCode +using ZENGINE_KEYCODE = ZEngine::Windows::Inputs::GlfwKeyCode; #ifdef _MSC_VER #define ZENGINE_DEBUG_BREAK() \ @@ -65,12 +74,12 @@ collection.shrink_to_fit(); \ } -#define SINGLE_ARG(...) __VA_ARGS__ +#define SINGLE_ARG(...) __VA_ARGS__ -#define MAX_FILE_PATH_COUNT 256 -#define DEFAULT_STR_BUFFER 256 +inline constexpr auto MAX_FILE_PATH_COUNT{256}; +inline constexpr auto DEFAULT_STR_BUFFER{256}; -#define ZDEFINE_PTR(X) typedef X* X##Ptr +#define ZDEFINE_PTR(X) typedef X* X##Ptr #define CHECK_AND_ESCAPE_NULL(handle) \ if (!handle) \ @@ -78,51 +87,137 @@ return; \ } -/* - * Allocator and Memory Macros - */ -#ifndef DEFAULT_ALIGNMENT -#define DEFAULT_ALIGNMENT (2 * sizeof(void*)) -#endif // !DEFAULT_ALIGNMENT +inline constexpr auto DEFAULT_ALIGNMENT{2 * sizeof(void*)}; -#define ZKilo(size) (static_cast(size) * 1024ULL) -#define ZMega(size) (static_cast(size) * 1024ULL * 1024ULL) -#define ZGiga(size) (static_cast(size) * 1024ULL * 1024ULL * 1024ULL) +inline constexpr uint64_t ZKilo(std::integral auto size) +{ + return static_cast(size) * 1024ULL; +} -#define ZPush(allocator, type, size) ((type*) (allocator)->Allocate(size, DEFAULT_ALIGNMENT, __FILE__, __LINE__)) +inline constexpr uint64_t ZMega(std::integral auto size) +{ + return static_cast(size) * 1024ULL * 1024ULL; +} -#define ZPushArray(arena, type, count) ZPush(arena, type, (sizeof(type) * count)) -#define ZPushString(arena, count) ZPushArray(arena, char, count) -#define ZPushStruct(arena, type) ZPushArray(arena, type, 1) +inline constexpr uint64_t ZGiga(std::integral auto size) +{ + return static_cast(size) * 1024ULL * 1024ULL * 1024ULL; +} + +// #define ZPush(allocator, type, size) ((type*) (allocator)->Allocate(size, DEFAULT_ALIGNMENT, __FILE__, __LINE__)) +template +inline void* ZPush(Allocator* allocator, std::size_t size, std::source_location location = std::source_location::current()) +{ + return allocator->Allocate(size, DEFAULT_ALIGNMENT, location.file_name(), location.line()); +} + +// #define ZPushArray(arena, type, count) ZPush(arena, type, (sizeof(type) * count)) +template +inline Type* ZPushArray(Allocator* allocator, auto count = 1, std::source_location location = std::source_location::current()) +{ + return static_cast(ZPush(allocator, (sizeof(Type) * count), location)); +} + +// #define ZPushString(arena, count) ZPushArray(arena, char, count) +template +inline char* ZPushString(Allocator* allocator, std::integral auto count = 1, std::source_location location = std::source_location::current()) +{ + return ZPushArray(allocator, count, location); +}; + +// #define ZPushStruct(arena, type) ZPushArray(arena, type, 1) +template +inline Type* ZPushStruct(Allocator* allocator, std::source_location location = std::source_location::current()) +{ + return ZPushArray(allocator, 1, location); +} #ifdef __cplusplus -#define ZPushStructCtor(arena, type) (new (ZPushStruct(arena, type)) type()) -#define ZPushStructCtorArgs(arena, type, ...) (new (ZPushStruct(arena, type)) type(__VA_ARGS__)) -#define ZConstruct(ptr, type) (new (ptr) type()) -#define ZConstructArgs(ptr, type, ...) (new (ptr) type(__VA_ARGS__)) +// #define ZPushStructCtor(arena, type) (new (ZPushStruct(arena, type)) type()) +template +inline Type* ZPushStructCtor(Allocator* arena, std::source_location location = std::source_location::current()) +{ + return new (ZPushStruct(arena, location)) Type(); +} + +// #define ZPushStructCtorArgs(arena, type, ...) (new (ZPushStruct(arena, type)) type(__VA_ARGS__)) +template +inline Type* ZPushStructCtorArgs(Allocator* arena, std::source_location location, ctorargs&&... args) +{ + return new (ZPushStruct(arena, location)) Type(std::forward(args)...); +} + +// #define ZConstruct(ptr, type) (new (ptr) type()) +template +inline Type* ZConstruct(void* ptr) +{ + return new (ptr) Type(); +} + +// #define ZConstructArgs(ptr, type, ...) (new (ptr) type(__VA_ARGS__)) + +template +inline Type* ZConstructArgs(Type* ptr, ctorargs... args) +{ + return new (ptr) Type(args...); +} + #endif -#define ZPushDynamicArray(pool, type) ((type*) (pool)->Allocate(__FILE__, __LINE__)) -#define ZAlloc(allocator, size, alignment) ((allocator)->Allocate((size), (alignment))) -#define ZResize(allocator, ptr, old_size, new_size, alignment) ((allocator)->Resize((ptr), (old_size), (new_size), (alignment))) -#define ZAlignof(type) ((alignof(type) < DEFAULT_ALIGNMENT) ? DEFAULT_ALIGNMENT : alignof(type)) +// #define ZPushDynamicArray(pool, type) ((type*) (pool)->Allocate(__FILE__, __LINE__)) +template +inline Type* ZPushDynamicArray(Allocator* pool, std::source_location location = std::source_location::current()) +{ + return static_cast(pool->Allocate(location.file_name(), location.line())); +} + +// #define ZAlloc(allocator, size, alignment) ((allocator)->Allocate((size), (alignment))) +template +inline void* ZAlloc(Allocator* allocator, std::integral auto size, std::integral auto alignment) +{ + return allocator->Allocate(size, alignment); +} + +// #define ZResize(allocator, ptr, old_size, new_size, alignment) ((allocator)->Resize((ptr), (old_size), (new_size), (alignment))) + +template +inline auto* ZResize(Allocator* allocator, auto ptr, std::size_t old_size, std::size_t new_size, auto alignment) +{ + return allocator->Resize(ptr, old_size, new_size, alignment); +} + +// #define ZAlignof(type) ((alignof(type) < DEFAULT_ALIGNMENT) ? DEFAULT_ALIGNMENT : alignof(type)) +template +inline constexpr std::integral auto ZAlignof() +{ + return (alignof(Type) < DEFAULT_ALIGNMENT) ? DEFAULT_ALIGNMENT : alignof(Type); +} /* * */ -#define MAKE_MAGIC(a, b, c, d) ((uint32_t) (a) << 24 | (uint32_t) (b) << 16 | (uint32_t) (c) << 8 | (uint32_t) (d)) -#define MAKE_VERSION(major, minor, patch) (((uint32_t) (major) << 16) | ((uint32_t) (minor) << 8) | ((uint32_t) (patch))) - -#define ZEASSET_MAGIC MAKE_MAGIC('Z', 'A', 'S', 'T') -#define ZEMESH_MAGIC MAKE_MAGIC('Z', 'M', 'S', 'H') -#define ZEMATERIAL_MAGIC MAKE_MAGIC('Z', 'M', 'A', 'T') -#define ZETEXTURES_MAGIC MAKE_MAGIC('Z', 'T', 'E', 'X') -#define ZESCENE_MAGIC MAKE_MAGIC('Z', 'S', 'C', 'N') -#define ZENVMAP_MAGIC MAKE_MAGIC('Z', 'E', 'N', 'V') -#define ASSET_FILE_VERSION MAKE_VERSION(1, 0, 0) -#define SCENE_FILE_VERSION MAKE_VERSION(2, 1, 0) - -typedef const char* cstring; + +inline consteval uint32_t make_magic(uint32_t first, uint32_t second, uint32_t third, uint32_t fourth) +{ + return first << 24 | second << 16 | third << 8 | fourth; +} + +inline consteval uint32_t make_version(uint32_t major, uint32_t minor, uint32_t patch) +{ + return major << 16 | minor << 8 | patch; +} + +inline constexpr auto ZEASSET_MAGIC = make_magic('Z', 'A', 'S', 'T'); +inline constexpr auto ZEMESH_MAGIC = make_magic('Z', 'M', 'S', 'H'); +inline constexpr auto ZEMATERIAL_MAGIC = make_magic('Z', 'M', 'A', 'T'); +inline constexpr auto ZETEXTURES_MAGIC = make_magic('Z', 'T', 'E', 'X'); +inline constexpr auto ZESCENE_MAGIC = make_magic('Z', 'S', 'C', 'N'); +inline constexpr auto ZENVMAP_MAGIC = make_magic('Z', 'E', 'N', 'V'); + +inline constexpr auto ASSET_FILE_VERSION = make_version(1, 0, 0); +inline constexpr auto SCENE_FILE_VERSION = make_version(2, 1, 0); + +using cstring = const char*; #ifdef __cpp_lib_hardware_interference_size #include diff --git a/ZEngine/tests/Memory/allocator_test.cpp b/ZEngine/tests/Memory/allocator_test.cpp index c56b35b7e..9e3a3b399 100644 --- a/ZEngine/tests/Memory/allocator_test.cpp +++ b/ZEngine/tests/Memory/allocator_test.cpp @@ -167,8 +167,8 @@ TEST(AllocatorTest, ArenaMemoryManager) void Func() {} }; - int* intPtr = ZPushArray(&(manager.MainArena), int, 1); - auto structPtr = ZPushStruct(&(manager.MainArena), Foo); + int* intPtr = ZPushArray(&(manager.MainArena), 1); + auto structPtr = ZPushStruct(&(manager.MainArena)); *intPtr = 12; structPtr->x = 12; @@ -208,7 +208,7 @@ TEST(AllocatorTest, ArenaMemoryTemp) manager.Initialize(ZKilo(10), {}); auto arena = &(manager.MainArena); { - auto fooPtr = ZPushStruct(arena, Foo); + auto fooPtr = ZPushStruct(arena); fooPtr->x = 10; fooPtr->y = 789.f; fooPtr->name = ZPushString(arena, 23); @@ -232,9 +232,9 @@ TEST(AllocatorTest, ArenaMemoryPool) PoolAllocator pool; pool.Initialize(arena, sizeof(Foo) * 100, sizeof(Foo)); - auto fooPtr = ZPushDynamicArray(&pool, Foo); - auto fooPtr1 = ZPushDynamicArray(&pool, Foo); - auto fooPtr2 = ZPushDynamicArray(&pool, Foo); + auto fooPtr = ZPushDynamicArray(&pool); + auto fooPtr1 = ZPushDynamicArray(&pool); + auto fooPtr2 = ZPushDynamicArray(&pool); fooPtr->name = ZPushString(arena, 5); Helpers::secure_strcpy(fooPtr->name, 5, "helo"); diff --git a/ZEngine/tests/Rendering/MaterialSystemTest.cpp b/ZEngine/tests/Rendering/MaterialSystemTest.cpp index 2ddec49c1..661c11d78 100644 --- a/ZEngine/tests/Rendering/MaterialSystemTest.cpp +++ b/ZEngine/tests/Rendering/MaterialSystemTest.cpp @@ -116,7 +116,7 @@ TEST(MaterialSystemTest, PrewarmReportsMissingAndRejectedRecipeProviders) const PassContext context[] = {PassContext::Lit}; MemoryManager manager = {}; manager.Initialize(ZMega(16), {}); - auto* cache = ZPushStructCtor(&manager.MainArena, ZEngine::Rendering::Renderers::Pipelines::PSOCache); + auto* cache = ZPushStructCtor(&manager.MainArena); MaterialPrewarmResult result = system.PrewarmForMaterials({&material, 1}, {context, 1}, *cache, {}); EXPECT_EQ(result.CandidateCount, 1u); diff --git a/ZEngine/tests/Rendering/PSOCacheTest.cpp b/ZEngine/tests/Rendering/PSOCacheTest.cpp index b8070392d..c3396f443 100644 --- a/ZEngine/tests/Rendering/PSOCacheTest.cpp +++ b/ZEngine/tests/Rendering/PSOCacheTest.cpp @@ -72,7 +72,7 @@ namespace PSOCacheTestStorage() { Manager.Initialize(ZMega(16), {}); - Cache = ZPushStructCtor(&Manager.MainArena, PSOCache); + Cache = ZPushStructCtor(&Manager.MainArena); } ~PSOCacheTestStorage()