diff --git a/stepmania/src/BannerCache.cpp b/stepmania/src/BannerCache.cpp index 4371c26b2f..b9963ec0d2 100644 --- a/stepmania/src/BannerCache.cpp +++ b/stepmania/src/BannerCache.cpp @@ -4,6 +4,7 @@ #include "RageUtil.h" #include "RageLog.h" #include "BannerCache.h" +#include "PrefsManager.h" #include "SDL_utils.h" #include "SDL_dither.h" #include "SDL_image.h" @@ -37,6 +38,10 @@ CString BannerCache::GetBannerCachePath( CString BannerPath ) /* Load all banners that havn't been loaded already. */ void BannerCache::LoadAllBanners() { + LOG->Trace("guh %i", PREFSMAN->m_bBannerCache); + if( !PREFSMAN->m_bBannerCache ) + return; + /* Load all banners. */ IniFile::const_iterator it = BannerData.begin(); for( ; it != BannerData.end(); ++it ) @@ -58,6 +63,17 @@ void BannerCache::LoadAllBanners() m_BannerPathToImage[BannerPath] = img; } + + + map::iterator ban; + int total_size = 0; + for( ban = m_BannerPathToImage.begin(); ban != m_BannerPathToImage.end(); ++ban ) + { + const SDL_Surface *&img = ban->second; + const int size = img->pitch * img->h; + total_size += size; + } + LOG->Info( "%i bytes of banners loaded", total_size ); } void BannerCache::UnloadAllBanners() @@ -228,6 +244,8 @@ static inline int closest( int num, int n1, int n2 ) return n1; } +/* We write the cache even if we won't use it, so we don't have to recache everything + * if the memory or settings change. */ void BannerCache::CacheSongBanner( CString BannerPath ) { SDL_Surface *img = IMG_Load( BannerPath ); @@ -325,7 +343,10 @@ void BannerCache::CacheSongBanner( CString BannerPath ) mySDL_SaveSurface( img, Path ); - m_BannerPathToImage[BannerPath] = img; + if( PREFSMAN->m_bBannerCache ) + m_BannerPathToImage[BannerPath] = img; + else + SDL_FreeSurface(img); /* Remember the original size. */ BannerData.SetValue ( BannerPath, "Path", Path ); diff --git a/stepmania/src/PrefsManager.cpp b/stepmania/src/PrefsManager.cpp index 7ad721f8c0..a565d7c85b 100644 --- a/stepmania/src/PrefsManager.cpp +++ b/stepmania/src/PrefsManager.cpp @@ -76,6 +76,7 @@ PrefsManager::PrefsManager() m_bSoloSingle = false; m_bDelayedTextureDelete = true; m_bDelayedScreenLoad = false; + m_bBannerCache = false; // XXX m_MusicWheelUsesSections = ALWAYS; m_iMusicWheelSwitchSpeed = 10; m_bEasterEggs = true; @@ -181,6 +182,7 @@ void PrefsManager::ReadGlobalPrefsFromDisk( bool bSwitchToLastPlayedGame ) ini.GetValue ( "Options", "DWIPath", m_DWIPath ); ini.GetValueB( "Options", "DelayedTextureDelete", m_bDelayedTextureDelete ); ini.GetValueB( "Options", "DelayedScreenLoad", m_bDelayedScreenLoad ); + ini.GetValueB( "Options", "BannerCache", m_bBannerCache ); ini.GetValueI( "Options", "MusicWheelUsesSections", (int&)m_MusicWheelUsesSections ); ini.GetValueI( "Options", "MusicWheelSwitchSpeed", m_iMusicWheelSwitchSpeed ); ini.GetValue ( "Options", "SoundDrivers", m_sSoundDrivers ); @@ -277,6 +279,7 @@ void PrefsManager::SaveGlobalPrefsToDisk() ini.SetValue ( "Options", "DWIPath", m_DWIPath ); ini.SetValueB( "Options", "DelayedTextureDelete", m_bDelayedTextureDelete ); ini.SetValueB( "Options", "DelayedScreenLoad", m_bDelayedScreenLoad ); + ini.SetValueB( "Options", "BannerCache", m_bBannerCache ); ini.SetValueI( "Options", "MusicWheelUsesSections", m_MusicWheelUsesSections ); ini.SetValueI( "Options", "MusicWheelSwitchSpeed", m_iMusicWheelSwitchSpeed ); ini.SetValueB( "Options", "EasterEggs", m_bEasterEggs ); diff --git a/stepmania/src/PrefsManager.h b/stepmania/src/PrefsManager.h index be8d537480..74109d55a8 100644 --- a/stepmania/src/PrefsManager.h +++ b/stepmania/src/PrefsManager.h @@ -36,6 +36,7 @@ public: bool m_bVsync; bool m_bDelayedTextureDelete; bool m_bDelayedScreenLoad; + bool m_bBannerCache; bool m_bIgnoreJoyAxes; bool m_bOnlyDedicatedMenuButtons; diff --git a/stepmania/src/StepMania.cpp b/stepmania/src/StepMania.cpp index 9c622ecc09..75a255d538 100644 --- a/stepmania/src/StepMania.cpp +++ b/stepmania/src/StepMania.cpp @@ -237,16 +237,17 @@ static void CheckSettings() * Actually, Windows lops off a meg or two; cut off a little lower to treat * 192-meg systems as high-memory. */ const bool HighMemory = (Memory >= 190); + const bool LowMemory = (Memory < 100); /* 64 and 96-meg systems */ /* Two memory-consuming features that we can disable are texture caching and * preloaded banners. Texture caching can use a lot of memory; disable it for * low-memory systems. */ PREFSMAN->m_bDelayedTextureDelete = HighMemory; - /* Preloaded banners takes about 9k per song. That adds up with a lot of songs, - * though it's smaller than the actual song data that we preload anyway. Maybe - * we should disable it for 64-meg systems? */ - // PREFSMAN->m_bPreloadBanners = !LowMemory; + /* Preloaded banners takes about 9k per song. Although it's smaller than the + * actual song data, it still adds up with a lot of songs. Disable it for 64-meg + * systems. */ + PREFSMAN->m_bBannerCache = !LowMemory; PREFSMAN->SaveGlobalPrefsToDisk(); #endif @@ -460,6 +461,8 @@ int main(int argc, char* argv[]) // GAMESTATE = new GameState; PREFSMAN = new PrefsManager; + CheckSettings(); + GAMEMAN = new GameManager; THEME = new ThemeManager; NOTESKIN = new NoteSkinManager; @@ -483,8 +486,6 @@ int main(int argc, char* argv[]) PREFSMAN->ReadGlobalPrefsFromDisk( true ); PREFSMAN->ReadGamePrefsFromDisk(); - CheckSettings(); - DISPLAY = CreateDisplay(); TEXTUREMAN = new RageTextureManager(); TEXTUREMAN->SetPrefs(