diff options
-rw-r--r-- | src/spritecache.cpp | 12 | ||||
-rw-r--r-- | src/table/misc_settings.ini | 4 |
2 files changed, 12 insertions, 4 deletions
diff --git a/src/spritecache.cpp b/src/spritecache.cpp index 4b705fc94..202f2f028 100644 --- a/src/spritecache.cpp +++ b/src/spritecache.cpp @@ -79,6 +79,7 @@ struct MemBlock { static uint _sprite_lru_counter; static MemBlock *_spritecache_ptr; +static uint _allocated_sprite_cache_size = 0; static int _compact_cache_counter; static void CompactSpriteCache(); @@ -843,10 +844,17 @@ void *GetRawSprite(SpriteID sprite, SpriteType type, AllocatorProc *allocator) static void GfxInitSpriteCache() { /* initialize sprite cache heap */ - if (_spritecache_ptr == NULL) _spritecache_ptr = (MemBlock*)MallocT<byte>(_sprite_cache_size * 1024 * 1024); + int bpp = BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth(); + uint target_size = _sprite_cache_size * 1024 * 1024 * max(1, bpp / 8); + + if (_spritecache_ptr == NULL || _allocated_sprite_cache_size != target_size) { + free(_spritecache_ptr); + _allocated_sprite_cache_size = target_size; + _spritecache_ptr = (MemBlock*)MallocT<byte>(_allocated_sprite_cache_size); + } /* A big free block */ - _spritecache_ptr->size = ((_sprite_cache_size * 1024 * 1024) - sizeof(MemBlock)) | S_FREE_MASK; + _spritecache_ptr->size = (_allocated_sprite_cache_size - sizeof(MemBlock)) | S_FREE_MASK; /* Sentinel block (identified by size == 0) */ NextBlock(_spritecache_ptr)->size = 0; } diff --git a/src/table/misc_settings.ini b/src/table/misc_settings.ini index 7e3c1539e..eeca619f1 100644 --- a/src/table/misc_settings.ini +++ b/src/table/misc_settings.ini @@ -213,10 +213,10 @@ var = _freetype.mono_aa def = false [SDTG_VAR] -name = ""max_sprite_cache_size"" +name = ""sprite_cache_size_px"" type = SLE_UINT var = _sprite_cache_size -def = 64 +def = 128 min = 1 max = 512 |