From 987a83d6bd431fbfb71ddf276c08f2565e52455f Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Thu, 22 Apr 2004 07:59:42 +0000 Subject: [PATCH] save last N scores in profile (for tournament score tracking) --- stepmania/src/HighScore.h | 3 +- stepmania/src/Profile.cpp | 111 ++++++++++++++++++++++++++++++++++++++ stepmania/src/Profile.h | 22 ++++++++ stepmania/src/SongUtil.h | 3 +- stepmania/src/StepsUtil.h | 3 +- 5 files changed, 139 insertions(+), 3 deletions(-) diff --git a/stepmania/src/HighScore.h b/stepmania/src/HighScore.h index ff99e24104..8d9020f2c1 100644 --- a/stepmania/src/HighScore.h +++ b/stepmania/src/HighScore.h @@ -27,7 +27,8 @@ struct HighScore CString sMachineGuid; // where this screenshot was taken - HighScore() + HighScore() { Unset(); } + void Unset() { grade = GRADE_NO_DATA; iScore = 0; diff --git a/stepmania/src/Profile.cpp b/stepmania/src/Profile.cpp index 6d65925ccc..40185f5228 100644 --- a/stepmania/src/Profile.cpp +++ b/stepmania/src/Profile.cpp @@ -46,6 +46,8 @@ const int SM_390A12_COURSE_SCORES_VERSION = 8; #define GUID_SIZE_BYTES 8 +#define MAX_LAST_SCORES_TO_SAVE 100 + #if defined(WIN32) #pragma warning (disable : 4706) // assignment within conditional expression #endif @@ -155,6 +157,11 @@ void Profile::InitAwards() } } +void Profile::InitLastScores() +{ + m_vLastScores.clear(); +} + CString Profile::GetDisplayName() const { if( !m_sDisplayName.empty() ) @@ -521,6 +528,7 @@ bool Profile::LoadAllFromDir( CString sDir, bool bRequireSignature ) LOAD_NODE( ScreenshotData ); LOAD_NODE( CalorieData ); LOAD_NODE( Awards ); + LOAD_NODE( LastScores ); } return true; // FIXME? Investigate what happens if we always return true. @@ -546,6 +554,7 @@ bool Profile::SaveAllToDir( CString sDir, bool bSignData ) const xml.AppendChild( SaveScreenshotDataCreateNode() ); xml.AppendChild( SaveCalorieDataCreateNode() ); xml.AppendChild( SaveAwardsCreateNode() ); + xml.AppendChild( SaveLastScoresCreateNode() ); bool bSaved = xml.SaveToFile(fn); if( bSaved && bSignData ) { @@ -1790,3 +1799,105 @@ bool Profile::HasPeakComboAward( PeakComboAward pca ) { return m_PeakComboAwards[pca].IsSet(); } + + + + + + + + + + + + + + + + + + + + + + + + + + +XNode* Profile::HighScoreForASongAndSteps::CreateNode() const +{ + XNode* pNode = new XNode; + pNode->name = "HighScoreForASongAndSteps"; + + pNode->AppendChild( songID.CreateNode() ); + pNode->AppendChild( stepsID.CreateNode() ); + pNode->AppendChild( hs.CreateNode() ); + + return pNode; +} + +void Profile::HighScoreForASongAndSteps::LoadFromNode( const XNode* pNode ) +{ + Unset(); + + ASSERT( pNode->name == "HighScoreForASongAndSteps" ); + XNode* p; + if( p = pNode->GetChild("Song") ) + songID.LoadFromNode( p ); + if( p = pNode->GetChild("Steps") ) + stepsID.LoadFromNode( p ); + if( p = pNode->GetChild("HighScore") ) + hs.LoadFromNode( p ); +} + +void Profile::LoadLastScoresFromNode( const XNode* pNode ) +{ + CHECKPOINT; + + ASSERT( pNode->name == "LastScores" ); + for( XNodes::const_iterator p = pNode->childs.begin(); + p != pNode->childs.end(); + p++ ) + { + if( (*p)->name == "HighScoreForASongAndSteps" ) + { + HighScoreForASongAndSteps h; + h.LoadFromNode( *p ); + + m_vLastScores.push_back( h ); + } + else + WARN_AND_CONTINUE; + } +} + +XNode* Profile::SaveLastScoresCreateNode() const +{ + CHECKPOINT; + + const Profile* pProfile = this; + ASSERT( pProfile ); + + XNode* pNode = new XNode; + pNode->name = "LastScores"; + + unsigned uNumToSave = min( m_vLastScores.size(), (unsigned)MAX_LAST_SCORES_TO_SAVE ); + + for( unsigned i=0; iAppendChild( m_vLastScores[i].CreateNode() ); + } + + return pNode; +} + +void Profile::AddLastScore( Song* pSong, Steps* pSteps, HighScore hs ) +{ + HighScoreForASongAndSteps h; + h.songID.FromSong( pSong ); + h.stepsID.FromSteps( pSteps ); + h.hs = hs; + m_vLastScores.push_back( h ); +} + diff --git a/stepmania/src/Profile.h b/stepmania/src/Profile.h index 0c55d7a221..8134fef5c6 100644 --- a/stepmania/src/Profile.h +++ b/stepmania/src/Profile.h @@ -237,6 +237,24 @@ public: bool HasPerDifficultyAward( StepsType st, Difficulty dc, PerDifficultyAward pda ); bool HasPeakComboAward( PeakComboAward pca ); + // + // LastScores + // + struct HighScoreForASongAndSteps + { + StepsID stepsID; + SongID songID; + HighScore hs; + + HighScoreForASongAndSteps() { Unset(); } + void Unset() { stepsID.Unset(); songID.Unset(); hs.Unset(); } + + XNode* CreateNode() const; + void LoadFromNode( const XNode* pNode ); + }; + vector m_vLastScores; + void AddLastScore( Song* pSong, Steps* pSteps, HighScore hs ); + // // Init'ing // @@ -250,6 +268,7 @@ public: InitScreenshotData(); InitCalorieData(); InitAwards(); + InitLastScores(); } void InitEditableData(); void InitGeneralData(); @@ -259,6 +278,7 @@ public: void InitScreenshotData(); void InitCalorieData(); void InitAwards(); + void InitLastScores(); // // Loading and saving @@ -279,6 +299,7 @@ public: void LoadScreenshotDataFromNode( const XNode* pNode ); void LoadCalorieDataFromNode( const XNode* pNode ); void LoadAwardsFromNode( const XNode* pNode ); + void LoadLastScoresFromNode( const XNode* pNode ); void SaveEditableDataToDir( CString sDir ) const; XNode* SaveGeneralDataCreateNode() const; @@ -288,6 +309,7 @@ public: XNode* SaveScreenshotDataCreateNode() const; XNode* SaveCalorieDataCreateNode() const; XNode* SaveAwardsCreateNode() const; + XNode* SaveLastScoresCreateNode() const; void DeleteProfileDataFromDirSM390a12( CString sDir ) const; void DeleteSongScoresFromDirSM390a12( CString sDir ) const; diff --git a/stepmania/src/SongUtil.h b/stepmania/src/SongUtil.h index 8d92588d37..e75666d0a6 100644 --- a/stepmania/src/SongUtil.h +++ b/stepmania/src/SongUtil.h @@ -39,7 +39,8 @@ class SongID CString sDir; public: - SongID() { FromSong(NULL); } + SongID() { Unset(); } + void Unset() { FromSong(NULL); } void FromSong( const Song *p ); Song *ToSong() const; bool operator<( const SongID &other ) const diff --git a/stepmania/src/StepsUtil.h b/stepmania/src/StepsUtil.h index b15a6a8c86..9eb1147e9a 100644 --- a/stepmania/src/StepsUtil.h +++ b/stepmania/src/StepsUtil.h @@ -39,7 +39,8 @@ class StepsID CString sDescription; public: - StepsID() { FromSteps(NULL); } + StepsID() { Unset(); } + void Unset() { FromSteps(NULL); } void FromSteps( const Steps *p ); Steps *ToSteps( const Song *p, bool bAllowNull ) const; bool operator<( const StepsID &other ) const