make LogFPS a self-registering pref

This commit is contained in:
Chris Danford
2004-09-13 03:58:39 +00:00
parent 36a2a876ff
commit 825c972bf5
3 changed files with 46 additions and 6 deletions
+31 -3
View File
@@ -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<IPreference*> *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<IPreference*>;
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 );
}
+11 -1
View File
@@ -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). */
+4 -2
View File
@@ -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<bool> 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 );
}
}