perf: eliminate ~70 unnecessary sqrt ops per frame, optimize caches and threading

Squared distance optimizations across 30 files:
- Convert glm::length() comparisons to glm::dot() (no sqrt)
- Use glm::inversesqrt() for check-then-normalize patterns (1 rsqrt vs 2 sqrt)
- Defer sqrt to after early-out checks in collision/movement code
- Hottest paths: camera_controller (21), weather particles, WMO collision,
  transport movement, creature interpolation, nameplate culling

Container and algorithm improvements:
- std::map<string> → std::unordered_map for asset/DBC/MPQ/warden caches
- std::mutex → std::shared_mutex for asset_manager and mpq_manager caches
- std::sort → std::partial_sort in lighting_manager (top-2 of N volumes)
- Double-lookup find()+operator[] → insert_or_assign in game_handler
- Add reserve() for per-frame vectors: weather, swim_effects, WMO/M2 collision

Threading and synchronization:
- Replace 1ms busy-wait polling with condition_variable in character_renderer
- Move timestamp capture before mutex in logger
- Use memory_order_acquire/release for normal map completion signaling

API additions:
- DBC getStringView()/getStringViewByOffset() for zero-copy string access
- Parse creature display IDs from SMSG_CREATURE_QUERY_SINGLE_RESPONSE
This commit is contained in:
Kelsi 2026-03-27 16:33:16 -07:00
parent cf0e2aa240
commit b0466e9029
29 changed files with 328 additions and 196 deletions

View file

@ -449,8 +449,9 @@ void ChargeEffect::emit(const glm::vec3& position, const glm::vec3& direction) {
}
// Only add a new trail point if we've moved enough
float dist = glm::length(position - lastEmitPos_);
if (dist >= TRAIL_SPAWN_DIST || trail_.empty()) {
glm::vec3 emitDelta = position - lastEmitPos_;
float distSq = glm::dot(emitDelta, emitDelta);
if (distSq >= TRAIL_SPAWN_DIST * TRAIL_SPAWN_DIST || trail_.empty()) {
// Ribbon is vertical: side vector points straight up
glm::vec3 side = glm::vec3(0.0f, 0.0f, 1.0f);
@ -466,9 +467,10 @@ void ChargeEffect::emit(const glm::vec3& position, const glm::vec3& direction) {
// Spawn dust puffs at feet
glm::vec3 horizDir = glm::vec3(direction.x, direction.y, 0.0f);
float horizLen = glm::length(horizDir);
if (horizLen < 0.001f) return;
glm::vec3 backDir = -horizDir / horizLen;
float horizLenSq = glm::dot(horizDir, horizDir);
if (horizLenSq < 1e-6f) return;
float invHorizLen = glm::inversesqrt(horizLenSq);
glm::vec3 backDir = -horizDir * invHorizLen;
glm::vec3 sideDir = glm::vec3(-backDir.y, backDir.x, 0.0f);
dustAccum_ += 30.0f * 0.016f;