and const fixes

This commit is contained in:
Glenn Maynard
2004-02-10 10:06:34 +00:00
parent 6137e5066d
commit e413fef34a
4 changed files with 62 additions and 41 deletions
+37 -21
View File
@@ -129,15 +129,15 @@ CString Profile::GetProfileDisplayNameFromDir( CString sDir )
return pro.GetDisplayName();
}
int Profile::GetSongNumTimesPlayed( Song* pSong )
int Profile::GetSongNumTimesPlayed( const Song* pSong ) const
{
int iTotalNumTimesPlayed = 0;
vector<Steps*> vpSteps;
pSong->GetSteps( vpSteps );
for( unsigned i=0; i<vpSteps.size(); i++ )
{
Steps* pSteps = vpSteps[i];
iTotalNumTimesPlayed += this->GetStepsHighScoreList(pSteps).iNumTimesPlayed;
const Steps* pSteps = vpSteps[i];
iTotalNumTimesPlayed += ((Profile*) this)->GetStepsHighScoreList(pSteps).iNumTimesPlayed;
}
return iTotalNumTimesPlayed;
}
@@ -154,6 +154,12 @@ void Profile::AddStepsHighScore( const Steps* pSteps, HighScore hs, int &iIndexO
iter->second.hs.AddHighScore( hs, iIndexOut );
}
const HighScoreList& Profile::GetStepsHighScoreList( const Steps* pSteps ) const
{
/* We're const, but insert a blank entry anyway if the requested pointer doesn't exist. */
return ((Profile *) this)->m_StepsHighScores[pSteps].hs;
}
HighScoreList& Profile::GetStepsHighScoreList( const Steps* pSteps )
{
std::map<const Steps*,HighScoresForASteps>::iterator iter = m_StepsHighScores.find( pSteps );
@@ -197,6 +203,11 @@ void Profile::AddCourseHighScore( const Course* pCourse, StepsType st, HighScore
iter->second.hs[st].AddHighScore( hs, iIndexOut );
}
const HighScoreList& Profile::GetCourseHighScoreList( const Course* pCourse, StepsType st ) const
{
return ((Profile *)this)->m_CourseHighScores[pCourse].hs[st];
}
HighScoreList& Profile::GetCourseHighScoreList( const Course* pCourse, StepsType st )
{
std::map<const Course*,HighScoresForACourse>::iterator iter = m_CourseHighScores.find( pCourse );
@@ -235,6 +246,11 @@ void Profile::AddCategoryHighScore( StepsType st, RankingCategory rc, HighScore
m_CategoryHighScores[st][rc].AddHighScore( hs, iIndexOut );
}
const HighScoreList& Profile::GetCategoryHighScoreList( StepsType st, RankingCategory rc ) const
{
return ((Profile *)this)->m_CategoryHighScores[st][rc];
}
HighScoreList& Profile::GetCategoryHighScoreList( StepsType st, RankingCategory rc )
{
return m_CategoryHighScores[st][rc];
@@ -300,7 +316,7 @@ bool Profile::LoadGeneralDataFromDir( CString sDir )
return true;
}
bool Profile::SaveGeneralDataToDir( CString sDir )
bool Profile::SaveGeneralDataToDir( CString sDir ) const
{
CString sIniPath = sDir + PROFILE_INI;
@@ -327,11 +343,11 @@ bool Profile::SaveGeneralDataToDir( CString sDir )
return ini.WriteFile();
}
void Profile::SaveSongScoresToDir( CString sDir )
void Profile::SaveSongScoresToDir( CString sDir ) const
{
CHECKPOINT;
Profile* pProfile = this;
const Profile* pProfile = this;
ASSERT( pProfile );
CString fn = sDir + SONG_SCORES_XML;
@@ -366,7 +382,7 @@ void Profile::SaveSongScoresToDir( CString sDir )
LPXNode pStepsNode = pSongNode->AppendChild( "Steps" );
HighScoreList &hsl = pProfile->GetStepsHighScoreList( pSteps );
const HighScoreList &hsl = pProfile->GetStepsHighScoreList( pSteps );
pStepsNode->AppendChild( "StepsType", pSteps->m_StepsType );
pStepsNode->AppendChild( "Difficulty", pSteps->GetDifficulty() );
@@ -721,11 +737,11 @@ void Profile::LoadCourseScoresFromDirSM390a12( CString sDir )
}
void Profile::SaveCourseScoresToDir( CString sDir )
void Profile::SaveCourseScoresToDir( CString sDir ) const
{
CHECKPOINT;
Profile* pProfile = this;
const Profile* pProfile = this;
ASSERT( pProfile );
CString fn = sDir + COURSE_SCORES_XML;
@@ -755,7 +771,7 @@ void Profile::SaveCourseScoresToDir( CString sDir )
LPXNode pStepsTypeNode = pCourseNode->AppendChild( "StepsType", st );
HighScoreList &hsl = pProfile->GetCourseHighScoreList( pCourse, st );
const HighScoreList &hsl = pProfile->GetCourseHighScoreList( pCourse, st );
pStepsTypeNode->AppendChild( hsl.CreateNode() );
}
@@ -817,11 +833,11 @@ void Profile::LoadCourseScoresFromDir( CString sDir )
xml.SaveToFile( fn );
}
void Profile::SaveCategoryScoresToDir( CString sDir )
void Profile::SaveCategoryScoresToDir( CString sDir ) const
{
CHECKPOINT;
Profile* pProfile = this;
const Profile* pProfile = this;
ASSERT( pProfile );
CString fn = sDir + CATEGORY_SCORES_XML;
@@ -845,7 +861,7 @@ void Profile::SaveCategoryScoresToDir( CString sDir )
XNode* pRankingCategoryNode = pStepsTypeNode->AppendChild( "RankingCategory", rc );
HighScoreList &hsl = pProfile->GetCategoryHighScoreList( (StepsType)st, (RankingCategory)rc );
const HighScoreList &hsl = pProfile->GetCategoryHighScoreList( (StepsType)st, (RankingCategory)rc );
pRankingCategoryNode->AppendChild( hsl.CreateNode() );
}
@@ -902,27 +918,27 @@ void Profile::LoadCategoryScoresFromDir( CString sDir )
}
}
void Profile::DeleteSongScoresFromDirSM390a12( CString sDir )
void Profile::DeleteSongScoresFromDirSM390a12( CString sDir ) const
{
CString fn = sDir + SM_390A12_SONG_SCORES_DAT;
// FIXME
}
void Profile::DeleteCourseScoresFromDirSM390a12( CString sDir )
void Profile::DeleteCourseScoresFromDirSM390a12( CString sDir ) const
{
CString fn = sDir + SM_390A12_COURSE_SCORES_DAT;
// FIXME
}
void Profile::DeleteCategoryScoresFromDirSM390a12( CString sDir )
void Profile::DeleteCategoryScoresFromDirSM390a12( CString sDir ) const
{
CString fn = sDir + SM_390A12_CATEGORY_SCORES_DAT;
// FIXME
}
void Profile::SaveStatsWebPageToDir( CString sDir )
void Profile::SaveStatsWebPageToDir( CString sDir ) const
{
Profile* pProfile = this;
const Profile* pProfile = this;
CString fn = sDir + STATS_HTML;
@@ -1203,7 +1219,7 @@ void Profile::SaveStatsWebPageToDir( CString sDir )
Steps* pSteps = pSong->GetStepsByDifficulty( st, dc, false );
if( pSteps )
{
HighScoreList &hsl = pProfile->GetStepsHighScoreList( pSteps );
const HighScoreList &hsl = pProfile->GetStepsHighScoreList( pSteps );
CString sHighScore;
if( !hsl.vHighScores.empty() )
{
@@ -1331,7 +1347,7 @@ void Profile::SaveStatsWebPageToDir( CString sDir )
Steps* pSteps = vpSteps[j];
if( pSteps->IsAutogen() )
continue; // skip autogen
HighScoreList &hsl = pProfile->GetStepsHighScoreList( pSteps );
const HighScoreList &hsl = pProfile->GetStepsHighScoreList( pSteps );
CString s =
GAMEMAN->NotesTypeToString(pSteps->m_StepsType) +
" - " +
@@ -1341,7 +1357,7 @@ void Profile::SaveStatsWebPageToDir( CString sDir )
for( unsigned i=0; i<hsl.vHighScores.size(); i++ )
{
HighScore &hs = hsl.vHighScores[i];
const HighScore &hs = hsl.vHighScores[i];
CString sName = ssprintf("#%d",i+1);
CString sHSName = hs.sName.empty() ? "????" : hs.sName;
CString sValue = ssprintf("%s, %s, %i, %.2f%%", sHSName.c_str(), GradeToString(hs.grade).c_str(), hs.iScore, hs.fPercentDP*100);
+13 -10
View File
@@ -38,7 +38,7 @@ public:
CString GetDisplayCaloriesBurned();
int GetTotalNumSongsPlayed();
static CString GetProfileDisplayNameFromDir( CString sDir );
int GetSongNumTimesPlayed( Song* pSong );
int GetSongNumTimesPlayed( const Song* pSong ) const;
//
// General data
@@ -70,6 +70,7 @@ public:
void AddStepsHighScore( const Steps* pSteps, HighScore hs, int &iIndexOut );
HighScoreList& GetStepsHighScoreList( const Steps* pSteps );
const HighScoreList& GetStepsHighScoreList( const Steps* pSteps ) const;
int GetStepsNumTimesPlayed( const Steps* pSteps ) const;
void IncrementStepsPlayCount( const Steps* pSteps );
@@ -87,6 +88,7 @@ public:
void AddCourseHighScore( const Course* pCourse, StepsType st, HighScore hs, int &iIndexOut );
HighScoreList& GetCourseHighScoreList( const Course* pCourse, StepsType st );
const HighScoreList& GetCourseHighScoreList( const Course* pCourse, StepsType st ) const;
int GetCourseNumTimesPlayed( const Course* pCourse ) const;
void IncrementCoursePlayCount( const Course* pCourse, StepsType st );
@@ -98,6 +100,7 @@ public:
void AddCategoryHighScore( StepsType st, RankingCategory rc, HighScore hs, int &iIndexOut );
HighScoreList& GetCategoryHighScoreList( StepsType st, RankingCategory rc );
const HighScoreList& GetCategoryHighScoreList( StepsType st, RankingCategory rc ) const;
int GetCategoryNumTimesPlayed( StepsType st ) const;
void IncrementCategoryPlayCount( StepsType st, RankingCategory rc );
@@ -132,7 +135,7 @@ public:
LoadCategoryScoresFromDir( sDir );
return bResult;
}
bool SaveAllToDir( CString sDir )
bool SaveAllToDir( CString sDir ) const
{
// Delete old files after saving new ones so we don't try to load old
// and make duplicate records.
@@ -149,24 +152,24 @@ public:
}
bool LoadGeneralDataFromDir( CString sDir );
bool SaveGeneralDataToDir( CString sDir );
bool SaveGeneralDataToDir( CString sDir ) const;
void LoadSongScoresFromDirSM390a12( CString sDir );
void LoadSongScoresFromDir( CString sDir );
void SaveSongScoresToDir( CString sDir );
void DeleteSongScoresFromDirSM390a12( CString sDir );
void SaveSongScoresToDir( CString sDir ) const;
void DeleteSongScoresFromDirSM390a12( CString sDir ) const;
void LoadCourseScoresFromDirSM390a12( CString sDir );
void LoadCourseScoresFromDir( CString sDir );
void SaveCourseScoresToDir( CString sDir );
void DeleteCourseScoresFromDirSM390a12( CString sDir );
void SaveCourseScoresToDir( CString sDir ) const;
void DeleteCourseScoresFromDirSM390a12( CString sDir ) const;
void LoadCategoryScoresFromDirSM390a12( CString sDir );
void LoadCategoryScoresFromDir( CString sDir );
void SaveCategoryScoresToDir( CString sDir );
void DeleteCategoryScoresFromDirSM390a12( CString sDir );
void SaveCategoryScoresToDir( CString sDir ) const;
void DeleteCategoryScoresFromDirSM390a12( CString sDir ) const;
void SaveStatsWebPageToDir( CString sDir );
void SaveStatsWebPageToDir( CString sDir ) const;
};
+5 -5
View File
@@ -207,7 +207,7 @@ void ProfileManager::UnloadProfile( PlayerNumber pn )
m_Profile[pn].InitAll();
}
Profile* ProfileManager::GetProfile( PlayerNumber pn )
const Profile* ProfileManager::GetProfile( PlayerNumber pn ) const
{
if( m_sProfileDir[pn].empty() )
return NULL;
@@ -217,7 +217,7 @@ Profile* ProfileManager::GetProfile( PlayerNumber pn )
CString ProfileManager::GetPlayerName( PlayerNumber pn )
{
Profile *prof = ProfileManager::GetProfile( pn );
Profile *prof = GetProfile( pn );
if( prof )
return prof->m_sLastUsedHighScoreName;
@@ -290,7 +290,7 @@ bool ProfileManager::DeleteLocalProfile( CString sProfileID )
return FILEMAN->Remove( sProfileDir );
}
void ProfileManager::SaveMachineScoresToDisk()
void ProfileManager::SaveMachineScoresToDisk() const
{
m_MachineProfile.SaveAllToDir( MACHINE_PROFILE_DIR );
}
@@ -399,7 +399,7 @@ CString ProfileManager::GetProfileDir( ProfileSlot slot )
}
}
Profile* ProfileManager::GetProfile( ProfileSlot slot )
const Profile* ProfileManager::GetProfile( ProfileSlot slot ) const
{
switch( slot )
{
@@ -420,7 +420,7 @@ Profile* ProfileManager::GetProfile( ProfileSlot slot )
//
// Song stats
//
int ProfileManager::GetSongNumTimesPlayed( Song* pSong, ProfileSlot slot )
int ProfileManager::GetSongNumTimesPlayed( const Song* pSong, ProfileSlot slot ) const
{
return GetProfile(slot)->GetSongNumTimesPlayed( pSong );
}
+7 -5
View File
@@ -55,8 +55,10 @@ public:
return false;
}
}
Profile* GetProfile( PlayerNumber pn );
Profile* GetProfile( ProfileSlot slot );
const Profile* GetProfile( PlayerNumber pn ) const;
Profile* GetProfile( PlayerNumber pn ) { return (Profile*) ((const ProfileManager *) this)->GetProfile(pn); }
const Profile* GetProfile( ProfileSlot slot ) const;
Profile* GetProfile( ProfileSlot slot ) { return (Profile*) ((const ProfileManager *) this)->GetProfile(slot); }
CString GetProfileDir( ProfileSlot slot );
Profile* GetMachineProfile() { return &m_MachineProfile; }
@@ -69,13 +71,13 @@ public:
// High scores
//
void InitMachineScoresFromDisk();
void SaveMachineScoresToDisk();
void SaveMachineScoresToDisk() const;
//
// Song stats
//
int GetSongNumTimesPlayed( Song* pSong, ProfileSlot card );
bool IsSongNew( Song* pSong ) { return GetSongNumTimesPlayed(pSong,PROFILE_SLOT_MACHINE)==0; }
int GetSongNumTimesPlayed( const Song* pSong, ProfileSlot card ) const;
bool IsSongNew( const Song* pSong ) const { return GetSongNumTimesPlayed(pSong,PROFILE_SLOT_MACHINE)==0; }
void AddStepsHighScore( const Steps* pSteps, PlayerNumber pn, HighScore hs, int &iPersonalIndexOut, int &iMachineIndexOut );
void IncrementStepsPlayCount( const Steps* pSteps, PlayerNumber pn );
HighScore GetHighScoreForDifficulty( const Song *s, const StyleDef *st, ProfileSlot slot, Difficulty dc );