From 3e07de66556e25dbc082d40fbc88b342d6205cab Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Mon, 30 Jun 2003 04:24:59 +0000 Subject: [PATCH] Split score reading into separate functions. Type fixes. --- stepmania/src/SongManager.cpp | 328 ++++++++++++++++++---------------- stepmania/src/SongManager.h | 5 + 2 files changed, 174 insertions(+), 159 deletions(-) diff --git a/stepmania/src/SongManager.cpp b/stepmania/src/SongManager.cpp index 9fa356f948..8f874933f9 100644 --- a/stepmania/src/SongManager.cpp +++ b/stepmania/src/SongManager.cpp @@ -237,6 +237,170 @@ void SongManager::ReloadSongArray() } +void SongManager::ReadNoteScoresFromFile( CString fn, int c ) +{ + ifstream f(fn); + if( !f.good() ) + return; + CString line; + + getline(f, line); + int version; + sscanf(line.c_str(), "%i", &version); + + if( version != NOTES_SCORES_VERSION ) + return; + + while( f && !f.eof() ) + { + CString sSongDir; + getline(f, sSongDir); + + getline(f, line); + unsigned uNumNotes; + sscanf(line.c_str(), "%u", &uNumNotes); + + Song* pSong = this->GetSongFromDir( sSongDir ); + + for( unsigned i=0; iGetNotes( nt, sDescription ); + else + pNotes = pSong->GetNotes( nt, dc ); + } + + getline(f, line); + + int iNumTimesPlayed; + Grade grade; + int iScore; + if( sscanf(line.c_str(), "%d %d %i\n", &iNumTimesPlayed, &grade, &iScore) != 3 ) + break; + if( pNotes ) + { + pNotes->m_MemCardScores[c].iNumTimesPlayed = iNumTimesPlayed; + pNotes->m_MemCardScores[c].grade = grade; + pNotes->m_MemCardScores[c].iScore = iScore; + } + } + } +} + +void SongManager::ReadCourseScoresFromFile( CString fn, int c ) +{ + FILE* fp = fopen( fn, "r" ); + + if( !fp ) + return; + + int version; + fscanf(fp, "%d\n", &version ); + + if( version == COURSE_SCORES_VERSION ) + { + while( fp && !feof(fp) ) + { + char szPath[256]; + fscanf(fp, "%[^\n]\n", szPath); + Course* pCourse = GetCourseFromPath( szPath ); + if( pCourse == NULL ) + pCourse = GetCourseFromName( szPath ); + + for( int i=0; im_MemCardScores[c][i].iNumTimesPlayed = iNumTimesPlayed; + pCourse->m_MemCardScores[c][i].iDancePoints = iDancePoints; + pCourse->m_MemCardScores[c][i].fSurviveTime = fSurviveTime; + } + } + } + } + + fclose(fp); +} + +void SongManager::ReadCategoryRankingsFromFile( CString fn ) +{ + FILE* fp = fopen( fn, "r" ); + if( !fp ) + return; + + int version; + fscanf(fp, "%d\n", &version ); + if( version == CATEGORY_RANKING_VERSION ) + { + for( int i=0; im_RankingScores[i][j].iDancePoints = iDancePoints; + pCourse->m_RankingScores[i][j].fSurviveTime = fSurviveTime; + pCourse->m_RankingScores[i][j].sName = szName; + } + } + } + } + + fclose(fp); +} void SongManager::InitMachineScoresFromDisk() { @@ -253,172 +417,18 @@ void SongManager::InitMachineScoresFromDisk() } // category ranking - { - FILE* fp = fopen( CATEGORY_RANKING_FILE, "r" ); - if( fp ) - { - int version; - fscanf(fp, "%d\n", &version ); - if( version == CATEGORY_RANKING_VERSION ) - { - for( int i=0; im_RankingScores[i][j].iDancePoints = iDancePoints; - pCourse->m_RankingScores[i][j].fSurviveTime = fSurviveTime; - pCourse->m_RankingScores[i][j].sName = szName; - } - } - } - } - fclose(fp); - } - } + ReadCourseRankingsFromFile( COURSE_RANKING_FILE ); // notes scores for( int c=0; cGetSongFromDir( sSongDir ); - - for( unsigned i=0; iGetNotes( nt, sDescription ); - else - pNotes = pSong->GetNotes( nt, dc ); - } - - getline(f, line); - - int iNumTimesPlayed; - Grade grade; - int iScore; - if( sscanf(line.c_str(), "%d %d %i\n", &iNumTimesPlayed, &grade, &iScore) != 3 ) - break; - if( pNotes ) - { - pNotes->m_MemCardScores[c].iNumTimesPlayed = iNumTimesPlayed; - pNotes->m_MemCardScores[c].grade = grade; - pNotes->m_MemCardScores[c].iScore = iScore; - } - } - } - } - } - } + ReadNoteScoresFromFile( NOTES_SCORES_FILE[c], c ); // course scores - { - for( int c=0; cm_MemCardScores[c][i].iNumTimesPlayed = iNumTimesPlayed; - pCourse->m_MemCardScores[c][i].iDancePoints = iDancePoints; - pCourse->m_MemCardScores[c][i].fSurviveTime = fSurviveTime; - } - } - } - } - fclose(fp); - } - } - } + for( int c=0; c m_pSongs; // all songs that can be played CStringArray m_arrayGroupNames; CStringArray m_GroupBannerPaths; // each song group has a banner associated with it