From a31f76e9ad53fcef32c17aedcde91cb66607beab Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sun, 1 Oct 2006 20:13:27 +0000 Subject: [PATCH] allocate GameCommand as needed --- stepmania/src/GameCommand.cpp | 2 ++ stepmania/src/MusicWheel.cpp | 23 +++++++++++++---------- stepmania/src/MusicWheelItem.cpp | 3 +-- stepmania/src/MusicWheelItem.h | 2 +- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/stepmania/src/GameCommand.cpp b/stepmania/src/GameCommand.cpp index bd69b2b89e..9325cf0968 100644 --- a/stepmania/src/GameCommand.cpp +++ b/stepmania/src/GameCommand.cpp @@ -26,6 +26,8 @@ static LocalizedString COULD_NOT_LAUNCH_BROWSER( "GameCommand", "Could not launch web browser." ); +REGISTER_CLASS_TRAITS( GameCommand, new GameCommand(*pCopy) ); + void GameCommand::Init() { m_bApplyCommitsScreens = true; diff --git a/stepmania/src/MusicWheel.cpp b/stepmania/src/MusicWheel.cpp index 7a382d776b..0b93a386f1 100644 --- a/stepmania/src/MusicWheel.cpp +++ b/stepmania/src/MusicWheel.cpp @@ -123,9 +123,10 @@ void MusicWheel::Load( RString sType ) const vector &from = m_WheelItemDatas[SORT_MODE_MENU]; for( unsigned i=0; im_Action.DescribesCurrentModeForAllPlayers() ) + ASSERT( &*from[i]->m_pAction ); + if( from[i]->m_pAction->DescribesCurrentModeForAllPlayers() ) { - m_sLastModeMenuItem = from[i]->m_Action.m_sName; + m_sLastModeMenuItem = from[i]->m_pAction->m_sName; break; } } @@ -285,11 +286,12 @@ bool MusicWheel::SelectCourse( const Course *p ) bool MusicWheel::SelectModeMenuItem() { /* Select the last-chosen option. */ + ASSERT( GAMESTATE->m_SortOrder == SORT_MODE_MENU ); const vector &from = m_WheelItemDatas[GAMESTATE->m_SortOrder]; unsigned i; for( i=0; im_Action; + const GameCommand &gc = *from[i]->m_pAction; if( gc.m_sName == m_sLastModeMenuItem ) break; } @@ -301,7 +303,7 @@ bool MusicWheel::SelectModeMenuItem() for( i=0; im_Action.m_sName != m_sLastModeMenuItem ) + if( GetCurWheelItemData(i)->m_pAction->m_sName != m_sLastModeMenuItem ) continue; m_iSelection = i; // select it break; @@ -391,11 +393,12 @@ void MusicWheel::BuildWheelItemDatas( vector &arrayWheelItemDat } WheelItemData wid( TYPE_SORT, NULL, "", NULL, SORT_MENU_COLOR ); - wid.m_Action.m_sName = vsNames[i]; - wid.m_Action.Load( i, ParseCommands(CHOICE.GetValue(vsNames[i])) ); + wid.m_pAction = HiddenPtr( new GameCommand ); + wid.m_pAction->m_sName = vsNames[i]; + wid.m_pAction->Load( i, ParseCommands(CHOICE.GetValue(vsNames[i])) ); wid.m_sLabel = WHEEL_TEXT(vsNames[i]); - if( !wid.m_Action.IsPlayable() ) + if( !wid.m_pAction->IsPlayable() ) continue; arrayWheelItemDatas.push_back( new WheelItemData(wid) ); @@ -924,10 +927,10 @@ bool MusicWheel::Select() // return true if this selection ends the screen case TYPE_SORT: LOG->Trace("New sort order selected: %s - %s", GetCurWheelItemData(m_iSelection)->m_sLabel.c_str(), - SortOrderToString(GetCurWheelItemData(m_iSelection)->m_Action.m_SortOrder).c_str() ); - GetCurWheelItemData(m_iSelection)->m_Action.ApplyToAllPlayers(); + SortOrderToString(GetCurWheelItemData(m_iSelection)->m_pAction->m_SortOrder).c_str() ); + GetCurWheelItemData(m_iSelection)->m_pAction->ApplyToAllPlayers(); ChangeSort( GAMESTATE->m_PreferredSortOrder ); - m_sLastModeMenuItem = GetCurWheelItemData(m_iSelection)->m_Action.m_sName; + m_sLastModeMenuItem = GetCurWheelItemData(m_iSelection)->m_pAction->m_sName; break; default: break; diff --git a/stepmania/src/MusicWheelItem.cpp b/stepmania/src/MusicWheelItem.cpp index c5c96a8782..edf9648007 100644 --- a/stepmania/src/MusicWheelItem.cpp +++ b/stepmania/src/MusicWheelItem.cpp @@ -29,7 +29,6 @@ WheelItemData::WheelItemData( WheelItemType wit, Song* pSong, RString sSectionNa m_pCourse = pCourse; } - MusicWheelItem::MusicWheelItem( RString sType ): WheelItemBase( sType ) { @@ -254,7 +253,7 @@ void MusicWheelItem::LoadFromWheelItemData( const WheelItemBaseData *pWIBD ) m_sprSectionBar.SetHidden( false ); break; case TYPE_SORT: - if( pWID->m_Action.m_pm != PlayMode_Invalid ) + if( pWID->m_pAction->m_pm != PlayMode_Invalid ) m_sprModeBar.SetHidden( false ); else m_sprSortBar.SetHidden( false ); diff --git a/stepmania/src/MusicWheelItem.h b/stepmania/src/MusicWheelItem.h index 2d8244266a..f06925ccae 100644 --- a/stepmania/src/MusicWheelItem.h +++ b/stepmania/src/MusicWheelItem.h @@ -56,7 +56,7 @@ struct WheelItemData : public WheelItemBaseData // for TYPE_SORT RString m_sLabel; - GameCommand m_Action; + HiddenPtr m_pAction; }; #endif