Optimize city performance and harden WMO grounding

This commit is contained in:
Kelsi 2026-02-25 10:22:05 -08:00
parent dd4b72e046
commit 2219ccde51
8 changed files with 196 additions and 55 deletions

View file

@ -296,7 +296,8 @@ void AmbientSoundManager::updatePositionalEmitters(float deltaTime, const glm::v
const int MAX_ACTIVE_WATER = 3; // Max 3 water sounds at once
for (auto& emitter : emitters_) {
float distance = glm::distance(emitter.position, cameraPos);
const glm::vec3 delta = emitter.position - cameraPos;
const float distSq = glm::dot(delta, delta);
// Determine max distance based on type
float maxDist = MAX_AMBIENT_DISTANCE;
@ -317,7 +318,8 @@ void AmbientSoundManager::updatePositionalEmitters(float deltaTime, const glm::v
}
// Update active state based on distance AND limits
bool withinRange = (distance < maxDist);
const float maxDistSq = maxDist * maxDist;
const bool withinRange = (distSq < maxDistSq);
if (isFire && withinRange && activeFireCount < MAX_ACTIVE_FIRE) {
emitter.active = true;
@ -336,6 +338,9 @@ void AmbientSoundManager::updatePositionalEmitters(float deltaTime, const glm::v
// Update play timer
emitter.lastPlayTime += deltaTime;
// We only need the true distance for volume attenuation once the emitter is active.
const float distance = std::sqrt(distSq);
// Handle different emitter types
switch (emitter.type) {
case AmbientType::FIREPLACE_SMALL: