From 548828f2ee79ebd8657ba349d769e29b4b4c6a86 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Mon, 30 Mar 2026 15:02:47 -0700 Subject: [PATCH] refactor: extract color write mask, name frustum epsilon, add comments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - vk_pipeline: extract kColorWriteAll constant from 4 duplicated RGBA bitmask expressions across blend mode functions, with why-comment - frustum: name kMinNormalLenSq epsilon (1e-8) with why-comment — prevents division by zero on degenerate planes - dbc_loader: add why-comment on DBC field width validation — all fields are fixed 4-byte uint32 per format spec - pin_auth: replace 0x30 hex literal with '0' char constant, add why-comment on ASCII encoding for server HMAC compatibility --- src/auth/pin_auth.cpp | 4 +++- src/pipeline/dbc_loader.cpp | 3 ++- src/rendering/frustum.cpp | 5 ++++- src/rendering/vk_pipeline.cpp | 18 ++++++++++-------- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/auth/pin_auth.cpp b/src/auth/pin_auth.cpp index 00293b6c..0ec47857 100644 --- a/src/auth/pin_auth.cpp +++ b/src/auth/pin_auth.cpp @@ -63,7 +63,9 @@ static std::vector randomizePinDigits(const std::string& pinDigits, if (idx == 0xFF) { throw std::runtime_error("PIN digit not found in remapped grid"); } - out.push_back(static_cast(idx + 0x30)); // ASCII '0'+idx + // PIN grid encodes each digit as its ASCII character ('0'..'9') for the + // server-side HMAC computation — this matches Blizzard's auth protocol. + out.push_back(static_cast(idx + '0')); } return out; diff --git a/src/pipeline/dbc_loader.cpp b/src/pipeline/dbc_loader.cpp index 71415f1e..d5ea4938 100644 --- a/src/pipeline/dbc_loader.cpp +++ b/src/pipeline/dbc_loader.cpp @@ -64,7 +64,8 @@ bool DBCFile::load(const std::vector& dbcData) { return false; } - // Validate record size matches field count + // DBC fields are fixed-width uint32 (4 bytes each); record size must match. + // Mismatches indicate a corrupted header or unsupported DBC variant. if (recordSize != fieldCount * 4) { LOG_WARNING("DBC record size mismatch: recordSize=", recordSize, " but fieldCount*4=", fieldCount * 4); diff --git a/src/rendering/frustum.cpp b/src/rendering/frustum.cpp index 872097cc..cec70fc6 100644 --- a/src/rendering/frustum.cpp +++ b/src/rendering/frustum.cpp @@ -64,7 +64,10 @@ void Frustum::extractFromMatrix(const glm::mat4& vp) { void Frustum::normalizePlane(Plane& plane) { float lenSq = glm::dot(plane.normal, plane.normal); - if (lenSq > 0.00000001f) { + // Skip normalization for degenerate planes (near-zero normal) to avoid + // division by zero or amplifying floating-point noise into huge normals. + constexpr float kMinNormalLenSq = 1e-8f; + if (lenSq > kMinNormalLenSq) { float invLen = glm::inversesqrt(lenSq); plane.normal *= invLen; plane.distance *= invLen; diff --git a/src/rendering/vk_pipeline.cpp b/src/rendering/vk_pipeline.cpp index 4119d8c8..2a95bd8b 100644 --- a/src/rendering/vk_pipeline.cpp +++ b/src/rendering/vk_pipeline.cpp @@ -202,18 +202,22 @@ VkPipeline PipelineBuilder::build(VkDevice device, VkPipelineCache cache) const return pipeline; } +// All RGBA channels enabled — used by every blend mode since we never need to +// mask individual channels (WoW's fixed-function pipeline always writes all four). +static constexpr VkColorComponentFlags kColorWriteAll = + VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | + VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT; + VkPipelineColorBlendAttachmentState PipelineBuilder::blendDisabled() { VkPipelineColorBlendAttachmentState state{}; - state.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | - VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT; + state.colorWriteMask = kColorWriteAll; state.blendEnable = VK_FALSE; return state; } VkPipelineColorBlendAttachmentState PipelineBuilder::blendAlpha() { VkPipelineColorBlendAttachmentState state{}; - state.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | - VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT; + state.colorWriteMask = kColorWriteAll; state.blendEnable = VK_TRUE; state.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA; state.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA; @@ -226,8 +230,7 @@ VkPipelineColorBlendAttachmentState PipelineBuilder::blendAlpha() { VkPipelineColorBlendAttachmentState PipelineBuilder::blendPremultiplied() { VkPipelineColorBlendAttachmentState state{}; - state.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | - VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT; + state.colorWriteMask = kColorWriteAll; state.blendEnable = VK_TRUE; state.srcColorBlendFactor = VK_BLEND_FACTOR_ONE; state.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA; @@ -240,8 +243,7 @@ VkPipelineColorBlendAttachmentState PipelineBuilder::blendPremultiplied() { VkPipelineColorBlendAttachmentState PipelineBuilder::blendAdditive() { VkPipelineColorBlendAttachmentState state{}; - state.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | - VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT; + state.colorWriteMask = kColorWriteAll; state.blendEnable = VK_TRUE; state.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA; state.dstColorBlendFactor = VK_BLEND_FACTOR_ONE;