mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-04 16:23:52 +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
|
|
@ -7,6 +7,7 @@
|
|||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <deque>
|
||||
#include <algorithm>
|
||||
|
||||
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<std::string, std::unique_ptr<VkTexture>> tileTextureCache;
|
||||
std::deque<std::string> tileInsertionOrder; // hashes of successfully loaded tiles, oldest first
|
||||
std::unique_ptr<VkTexture> noDataTexture;
|
||||
|
||||
// Composite render target (3x3 tiles = 768x768)
|
||||
|
|
|
|||
|
|
@ -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