Change: Simplify sprite cache memory management

* Remove custom allocator
* Use std::unique_ptr for sprite data
* Perform LRU cache eviction in a single pass
This commit is contained in:
Peter Nelson
2024-01-28 14:46:58 +00:00
committed by Peter Nelson
parent 1d67094863
commit 7744f49a9e
4 changed files with 99 additions and 247 deletions

View File

@@ -19,15 +19,16 @@
static bool MockLoadNextSprite(SpriteID load_index)
{
static UniquePtrSpriteAllocator allocator;
static Sprite *sprite = allocator.Allocate<Sprite>(sizeof(*sprite));
UniquePtrSpriteAllocator allocator;
allocator.Allocate<Sprite>(sizeof(Sprite));
bool is_mapgen = IsMapgenSpriteID(load_index);
SpriteCache *sc = AllocateSpriteCache(load_index);
sc->file = nullptr;
sc->file_pos = 0;
sc->ptr = sprite;
sc->ptr = std::move(allocator.data);
sc->length = static_cast<uint32_t>(allocator.size);
sc->lru = 0;
sc->id = 0;
sc->type = is_mapgen ? SpriteType::MapGen : SpriteType::Normal;