From d351f3dae5367b626fa93d97fd864dff545d67b7 Mon Sep 17 00:00:00 2001 From: frosch Date: Tue, 15 May 2012 20:37:42 +0000 Subject: (svn r24252) -Fix [FS#5162]: Change the unit of the sprite-cache size setting from megabytes to megapixels, so it depends on the blitter being used. Also increase it from 64 to 128, and change the name in the cfg file, so everyone gets the new default. --- src/spritecache.cpp | 12 ++++++++++-- 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(_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(_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 -- cgit v1.2.3-70-g09d2