Kelsidavis-WoWee/include/rendering/quest_marker_renderer.hpp
Pavel Okhlopkov 97106bd6ae 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>
2026-04-06 22:43:13 +03:00

96 lines
2.8 KiB
C++

#pragma once
#include <glm/glm.hpp>
#include <vulkan/vulkan.h>
#include <vk_mem_alloc.h>
#include <cstdint>
#include <vector>
#include <unordered_map>
#include "rendering/vk_texture.hpp"
namespace wowee {
namespace pipeline { class AssetManager; }
namespace rendering {
class Camera;
class VkContext;
/**
* Renders quest markers as billboarded sprites above NPCs
* Uses BLP textures from Interface\GossipFrame\
*/
class QuestMarkerRenderer {
public:
QuestMarkerRenderer();
~QuestMarkerRenderer();
[[nodiscard]] bool initialize(VkContext* ctx, VkDescriptorSetLayout perFrameLayout, pipeline::AssetManager* assetManager);
void shutdown();
void recreatePipelines();
/**
* Add or update a quest marker at a position
* @param guid NPC GUID
* @param position World position (NPC base position)
* @param markerType 0=available(!), 1=turnin(?), 2=incomplete(?)
* @param boundingHeight NPC bounding height (optional, default 2.0f)
* @param grayscale 0 = full colour, 1 = desaturated grey (trivial/low-level quests)
*/
void setMarker(uint64_t guid, const glm::vec3& position, int markerType,
float boundingHeight = 2.0f, float grayscale = 0.0f);
/**
* Remove a quest marker
*/
void removeMarker(uint64_t guid);
/**
* Clear all markers
*/
void clear();
/**
* Render all quest markers (call after world rendering, before UI)
* @param cmd Command buffer to record into
* @param perFrameSet Per-frame descriptor set (set 0, contains camera UBO)
* @param camera Camera for billboard calculation (CPU-side view matrix)
*/
void render(VkCommandBuffer cmd, VkDescriptorSet perFrameSet, const Camera& camera);
private:
struct Marker {
glm::vec3 position;
int type; // 0=available, 1=turnin, 2=incomplete
float boundingHeight = 2.0f;
float grayscale = 0.0f; // 0 = colour, 1 = desaturated (trivial quests)
};
std::unordered_map<uint64_t, Marker> markers_;
// Vulkan context
VkContext* vkCtx_ = nullptr;
// Pipeline
VkPipeline pipeline_ = VK_NULL_HANDLE;
VkPipelineLayout pipelineLayout_ = VK_NULL_HANDLE;
// Descriptor resources for per-material texture (set 1)
VkDescriptorSetLayout materialSetLayout_ = VK_NULL_HANDLE;
VkDescriptorPool descriptorPool_ = VK_NULL_HANDLE;
VkDescriptorSet texDescSets_[3] = {VK_NULL_HANDLE, VK_NULL_HANDLE, VK_NULL_HANDLE};
// Textures: available, turnin, incomplete
VkTexture textures_[3];
// Quad vertex buffer
VkBuffer quadVB_ = VK_NULL_HANDLE;
VmaAllocation quadVBAlloc_ = VK_NULL_HANDLE;
void createQuad();
void loadTextures(pipeline::AssetManager* assetManager);
void createDescriptorResources();
};
} // namespace rendering
} // namespace wowee