Revert "Previously, we didn't create MusicWheel sorts when the screen loads"

This reverts commit 0dc297ba76508bb7244ed70f9f72761087e1f177.

It didn't work out so well.
This commit is contained in:
AJ Kelly
2011-03-13 20:23:07 -05:00
parent e89ddce064
commit 919279938e
2 changed files with 161 additions and 198 deletions
+160 -196
View File
@@ -113,31 +113,25 @@ void MusicWheel::Load( RString sType )
* stable_sort) from its output, and title will be the secondary sort, without having
* to re-sort by title each time. */
SONGMAN->SortSongs();
}
void MusicWheel::BeginScreen()
{
RageTimer timer;
RString times;
/* Build all of the wheel item data. Do this after selecting the extra stage,
* so it knows to always display it. */
FOREACH_ENUM( SortOrder, so )
{
BuildWheelItemDatas( m_UnfilteredWheelItemDatas[so], so );
BuildWheelItemDatas( m_WheelItemDatas[so], so );
times += ssprintf( "%i:%.3f ", so, timer.GetDeltaTime() );
}
LOG->Trace( "MusicWheel sorting took: %s", times.c_str() );
}
void MusicWheel::BeginScreen()
{
FOREACH_ENUM( SortOrder, so )
{
m_UnfilteredWheelItemDatas[so] = m_UnfilteredWheelItemDatas[so];
UpdateWheelItemDatas( so );
}
/* Set m_LastModeMenuItem to the first item that matches the current mode. (Do this
* after building wheel item data.) */
{
const vector<MusicWheelItemData *> &from = m_UnfilteredWheelItemDatas[SORT_MODE_MENU];
const vector<MusicWheelItemData *> &from = m_WheelItemDatas[SORT_MODE_MENU];
for( unsigned i=0; i<from.size(); i++ )
{
ASSERT( &*from[i]->m_pAction );
@@ -234,7 +228,7 @@ void MusicWheel::BeginScreen()
MusicWheel::~MusicWheel()
{
FOREACH_ENUM( SortOrder, so )
FOREACH( MusicWheelItemData*, m_UnfilteredWheelItemDatas[so], i )
FOREACH( MusicWheelItemData*, m_WheelItemDatas[so], i )
delete *i;
}
@@ -253,7 +247,7 @@ bool MusicWheel::SelectSongOrCourse()
return true;
// Select the first selectable song based on the sort order...
vector<MusicWheelItemData *> &wiWheelItems = m_UnfilteredWheelItemDatas[GAMESTATE->m_SortOrder];
vector<MusicWheelItemData *> &wiWheelItems = m_WheelItemDatas[GAMESTATE->m_SortOrder];
for( unsigned i = 0; i < wiWheelItems.size(); i++ )
{
if( wiWheelItems[i]->m_pSong )
@@ -286,7 +280,7 @@ bool MusicWheel::SelectSong( const Song *p )
return false;
unsigned i;
vector<MusicWheelItemData *> &from = m_UnfilteredWheelItemDatas[GAMESTATE->m_SortOrder];
vector<MusicWheelItemData *> &from = m_WheelItemDatas[GAMESTATE->m_SortOrder];
for( i=0; i<from.size(); i++ )
{
if( from[i]->m_pSong == p )
@@ -314,7 +308,7 @@ bool MusicWheel::SelectCourse( const Course *p )
return false;
unsigned i;
vector<MusicWheelItemData *> &from = m_UnfilteredWheelItemDatas[GAMESTATE->m_SortOrder];
vector<MusicWheelItemData *> &from = m_WheelItemDatas[GAMESTATE->m_SortOrder];
for( i=0; i<from.size(); i++ )
{
if( from[i]->m_pCourse == p )
@@ -331,7 +325,7 @@ bool MusicWheel::SelectCourse( const Course *p )
for( i=0; i<m_CurWheelItemData.size(); i++ )
{
if( GetCurWheelItemData(i)->m_pCourse == p )
m_iSelection = i; // select it
m_iSelection = i; // select it
}
return true;
@@ -339,9 +333,9 @@ bool MusicWheel::SelectCourse( const Course *p )
bool MusicWheel::SelectModeMenuItem()
{
/* Select the last-chosen option. */
// Select the last-chosen option.
ASSERT( GAMESTATE->m_SortOrder == SORT_MODE_MENU );
const vector<MusicWheelItemData *> &from = m_UnfilteredWheelItemDatas[GAMESTATE->m_SortOrder];
const vector<MusicWheelItemData *> &from = m_WheelItemDatas[GAMESTATE->m_SortOrder];
unsigned i;
for( i=0; i<from.size(); i++ )
{
@@ -366,12 +360,120 @@ bool MusicWheel::SelectModeMenuItem()
return true;
}
void MusicWheel::GetSongList( vector<Song*> &arraySongs, SortOrder so )
{
vector<Song*> apAllSongs;
switch( so )
{
case SORT_PREFERRED:
SONGMAN->GetPreferredSortSongs( apAllSongs );
break;
case SORT_POPULARITY:
apAllSongs = SONGMAN->GetPopularSongs();
break;
case SORT_GROUP:
// if we're not using sections with a preferred song group, and there
// is a group to load, only load those songs. -aj
if(GAMESTATE->m_sPreferredSongGroup != GROUP_ALL && !USE_SECTIONS_WITH_PREFERRED_GROUP )
{
apAllSongs = SONGMAN->GetSongs(GAMESTATE->m_sPreferredSongGroup);
break;
}
// otherwise fall through
default:
apAllSongs = SONGMAN->GetAllSongs();
break;
}
// filter songs that we don't have enough stages to play
{
vector<Song*> vTempSongs;
SongCriteria sc;
sc.m_iMaxStagesForSong = GAMESTATE->GetSmallestNumStagesLeftForAnyHumanPlayer();
SongUtil::FilterSongs( sc, apAllSongs, vTempSongs );
apAllSongs = vTempSongs;
}
// copy only songs that have at least one Steps for the current GameMode
for( unsigned i=0; i<apAllSongs.size(); i++ )
{
Song* pSong = apAllSongs[i];
int iLocked = UNLOCKMAN->SongIsLocked( pSong );
if( iLocked & LOCKED_DISABLED )
continue;
// If we're on an extra stage, and this song is selected, ignore #SELECTABLE.
if( pSong != GAMESTATE->m_pCurSong || !GAMESTATE->IsAnExtraStage() )
{
// Hide songs that asked to be hidden via #SELECTABLE.
if( iLocked & LOCKED_SELECTABLE )
continue;
if( so != SORT_ROULETTE && iLocked & LOCKED_ROULETTE )
continue;
}
/* Hide locked songs. If RANDOM_PICKS_LOCKED_SONGS, hide in Roulette
* and Random, too. */
if( (so!=SORT_ROULETTE || !RANDOM_PICKS_LOCKED_SONGS) && iLocked )
continue;
if( PREFSMAN->m_bOnlyPreferredDifficulties )
{
// if the song has steps that fit the preferred difficulty of the default player
if( pSong->HasStepsTypeAndDifficulty( GAMESTATE->GetCurrentStyle()->m_StepsType,GAMESTATE->m_PreferredDifficulty[GAMESTATE->GetFirstHumanPlayer()] ) )
arraySongs.push_back( pSong );
}
else
{
if(CommonMetrics::AUTO_SET_STYLE)
{
// with AUTO_SET_STYLE on and Autogen off, some songs may get
// hidden. Search through every playable StepsType until you
// find one, then add the song.
// see Issue 147 for more information. -aj
// http://ssc.ajworld.net/sm-ssc/bugtracker/view.php?id=147
set<StepsType> vStepsType;
SongUtil::GetPlayableStepsTypes( pSong, vStepsType );
FOREACHS( StepsType, vStepsType, st )
{
if(pSong->HasStepsType(*st))
{
arraySongs.push_back( pSong );
break;
}
}
}
else
{
// If the song has at least one steps, add it.
if( pSong->HasStepsType(GAMESTATE->GetCurrentStyle()->m_StepsType) )
arraySongs.push_back( pSong );
}
}
}
/* Hack: Add extra stage item if it was eliminated for any reason
* (eg. it's a long song). */
if( GAMESTATE->IsAnExtraStage() )
{
Song* pSong;
Steps* pSteps;
SONGMAN->GetExtraStageInfo( GAMESTATE->IsExtraStage2(), GAMESTATE->GetCurrentStyle(), pSong, pSteps );
if( find( arraySongs.begin(), arraySongs.end(), pSong ) == arraySongs.end() )
arraySongs.push_back( pSong );
}
}
void MusicWheel::BuildWheelItemDatas( vector<MusicWheelItemData *> &arrayWheelItemDatas, SortOrder so )
{
switch( so )
{
case SORT_MODE_MENU:
{
arrayWheelItemDatas.clear(); // clear out the previous wheel items
vector<RString> vsNames;
split( MODE_MENU_CHOICE_NAMES, ",", vsNames );
for( unsigned i=0; i<vsNames.size(); ++i )
@@ -406,21 +508,9 @@ void MusicWheel::BuildWheelItemDatas( vector<MusicWheelItemData *> &arrayWheelIt
case SORT_LENGTH:
case SORT_RECENT:
{
// Get all songs that can be shown in this sort. Filtering songs
// that can't be played will happen later, in UpdateWheelItemDatas.
// Make an array of Song*, then sort them
vector<Song*> arraySongs;
switch( so )
{
case SORT_PREFERRED:
SONGMAN->GetPreferredSortSongs( arraySongs );
break;
case SORT_POPULARITY:
arraySongs = SONGMAN->GetPopularSongs();
break;
default:
arraySongs = SONGMAN->GetAllSongs();
break;
}
GetSongList( arraySongs, so );
bool bUseSections = true;
@@ -543,6 +633,16 @@ void MusicWheel::BuildWheelItemDatas( vector<MusicWheelItemData *> &arrayWheelIt
if( sThisSection != sLastSection )
{
int iSectionCount = 0;
// Count songs in this section
unsigned j;
for( j=i; j < arraySongs.size(); j++ )
{
if( SongUtil::GetSectionNameFromSongAndSort( arraySongs[j], so ) != sThisSection )
break;
}
iSectionCount = j-i;
// new section, make a section item
// todo: preferred sort section color handling? -aj
RageColor colorSection = (so==SORT_GROUP) ? SONGMAN->GetSongGroupColor(pSong->m_sGroupName) : SECTION_COLORS.GetValue(iSectionColorIndex);
@@ -550,7 +650,7 @@ void MusicWheel::BuildWheelItemDatas( vector<MusicWheelItemData *> &arrayWheelIt
// In certain situations (e.g. simulating Pump it Up), themes may
// want to only show one group at a time.
if( !HIDE_INACTIVE_SECTIONS )
arrayWheelItemDatas.push_back( new MusicWheelItemData(TYPE_SECTION, NULL, sThisSection, NULL, colorSection, 0) );
arrayWheelItemDatas.push_back( new MusicWheelItemData(TYPE_SECTION, NULL, sThisSection, NULL, colorSection, iSectionCount) );
sLastSection = sThisSection;
}
}
@@ -562,10 +662,17 @@ void MusicWheel::BuildWheelItemDatas( vector<MusicWheelItemData *> &arrayWheelIt
if( SHOW_ROULETTE )
arrayWheelItemDatas.push_back( new MusicWheelItemData(TYPE_ROULETTE, NULL, "", NULL, ROULETTE_COLOR, 0) );
if( SHOW_RANDOM )
// Only add TYPE_RANDOM and TYPE_PORTAL if there's at least
// one song on the list.
bool bFoundAnySong = false;
for( unsigned i=0; !bFoundAnySong && i < arrayWheelItemDatas.size(); i++ )
if( arrayWheelItemDatas[i]->m_Type == TYPE_SONG )
bFoundAnySong = true;
if( SHOW_RANDOM && bFoundAnySong )
arrayWheelItemDatas.push_back( new MusicWheelItemData(TYPE_RANDOM, NULL, "", NULL, RANDOM_COLOR, 0) );
if( SHOW_PORTAL )
if( SHOW_PORTAL && bFoundAnySong )
arrayWheelItemDatas.push_back( new MusicWheelItemData(TYPE_PORTAL, NULL, "", NULL, PORTAL_COLOR, 0) );
// add custom wheel items
@@ -666,6 +773,8 @@ void MusicWheel::BuildWheelItemDatas( vector<MusicWheelItemData *> &arrayWheelIt
if( so == SORT_ALL_COURSES )
CourseUtil::SortCoursePointerArrayByType( apCourses );
arrayWheelItemDatas.clear(); // clear out the previous wheel items
RString sLastSection = "";
int iSectionColorIndex = 0;
for( unsigned i=0; i<apCourses.size(); i++ ) // foreach course
@@ -687,6 +796,10 @@ void MusicWheel::BuildWheelItemDatas( vector<MusicWheelItemData *> &arrayWheelIt
}
}
// check that this course has at least one song playable in the current style
if( !pCourse->IsPlayableIn(GAMESTATE->GetCurrentStyle()->m_StepsType) )
continue;
if( sThisSection != sLastSection ) // new section, make a section item
{
RageColor c = SECTION_COLORS.GetValue(iSectionColorIndex);
@@ -708,6 +821,7 @@ void MusicWheel::BuildWheelItemDatas( vector<MusicWheelItemData *> &arrayWheelIt
MusicWheelItemData& WID = *arrayWheelItemDatas[i];
if( WID.m_pSong != NULL )
{
WID.m_Flags.bHasBeginnerOr1Meter = WID.m_pSong->IsEasy( GAMESTATE->GetCurrentStyle()->m_StepsType ) && SHOW_EASY_FLAG;
WID.m_Flags.bEdits = false;
set<StepsType> vStepsType;
SongUtil::GetPlayableStepsTypes( WID.m_pSong, vStepsType );
@@ -717,175 +831,25 @@ void MusicWheel::BuildWheelItemDatas( vector<MusicWheelItemData *> &arrayWheelIt
}
else if( WID.m_pCourse != NULL )
{
WID.m_Flags.bHasBeginnerOr1Meter = false;
WID.m_Flags.bEdits = WID.m_pCourse->IsAnEdit();
WID.m_Flags.iStagesForSong = 1;
}
}
}
/* The screen is starting. Take m_UnfilteredWheelItemDatas created on load by
* BuildWheelItemDatas and update them for the current state. Output the
* results into m_WheelItemDatas. */
void MusicWheel::UpdateWheelItemDatas( SortOrder so )
{
vector<MusicWheelItemData *> &aWheelItemDatas = m_UnfilteredWheelItemDatas[so];
// Only add TYPE_PORTAL if there's at least one song on the list.
bool bFoundAnySong = false;
for( unsigned i=0; !bFoundAnySong && i < aWheelItemDatas.size(); i++ )
if( aWheelItemDatas[i]->m_Type == TYPE_SONG )
bFoundAnySong = true;
vector<bool> aiRemove;
aiRemove.insert( aiRemove.begin(), aWheelItemDatas.size(), false );
const int iMaxStagesForSong = GAMESTATE->GetSmallestNumStagesLeftForAnyHumanPlayer();
Song *pExtraStageSong = NULL;
if( GAMESTATE->IsAnExtraStage() )
{
Steps *pSteps;
SONGMAN->GetExtraStageInfo( GAMESTATE->IsExtraStage2(), GAMESTATE->GetCurrentStyle(), pExtraStageSong, pSteps );
}
// Mark any songs that aren't playable in aiRemove.
for( unsigned i=0; i< aWheelItemDatas.size(); i++ )
{
MusicWheelItemData& WID = *aWheelItemDatas[i];
// If we have no songs, remove Random and Portal.
if( WID.m_Type == TYPE_RANDOM || WID.m_Type == TYPE_PORTAL )
{
if( !bFoundAnySong )
aiRemove[i] = true;
continue;
}
// Filter songs that we don't have enough stages to play.
if( WID.m_Type == TYPE_SONG )
{
Song* pSong = WID.m_pSong;
// Never remove the extra stage song.
if( pExtraStageSong && WID.m_pSong == pExtraStageSong )
continue;
// Check that we have enough stages to play this song, and that it's not disabled.
if( GAMESTATE->GetNumStagesMultiplierForSong(WID.m_pSong) > iMaxStagesForSong )
{
aiRemove[i] = true;
continue;
}
int iLocked = UNLOCKMAN->SongIsLocked( pSong );
if( UNLOCKMAN->SongIsLocked(pSong) & LOCKED_DISABLED )
{
aiRemove[i] = true;
continue;
}
// If we're on an extra stage, and this song is selected, ignore #SELECTABLE.
if( pSong != GAMESTATE->m_pCurSong || !GAMESTATE->IsAnExtraStage() )
{
// Hide songs that asked to be hidden via #SELECTABLE.
if( iLocked & LOCKED_SELECTABLE )
{
aiRemove[i] = true;
continue;
}
if( so != SORT_ROULETTE && iLocked & LOCKED_ROULETTE )
{
aiRemove[i] = true;
continue;
}
}
/* Hide locked songs. If RANDOM_PICKS_LOCKED_SONGS, hide in Roulette
* and Random, too. */
if( (so!=SORT_ROULETTE || !RANDOM_PICKS_LOCKED_SONGS) && iLocked )
{
aiRemove[i] = true;
continue;
}
// If the song has no steps for the current style, remove it.
if( !pSong->HasStepsType(GAMESTATE->GetCurrentStyle()->m_StepsType) )
{
aiRemove[i] = true;
continue;
}
}
if( WID.m_Type == TYPE_COURSE )
{
if( !WID.m_pCourse->IsPlayableIn(GAMESTATE->GetCurrentStyle()->m_StepsType) )
aiRemove[i] = true;
}
}
// Filter out the songs we're removing.
vector<MusicWheelItemData *> &aFilteredData = m_WheelItemDatas[so];
aFilteredData.reserve( aWheelItemDatas.size() );
for( unsigned i=0; i< aWheelItemDatas.size(); i++ )
{
if( aiRemove[i] )
continue;
aFilteredData.push_back( aWheelItemDatas[i] );
}
// Update the song count in each section header.
for( unsigned i=0; i < aFilteredData.size(); )
{
MusicWheelItemData& WID = *aFilteredData[i];
++i;
if( WID.m_Type != TYPE_SECTION )
continue;
// Count songs in this section
WID.m_iSectionCount = 0;
for( ; i < aFilteredData.size() && aFilteredData[i]->m_sText == WID.m_sText; ++i )
++WID.m_iSectionCount;
}
// If we have any section headers with no songs, then we filtered all of
// the songs in that group, so remove it. This isn't optimized like the
// above since this is a rare case.
for( unsigned i=0; i < aFilteredData.size(); ++i )
{
MusicWheelItemData& WID = *aFilteredData[i];
if( WID.m_Type != TYPE_SECTION )
continue;
if( WID.m_iSectionCount > 0 )
continue;
aFilteredData.erase( aFilteredData.begin()+i, aFilteredData.begin()+i+1 );
--i;
}
// Update the popularity. This is affected by filtering.
// Update the popularity and init icons.
if( so == SORT_POPULARITY )
{
for( unsigned i=0; i< min(3u,aFilteredData.size()); i++ )
for( unsigned i=0; i< min(3u,arrayWheelItemDatas.size()); i++ )
{
MusicWheelItemData& WID = *aFilteredData[i];
MusicWheelItemData& WID = *arrayWheelItemDatas[i];
WID.m_Flags.iPlayersBestNumber = i+1;
}
}
// Update the easy status. This is affected by the steps type.
if( SHOW_EASY_FLAG )
{
for( unsigned i=0; i<aFilteredData.size(); i++ )
{
MusicWheelItemData& WID = *aFilteredData[i];
if( WID.m_pSong == NULL )
continue;
WID.m_Flags.bHasBeginnerOr1Meter = WID.m_pSong->IsEasy( GAMESTATE->GetCurrentStyle()->m_StepsType );
}
}
// If we've filtered all items, insert a dummy.
if( aFilteredData.empty() )
aFilteredData.push_back( new MusicWheelItemData(TYPE_SECTION, NULL, "- EMPTY -", NULL, RageColor(1,0,0,1), 0) );
if( arrayWheelItemDatas.empty() )
arrayWheelItemDatas.push_back( new MusicWheelItemData(TYPE_SECTION, NULL, "- EMPTY -", NULL, RageColor(1,0,0,1), 0) );
}
void MusicWheel::UpdateSwitch()
@@ -1013,7 +977,7 @@ bool MusicWheel::ChangeSort( SortOrder new_so ) // return true if change success
return false;
// Don't change to SORT_MODE_MENU if it doesn't have at least two choices.
if( new_so == SORT_MODE_MENU && m_UnfilteredWheelItemDatas[new_so].size() < 2 )
if( new_so == SORT_MODE_MENU && m_WheelItemDatas[new_so].size() < 2 )
return false;
switch( m_WheelState )
@@ -1149,7 +1113,7 @@ void MusicWheel::StartRandom()
{
// Shuffle and use the roulette wheel.
RandomGen rnd;
random_shuffle( m_UnfilteredWheelItemDatas[SORT_ROULETTE].begin(), m_UnfilteredWheelItemDatas[SORT_ROULETTE].end(), rnd );
random_shuffle( m_WheelItemDatas[SORT_ROULETTE].begin(), m_WheelItemDatas[SORT_ROULETTE].end(), rnd );
GAMESTATE->m_SortOrder.Set( SORT_ROULETTE );
}
else
@@ -1187,7 +1151,7 @@ void MusicWheel::SetOpenSection( RString group )
GAMEMAN->GetCompatibleStyles( GAMESTATE->m_pCurGame, GAMESTATE->GetNumPlayersEnabled(), vpPossibleStyles );
m_CurWheelItemData.clear();
vector<MusicWheelItemData *> &from = m_UnfilteredWheelItemDatas[GAMESTATE->m_SortOrder];
vector<MusicWheelItemData *> &from = m_WheelItemDatas[GAMESTATE->m_SortOrder];
m_CurWheelItemData.reserve( from.size() );
for( unsigned i = 0; i < from.size(); ++i )
{
@@ -1349,7 +1313,7 @@ void MusicWheel::PlayerJoined()
// We need to rebuild the wheel item data in this situation. -aj
if( !GAMESTATE->IsCourseMode() && !PREFSMAN->m_bAutogenSteps )
{
BuildWheelItemDatas( m_UnfilteredWheelItemDatas[GAMESTATE->m_SortOrder], GAMESTATE->m_SortOrder );
BuildWheelItemDatas( m_WheelItemDatas[GAMESTATE->m_SortOrder], GAMESTATE->m_SortOrder );
}
SetOpenSection( m_sExpandedSectionName );
@@ -1399,7 +1363,7 @@ Song *MusicWheel::GetPreferredSelectionForRandomOrPortal()
}
RString sPreferredGroup = m_sExpandedSectionName;
vector<MusicWheelItemData *> &wid = m_UnfilteredWheelItemDatas[GAMESTATE->m_SortOrder];
vector<MusicWheelItemData *> &wid = m_WheelItemDatas[GAMESTATE->m_SortOrder];
StepsType st = GAMESTATE->GetCurrentStyle()->m_StepsType;
+1 -2
View File
@@ -52,15 +52,14 @@ public:
protected:
MusicWheelItem *MakeItem();
void GetSongList( vector<Song*> &arraySongs, SortOrder so );
void BuildWheelItemDatas( vector<MusicWheelItemData *> &arrayWheelItems, SortOrder so );
void UpdateWheelItemDatas( SortOrder so );
bool SelectSongOrCourse();
bool SelectCourse( const Course *p );
bool SelectModeMenuItem();
virtual void UpdateSwitch();
vector<MusicWheelItemData *> m_UnfilteredWheelItemDatas[NUM_SortOrder];
vector<MusicWheelItemData *> m_WheelItemDatas[NUM_SortOrder]; // aliases into m_UnfilteredWheelItemDatas
RString m_sLastModeMenuItem;