perf: eliminate double map lookups, dynamic_cast in render loops, div by 255

- Replace count()+operator[] double lookups with find() or try_emplace()
  in gameObjectInstances_, playerTextureSlotsByModelId_, onlinePlayerAppearance_
- Add Entity::isUnit() helper; replace 5 dynamic_cast<Unit*> in per-frame
  UI rendering (nameplates, combat text, pet frame) with isUnit()+static_cast
- Add constexpr kInv255 reciprocal for per-pixel normal map generation loops
  in character_renderer and wmo_renderer
This commit is contained in:
Kelsi 2026-03-27 17:04:13 -07:00
parent 6f2c8962e5
commit 6b1c728377
5 changed files with 36 additions and 27 deletions

View file

@ -546,12 +546,13 @@ CharacterRenderer::NormalMapResult CharacterRenderer::generateNormalHeightMapCPU
const uint8_t* pixels = srcPixels.data();
// Step 1: Compute height from luminance
constexpr float kInv255 = 1.0f / 255.0f;
std::vector<float> heightMap(totalPixels);
double sumH = 0.0, sumH2 = 0.0;
for (uint32_t i = 0; i < totalPixels; i++) {
float r = pixels[i * 4 + 0] / 255.0f;
float g = pixels[i * 4 + 1] / 255.0f;
float b = pixels[i * 4 + 2] / 255.0f;
float r = pixels[i * 4 + 0] * kInv255;
float g = pixels[i * 4 + 1] * kInv255;
float b = pixels[i * 4 + 2] * kInv255;
float h = 0.299f * r + 0.587f * g + 0.114f * b;
heightMap[i] = h;
sumH += h;