diff --git a/stepmania/src/PrefsManager.cpp b/stepmania/src/PrefsManager.cpp index f24e196a74..4d8a8488d4 100644 --- a/stepmania/src/PrefsManager.cpp +++ b/stepmania/src/PrefsManager.cpp @@ -9,6 +9,8 @@ #include "RageFile.h" #include "ProductInfo.h" #include "GameConstantsAndTypes.h" +#include "Foreach.h" +#include "Preference.h" #define DEFAULTS_INI_PATH "Data/Defaults.ini" // these can be overridden #define STEPMANIA_INI_PATH "Data/StepMania.ini" // overlay on Defaults.ini, contains the user's choices @@ -19,6 +21,27 @@ PrefsManager* PREFSMAN = NULL; // global and accessable from anywhere in our pro const float DEFAULT_SOUND_VOLUME = 1.00f; const CString DEFAULT_LIGHTS_DRIVER = "Null"; + +// +// For self-registering prefs +// +vector *g_pvpSubscribers = NULL; + +void Subscribe( IPreference *p ) +{ + // TRICKY: If we make this a global vector instead of a global pointer, + // then we'd have to be careful that the static constructors of all + // Preferences are called before the vector constructor. It's + // too tricky to enfore that, so we'll allocate the vector ourself + // so that the compiler can't possibly call the vector constructor + // after we've already added to the vector. + if( g_pvpSubscribers == NULL ) + g_pvpSubscribers = new vector; + g_pvpSubscribers->push_back( p ); +} + + + bool g_bAutoRestart = false; PrefsManager::PrefsManager() @@ -278,7 +301,6 @@ void PrefsManager::Init() m_bTimestamping = false; m_bLogSkips = false; m_bLogCheckpoints = false; - m_bLogFPS = true; m_bShowLoadingWindow = true; m_bMemoryCards = false; @@ -292,6 +314,9 @@ void PrefsManager::Init() m_sMemoryCardProfileSubdir = PRODUCT_NAME; m_iProductID = 1; + + + FOREACH_CONST( IPreference*, *g_pvpSubscribers, p ) (*p)->LoadDefault(); } PrefsManager::~PrefsManager() @@ -552,8 +577,10 @@ void PrefsManager::ReadPrefsFromFile( CString sIni ) ini.GetValue( "Debug", "Timestamping", m_bTimestamping ); ini.GetValue( "Debug", "LogSkips", m_bLogSkips ); ini.GetValue( "Debug", "LogCheckpoints", m_bLogCheckpoints ); - ini.GetValue( "Debug", "LogFPS", m_bLogFPS ); ini.GetValue( "Debug", "ShowLoadingWindow", m_bShowLoadingWindow ); + + + FOREACH( IPreference*, *g_pvpSubscribers, p ) (*p)->ReadFrom( ini ); } void PrefsManager::SaveGlobalPrefsToDisk() const @@ -793,9 +820,10 @@ void PrefsManager::SaveGlobalPrefsToDisk() const ini.SetValue( "Debug", "Timestamping", m_bTimestamping ); ini.SetValue( "Debug", "LogSkips", m_bLogSkips ); ini.SetValue( "Debug", "LogCheckpoints", m_bLogCheckpoints ); - ini.SetValue( "Debug", "LogFPS", m_bLogFPS ); ini.SetValue( "Debug", "ShowLoadingWindow", m_bShowLoadingWindow ); + FOREACH_CONST( IPreference*, *g_pvpSubscribers, p ) (*p)->WriteTo( ini ); + ini.WriteFile( STEPMANIA_INI_PATH ); } diff --git a/stepmania/src/PrefsManager.h b/stepmania/src/PrefsManager.h index ccd97a2d8e..972e9fa7f5 100644 --- a/stepmania/src/PrefsManager.h +++ b/stepmania/src/PrefsManager.h @@ -6,6 +6,9 @@ #include "PlayerNumber.h" #include "Grade.h" // for NUM_GRADE_TIERS +class IPreference; +class IniFile; + class PrefsManager { public: @@ -268,7 +271,6 @@ public: bool m_bTimestamping; bool m_bLogSkips; bool m_bLogCheckpoints; - bool m_bLogFPS; bool m_bShowLoadingWindow; /* Game-specific prefs: */ @@ -281,8 +283,16 @@ public: protected: void ReadPrefsFromFile( CString sIni ); + }; + +// +// For self-registering prefs +// +void Subscribe( IPreference *p ); + + /* This is global, because it can be accessed by crash handlers and error handlers * that are run after PREFSMAN shuts down (and probably don't want to deref tht * pointer anyway). */ diff --git a/stepmania/src/RageDisplay.cpp b/stepmania/src/RageDisplay.cpp index 2dbbd4df6e..812126b57b 100644 --- a/stepmania/src/RageDisplay.cpp +++ b/stepmania/src/RageDisplay.cpp @@ -10,7 +10,7 @@ #include "RageSurface_Save_BMP.h" #include "SDL_rotozoom.h" #include "RageSurface.h" -#include "PrefsManager.h" +#include "Preference.h" // // Statistics stuff @@ -30,6 +30,8 @@ static int g_iFramesRenderedSinceLastCheck, RageDisplay* DISPLAY = NULL; +Preference LOG_FPS( Debug, "LogFPS", true ); + CString RageDisplay::PixelFormatToString( PixelFormat pixfmt ) { const CString s[NUM_PIX_FORMATS] = { @@ -109,7 +111,7 @@ void RageDisplay::ProcessStatsOnFlip() g_iCFPS = g_iFramesRenderedSinceLastReset / g_iNumChecksSinceLastReset; g_iVPF = g_iVertsRenderedSinceLastCheck / g_iFPS; g_iFramesRenderedSinceLastCheck = g_iVertsRenderedSinceLastCheck = 0; - if( PREFSMAN->m_bLogFPS ) + if( LOG_FPS.GetValue() ) LOG->Trace( "FPS: %d, CFPS %d, VPF: %d", g_iFPS, g_iCFPS, g_iVPF ); } }