From 2307fa23d995d35d8dbfa6e241e54b9519301ff1 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Fri, 12 Aug 2005 01:52:01 +0000 Subject: [PATCH] hidden HighScore::sName --- stepmania/src/GameCommand.cpp | 2 +- stepmania/src/GameState.cpp | 24 ++++----- stepmania/src/HighScore.cpp | 56 +++++++++++++++++--- stepmania/src/HighScore.h | 6 ++- stepmania/src/PaneDisplay.cpp | 4 +- stepmania/src/ProfileManager.cpp | 14 ++--- stepmania/src/ScreenEvaluation.cpp | 2 +- stepmania/src/ScreenNameEntryTraditional.cpp | 2 +- stepmania/src/ScreenRanking.cpp | 16 +++--- 9 files changed, 86 insertions(+), 40 deletions(-) diff --git a/stepmania/src/GameCommand.cpp b/stepmania/src/GameCommand.cpp index f90ef19573..3c0931348f 100644 --- a/stepmania/src/GameCommand.cpp +++ b/stepmania/src/GameCommand.cpp @@ -611,7 +611,7 @@ void GameCommand::Apply( PlayerNumber pn ) const static HighScore MakeRandomHighScore( float fPercentDP ) { HighScore hs; - hs.sName = "FAKE"; + hs.SetName( "FAKE" ); hs.grade = (Grade)SCALE( rand()%5, 0, 4, GRADE_TIER01, GRADE_TIER05 ); hs.iScore = rand()%100*1000; hs.fPercentDP = fPercentDP; diff --git a/stepmania/src/GameState.cpp b/stepmania/src/GameState.cpp index df6f78b556..fc32b1f6d7 100644 --- a/stepmania/src/GameState.cpp +++ b/stepmania/src/GameState.cpp @@ -1382,7 +1382,7 @@ void GameState::GetRankingFeats( PlayerNumber pn, vector &asFeatsOu { HighScore &hs = hsl.vHighScores[j]; - if( hs.sName != RANKING_TO_FILL_IN_MARKER[pn] ) + if( hs.GetName() != RANKING_TO_FILL_IN_MARKER[pn] ) continue; RankingFeat feat; @@ -1390,7 +1390,7 @@ void GameState::GetRankingFeats( PlayerNumber pn, vector &asFeatsOu feat.pSong = pSong; feat.pSteps = pSteps; feat.Feat = ssprintf("MR #%d in %s %s", j+1, pSong->GetTranslitMainTitle().c_str(), DifficultyToString(pSteps->GetDifficulty()).c_str() ); - feat.pStringToFill = &hs.sName; + feat.pStringToFill = hs.GetNameMutable(); feat.grade = hs.grade; feat.fPercentDP = hs.fPercentDP; feat.iScore = hs.iScore; @@ -1410,7 +1410,7 @@ void GameState::GetRankingFeats( PlayerNumber pn, vector &asFeatsOu { HighScore &hs = hsl.vHighScores[j]; - if( hs.sName != RANKING_TO_FILL_IN_MARKER[pn] ) + if( hs.GetName() != RANKING_TO_FILL_IN_MARKER[pn] ) continue; RankingFeat feat; @@ -1418,7 +1418,7 @@ void GameState::GetRankingFeats( PlayerNumber pn, vector &asFeatsOu feat.pSteps = pSteps; feat.Type = RankingFeat::SONG; feat.Feat = ssprintf("PR #%d in %s %s", j+1, pSong->GetTranslitMainTitle().c_str(), DifficultyToString(pSteps->GetDifficulty()).c_str() ); - feat.pStringToFill = &hs.sName; + feat.pStringToFill = hs.GetNameMutable(); feat.grade = hs.grade; feat.fPercentDP = hs.fPercentDP; feat.iScore = hs.iScore; @@ -1446,13 +1446,13 @@ void GameState::GetRankingFeats( PlayerNumber pn, vector &asFeatsOu for( unsigned j=0; j &asFeatsOu for( unsigned j=0; j &asFeatsOu for( unsigned i=0; i &asFeatsOu feat.Feat = ssprintf("MR #%d in %s", i+1, pCourse->GetDisplayFullTitle().c_str() ); if( cd != DIFFICULTY_MEDIUM ) feat.Feat += " " + CourseDifficultyToThemedString(cd); - feat.pStringToFill = &hs.sName; + feat.pStringToFill = hs.GetNameMutable(); feat.grade = GRADE_NO_DATA; feat.iScore = hs.iScore; feat.fPercentDP = hs.fPercentDP; @@ -1529,14 +1529,14 @@ void GameState::GetRankingFeats( PlayerNumber pn, vector &asFeatsOu for( unsigned i=0; iGetDisplayFullTitle().c_str() ); - feat.pStringToFill = &hs.sName; + feat.pStringToFill = hs.GetNameMutable(); feat.grade = GRADE_NO_DATA; feat.iScore = hs.iScore; feat.fPercentDP = hs.fPercentDP; diff --git a/stepmania/src/HighScore.cpp b/stepmania/src/HighScore.cpp index eaac8aa87c..e7e63427f2 100644 --- a/stepmania/src/HighScore.cpp +++ b/stepmania/src/HighScore.cpp @@ -11,8 +11,41 @@ struct HighScoreImpl { + CString sName; // name that shows in the machine's ranking screen + void Unset(); + void AppendChildren( XNode *pNode ) const; + void LoadFromNode( const XNode *pNode ); + + bool operator==( const HighScoreImpl& other ) const; + bool operator!=( const HighScoreImpl& other ) const { return !(*this == other); } }; + +bool HighScoreImpl::operator==( const HighScoreImpl& other ) const +{ +#define COMPARE(x) if( x!=other.x ) return false; + COMPARE( sName ); +#undef COMPARE + + return true; +} + +void HighScoreImpl::Unset() +{ + sName = ""; + +} + +void HighScoreImpl::AppendChildren( XNode *pNode ) const +{ + pNode->AppendChild( "Name", IsRankingToFillIn(sName) ? CString("") : sName ); +} + +void HighScoreImpl::LoadFromNode( const XNode *pNode ) +{ + pNode->GetChildValue( "Name", sName ); +} + REGISTER_CLASS_TRAITS( HighScoreImpl, new HighScoreImpl(*pCopy) ) HighScore::HighScore() @@ -23,7 +56,7 @@ HighScore::HighScore() void HighScore::Unset() { - sName = ""; + m_Impl->Unset(); grade = GRADE_NO_DATA; iScore = 0; fPercentDP = 0; @@ -39,6 +72,14 @@ void HighScore::Unset() fLifeRemainingSeconds = 0; } +CString HighScore::GetName() const { return m_Impl->sName; } +void HighScore::SetName( const CString &sName ) { m_Impl->sName = sName; } + +/* We normally don't give direct access to the members. We need this one + * for NameToFillIn; use a special accessor so it's easy to find where this + * is used. */ +CString *HighScore::GetNameMutable() { return &m_Impl->sName; } + bool HighScore::operator>=( const HighScore& other ) const { /* Make sure we treat AAAA as higher than AAA, even though the score @@ -61,8 +102,9 @@ bool HighScore::operator>=( const HighScore& other ) const bool HighScore::operator==( const HighScore& other ) const { + if( *m_Impl != *other.m_Impl ) + return false; #define COMPARE(x) if( x!=other.x ) return false; - COMPARE( sName ); COMPARE( grade ); COMPARE( iScore ); COMPARE( fPercentDP ); @@ -88,7 +130,7 @@ XNode* HighScore::CreateNode() const pNode->m_sName = "HighScore"; // TRICKY: Don't write "name to fill in" markers. - pNode->AppendChild( "Name", IsRankingToFillIn(sName) ? CString("") : sName ); + m_Impl->AppendChildren( pNode ); pNode->AppendChild( "Grade", GradeToString(grade) ); pNode->AppendChild( "Score", iScore ); pNode->AppendChild( "PercentDP", fPercentDP ); @@ -117,7 +159,7 @@ void HighScore::LoadFromNode( const XNode* pNode ) CString s; - pNode->GetChildValue( "Name", sName ); + m_Impl->LoadFromNode( pNode ); pNode->GetChildValue( "Grade", s ); /* Pre-a19 compatibility; remove eventually */ if( IsAnInt(s) ) @@ -151,10 +193,10 @@ void HighScore::LoadFromNode( const XNode* pNode ) CString HighScore::GetDisplayName() const { - if( sName.empty() ) + if( GetName().empty() ) return EMPTY_NAME; else - return sName; + return GetName(); } @@ -259,7 +301,7 @@ void HighScoreList::RemoveAllButOneOfEachName() { for( vector::iterator j = i+1; j != vHighScores.end(); j++ ) { - if( i->sName == j->sName ) + if( i->GetName() == j->GetName() ) { j--; vHighScores.erase( j+1 ); diff --git a/stepmania/src/HighScore.h b/stepmania/src/HighScore.h index 240e35c10f..a3446e219e 100644 --- a/stepmania/src/HighScore.h +++ b/stepmania/src/HighScore.h @@ -14,7 +14,11 @@ struct XNode; struct HighScoreImpl; struct HighScore { - CString sName; // name that shows in the machine's ranking screen + CString GetName() const; + void SetName( const CString &sName ); + CString *GetNameMutable(); + const CString *GetNameMutable() const { return const_cast (const_cast(this)->GetNameMutable()); } + Grade grade; int iScore; float fPercentDP; diff --git a/stepmania/src/PaneDisplay.cpp b/stepmania/src/PaneDisplay.cpp index aead7a78c1..95d9addbdd 100644 --- a/stepmania/src/PaneDisplay.cpp +++ b/stepmania/src/PaneDisplay.cpp @@ -212,7 +212,7 @@ void PaneDisplay::SetContent( PaneContents c ) } else { - str = PROFILEMAN->GetMachineProfile()->GetStepsHighScoreList(pSong,pSteps).GetTopScore().sName; + str = PROFILEMAN->GetMachineProfile()->GetStepsHighScoreList(pSong,pSteps).GetTopScore().GetName(); if( str.empty() ) str = "????"; } @@ -224,7 +224,7 @@ void PaneDisplay::SetContent( PaneContents c ) } else { - str = PROFILEMAN->GetMachineProfile()->GetCourseHighScoreList(pCourse,pTrail).GetTopScore().sName; + str = PROFILEMAN->GetMachineProfile()->GetCourseHighScoreList(pCourse,pTrail).GetTopScore().GetName(); if( str.empty() ) str = "????"; } diff --git a/stepmania/src/ProfileManager.cpp b/stepmania/src/ProfileManager.cpp index cdbe7aa4ac..d58abe8269 100644 --- a/stepmania/src/ProfileManager.cpp +++ b/stepmania/src/ProfileManager.cpp @@ -541,13 +541,13 @@ void ProfileManager::AddStepsScore( const Song* pSong, const Steps* pSteps, Play { Profile* pProfile = PROFILEMAN->GetProfile(pn); if( pProfile && !pProfile->m_sLastUsedHighScoreName.empty() ) - hs.sName = pProfile->m_sLastUsedHighScoreName; + hs.SetName( pProfile->m_sLastUsedHighScoreName ); else - hs.sName = "EVNT"; + hs.SetName( "EVNT" ); } else { - hs.sName = RANKING_TO_FILL_IN_MARKER[pn]; + hs.SetName( RANKING_TO_FILL_IN_MARKER[pn] ); } // @@ -611,13 +611,13 @@ void ProfileManager::AddCourseScore( const Course* pCourse, const Trail* pTrail, { Profile* pProfile = PROFILEMAN->GetProfile(pn); if( pProfile && !pProfile->m_sLastUsedHighScoreName.empty() ) - hs.sName = pProfile->m_sLastUsedHighScoreName; + hs.SetName( pProfile->m_sLastUsedHighScoreName ); else - hs.sName = "EVNT"; + hs.SetName( "EVNT" ); } else { - hs.sName = RANKING_TO_FILL_IN_MARKER[pn]; + hs.SetName( RANKING_TO_FILL_IN_MARKER[pn] ); } @@ -651,7 +651,7 @@ void ProfileManager::IncrementCoursePlayCount( const Course* pCourse, const Trai void ProfileManager::AddCategoryScore( StepsType st, RankingCategory rc, PlayerNumber pn, const HighScore &hs_, int &iPersonalIndexOut, int &iMachineIndexOut ) { HighScore hs = hs_; - hs.sName = RANKING_TO_FILL_IN_MARKER[pn]; + hs.SetName( RANKING_TO_FILL_IN_MARKER[pn] ); if( PROFILEMAN->IsPersistentProfile(pn) ) PROFILEMAN->GetProfile(pn)->AddCategoryHighScore( st, rc, hs, iPersonalIndexOut ); if( hs.fPercentDP > PREFSMAN->m_fMinPercentageForMachineSongHighScore ) diff --git a/stepmania/src/ScreenEvaluation.cpp b/stepmania/src/ScreenEvaluation.cpp index dd369c3646..6b47135d38 100644 --- a/stepmania/src/ScreenEvaluation.cpp +++ b/stepmania/src/ScreenEvaluation.cpp @@ -896,7 +896,7 @@ void ScreenEvaluation::CommitScores( // below in the switch HighScore &hs = m_HighScore[p]; - hs.sName = RANKING_TO_FILL_IN_MARKER[p]; + hs.SetName( RANKING_TO_FILL_IN_MARKER[p] ); hs.grade = stageStats.m_player[p].GetGrade(); hs.iScore = stageStats.m_player[p].iScore; hs.fPercentDP = stageStats.m_player[p].GetPercentDancePoints(); diff --git a/stepmania/src/ScreenNameEntryTraditional.cpp b/stepmania/src/ScreenNameEntryTraditional.cpp index 2258a0807e..208a8d393e 100644 --- a/stepmania/src/ScreenNameEntryTraditional.cpp +++ b/stepmania/src/ScreenNameEntryTraditional.cpp @@ -359,7 +359,7 @@ void ScreenNameEntryTraditional::Init() for( int h=0; h<(int)hsl.vHighScores.size() && hm_iMaxHighScoresPerListForMachine; h++ ) { const HighScore &hs = hsl.vHighScores[h]; - if( hs.sName == RANKING_TO_FILL_IN_MARKER[p] && + if( hs.GetName() == RANKING_TO_FILL_IN_MARKER[p] && hs.fPercentDP == fPercentDP && hs.iScore == iScore ) { diff --git a/stepmania/src/ScreenRanking.cpp b/stepmania/src/ScreenRanking.cpp index 57aba5844b..7a0e6f51af 100644 --- a/stepmania/src/ScreenRanking.cpp +++ b/stepmania/src/ScreenRanking.cpp @@ -760,12 +760,12 @@ float ScreenRanking::SetPage( PageToShow pts ) if( l < (int)hsl.vHighScores.size() ) { hs = hsl.vHighScores[l]; - CString *psName = &hsl.vHighScores[l].sName; + CString *psName = hsl.vHighScores[l].GetNameMutable(); bRecentHighScore = find( GAMESTATE->m_vpsNamesThatWereFilled.begin(), GAMESTATE->m_vpsNamesThatWereFilled.end(), psName ) != GAMESTATE->m_vpsNamesThatWereFilled.end(); } else { - hs.sName = NO_SCORE_NAME; + hs.SetName( NO_SCORE_NAME ); } m_textNames[l].SetText( hs.GetDisplayName() ); @@ -800,12 +800,12 @@ float ScreenRanking::SetPage( PageToShow pts ) if( l < (int)hsl.vHighScores.size() ) { hs = hsl.vHighScores[l]; - const CString *psName = &hsl.vHighScores[l].sName; + const CString *psName = hsl.vHighScores[l].GetNameMutable(); bRecentHighScore = find( GAMESTATE->m_vpsNamesThatWereFilled.begin(), GAMESTATE->m_vpsNamesThatWereFilled.end(), psName ) != GAMESTATE->m_vpsNamesThatWereFilled.end(); } else { - hs.sName = NO_SCORE_NAME; + hs.SetName( NO_SCORE_NAME ); } m_textNames[l].SetText( hs.GetDisplayName() ); @@ -868,12 +868,12 @@ float ScreenRanking::SetPage( PageToShow pts ) if( !hsl.vHighScores.empty() ) { hs = hsl.GetTopScore(); - const CString *psName = &hsl.GetTopScore().sName; + const CString *psName = hsl.GetTopScore().GetNameMutable(); bRecentHighScore = find( GAMESTATE->m_vpsNamesThatWereFilled.begin(), GAMESTATE->m_vpsNamesThatWereFilled.end(), psName ) != GAMESTATE->m_vpsNamesThatWereFilled.end(); } else { - hs.sName = NO_SCORE_NAME; + hs.SetName( NO_SCORE_NAME ); } CString s = hs.GetDisplayName() + "\n" + PercentageDisplay::FormatPercentScore( hs.fPercentDP ); @@ -915,12 +915,12 @@ float ScreenRanking::SetPage( PageToShow pts ) if( !hsl.vHighScores.empty() ) { hs = hsl.vHighScores[0]; - const CString *psName = &hsl.GetTopScore().sName; + const CString *psName = hsl.GetTopScore().GetNameMutable(); bRecentHighScore = find( GAMESTATE->m_vpsNamesThatWereFilled.begin(), GAMESTATE->m_vpsNamesThatWereFilled.end(), psName ) != GAMESTATE->m_vpsNamesThatWereFilled.end(); } else { - hs.sName = NO_SCORE_NAME; + hs.SetName( NO_SCORE_NAME ); } CString s = hs.GetDisplayName() + "\n" + PercentageDisplay::FormatPercentScore( hs.fPercentDP );