From a58a2a2bb2e2dd160c3bad4a35437215b94e46f7 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Mon, 31 Oct 2005 01:18:10 +0000 Subject: [PATCH] This seems to have optimized an uncommon case at the cost of the common case. Normally, most songs in most courses are static. Previously, in those cases, the filtered song list would never be generated; now it's generated for every course. Optimize the filtering (erase() on a vector is slow). --- stepmania/src/Course.cpp | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/stepmania/src/Course.cpp b/stepmania/src/Course.cpp index ba5dec6cd2..2c8716b8e8 100644 --- a/stepmania/src/Course.cpp +++ b/stepmania/src/Course.cpp @@ -539,28 +539,27 @@ bool Course::GetTrailUnsorted( StepsType st, CourseDifficulty cd, Trail &trail ) /* Set to true if CourseDifficulty is able to change something. */ bool bCourseDifficultyIsSignificant = (cd == DIFFICULTY_MEDIUM); - // get a list of all songs that are 1 stage long vector vpAllPossibleSongs; - SONGMAN->GetSongs(vpAllPossibleSongs, 1); - - // remove locked and tutorial songs from the list - for( vector::iterator song = vpAllPossibleSongs.begin(); song != vpAllPossibleSongs.end(); ) { - // Ignore locked songs when choosing randomly - // TODO: Move Course initialization after UNLOCKMAN is created - if( UNLOCKMAN && UNLOCKMAN->SongIsLocked(*song) ) - { - song = vpAllPossibleSongs.erase( song ); - continue; - } + const vector &vpAllSongs = SONGMAN->GetAllSongs(); - // Ignore boring tutorial songs - if( (*song)->IsTutorial() ) + FOREACH_CONST( Song*, vpAllSongs, song ) { - song = vpAllPossibleSongs.erase( song ); - continue; + // Ignore locked songs when choosing randomly + // TODO: Move Course initialization after UNLOCKMAN is created + if( UNLOCKMAN && UNLOCKMAN->SongIsLocked(*song) ) + continue; + + // Ignore boring tutorial songs + if( (*song)->IsTutorial() ) + continue; + + // Don't allow long songs + if( SONGMAN->GetNumStagesForSong(*song) > 1 ) + continue; + + vpAllPossibleSongs.push_back( *song ); } - ++song; } // Resolve each entry to a Song and Steps. @@ -574,7 +573,6 @@ bool Course::GetTrailUnsorted( StepsType st, CourseDifficulty cd, Trail &trail ) // // Start with all songs - vector vpPossibleSongs; vector vpPossibleSteps; if( e->pSong ) @@ -590,6 +588,7 @@ bool Course::GetTrailUnsorted( StepsType st, CourseDifficulty cd, Trail &trail ) { // copy over any songs that match our group filter, if one is set, and match our // steps filter. + vector vpPossibleSongs; FOREACH( Song*, vpAllPossibleSongs, song ) { if( !e->sSongGroup.empty() && (*song)->m_sGroupName != e->sSongGroup )