mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-03-22 23:30:14 +00:00
fix: evict oldest minimap tile textures when cache exceeds 128 entries
Prevents unbounded GPU memory growth in long play sessions where the player visits many zones. Tiles are inserted into a FIFO deque; when the count of successfully-loaded tiles exceeds MAX_TILE_CACHE (128), the oldest entry is destroyed and removed from both the cache map and the deque. At 256×256×4 bytes per tile this caps minimap GPU usage at ~32 MB.
This commit is contained in:
parent
217edc81d9
commit
a43a43ed8e
2 changed files with 14 additions and 0 deletions
|
|
@ -228,6 +228,7 @@ void Minimap::shutdown() {
|
|||
if (tex) tex->destroy(device, alloc);
|
||||
}
|
||||
tileTextureCache.clear();
|
||||
tileInsertionOrder.clear();
|
||||
|
||||
if (noDataTexture) { noDataTexture->destroy(device, alloc); noDataTexture.reset(); }
|
||||
if (compositeTarget) { compositeTarget->destroy(device, alloc); compositeTarget.reset(); }
|
||||
|
|
@ -362,6 +363,15 @@ VkTexture* Minimap::getOrLoadTileTexture(int tileX, int tileY) {
|
|||
|
||||
VkTexture* ptr = tex.get();
|
||||
tileTextureCache[hash] = std::move(tex);
|
||||
tileInsertionOrder.push_back(hash);
|
||||
|
||||
// Evict oldest tiles when cache grows too large to bound GPU memory usage.
|
||||
while (tileInsertionOrder.size() > MAX_TILE_CACHE) {
|
||||
const std::string& oldest = tileInsertionOrder.front();
|
||||
tileTextureCache.erase(oldest);
|
||||
tileInsertionOrder.pop_front();
|
||||
}
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue