remove unused stuff

pre-parse levels commands, instead of constantly re-parsing them
This commit is contained in:
Glenn Maynard
2005-01-29 23:05:21 +00:00
parent b3e9d3aed0
commit 4b2da16b42
2 changed files with 57 additions and 107 deletions
+47 -88
View File
@@ -37,12 +37,12 @@ static const Content_t g_Contents[NUM_PANE_CONTENTS] =
{ "DifficultyAir", NUM_PANES, NEED_NOTES }, { "DifficultyAir", NUM_PANES, NEED_NOTES },
{ "DifficultyVoltage", NUM_PANES, NEED_NOTES }, { "DifficultyVoltage", NUM_PANES, NEED_NOTES },
{ "MachineHighScore", PANE_SONG_DIFFICULTY, NEED_NOTES }, { "MachineHighScore", PANE_SONG_DIFFICULTY, NEED_NOTES },
{ "MachineNumPlays", PANE_SONG_MACHINE_SCORES, NEED_NOTES }, { "MachineNumPlays", NUM_PANES, NEED_NOTES },
{ "MachineRank", PANE_SONG_MACHINE_SCORES, NEED_NOTES }, { "MachineRank", NUM_PANES, NEED_NOTES },
{ "MachineHighName", PANE_SONG_DIFFICULTY, NEED_NOTES }, { "MachineHighName", PANE_SONG_DIFFICULTY, NEED_NOTES },
{ "ProfileHighScore", PANE_SONG_DIFFICULTY, NEED_NOTES|NEED_PROFILE }, { "ProfileHighScore", PANE_SONG_DIFFICULTY, NEED_NOTES|NEED_PROFILE },
{ "ProfileNumPlays", PANE_SONG_PROFILE_SCORES, NEED_NOTES|NEED_PROFILE }, { "ProfileNumPlays", NUM_PANES, NEED_NOTES|NEED_PROFILE },
{ "ProfileRank", PANE_SONG_PROFILE_SCORES, NEED_NOTES|NEED_PROFILE }, { "ProfileRank", NUM_PANES, NEED_NOTES|NEED_PROFILE },
{ "CourseMachineHighScore", PANE_COURSE_MACHINE_SCORES, NEED_COURSE }, { "CourseMachineHighScore", PANE_COURSE_MACHINE_SCORES, NEED_COURSE },
{ "CourseMachineNumPlays", NUM_PANES, NEED_COURSE }, { "CourseMachineNumPlays", NUM_PANES, NEED_COURSE },
{ "CourseMachineRank", NUM_PANES, NEED_COURSE }, { "CourseMachineRank", NUM_PANES, NEED_COURSE },
@@ -57,17 +57,6 @@ static const Content_t g_Contents[NUM_PANE_CONTENTS] =
{ "CourseHands", PANE_COURSE_MACHINE_SCORES, NEED_COURSE } { "CourseHands", PANE_COURSE_MACHINE_SCORES, NEED_COURSE }
}; };
static const PaneModes PaneMode[NUM_PANES] =
{
PANEMODE_SONG,
PANEMODE_SONG,
PANEMODE_SONG,
// PANEMODE_SONG,
PANEMODE_COURSE,
PANEMODE_COURSE
// PANEMODE_COURSE
};
static ProfileSlot PlayerMemCard( PlayerNumber pn ) static ProfileSlot PlayerMemCard( PlayerNumber pn )
{ {
switch( pn ) switch( pn )
@@ -81,22 +70,46 @@ static ProfileSlot PlayerMemCard( PlayerNumber pn )
PaneDisplay::PaneDisplay() PaneDisplay::PaneDisplay()
{ {
m_CurPane = PANE_INVALID; m_CurPane = PANE_INVALID;
m_CurMode = PANEMODE_SONG;
} }
void PaneDisplay::Load( PlayerNumber pn ) void PaneDisplay::Load( PlayerNumber pn )
{ {
m_PlayerNumber = pn; m_PlayerNumber = pn;
m_PreferredPaneForMode[PANEMODE_SONG] = PANE_SONG_DIFFICULTY;
m_PreferredPaneForMode[PANEMODE_COURSE] = PANE_COURSE_MACHINE_SCORES;
m_sprPaneUnder.Load( THEME->GetPathToG( ssprintf("PaneDisplay under p%i", pn+1)) ); m_sprPaneUnder.Load( THEME->GetPathToG( ssprintf("PaneDisplay under p%i", pn+1)) );
m_sprPaneUnder->SetName( "Under" ); m_sprPaneUnder->SetName( "Under" );
ON_COMMAND( m_sprPaneUnder ); ON_COMMAND( m_sprPaneUnder );
this->AddChild( m_sprPaneUnder ); this->AddChild( m_sprPaneUnder );
int p; FOREACH_PaneContents(p)
for( p = 0; p < NUM_PANE_CONTENTS; ++p ) {
ArrayLevels &levels = m_Levels[p];
levels.clear();
if( g_Contents[p].type == NUM_PANES )
continue;
const int num = NUM_ITEM_COLORS( g_Contents[p].name );
for( int c = 0; c < num; ++c )
{
levels.push_back( Level() );
Level &level = levels.back();
const CString metric = ITEM_COLOR(g_Contents[p].name, c);
Commands cmds;
ParseCommands( metric, cmds );
if( cmds.v.size() < 2 )
RageException::Throw( "Metric '%s' malformed", metric.c_str() );
level.m_fIfLessThan = cmds.v[0].GetArg(0);
cmds.v.erase( cmds.v.begin(), cmds.v.begin()+1 );
level.m_Command = apActorCommands(new ActorCommands( cmds ));
}
}
for( int p = 0; p < NUM_PANE_CONTENTS; ++p )
{ {
if( g_Contents[p].type == NUM_PANES ) if( g_Contents[p].type == NUM_PANES )
continue; /* skip, disabled */ continue; /* skip, disabled */
@@ -130,8 +143,8 @@ void PaneDisplay::Load( PlayerNumber pn )
m_Labels[i]->FinishTweening(); m_Labels[i]->FinishTweening();
} }
m_CurMode = GetMode(); m_CurPane = PANE_INVALID;
SetFocus( GetNext( m_PreferredPaneForMode[m_CurMode], 0 ) ); SetFocus( GetPane() );
} }
void PaneDisplay::Update( float fDeltaTime ) void PaneDisplay::Update( float fDeltaTime )
@@ -307,31 +320,20 @@ void PaneDisplay::SetContent( PaneContents c )
done: done:
m_textContents[c].SetText( str ); m_textContents[c].SetText( str );
const int num = NUM_ITEM_COLORS( g_Contents[c].name ); const ArrayLevels &levels = m_Levels[c];
for( int p = 0; p < num; ++p ) unsigned p;
{ for( p = 0; p+1 < levels.size(); ++p )
const CString metric = ITEM_COLOR(g_Contents[c].name, p); if( val < levels[p].m_fIfLessThan )
CStringArray spec; break;
split( metric, ";", spec );
if( spec.size() < 2 )
RageException::Throw( "Metric '%s' malformed", metric.c_str() );
const float n = strtof( spec[0], NULL ); if( p < levels.size() )
if( val >= n ) m_textContents[c].RunCommands( levels[p].m_Command );
continue;
spec.erase( spec.begin(), spec.begin()+1 );
m_textContents[c].RunCommands( ActorCommands( ParseCommands(join(";", spec)) ) );
break;
}
} }
void PaneDisplay::SetFromGameState( SortOrder so ) void PaneDisplay::SetFromGameState( SortOrder so )
{ {
m_SortOrder = so; m_SortOrder = so;
m_CurMode = GetMode(); SetFocus( GetPane() );
if( PaneMode[m_CurPane] != m_CurMode )
SetFocus( GetNext( m_PreferredPaneForMode[m_CurMode], 0 ) );
/* Don't update text that doesn't apply to the current mode. It's still tweening off. */ /* Don't update text that doesn't apply to the current mode. It's still tweening off. */
for( unsigned i = 0; i < NUM_PANE_CONTENTS; ++i ) for( unsigned i = 0; i < NUM_PANE_CONTENTS; ++i )
@@ -342,7 +344,7 @@ void PaneDisplay::SetFromGameState( SortOrder so )
} }
} }
PaneModes PaneDisplay::GetMode() const PaneTypes PaneDisplay::GetPane() const
{ {
switch( m_SortOrder ) switch( m_SortOrder )
{ {
@@ -350,11 +352,11 @@ PaneModes PaneDisplay::GetMode() const
case SORT_NONSTOP_COURSES: case SORT_NONSTOP_COURSES:
case SORT_ONI_COURSES: case SORT_ONI_COURSES:
case SORT_ENDLESS_COURSES: case SORT_ENDLESS_COURSES:
return PANEMODE_COURSE; return PANE_COURSE_MACHINE_SCORES;
case SORT_MODE_MENU: case SORT_MODE_MENU:
return m_CurMode; // leave it return m_CurPane; // leave it
default: default:
return PANEMODE_SONG; return PANE_SONG_DIFFICULTY;
} }
} }
@@ -382,53 +384,10 @@ void PaneDisplay::SetFocus( PaneTypes NewPane )
} }
m_CurPane = NewPane; m_CurPane = NewPane;
m_PreferredPaneForMode[m_CurMode] = NewPane;
SetFromGameState( m_SortOrder ); SetFromGameState( m_SortOrder );
} }
bool PaneDisplay::PaneIsValid( PaneTypes p ) const
{
if( PaneMode[p] != m_CurMode )
return false;
switch( p )
{
case PANE_SONG_PROFILE_SCORES:
case PANE_COURSE_PROFILE_SCORES:
if( !PROFILEMAN->IsUsingProfile( m_PlayerNumber ) )
return false;
}
return true;
}
PaneTypes PaneDisplay::GetNext( PaneTypes current, int dir ) const
{
if( dir == 0 )
{
/* Only move the selection if the current selection is invalid. */
if( PaneIsValid( current ) )
return current;
dir = 1;
}
PaneTypes ret = current;
while( 1 )
{
ret = (PaneTypes) (ret + dir);
wrap( (int&) ret, NUM_PANES );
if( PaneIsValid( ret ) )
break;
}
LOG->Trace("pane %i", ret);
return ret;
}
/* /*
* (c) 2003 Glenn Maynard * (c) 2003 Glenn Maynard
* All rights reserved. * All rights reserved.
+10 -19
View File
@@ -2,6 +2,7 @@
#define PANE_DISPLAY_H #define PANE_DISPLAY_H
#include "ActorFrame.h" #include "ActorFrame.h"
#include "ActorCommands.h"
#include "Sprite.h" #include "Sprite.h"
#include "PlayerNumber.h" #include "PlayerNumber.h"
#include "BitmapText.h" #include "BitmapText.h"
@@ -11,24 +12,11 @@
enum PaneTypes enum PaneTypes
{ {
PANE_SONG_DIFFICULTY, PANE_SONG_DIFFICULTY,
PANE_SONG_PROFILE_SCORES,
PANE_SONG_MACHINE_SCORES,
// PANE_SONG_STATISTICS,
PANE_COURSE_MACHINE_SCORES, PANE_COURSE_MACHINE_SCORES,
PANE_COURSE_PROFILE_SCORES,
// PANE_COURSE_DIFFICULTY,
NUM_PANES, NUM_PANES,
PANE_INVALID PANE_INVALID
}; };
enum PaneModes
{
PANEMODE_SONG,
PANEMODE_BATTLE,
PANEMODE_COURSE,
NUM_PANE_MODES
};
/* If the same piece of data is in multiple panes, use separate contents entries, /* If the same piece of data is in multiple panes, use separate contents entries,
* so it can be themed differently. */ * so it can be themed differently. */
enum PaneContents enum PaneContents
@@ -64,6 +52,7 @@ enum PaneContents
COURSE_HANDS, COURSE_HANDS,
NUM_PANE_CONTENTS NUM_PANE_CONTENTS
}; };
#define FOREACH_PaneContents( p ) FOREACH_ENUM( PaneContents, NUM_PANE_CONTENTS, p )
class PaneDisplay: public ActorFrame class PaneDisplay: public ActorFrame
{ {
@@ -76,11 +65,8 @@ public:
void Update( float fDeltaTime ); void Update( float fDeltaTime );
private: private:
bool PaneIsValid( PaneTypes p ) const;
PaneTypes GetNext( PaneTypes current, int dir ) const;
void SetFocus( PaneTypes NewPane ); void SetFocus( PaneTypes NewPane );
// void SetMode(); PaneTypes GetPane() const;
PaneModes GetMode() const;
void SetContent( PaneContents c ); void SetContent( PaneContents c );
SortOrder m_SortOrder; SortOrder m_SortOrder;
@@ -92,10 +78,15 @@ private:
ActorFrame m_ContentsFrame; ActorFrame m_ContentsFrame;
PaneTypes m_CurPane; PaneTypes m_CurPane;
PaneModes m_CurMode;
PlayerNumber m_PlayerNumber; PlayerNumber m_PlayerNumber;
PaneTypes m_PreferredPaneForMode[NUM_PANE_MODES]; struct Level
{
apActorCommands m_Command;
float m_fIfLessThan;
};
typedef vector<Level> ArrayLevels;
ArrayLevels m_Levels[NUM_PANE_CONTENTS];
}; };
#endif #endif