fix course entry sorting

This commit is contained in:
Chris Danford
2006-07-03 00:05:13 +00:00
parent d743fc5a65
commit 380f97f903
+25 -19
View File
@@ -375,35 +375,27 @@ bool Course::GetTrailSorted( StepsType st, CourseDifficulty cd, Trail &trail ) c
} }
// TODO: Move Course initialization after PROFILEMAN is created // TODO: Move Course initialization after PROFILEMAN is created
static void CourseSortSongs( SongSort sort, vector<SongAndSteps> &vPossible, RandomGen &rnd ) static void CourseSortSongs( SongSort sort, vector<Song*> &vpPossibleSongs, RandomGen &rnd )
{ {
switch( sort ) switch( sort )
{ {
DEFAULT_FAIL(sort); DEFAULT_FAIL(sort);
case SongSort_Randomize: case SongSort_Randomize:
random_shuffle( vPossible.begin(), vPossible.end(), rnd ); random_shuffle( vpPossibleSongs.begin(), vpPossibleSongs.end(), rnd );
break; break;
case SongSort_MostPlays: case SongSort_MostPlays:
ASSERT(0); if( PROFILEMAN )
// TODO: fix SongUtil::SortSongPointerArrayByNumPlays( vpPossibleSongs, PROFILEMAN->GetMachineProfile(), true ); // descending
//if( PROFILEMAN )
// SongUtil::SortSongPointerArrayByNumPlays( vpPossibleSongs, PROFILEMAN->GetMachineProfile(), true ); // descending
break; break;
case SongSort_FewestPlays: case SongSort_FewestPlays:
ASSERT(0); if( PROFILEMAN )
// TODO: fix SongUtil::SortSongPointerArrayByNumPlays( vpPossibleSongs, PROFILEMAN->GetMachineProfile(), false ); // ascending
//if( PROFILEMAN )
// SongUtil::SortSongPointerArrayByNumPlays( vpPossibleSongs, PROFILEMAN->GetMachineProfile(), false ); // ascending
break; break;
case SongSort_TopGrades: case SongSort_TopGrades:
ASSERT(0); SongUtil::SortSongPointerArrayByGrades( vpPossibleSongs, true ); // descending
// TODO: fix
//SongUtil::SortSongPointerArrayByGrades( vpPossibleSongs, true ); // descending
break; break;
case SongSort_LowestGrades: case SongSort_LowestGrades:
ASSERT(0); SongUtil::SortSongPointerArrayByGrades( vpPossibleSongs, false ); // ascending
// TODO: fix
//SongUtil::SortSongPointerArrayByGrades( vpPossibleSongs, false ); // ascending
break; break;
} }
} }
@@ -501,14 +493,28 @@ bool Course::GetTrailUnsorted( StepsType st, CourseDifficulty cd, Trail &trail )
if( vSongAndSteps.empty() ) if( vSongAndSteps.empty() )
continue; continue;
// TODO: fixme vector<Song*> vpSongs;
CourseSortSongs( e->songSort, vSongAndSteps, rnd ); typedef vector<Steps*> StepsVector;
map<Song*,StepsVector> 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 ); ASSERT( e->iChooseIndex >= 0 );
if( e->iChooseIndex < int(vSongAndSteps.size()) ) if( e->iChooseIndex < int(vSongAndSteps.size()) )
resolved = vSongAndSteps[e->iChooseIndex]; {
resolved.pSong = vpSongs[e->iChooseIndex];
const vector<Steps*> &vpSongs = mapSongToSteps[resolved.pSong];
resolved.pSteps = vpSongs[ rand()%vpSongs.size() ];
}
else else
{
continue; continue;
}
/* If we're not COURSE_DIFFICULTY_REGULAR, then we should be choosing steps that are /* 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 * either easier or harder than the base difficulty. If no such steps exist, then