From 380f97f9034a7b5fcc1633dd1cdb5ea2ef4a7568 Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Mon, 3 Jul 2006 00:05:13 +0000 Subject: [PATCH] fix course entry sorting --- stepmania/src/Course.cpp | 44 +++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/stepmania/src/Course.cpp b/stepmania/src/Course.cpp index cca5e6cf8b..0b2d862846 100644 --- a/stepmania/src/Course.cpp +++ b/stepmania/src/Course.cpp @@ -375,35 +375,27 @@ bool Course::GetTrailSorted( StepsType st, CourseDifficulty cd, Trail &trail ) c } // TODO: Move Course initialization after PROFILEMAN is created -static void CourseSortSongs( SongSort sort, vector &vPossible, RandomGen &rnd ) +static void CourseSortSongs( SongSort sort, vector &vpPossibleSongs, RandomGen &rnd ) { switch( sort ) { DEFAULT_FAIL(sort); case SongSort_Randomize: - random_shuffle( vPossible.begin(), vPossible.end(), rnd ); + random_shuffle( vpPossibleSongs.begin(), vpPossibleSongs.end(), rnd ); break; case SongSort_MostPlays: - ASSERT(0); - // TODO: fix - //if( PROFILEMAN ) - // SongUtil::SortSongPointerArrayByNumPlays( vpPossibleSongs, PROFILEMAN->GetMachineProfile(), true ); // descending + if( PROFILEMAN ) + SongUtil::SortSongPointerArrayByNumPlays( vpPossibleSongs, PROFILEMAN->GetMachineProfile(), true ); // descending break; case SongSort_FewestPlays: - ASSERT(0); - // TODO: fix - //if( PROFILEMAN ) - // SongUtil::SortSongPointerArrayByNumPlays( vpPossibleSongs, PROFILEMAN->GetMachineProfile(), false ); // ascending + if( PROFILEMAN ) + SongUtil::SortSongPointerArrayByNumPlays( vpPossibleSongs, PROFILEMAN->GetMachineProfile(), false ); // ascending break; case SongSort_TopGrades: - ASSERT(0); - // TODO: fix - //SongUtil::SortSongPointerArrayByGrades( vpPossibleSongs, true ); // descending + SongUtil::SortSongPointerArrayByGrades( vpPossibleSongs, true ); // descending break; case SongSort_LowestGrades: - ASSERT(0); - // TODO: fix - //SongUtil::SortSongPointerArrayByGrades( vpPossibleSongs, false ); // ascending + SongUtil::SortSongPointerArrayByGrades( vpPossibleSongs, false ); // ascending break; } } @@ -501,14 +493,28 @@ bool Course::GetTrailUnsorted( StepsType st, CourseDifficulty cd, Trail &trail ) if( vSongAndSteps.empty() ) continue; - // TODO: fixme - CourseSortSongs( e->songSort, vSongAndSteps, rnd ); + vector vpSongs; + typedef vector StepsVector; + map mapSongToSteps; + FOREACH_CONST( SongAndSteps, vSongAndSteps, sas ) + { + mapSongToSteps[sas->pSong].push_back(sas->pSteps); + vpSongs.push_back( sas->pSong ); + } + + CourseSortSongs( e->songSort, vpSongs, rnd ); ASSERT( e->iChooseIndex >= 0 ); if( e->iChooseIndex < int(vSongAndSteps.size()) ) - resolved = vSongAndSteps[e->iChooseIndex]; + { + resolved.pSong = vpSongs[e->iChooseIndex]; + const vector &vpSongs = mapSongToSteps[resolved.pSong]; + resolved.pSteps = vpSongs[ rand()%vpSongs.size() ]; + } else + { continue; + } /* If we're not COURSE_DIFFICULTY_REGULAR, then we should be choosing steps that are * either easier or harder than the base difficulty. If no such steps exist, then