We load lots of the same thing in OptionRows. Instead of loading each one

individually, just load one and copy it for the rest; this avoids doing
the whole "search, read redir, find refcounted" code path for every
option.  Don't load data from OptionRow::AfterImportOptions.
This commit is contained in:
Glenn Maynard
2005-07-15 05:34:54 +00:00
parent 7afc69b2fd
commit 5c441a5fdf
4 changed files with 29 additions and 17 deletions
+10 -11
View File
@@ -146,6 +146,11 @@ void OptionRow::LoadMetrics( const CString &sType )
m_OptionIcons[p].Load( m_sType );
m_OptionIcons[p].RunCommands( ICONS_ON_COMMAND );
}
m_textItemParent.LoadFromFont( THEME->GetPathF(m_sType,"item") );
m_UnderlineParent.Load( m_sType, OptionsCursor::underline );
m_textTitle.LoadFromFont( THEME->GetPathF(m_sType,"title") );
m_sprBullet.Load( THEME->GetPathG(m_sType,"bullet") );
}
void OptionRow::LoadNormal( const OptionRowDefinition &def, OptionRowHandler *pHand, bool bFirstItemGoesDown )
@@ -278,11 +283,9 @@ void OptionRow::AfterImportOptions()
LoadOptionIcon( p, "" );
}
// If the items will go off the edge of the screen, then re-init with the "long row" style.
{
BitmapText bt;
bt.LoadFromFont( THEME->GetPathF(m_sType,"item") );
BitmapText bt( m_textItemParent );
bt.RunCommands( ITEMS_ON_COMMAND );
float fX = ITEMS_START_X;
@@ -315,12 +318,11 @@ void OptionRow::AfterImportOptions()
// init text
FOREACH_HumanPlayer( p )
{
BitmapText *bt = new BitmapText;
BitmapText *bt = new BitmapText( m_textItemParent );
m_textItems.push_back( bt );
const int iChoiceInRowWithFocus = m_iChoiceInRowWithFocus[p];
bt->LoadFromFont( THEME->GetPathF(m_sType,"item") );
CString sText = (iChoiceInRowWithFocus==-1) ? "" : m_RowDef.m_vsChoices[iChoiceInRowWithFocus];
PrepareItemText( sText );
bt->SetText( sText );
@@ -341,9 +343,9 @@ void OptionRow::AfterImportOptions()
// init underlines
FOREACH_HumanPlayer( p )
{
OptionsCursor *ul = new OptionsCursor;
OptionsCursor *ul = new OptionsCursor( m_UnderlineParent );
m_Underline[p].push_back( ul );
ul->Load( m_sType, OptionsCursor::underline );
ul->Set( p );
int iWidth, iX, iY;
GetWidthXY( p, 0, iWidth, iX, iY );
@@ -375,9 +377,8 @@ void OptionRow::AfterImportOptions()
// init underlines
FOREACH_HumanPlayer( p )
{
OptionsCursor *ul = new OptionsCursor;
OptionsCursor *ul = new OptionsCursor( m_UnderlineParent );
m_Underline[p].push_back( ul );
ul->Load( m_sType, OptionsCursor::underline );
ul->Set( p );
ul->SetX( fX );
ul->SetWidth( truncf(fItemWidth) );
@@ -399,13 +400,11 @@ void OptionRow::AfterImportOptions()
m_Frame.AddChild( m_Underline[p][c] );
m_textTitle.LoadFromFont( THEME->GetPathF(m_sType,"title") );
CString sTitle = GetRowTitle();
m_textTitle.SetText( sTitle );
m_textTitle.SetX( LABELS_X );
m_textTitle.RunCommands( LABELS_ON_COMMAND );
m_sprBullet.Load( THEME->GetPathG(m_sType,"bullet") );
m_sprBullet.SetX( ARROWS_X );
//
+2
View File
@@ -171,7 +171,9 @@ protected:
RowType m_RowType;
OptionRowHandler* m_pHand;
ActorFrame m_Frame;
BitmapText m_textItemParent;
vector<BitmapText *> m_textItems; // size depends on m_bRowIsLong and which players are joined
OptionsCursor m_UnderlineParent;
vector<OptionsCursor *> m_Underline[NUM_PLAYERS]; // size depends on m_bRowIsLong and which players are joined
Sprite m_sprBullet;
BitmapText m_textTitle;
+16 -6
View File
@@ -7,16 +7,26 @@
OptionsCursor::OptionsCursor()
{
this->AddChild( &m_sprMiddle );
this->AddChild( &m_sprLeft );
this->AddChild( &m_sprRight );
}
OptionsCursor::OptionsCursor( const OptionsCursor &cpy ):
ActorFrame( cpy ),
m_sprLeft( cpy.m_sprLeft ),
m_sprMiddle( cpy.m_sprMiddle ),
m_sprRight( cpy.m_sprRight )
{
/* Re-add children, or m_SubActors will point to cpy's children and not our own. */
m_SubActors.clear();
this->AddChild( &m_sprMiddle );
this->AddChild( &m_sprLeft );
this->AddChild( &m_sprRight );
}
void OptionsCursor::Load( CString sType, Element elem )
{
ASSERT( m_SubActors.empty() ); // don't load twice
this->AddChild( &m_sprMiddle );
this->AddChild( &m_sprLeft );
this->AddChild( &m_sprRight );
CString sPath = THEME->GetPathG( sType, ssprintf("%s 3x2",elem==cursor?"cursor":"underline") );
m_sprLeft.Load( sPath );
+1
View File
@@ -12,6 +12,7 @@ class OptionsCursor : public ActorFrame
{
public:
OptionsCursor();
OptionsCursor( const OptionsCursor &cpy );
enum Element { cursor, underline };
void Load( CString sType, Element elem );