fix(render): code quality cleanup

Magic number elimination:
- Create protocol_constants.hpp, warden_constants.hpp,
  render_constants.hpp, ui_constants.hpp
- Replace ~55 magic numbers across game_handler, warden_handler,
  m2_renderer_render

Reduce nesting depth:
- Extract 5 parseEffect* methods from handleSpellLogExecute
  (max indent 52 → 16 cols)
- Extract resolveSpellSchool/playSpellCastSound/playSpellImpactSound
  from 3× duplicate audio blocks in handleSpellGo
- Flatten SMSG_INVENTORY_CHANGE_FAILURE with early-return guards
- Extract drawScreenEdgeVignette() for 3 duplicate vignette blocks

DRY extract patterns:
- Replace 12 compound expansion checks with isPreWotlk() across
  movement_handler (9), chat_handler (1), social_handler (1)

const to constexpr:
- Promote 23+ static const arrays/scalars to static constexpr across
  12 source files

Error handling:
- Convert PIN auth from exceptions to std::optional<PinProof>
- Add [[nodiscard]] to 15+ initialize/parse methods
- Wrap ~20 unchecked initialize() calls with LOG_WARNING/LOG_ERROR

Signed-off-by: Pavel Okhlopkov <pavel.okhlopkov@flant.com>
This commit is contained in:
Pavel Okhlopkov 2026-04-06 22:43:13 +03:00
parent 2e8856bacd
commit 97106bd6ae
41 changed files with 849 additions and 424 deletions

View file

@ -49,7 +49,7 @@ public:
CharacterRenderer();
~CharacterRenderer();
bool initialize(VkContext* ctx, VkDescriptorSetLayout perFrameLayout, pipeline::AssetManager* am,
[[nodiscard]] bool initialize(VkContext* ctx, VkDescriptorSetLayout perFrameLayout, pipeline::AssetManager* am,
VkRenderPass renderPassOverride = VK_NULL_HANDLE,
VkSampleCountFlagBits msaaSamples = VK_SAMPLE_COUNT_1_BIT);
void shutdown();
@ -71,7 +71,7 @@ public:
void prepareRender(uint32_t frameIndex);
void render(VkCommandBuffer cmd, VkDescriptorSet perFrameSet, const Camera& camera);
void recreatePipelines();
bool initializeShadow(VkRenderPass shadowRenderPass);
[[nodiscard]] bool initializeShadow(VkRenderPass shadowRenderPass);
void renderShadow(VkCommandBuffer cmd, const glm::mat4& lightSpaceMatrix,
const glm::vec3& shadowCenter = glm::vec3(0), float shadowRadius = 1e9f);

View file

@ -22,7 +22,7 @@ public:
ChargeEffect();
~ChargeEffect();
bool initialize(VkContext* ctx, VkDescriptorSetLayout perFrameLayout);
[[nodiscard]] bool initialize(VkContext* ctx, VkDescriptorSetLayout perFrameLayout);
void shutdown();
void recreatePipelines();

View file

@ -26,7 +26,7 @@ public:
Lightning();
~Lightning();
bool initialize(VkContext* ctx, VkDescriptorSetLayout perFrameLayout);
[[nodiscard]] bool initialize(VkContext* ctx, VkDescriptorSetLayout perFrameLayout);
void shutdown();
void recreatePipelines();

View file

@ -276,7 +276,7 @@ public:
M2Renderer();
~M2Renderer();
bool initialize(VkContext* ctx, VkDescriptorSetLayout perFrameLayout,
[[nodiscard]] bool initialize(VkContext* ctx, VkDescriptorSetLayout perFrameLayout,
pipeline::AssetManager* assets);
void shutdown();
@ -310,7 +310,7 @@ public:
/**
* Initialize shadow pipeline (Phase 7)
*/
bool initializeShadow(VkRenderPass shadowRenderPass);
[[nodiscard]] bool initializeShadow(VkRenderPass shadowRenderPass);
bool hasShadowPipeline() const { return shadowPipeline_ != VK_NULL_HANDLE; }
/**

View file

@ -16,7 +16,7 @@ public:
MountDust();
~MountDust();
bool initialize(VkContext* ctx, VkDescriptorSetLayout perFrameLayout);
[[nodiscard]] bool initialize(VkContext* ctx, VkDescriptorSetLayout perFrameLayout);
void shutdown();
void recreatePipelines();

View file

@ -25,7 +25,7 @@ public:
QuestMarkerRenderer();
~QuestMarkerRenderer();
bool initialize(VkContext* ctx, VkDescriptorSetLayout perFrameLayout, pipeline::AssetManager* assetManager);
[[nodiscard]] bool initialize(VkContext* ctx, VkDescriptorSetLayout perFrameLayout, pipeline::AssetManager* assetManager);
void shutdown();
void recreatePipelines();

View file

@ -0,0 +1,74 @@
#pragma once
#include <cstdint>
// Rendering-domain constants: distances, LOD thresholds, particle tuning.
namespace wowee {
namespace rendering {
// ---------------------------------------------------------------------------
// M2 instance-count → render-distance mapping
// ---------------------------------------------------------------------------
constexpr uint32_t M2_HIGH_DENSITY_INSTANCE_THRESHOLD = 2000;
constexpr float M2_MAX_RENDER_DISTANCE_HIGH_DENSITY = 800.0f;
constexpr float M2_MAX_RENDER_DISTANCE_LOW_DENSITY = 2800.0f;
// ---------------------------------------------------------------------------
// M2 LOD / bone-update distance thresholds (world units)
// ---------------------------------------------------------------------------
constexpr float M2_LOD3_DISTANCE = 150.0f; // Beyond this: no bone updates
constexpr float M2_BONE_SKIP_DIST_FAR = 100.0f; // Beyond this: every 4th frame
constexpr float M2_BONE_SKIP_DIST_MID = 50.0f; // Beyond this: every 2nd frame
// ---------------------------------------------------------------------------
// M2 culling geometry
// ---------------------------------------------------------------------------
constexpr float M2_CULL_RADIUS_SCALE_DIVISOR = 12.0f;
constexpr float M2_PADDED_RADIUS_SCALE = 1.5f;
constexpr float M2_PADDED_RADIUS_MIN_MARGIN = 3.0f;
// ---------------------------------------------------------------------------
// M2 variation / idle animation timing (milliseconds)
// ---------------------------------------------------------------------------
constexpr float M2_VARIATION_TIMER_MIN_MS = 3000.0f;
constexpr float M2_VARIATION_TIMER_MAX_MS = 11000.0f;
constexpr float M2_LOOP_VARIATION_TIMER_MIN_MS = 4000.0f;
constexpr float M2_LOOP_VARIATION_TIMER_MAX_MS = 10000.0f;
constexpr float M2_IDLE_VARIATION_TIMER_MIN_MS = 2000.0f;
constexpr float M2_IDLE_VARIATION_TIMER_MAX_MS = 6000.0f;
constexpr float M2_DEFAULT_PARTICLE_ANIM_MS = 3333.0f;
// ---------------------------------------------------------------------------
// HiZ occlusion culling
// ---------------------------------------------------------------------------
// VP matrix diff threshold — below this HiZ is considered safe.
// Typical tracking camera (following a walking character) produces 0.050.25.
constexpr float HIZ_VP_DIFF_THRESHOLD = 0.5f;
// ---------------------------------------------------------------------------
// Smoke / spark particle tuning
// ---------------------------------------------------------------------------
constexpr float SMOKE_OFFSET_XY_MIN = -0.4f;
constexpr float SMOKE_OFFSET_XY_MAX = 0.4f;
constexpr float SMOKE_VEL_Z_MIN = 3.0f;
constexpr float SMOKE_VEL_Z_MAX = 5.0f;
constexpr float SMOKE_LIFETIME_MIN = 4.0f;
constexpr float SMOKE_LIFETIME_MAX = 7.0f;
constexpr float SMOKE_Z_VEL_DAMPING = 0.98f;
constexpr float SMOKE_SIZE_START = 1.0f;
constexpr float SMOKE_SIZE_GROWTH = 2.5f;
constexpr int SPARK_PROBABILITY_DENOM = 8; // 1-in-8 chance per frame
constexpr float SPARK_LIFE_BASE = 0.8f;
constexpr float SPARK_LIFE_RANGE = 1.2f;
// ---------------------------------------------------------------------------
// Character rendering
// ---------------------------------------------------------------------------
// Default frustum-cull radius when model bounds are unavailable (world units).
// 4.0 covers Tauren, mounted characters, and most creature models.
constexpr float DEFAULT_CHARACTER_CULL_RADIUS = 4.0f;
} // namespace rendering
} // namespace wowee

View file

@ -19,7 +19,7 @@ public:
SwimEffects();
~SwimEffects();
bool initialize(VkContext* ctx, VkDescriptorSetLayout perFrameLayout);
[[nodiscard]] bool initialize(VkContext* ctx, VkDescriptorSetLayout perFrameLayout);
void shutdown();
void recreatePipelines();
void update(const Camera& camera, const CameraController& cc,

View file

@ -41,7 +41,7 @@ public:
* @param perFrameLayout Descriptor set layout for the per-frame UBO (set 0)
* @return true if initialization succeeded
*/
bool initialize(VkContext* ctx, VkDescriptorSetLayout perFrameLayout);
[[nodiscard]] bool initialize(VkContext* ctx, VkDescriptorSetLayout perFrameLayout);
void recreatePipelines();
/**

View file

@ -49,7 +49,7 @@ public:
* @param perFrameLayout Descriptor set layout for set 0 (per-frame UBO)
* @param assetManager Asset manager for loading textures (optional)
*/
bool initialize(VkContext* ctx, VkDescriptorSetLayout perFrameLayout,
[[nodiscard]] bool initialize(VkContext* ctx, VkDescriptorSetLayout perFrameLayout,
pipeline::AssetManager* assetManager = nullptr);
/**
@ -163,7 +163,7 @@ public:
/**
* Initialize shadow pipeline (Phase 7)
*/
bool initializeShadow(VkRenderPass shadowRenderPass);
[[nodiscard]] bool initializeShadow(VkRenderPass shadowRenderPass);
/**
* Render depth-only for shadow casting