Don't preload low-quality banners on very low-memory systems.

This commit is contained in:
Glenn Maynard
2003-06-11 02:58:13 +00:00
parent 9410457599
commit 5faa1d7c17
4 changed files with 33 additions and 7 deletions
+22 -1
View File
@@ -4,6 +4,7 @@
#include "RageUtil.h" #include "RageUtil.h"
#include "RageLog.h" #include "RageLog.h"
#include "BannerCache.h" #include "BannerCache.h"
#include "PrefsManager.h"
#include "SDL_utils.h" #include "SDL_utils.h"
#include "SDL_dither.h" #include "SDL_dither.h"
#include "SDL_image.h" #include "SDL_image.h"
@@ -37,6 +38,10 @@ CString BannerCache::GetBannerCachePath( CString BannerPath )
/* Load all banners that havn't been loaded already. */ /* Load all banners that havn't been loaded already. */
void BannerCache::LoadAllBanners() void BannerCache::LoadAllBanners()
{ {
LOG->Trace("guh %i", PREFSMAN->m_bBannerCache);
if( !PREFSMAN->m_bBannerCache )
return;
/* Load all banners. */ /* Load all banners. */
IniFile::const_iterator it = BannerData.begin(); IniFile::const_iterator it = BannerData.begin();
for( ; it != BannerData.end(); ++it ) for( ; it != BannerData.end(); ++it )
@@ -58,6 +63,17 @@ void BannerCache::LoadAllBanners()
m_BannerPathToImage[BannerPath] = img; m_BannerPathToImage[BannerPath] = img;
} }
map<CString,SDL_Surface *>::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() void BannerCache::UnloadAllBanners()
@@ -228,6 +244,8 @@ static inline int closest( int num, int n1, int n2 )
return n1; 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 ) void BannerCache::CacheSongBanner( CString BannerPath )
{ {
SDL_Surface *img = IMG_Load( BannerPath ); SDL_Surface *img = IMG_Load( BannerPath );
@@ -325,7 +343,10 @@ void BannerCache::CacheSongBanner( CString BannerPath )
mySDL_SaveSurface( img, Path ); mySDL_SaveSurface( img, Path );
m_BannerPathToImage[BannerPath] = img; if( PREFSMAN->m_bBannerCache )
m_BannerPathToImage[BannerPath] = img;
else
SDL_FreeSurface(img);
/* Remember the original size. */ /* Remember the original size. */
BannerData.SetValue ( BannerPath, "Path", Path ); BannerData.SetValue ( BannerPath, "Path", Path );
+3
View File
@@ -76,6 +76,7 @@ PrefsManager::PrefsManager()
m_bSoloSingle = false; m_bSoloSingle = false;
m_bDelayedTextureDelete = true; m_bDelayedTextureDelete = true;
m_bDelayedScreenLoad = false; m_bDelayedScreenLoad = false;
m_bBannerCache = false; // XXX
m_MusicWheelUsesSections = ALWAYS; m_MusicWheelUsesSections = ALWAYS;
m_iMusicWheelSwitchSpeed = 10; m_iMusicWheelSwitchSpeed = 10;
m_bEasterEggs = true; m_bEasterEggs = true;
@@ -181,6 +182,7 @@ void PrefsManager::ReadGlobalPrefsFromDisk( bool bSwitchToLastPlayedGame )
ini.GetValue ( "Options", "DWIPath", m_DWIPath ); ini.GetValue ( "Options", "DWIPath", m_DWIPath );
ini.GetValueB( "Options", "DelayedTextureDelete", m_bDelayedTextureDelete ); ini.GetValueB( "Options", "DelayedTextureDelete", m_bDelayedTextureDelete );
ini.GetValueB( "Options", "DelayedScreenLoad", m_bDelayedScreenLoad ); ini.GetValueB( "Options", "DelayedScreenLoad", m_bDelayedScreenLoad );
ini.GetValueB( "Options", "BannerCache", m_bBannerCache );
ini.GetValueI( "Options", "MusicWheelUsesSections", (int&)m_MusicWheelUsesSections ); ini.GetValueI( "Options", "MusicWheelUsesSections", (int&)m_MusicWheelUsesSections );
ini.GetValueI( "Options", "MusicWheelSwitchSpeed", m_iMusicWheelSwitchSpeed ); ini.GetValueI( "Options", "MusicWheelSwitchSpeed", m_iMusicWheelSwitchSpeed );
ini.GetValue ( "Options", "SoundDrivers", m_sSoundDrivers ); ini.GetValue ( "Options", "SoundDrivers", m_sSoundDrivers );
@@ -277,6 +279,7 @@ void PrefsManager::SaveGlobalPrefsToDisk()
ini.SetValue ( "Options", "DWIPath", m_DWIPath ); ini.SetValue ( "Options", "DWIPath", m_DWIPath );
ini.SetValueB( "Options", "DelayedTextureDelete", m_bDelayedTextureDelete ); ini.SetValueB( "Options", "DelayedTextureDelete", m_bDelayedTextureDelete );
ini.SetValueB( "Options", "DelayedScreenLoad", m_bDelayedScreenLoad ); ini.SetValueB( "Options", "DelayedScreenLoad", m_bDelayedScreenLoad );
ini.SetValueB( "Options", "BannerCache", m_bBannerCache );
ini.SetValueI( "Options", "MusicWheelUsesSections", m_MusicWheelUsesSections ); ini.SetValueI( "Options", "MusicWheelUsesSections", m_MusicWheelUsesSections );
ini.SetValueI( "Options", "MusicWheelSwitchSpeed", m_iMusicWheelSwitchSpeed ); ini.SetValueI( "Options", "MusicWheelSwitchSpeed", m_iMusicWheelSwitchSpeed );
ini.SetValueB( "Options", "EasterEggs", m_bEasterEggs ); ini.SetValueB( "Options", "EasterEggs", m_bEasterEggs );
+1
View File
@@ -36,6 +36,7 @@ public:
bool m_bVsync; bool m_bVsync;
bool m_bDelayedTextureDelete; bool m_bDelayedTextureDelete;
bool m_bDelayedScreenLoad; bool m_bDelayedScreenLoad;
bool m_bBannerCache;
bool m_bIgnoreJoyAxes; bool m_bIgnoreJoyAxes;
bool m_bOnlyDedicatedMenuButtons; bool m_bOnlyDedicatedMenuButtons;
+7 -6
View File
@@ -237,16 +237,17 @@ static void CheckSettings()
* Actually, Windows lops off a meg or two; cut off a little lower to treat * Actually, Windows lops off a meg or two; cut off a little lower to treat
* 192-meg systems as high-memory. */ * 192-meg systems as high-memory. */
const bool HighMemory = (Memory >= 190); 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 /* 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 * preloaded banners. Texture caching can use a lot of memory; disable it for
* low-memory systems. */ * low-memory systems. */
PREFSMAN->m_bDelayedTextureDelete = HighMemory; PREFSMAN->m_bDelayedTextureDelete = HighMemory;
/* Preloaded banners takes about 9k per song. That adds up with a lot of songs, /* Preloaded banners takes about 9k per song. Although it's smaller than the
* though it's smaller than the actual song data that we preload anyway. Maybe * actual song data, it still adds up with a lot of songs. Disable it for 64-meg
* we should disable it for 64-meg systems? */ * systems. */
// PREFSMAN->m_bPreloadBanners = !LowMemory; PREFSMAN->m_bBannerCache = !LowMemory;
PREFSMAN->SaveGlobalPrefsToDisk(); PREFSMAN->SaveGlobalPrefsToDisk();
#endif #endif
@@ -460,6 +461,8 @@ int main(int argc, char* argv[])
// //
GAMESTATE = new GameState; GAMESTATE = new GameState;
PREFSMAN = new PrefsManager; PREFSMAN = new PrefsManager;
CheckSettings();
GAMEMAN = new GameManager; GAMEMAN = new GameManager;
THEME = new ThemeManager; THEME = new ThemeManager;
NOTESKIN = new NoteSkinManager; NOTESKIN = new NoteSkinManager;
@@ -483,8 +486,6 @@ int main(int argc, char* argv[])
PREFSMAN->ReadGlobalPrefsFromDisk( true ); PREFSMAN->ReadGlobalPrefsFromDisk( true );
PREFSMAN->ReadGamePrefsFromDisk(); PREFSMAN->ReadGamePrefsFromDisk();
CheckSettings();
DISPLAY = CreateDisplay(); DISPLAY = CreateDisplay();
TEXTUREMAN = new RageTextureManager(); TEXTUREMAN = new RageTextureManager();
TEXTUREMAN->SetPrefs( TEXTUREMAN->SetPrefs(