Throttle proactive tile streaming to reduce post-load hitching

Add 2-second cooldown timer before re-checking for unloaded tiles
when workers are idle, preventing excessive streamTiles() calls
that caused frame hitches right after world load.
This commit is contained in:
Kelsi 2026-03-07 22:40:07 -08:00
parent c13dbf2198
commit 6cf08fbaa6
2 changed files with 15 additions and 10 deletions

View file

@ -348,6 +348,7 @@ private:
int unloadRadius = 7; // Unload tiles beyond this radius
float updateInterval = 0.033f; // Check streaming every 33ms (~30 fps)
float timeSinceLastUpdate = 0.0f;
float proactiveStreamTimer_ = 0.0f;
bool taxiStreamingMode_ = false;
// Tile size constants (WoW ADT specifications)

View file

@ -207,16 +207,20 @@ void TerrainManager::update(const Camera& camera, float deltaTime) {
streamTiles();
lastStreamTile = newTile;
} else {
// Proactive loading: when workers are idle, re-check for unloaded tiles
// within range. This catches tiles that weren't queued on the initial
// streamTiles pass (e.g. cache eviction, late-arriving ADT availability).
bool workersIdle;
{
std::lock_guard<std::mutex> lock(queueMutex);
workersIdle = loadQueue.empty();
}
if (workersIdle) {
streamTiles();
// Proactive loading: when workers are idle, periodically re-check for
// unloaded tiles within range. Throttled to avoid hitching right after
// world load when many tiles finalize simultaneously.
proactiveStreamTimer_ += deltaTime;
if (proactiveStreamTimer_ >= 2.0f) {
proactiveStreamTimer_ = 0.0f;
bool workersIdle;
{
std::lock_guard<std::mutex> lock(queueMutex);
workersIdle = loadQueue.empty();
}
if (workersIdle) {
streamTiles();
}
}
}
}