From 4be7910fdf1730708c3728f0c6bab1858cabbaef Mon Sep 17 00:00:00 2001 From: Kelsi Date: Wed, 11 Mar 2026 11:42:01 -0700 Subject: [PATCH] refactor: consolidate QueryTimer struct to shared header Move QueryTimer from m2_renderer.cpp and wmo_renderer.cpp to vk_frame_data.hpp for reuse. Removes 13 lines of duplicate code. --- include/rendering/vk_frame_data.hpp | 18 ++++++++++++++++++ src/rendering/m2_renderer.cpp | 16 ---------------- src/rendering/wmo_renderer.cpp | 19 ++----------------- 3 files changed, 20 insertions(+), 33 deletions(-) diff --git a/include/rendering/vk_frame_data.hpp b/include/rendering/vk_frame_data.hpp index 114e0f05..482e76e7 100644 --- a/include/rendering/vk_frame_data.hpp +++ b/include/rendering/vk_frame_data.hpp @@ -2,6 +2,7 @@ #include #include +#include namespace wowee { namespace rendering { @@ -41,5 +42,22 @@ struct ShadowParamsUBO { float foliageMotionDamp; }; +// Timer utility for performance profiling queries +struct QueryTimer { + double* totalMs = nullptr; + uint32_t* callCount = nullptr; + std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now(); + QueryTimer(double* total, uint32_t* calls) : totalMs(total), callCount(calls) {} + ~QueryTimer() { + if (callCount) { + (*callCount)++; + } + if (totalMs) { + auto end = std::chrono::steady_clock::now(); + *totalMs += std::chrono::duration(end - start).count(); + } + } +}; + } // namespace rendering } // namespace wowee diff --git a/src/rendering/m2_renderer.cpp b/src/rendering/m2_renderer.cpp index a2dfe54a..332b8849 100644 --- a/src/rendering/m2_renderer.cpp +++ b/src/rendering/m2_renderer.cpp @@ -192,22 +192,6 @@ float pointAABBDistanceSq(const glm::vec3& p, const glm::vec3& bmin, const glm:: return glm::dot(d, d); } -struct QueryTimer { - double* totalMs = nullptr; - uint32_t* callCount = nullptr; - std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now(); - QueryTimer(double* total, uint32_t* calls) : totalMs(total), callCount(calls) {} - ~QueryTimer() { - if (callCount) { - (*callCount)++; - } - if (totalMs) { - auto end = std::chrono::steady_clock::now(); - *totalMs += std::chrono::duration(end - start).count(); - } - } -}; - // Möller–Trumbore ray-triangle intersection. // Returns distance along ray if hit, negative if miss. float rayTriangleIntersect(const glm::vec3& origin, const glm::vec3& dir, diff --git a/src/rendering/wmo_renderer.cpp b/src/rendering/wmo_renderer.cpp index 3401cc07..fb635803 100644 --- a/src/rendering/wmo_renderer.cpp +++ b/src/rendering/wmo_renderer.cpp @@ -2492,22 +2492,6 @@ static float pointAABBDistanceSq(const glm::vec3& p, const glm::vec3& bmin, cons return glm::dot(d, d); } -struct QueryTimer { - double* totalMs = nullptr; - uint32_t* callCount = nullptr; - std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now(); - QueryTimer(double* total, uint32_t* calls) : totalMs(total), callCount(calls) {} - ~QueryTimer() { - if (callCount) { - (*callCount)++; - } - if (totalMs) { - auto end = std::chrono::steady_clock::now(); - *totalMs += std::chrono::duration(end - start).count(); - } - } -}; - // Möller–Trumbore ray-triangle intersection // Returns distance along ray if hit, or negative if miss static float rayTriangleIntersect(const glm::vec3& origin, const glm::vec3& dir, @@ -3599,12 +3583,13 @@ void WMORenderer::recreatePipelines() { } // --- Vertex input --- + // WMO vertex: pos3 + normal3 + texCoord2 + color4 + tangent4 = 64 bytes struct WMOVertexData { glm::vec3 position; glm::vec3 normal; glm::vec2 texCoord; glm::vec4 color; - glm::vec4 tangent; + glm::vec4 tangent; // xyz=tangent dir, w=handedness ±1 }; VkVertexInputBindingDescription vertexBinding{};