diff --git a/include/rendering/minimap.hpp b/include/rendering/minimap.hpp index ca7c5345..906f4666 100644 --- a/include/rendering/minimap.hpp +++ b/include/rendering/minimap.hpp @@ -7,6 +7,7 @@ #include #include #include +#include #include namespace wowee { @@ -73,7 +74,10 @@ private: bool trsParsed = false; // Tile texture cache: hash → VkTexture + // Evicted (FIFO) when the count of successfully-loaded tiles exceeds MAX_TILE_CACHE. + static constexpr size_t MAX_TILE_CACHE = 128; std::unordered_map> tileTextureCache; + std::deque tileInsertionOrder; // hashes of successfully loaded tiles, oldest first std::unique_ptr noDataTexture; // Composite render target (3x3 tiles = 768x768) diff --git a/src/rendering/minimap.cpp b/src/rendering/minimap.cpp index f47264d0..cce494d9 100644 --- a/src/rendering/minimap.cpp +++ b/src/rendering/minimap.cpp @@ -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; }