From a35829aea05a34b5b5497f242156a653ac2f0673 Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Wed, 10 Dec 2003 07:49:54 +0000 Subject: [PATCH] make high score data file smaller, make formats more future-proof --- stepmania/src/ProfileManager.cpp | 78 +++++++++++++++++++------------- 1 file changed, 46 insertions(+), 32 deletions(-) diff --git a/stepmania/src/ProfileManager.cpp b/stepmania/src/ProfileManager.cpp index b1159800ae..0e6ca15245 100644 --- a/stepmania/src/ProfileManager.cpp +++ b/stepmania/src/ProfileManager.cpp @@ -49,9 +49,9 @@ ProfileManager* PROFILEMAN = NULL; // global and accessable from anywhere in our #define USER_PROFILES_DIR BASE_PATH "Data" SLASH "LocalProfiles" SLASH #define MACHINE_PROFILE_DIR BASE_PATH "Data" SLASH "MachineProfile" SLASH -const int CATEGORY_RANKING_VERSION = 4; -const int STEPS_SCORES_VERSION = 8; -const int COURSE_SCORES_VERSION = 6; +const int CATEGORY_RANKING_VERSION = 5; +const int SONG_SCORES_VERSION = 9; +const int COURSE_SCORES_VERSION = 7; #define STATS_TITLE THEME->GetMetric("ProfileManager","StatsTitle") @@ -116,10 +116,9 @@ bool ProfileManager::LoadProfile( PlayerNumber pn, CString sProfileDir, bool bIs return false; } - // Load scores into SONGMAN - PROFILEMAN->ReadCategoryScoresFromDir( m_sProfileDir[pn], (MemoryCard)pn ); - PROFILEMAN->ReadSongScoresFromDir( m_sProfileDir[pn], (MemoryCard)pn ); - PROFILEMAN->ReadCourseScoresFromDir( m_sProfileDir[pn], (MemoryCard)pn ); + ReadCategoryScoresFromDir( m_sProfileDir[pn], (MemoryCard)pn ); + ReadSongScoresFromDir( m_sProfileDir[pn], (MemoryCard)pn ); + ReadCourseScoresFromDir( m_sProfileDir[pn], (MemoryCard)pn ); // apply saved default modifiers if any if( m_Profile[pn].m_bUsingProfileDefaultModifiers ) @@ -401,7 +400,6 @@ void ProfileManager::CategoryData::AddHighScore( HighScore hs, int &iIndexOut ) #define WARN_AND_RETURN { LOG->Warn("Error parsing file '%s' at %s:%d",fn.c_str(),__FILE__,__LINE__); return; } - void ProfileManager::ReadSongScoresFromDir( CString sDir, MemoryCard mc ) { CString fn = sDir + SONG_SCORES_FILE; @@ -416,7 +414,7 @@ void ProfileManager::ReadSongScoresFromDir( CString sDir, MemoryCard mc ) int version; if( !FileRead(f, version) ) WARN_AND_RETURN; - if( version != STEPS_SCORES_VERSION ) + if( version != SONG_SCORES_VERSION ) WARN_AND_RETURN; int iNumSongs; @@ -467,10 +465,14 @@ void ProfileManager::ReadSongScoresFromDir( CString sDir, MemoryCard mc ) if( pNotes ) pNotes->m_MemCardDatas[mc].iNumTimesPlayed = iNumTimesPlayed; - if( pNotes ) - pNotes->m_MemCardDatas[mc].vHighScores.resize(NUM_RANKING_LINES); + int iNumHighScores; + if( !FileRead(f, iNumHighScores) ) + WARN_AND_RETURN; - for( int l=0; lm_MemCardDatas[mc].vHighScores.resize( iNumHighScores ); + + for( unsigned l=0; lm_MemCardDatas[mc].vHighScores[l].sName = sName; - pNotes->m_MemCardDatas[mc].vHighScores[l].grade = grade; - pNotes->m_MemCardDatas[mc].vHighScores[l].iScore = iScore; - pNotes->m_MemCardDatas[mc].vHighScores[l].fPercentDP = fPercentDP; - } + if( pNotes == NULL ) + continue; // ignore this high score + + pNotes->m_MemCardDatas[mc].vHighScores[l].sName = sName; + pNotes->m_MemCardDatas[mc].vHighScores[l].grade = grade; + pNotes->m_MemCardDatas[mc].vHighScores[l].iScore = iScore; + pNotes->m_MemCardDatas[mc].vHighScores[l].fPercentDP = fPercentDP; } } } @@ -523,8 +525,13 @@ void ProfileManager::ReadCategoryScoresFromDir( CString sDir, MemoryCard mc ) { for( int rc=0; rcm_MemCardDatas[st][mc].iNumTimesPlayed = iNumTimesPlayed; - if( pCourse ) - pCourse->m_MemCardDatas[st][mc].vHighScores.resize(NUM_RANKING_LINES); - for( int l=0; lm_MemCardDatas[st][mc].vHighScores.resize(iNumHighScores); + + for( int l=0; lm_MemCardDatas[st][mc].iNumTimesPlayed ); - pCourse->m_MemCardDatas[st][mc].vHighScores.resize(NUM_RANKING_LINES); - for( int l=0; lm_MemCardDatas[st][mc].vHighScores.size() ); + for( unsigned l=0; lm_MemCardDatas[st][mc].vHighScores.size(); l++ ) { // tricky: wipe out "name to fill in" markers if( IsRankingToFillIn(pCourse->m_MemCardDatas[st][mc].vHighScores[l].sName) ) @@ -809,7 +822,7 @@ void ProfileManager::SaveSongScoresToDir( CString sDir, MemoryCard mc ) return; } - FileWrite( f, STEPS_SCORES_VERSION ); + FileWrite( f, SONG_SCORES_VERSION ); const vector &vpSongs = SONGMAN->GetAllSongs(); @@ -827,7 +840,7 @@ void ProfileManager::SaveSongScoresToDir( CString sDir, MemoryCard mc ) for( unsigned i=0; im_apNotes.size(); ++i ) { Steps* pNotes = pSong->m_apNotes[i]; - if( !pNotes->m_MemCardDatas[mc].iNumTimesPlayed ) + if( pNotes->m_MemCardDatas[mc].iNumTimesPlayed == 0 && pNotes->m_MemCardDatas[mc].vHighScores.empty() ) continue; vNotes.push_back( pNotes ); } @@ -848,8 +861,9 @@ void ProfileManager::SaveSongScoresToDir( CString sDir, MemoryCard mc ) FileWrite( f, pNotes->GetDescription() ); FileWrite( f, pNotes->m_MemCardDatas[mc].iNumTimesPlayed ); - pNotes->m_MemCardDatas[mc].vHighScores.resize(NUM_RANKING_LINES); - for( int l=0; lm_MemCardDatas[mc].vHighScores.size() ); + + for( int l=0; lm_MemCardDatas[mc].vHighScores.size(); l++ ) { // tricky: wipe out "name to fill in" markers if( IsRankingToFillIn(pNotes->m_MemCardDatas[mc].vHighScores[l].sName) )