move DifficultiesToShow into CommonMetrics

re-cache on theme reload, not on timer expired
This commit is contained in:
Chris Danford
2005-03-10 19:57:43 +00:00
parent 22d64c8fd9
commit 8b32383969
9 changed files with 98 additions and 101 deletions
+7 -10
View File
@@ -18,6 +18,7 @@
#include "ThemeManager.h" #include "ThemeManager.h"
#include "PrefsManager.h" #include "PrefsManager.h"
#include "Style.h" #include "Style.h"
#include "CommonMetrics.h"
#define SHOW_PLAY_MODE(pm) THEME->GetMetricB("CatalogXml",ssprintf("ShowPlayMode%s",PlayModeToString(pm).c_str())) #define SHOW_PLAY_MODE(pm) THEME->GetMetricB("CatalogXml",ssprintf("ShowPlayMode%s",PlayModeToString(pm).c_str()))
#define SHOW_STYLE(ps) THEME->GetMetricB("CatalogXml",ssprintf("ShowStyle%s",Capitalize((ps)->m_szName).c_str())) #define SHOW_STYLE(ps) THEME->GetMetricB("CatalogXml",ssprintf("ShowStyle%s",Capitalize((ps)->m_szName).c_str()))
@@ -63,8 +64,7 @@ void SaveCatalogXml()
pSongNode->AppendChild( "MainTitle", pSong->GetDisplayMainTitle() ); pSongNode->AppendChild( "MainTitle", pSong->GetDisplayMainTitle() );
pSongNode->AppendChild( "SubTitle", pSong->GetDisplaySubTitle() ); pSongNode->AppendChild( "SubTitle", pSong->GetDisplaySubTitle() );
set<Difficulty> vDiffs; const set<Difficulty> &vDiffs = CommonMetrics::GetDifficultiesToShow();
GAMESTATE->GetDifficultiesToShow( vDiffs );
FOREACH_StepsType( st ) FOREACH_StepsType( st )
{ {
@@ -111,8 +111,7 @@ void SaveCatalogXml()
pCourseNode->AppendChild( "SubTitle", pCourse->GetDisplaySubTitle() ); pCourseNode->AppendChild( "SubTitle", pCourse->GetDisplaySubTitle() );
pCourseNode->AppendChild( "HasMods", pCourse->HasMods() ); pCourseNode->AppendChild( "HasMods", pCourse->HasMods() );
set<CourseDifficulty> vDiffs; const set<CourseDifficulty> &vDiffs = CommonMetrics::GetCourseDifficultiesToShow();
GAMESTATE->GetCourseDifficultiesToShow( vDiffs );
FOREACH_StepsType( st ) FOREACH_StepsType( st )
{ {
@@ -144,9 +143,8 @@ void SaveCatalogXml()
XNode* pNode = xml.AppendChild( "Types" ); XNode* pNode = xml.AppendChild( "Types" );
{ {
set<Difficulty> vDiffs; const set<Difficulty> &vDiffs = CommonMetrics::GetDifficultiesToShow();
GAMESTATE->GetDifficultiesToShow( vDiffs ); FOREACHS_CONST( Difficulty, vDiffs, iter )
for( set<Difficulty>::const_iterator iter = vDiffs.begin(); iter != vDiffs.end(); iter++ )
{ {
XNode* pNode2 = pNode->AppendChild( "Difficulty", DifficultyToString(*iter) ); XNode* pNode2 = pNode->AppendChild( "Difficulty", DifficultyToString(*iter) );
pNode2->AppendAttr( "DisplayAs", DifficultyToThemedString(*iter) ); pNode2->AppendAttr( "DisplayAs", DifficultyToThemedString(*iter) );
@@ -154,9 +152,8 @@ void SaveCatalogXml()
} }
{ {
set<CourseDifficulty> vDiffs; const set<CourseDifficulty> &vDiffs = CommonMetrics::GetCourseDifficultiesToShow();
GAMESTATE->GetCourseDifficultiesToShow( vDiffs ); FOREACHS_CONST( CourseDifficulty, vDiffs, iter )
for( set<CourseDifficulty>::const_iterator iter = vDiffs.begin(); iter != vDiffs.end(); iter++ )
{ {
XNode* pNode2 = pNode->AppendChild( "CourseDifficulty", CourseDifficultyToString(*iter) ); XNode* pNode2 = pNode->AppendChild( "CourseDifficulty", CourseDifficultyToString(*iter) );
pNode2->AppendAttr( "DisplayAs", CourseDifficultyToThemedString(*iter) ); pNode2->AppendAttr( "DisplayAs", CourseDifficultyToThemedString(*iter) );
+60 -2
View File
@@ -1,16 +1,15 @@
#include "global.h" #include "global.h"
#include "CommonMetrics.h" #include "CommonMetrics.h"
#include "RageUtil.h" #include "RageUtil.h"
#include "Foreach.h"
CString PLAYER_COLOR_NAME( size_t p ) { return ssprintf("ColorP%d",p+1); } CString PLAYER_COLOR_NAME( size_t p ) { return ssprintf("ColorP%d",p+1); }
ThemeMetric<CString> DIFFICULTIES_TO_SHOW ("Common","DifficultiesToShow");
ThemeMetric<CString> INITIAL_SCREEN ("Common","InitialScreen"); ThemeMetric<CString> INITIAL_SCREEN ("Common","InitialScreen");
ThemeMetric<CString> FIRST_RUN_INITIAL_SCREEN ("Common","FirstRunInitialScreen"); ThemeMetric<CString> FIRST_RUN_INITIAL_SCREEN ("Common","FirstRunInitialScreen");
ThemeMetric<CString> DEFAULT_MODIFIERS ("Common","DefaultModifiers" ); ThemeMetric<CString> DEFAULT_MODIFIERS ("Common","DefaultModifiers" );
ThemeMetric<CString> DEFAULT_CPU_MODIFIERS ("Common","DefaultCpuModifiers" ); ThemeMetric<CString> DEFAULT_CPU_MODIFIERS ("Common","DefaultCpuModifiers" );
ThemeMetric<CString> COURSE_DIFFICULTIES_TO_SHOW ("Common","CourseDifficultiesToShow");
ThemeMetric1D<RageColor> PLAYER_COLOR ("Common",PLAYER_COLOR_NAME,NUM_PLAYERS); ThemeMetric1D<RageColor> PLAYER_COLOR ("Common",PLAYER_COLOR_NAME,NUM_PLAYERS);
ThemeMetric<float> JOIN_PAUSE_SECONDS ("Common","JoinPauseSeconds"); ThemeMetric<float> JOIN_PAUSE_SECONDS ("Common","JoinPauseSeconds");
ThemeMetric<CString> WINDOW_TITLE ("Common","WindowTitle"); ThemeMetric<CString> WINDOW_TITLE ("Common","WindowTitle");
@@ -18,6 +17,65 @@ ThemeMetric<bool> HOME_EDIT_MODE ("Common","HomeEditMode");
ThemeMetric<int> MAX_STEPS_LOADED_FROM_PROFILE ("Common","MaxStepsLoadedFromProfile"); ThemeMetric<int> MAX_STEPS_LOADED_FROM_PROFILE ("Common","MaxStepsLoadedFromProfile");
class ThemeMetricDifficultiesToShow : ThemeMetric<CString>
{
public:
set<Difficulty> m_v;
ThemeMetricDifficultiesToShow() : ThemeMetric<CString>("Common","DifficultiesToShow") {}
void Read()
{
ThemeMetric<CString>::Read();
m_v.clear();
CStringArray v;
split( GetValue(), ",", v );
ASSERT( v.size() > 0 );
FOREACH_CONST( CString, v, i )
{
Difficulty d = StringToDifficulty( *i );
if( d == DIFFICULTY_INVALID )
RageException::Throw( "Unknown difficulty \"%s\" in CourseDifficultiesToShow", i->c_str() );
m_v.insert( d );
}
}
};
ThemeMetricDifficultiesToShow DIFFICULTIES_TO_SHOW;
const set<Difficulty>& CommonMetrics::GetDifficultiesToShow() { return DIFFICULTIES_TO_SHOW.m_v; }
class ThemeMetricCourseDifficultiesToShow : ThemeMetric<CString>
{
public:
set<CourseDifficulty> m_v;
ThemeMetricCourseDifficultiesToShow() : ThemeMetric<CString>("Common","CourseDifficultiesToShow") {}
void Read()
{
ThemeMetric<CString>::Read();
m_v.clear();
CStringArray v;
split( GetValue(), ",", v );
ASSERT( v.size() > 0 );
FOREACH_CONST( CString, v, i )
{
CourseDifficulty d = StringToCourseDifficulty( *i );
if( d == DIFFICULTY_INVALID )
RageException::Throw( "Unknown CourseDifficulty \"%s\" in CourseDifficultiesToShow", i->c_str() );
m_v.insert( d );
}
}
};
ThemeMetricCourseDifficultiesToShow COURSE_DIFFICULTIES_TO_SHOW;
const set<CourseDifficulty>& CommonMetrics::GetCourseDifficultiesToShow() { return COURSE_DIFFICULTIES_TO_SHOW.m_v; }
/* /*
* (c) 2001-2004 Chris Danford * (c) 2001-2004 Chris Danford
* All rights reserved. * All rights reserved.
+6 -2
View File
@@ -5,19 +5,23 @@
#include "ThemeMetric.h" #include "ThemeMetric.h"
#include "PlayerNumber.h" #include "PlayerNumber.h"
#include "Difficulty.h"
extern ThemeMetric<CString> DIFFICULTIES_TO_SHOW;
extern ThemeMetric<CString> INITIAL_SCREEN; extern ThemeMetric<CString> INITIAL_SCREEN;
extern ThemeMetric<CString> FIRST_RUN_INITIAL_SCREEN; extern ThemeMetric<CString> FIRST_RUN_INITIAL_SCREEN;
extern ThemeMetric<CString> DEFAULT_MODIFIERS; extern ThemeMetric<CString> DEFAULT_MODIFIERS;
extern ThemeMetric<CString> DEFAULT_CPU_MODIFIERS; extern ThemeMetric<CString> DEFAULT_CPU_MODIFIERS;
extern ThemeMetric<CString> COURSE_DIFFICULTIES_TO_SHOW;
extern ThemeMetric1D<RageColor> PLAYER_COLOR; extern ThemeMetric1D<RageColor> PLAYER_COLOR;
extern ThemeMetric<float> JOIN_PAUSE_SECONDS; extern ThemeMetric<float> JOIN_PAUSE_SECONDS;
extern ThemeMetric<CString> WINDOW_TITLE; extern ThemeMetric<CString> WINDOW_TITLE;
extern ThemeMetric<bool> HOME_EDIT_MODE; extern ThemeMetric<bool> HOME_EDIT_MODE;
extern ThemeMetric<int> MAX_STEPS_LOADED_FROM_PROFILE; extern ThemeMetric<int> MAX_STEPS_LOADED_FROM_PROFILE;
namespace CommonMetrics
{
const set<Difficulty>& GetDifficultiesToShow();
const set<CourseDifficulty>& GetCourseDifficultiesToShow();
}
#endif #endif
+2
View File
@@ -275,8 +275,10 @@ void Course::LoadFromCRSFile( CString sPath )
m_RadarCache[CacheEntry(st, cd)] = rv; m_RadarCache[CacheEntry(st, cd)] = rv;
} }
else else
{
LOG->Trace( "Unexpected value named '%s'", sValueName.c_str() ); LOG->Trace( "Unexpected value named '%s'", sValueName.c_str() );
} }
}
static TitleSubst tsub("courses"); static TitleSubst tsub("courses");
TitleFields title; TitleFields title;
+11 -12
View File
@@ -12,6 +12,7 @@
#include "StepsUtil.h" #include "StepsUtil.h"
#include "CommonMetrics.h" #include "CommonMetrics.h"
#include "Command.h" #include "Command.h"
#include "Foreach.h"
#define MAX_METERS NUM_DIFFICULTIES + MAX_EDITS_PER_SONG #define MAX_METERS NUM_DIFFICULTIES + MAX_EDITS_PER_SONG
@@ -283,27 +284,25 @@ void DifficultyList::SetFromGameState()
// FIXME: This clamps to between the min and the max difficulty, but // FIXME: This clamps to between the min and the max difficulty, but
// it really should round to the nearest difficulty that's in // it really should round to the nearest difficulty that's in
// DIFFICULTIES_TO_SHOW. // DIFFICULTIES_TO_SHOW.
CStringArray asDiff; const set<Difficulty> &diffs = CommonMetrics::GetDifficultiesToShow();
split( DIFFICULTIES_TO_SHOW.GetValue(), ",", asDiff ); unsigned i=0;
for( unsigned i=0; i<asDiff.size(); i++ ) FOREACHS_CONST( Difficulty, diffs, d )
{ {
Difficulty d = StringToDifficulty( asDiff[i] );
if( d == DIFFICULTY_INVALID )
continue;
m_Rows.resize( m_Rows.size()+1 ); m_Rows.resize( m_Rows.size()+1 );
Row &row = m_Rows.back(); Row &row = m_Rows.back();
row.m_dc = d; row.m_dc = *d;
m_Lines[i].m_Meter.SetFromMeterAndDifficulty( 3*(d), d ); m_Lines[i].m_Meter.SetFromMeterAndDifficulty( 3*(*d), *d );
m_Lines[i].m_Description.SetText( GetDifficultyString(d) ); m_Lines[i].m_Description.SetText( GetDifficultyString(*d) );
m_Lines[i].m_Description.SetDiffuseColor( SONGMAN->GetDifficultyColor(d) ); m_Lines[i].m_Description.SetDiffuseColor( SONGMAN->GetDifficultyColor(*d) );
m_Lines[i].m_Number.SetDiffuseColor( SONGMAN->GetDifficultyColor(d) ); m_Lines[i].m_Number.SetDiffuseColor( SONGMAN->GetDifficultyColor(*d) );
m_Lines[i].m_Number.SetText( "?" ); m_Lines[i].m_Number.SetText( "?" );
i++;
} }
} }
else else
+4 -60
View File
@@ -31,6 +31,7 @@
#include "PlayerState.h" #include "PlayerState.h"
#include "Style.h" #include "Style.h"
#include "MessageManager.h" #include "MessageManager.h"
#include "CommonMetrics.h"
#include <ctime> #include <ctime>
#include <set> #include <set>
@@ -1658,37 +1659,9 @@ bool GameState::ChangePreferredDifficulty( PlayerNumber pn, Difficulty dc )
return true; return true;
} }
void GameState::GetDifficultiesToShow( set<Difficulty> &ret )
{
static float fExpiration = -999;
static set<Difficulty> cache;
if( RageTimer::GetTimeSinceStart() < fExpiration )
{
ret = cache;
return;
}
CStringArray asDiff;
split( DIFFICULTIES_TO_SHOW, ",", asDiff );
ASSERT( asDiff.size() > 0 );
cache.clear();
for( unsigned i = 0; i < asDiff.size(); ++i )
{
Difficulty d = StringToDifficulty(asDiff[i]);
if( d == DIFFICULTY_INVALID )
RageException::Throw( "Unknown difficulty \"%s\" in CourseDifficultiesToShow", asDiff[i].c_str() );
cache.insert( d );
}
fExpiration = RageTimer::GetTimeSinceStart()+1;
ret = cache;
}
bool GameState::ChangePreferredDifficulty( PlayerNumber pn, int dir ) bool GameState::ChangePreferredDifficulty( PlayerNumber pn, int dir )
{ {
set<Difficulty> asDiff; const set<Difficulty> &asDiff = CommonMetrics::GetDifficultiesToShow();
GetDifficultiesToShow( asDiff );
Difficulty d = m_PreferredDifficulty[pn]; Difficulty d = m_PreferredDifficulty[pn];
while( 1 ) while( 1 )
@@ -1703,33 +1676,6 @@ bool GameState::ChangePreferredDifficulty( PlayerNumber pn, int dir )
return ChangePreferredDifficulty( pn, d ); return ChangePreferredDifficulty( pn, d );
} }
void GameState::GetCourseDifficultiesToShow( set<CourseDifficulty> &ret )
{
static float fExpiration = -999;
static set<CourseDifficulty> cache;
if( RageTimer::GetTimeSinceStart() < fExpiration )
{
ret = cache;
return;
}
CStringArray asDiff;
split( COURSE_DIFFICULTIES_TO_SHOW, ",", asDiff );
ASSERT( asDiff.size() > 0 );
cache.clear();
for( unsigned i = 0; i < asDiff.size(); ++i )
{
CourseDifficulty cd = StringToCourseDifficulty(asDiff[i]);
if( cd == DIFFICULTY_INVALID )
RageException::Throw( "Unknown difficulty \"%s\" in CourseDifficultiesToShow", asDiff[i].c_str() );
cache.insert( cd );
}
fExpiration = RageTimer::GetTimeSinceStart()+1;
ret = cache;
}
bool GameState::ChangePreferredCourseDifficulty( PlayerNumber pn, CourseDifficulty cd ) bool GameState::ChangePreferredCourseDifficulty( PlayerNumber pn, CourseDifficulty cd )
{ {
m_PreferredCourseDifficulty[pn].Set( cd ); m_PreferredCourseDifficulty[pn].Set( cd );
@@ -1747,8 +1693,7 @@ bool GameState::ChangePreferredCourseDifficulty( PlayerNumber pn, int dir )
/* If we have a course selected, only choose among difficulties available in the course. */ /* If we have a course selected, only choose among difficulties available in the course. */
const Course *pCourse = this->m_pCurCourse; const Course *pCourse = this->m_pCurCourse;
set<CourseDifficulty> asDiff; const set<CourseDifficulty> &asDiff = CommonMetrics::GetCourseDifficultiesToShow();
GetCourseDifficultiesToShow( asDiff );
CourseDifficulty cd = m_PreferredCourseDifficulty[pn]; CourseDifficulty cd = m_PreferredCourseDifficulty[pn];
while( 1 ) while( 1 )
@@ -1767,8 +1712,7 @@ bool GameState::ChangePreferredCourseDifficulty( PlayerNumber pn, int dir )
bool GameState::IsCourseDifficultyShown( CourseDifficulty cd ) bool GameState::IsCourseDifficultyShown( CourseDifficulty cd )
{ {
set<CourseDifficulty> asDiff; const set<CourseDifficulty> &asDiff = CommonMetrics::GetCourseDifficultiesToShow();
GetCourseDifficultiesToShow( asDiff );
return asDiff.find(cd) != asDiff.end(); return asDiff.find(cd) != asDiff.end();
} }
-6
View File
@@ -261,12 +261,6 @@ public:
int m_iNumTimesThroughAttract; // negative means play regardless of m_iAttractSoundFrequency setting int m_iNumTimesThroughAttract; // negative means play regardless of m_iAttractSoundFrequency setting
bool IsTimeToPlayAttractSounds(); bool IsTimeToPlayAttractSounds();
//
// DifficultiesToShow stuff
//
void GetDifficultiesToShow( set<Difficulty> &AddTo );
void GetCourseDifficultiesToShow( set<CourseDifficulty> &AddTo );
// //
// PlayerState // PlayerState
// //
+2 -2
View File
@@ -18,6 +18,7 @@
#include "Foreach.h" #include "Foreach.h"
#include "ScreenManager.h" #include "ScreenManager.h"
#include "GameSoundManager.h" #include "GameSoundManager.h"
#include "CommonMetrics.h"
#define ENTRY(s) THEME->GetMetric ("ScreenOptionsMaster",s) #define ENTRY(s) THEME->GetMetric ("ScreenOptionsMaster",s)
#define ENTRY_MODE(s,i) THEME->GetMetric ("ScreenOptionsMaster",ssprintf("%s,%i",(s).c_str(),(i+1))) #define ENTRY_MODE(s,i) THEME->GetMetric ("ScreenOptionsMaster",ssprintf("%s,%i",(s).c_str(),(i+1)))
@@ -451,8 +452,7 @@ public:
ASSERT( sParam.size() ); ASSERT( sParam.size() );
m_sName = sParam; m_sName = sParam;
set<Difficulty> vDifficulties; const set<Difficulty> &vDifficulties = CommonMetrics::GetDifficultiesToShow();
GAMESTATE->GetDifficultiesToShow( vDifficulties );
defOut.bOneChoiceForAllPlayers = true; defOut.bOneChoiceForAllPlayers = true;
defOut.name = "Difficulty"; defOut.name = "Difficulty";
+6 -7
View File
@@ -18,6 +18,8 @@
#include "StatsManager.h" #include "StatsManager.h"
#include "PlayerState.h" #include "PlayerState.h"
#include "BGAnimation.h" #include "BGAnimation.h"
#include "CommonMetrics.h"
#include "Foreach.h"
#define SCROLL_DELAY THEME->GetMetricF("ScreenEnding","ScrollDelay") #define SCROLL_DELAY THEME->GetMetricF("ScreenEnding","ScrollDelay")
@@ -25,7 +27,6 @@
#define TEXT_ZOOM THEME->GetMetricF("ScreenEnding","TextZoom") #define TEXT_ZOOM THEME->GetMetricF("ScreenEnding","TextZoom")
CString GetStatsLineTitle( PlayerNumber pn, EndingStatsLine line ) CString GetStatsLineTitle( PlayerNumber pn, EndingStatsLine line )
{ {
switch( line ) switch( line )
@@ -83,9 +84,8 @@ CString GetStatsLineValue( PlayerNumber pn, EndingStatsLine line )
if( GAMESTATE->IsCourseMode() ) if( GAMESTATE->IsCourseMode() )
{ {
set<CourseDifficulty> vDiffs; const set<CourseDifficulty> &vDiffs = CommonMetrics::GetCourseDifficultiesToShow();
GAMESTATE->GetCourseDifficultiesToShow( vDiffs ); FOREACHS_CONST( CourseDifficulty, vDiffs, iter )
for( set<CourseDifficulty>::iterator iter = vDiffs.begin(); iter != vDiffs.end(); iter++ )
{ {
fActual += pProfile->GetCoursesActual(st,*iter); fActual += pProfile->GetCoursesActual(st,*iter);
fPossible += pProfile->GetCoursesPossible(st,*iter); fPossible += pProfile->GetCoursesPossible(st,*iter);
@@ -93,9 +93,8 @@ CString GetStatsLineValue( PlayerNumber pn, EndingStatsLine line )
} }
else else
{ {
set<Difficulty> vDiffs; const set<Difficulty> &vDiffs = CommonMetrics::GetDifficultiesToShow();
GAMESTATE->GetDifficultiesToShow( vDiffs ); FOREACHS_CONST( Difficulty, vDiffs, iter )
for( set<Difficulty>::iterator iter = vDiffs.begin(); iter != vDiffs.end(); iter++ )
{ {
fActual += pProfile->GetSongsActual(st,*iter); fActual += pProfile->GetSongsActual(st,*iter);
fPossible += pProfile->GetSongsPossible(st,*iter); fPossible += pProfile->GetSongsPossible(st,*iter);