clean up GetVisible() optimization to not process things that won't show. Fixes editor crash on playback.

This commit is contained in:
Chris Danford
2007-09-16 21:22:09 +00:00
parent 2322929f9c
commit 5272d5994c
3 changed files with 12 additions and 12 deletions
+8 -8
View File
@@ -142,7 +142,7 @@ float Player::GetWindowSeconds( TimingWindow tw )
return fSecs; return fSecs;
} }
Player::Player( NoteData &nd, bool bVisible ) : m_NoteData(nd) Player::Player( NoteData &nd, bool bVisibleParts ) : m_NoteData(nd)
{ {
m_bLoaded = false; m_bLoaded = false;
@@ -166,7 +166,7 @@ Player::Player( NoteData &nd, bool bVisible ) : m_NoteData(nd)
m_bPaused = false; m_bPaused = false;
m_pAttackDisplay = NULL; m_pAttackDisplay = NULL;
if( bVisible ) if( bVisibleParts )
{ {
m_pAttackDisplay = new AttackDisplay; m_pAttackDisplay = new AttackDisplay;
this->AddChild( m_pAttackDisplay ); this->AddChild( m_pAttackDisplay );
@@ -175,14 +175,12 @@ Player::Player( NoteData &nd, bool bVisible ) : m_NoteData(nd)
PlayerAI::InitFromDisk(); PlayerAI::InitFromDisk();
m_pNoteField = NULL; m_pNoteField = NULL;
if( bVisible ) if( bVisibleParts )
{ {
m_pNoteField = new NoteField; m_pNoteField = new NoteField;
m_pNoteField->SetName( "NoteField" ); m_pNoteField->SetName( "NoteField" );
} }
m_pJudgedRows = new JudgedRows; m_pJudgedRows = new JudgedRows;
this->SetVisible( bVisible );
} }
Player::~Player() Player::~Player()
@@ -339,7 +337,7 @@ void Player::Init(
m_soundAttackEnding.SetProperty( "Pan", fBalance ); m_soundAttackEnding.SetProperty( "Pan", fBalance );
if( this->GetVisible() ) if( HasVisibleParts() )
{ {
LuaThreadVariable var( "Player", LuaReference::Create(m_pPlayerState->m_PlayerNumber) ); LuaThreadVariable var( "Player", LuaReference::Create(m_pPlayerState->m_PlayerNumber) );
LuaThreadVariable var2( "MultiPlayer", LuaReference::Create(m_pPlayerState->m_mp) ); LuaThreadVariable var2( "MultiPlayer", LuaReference::Create(m_pPlayerState->m_mp) );
@@ -360,7 +358,7 @@ void Player::Init(
for( int i = 0; i < GAMESTATE->GetCurrentStyle()->m_iColsPerPlayer; ++i ) for( int i = 0; i < GAMESTATE->GetCurrentStyle()->m_iColsPerPlayer; ++i )
m_vpHoldJudgment[i] = NULL; m_vpHoldJudgment[i] = NULL;
if( this->GetVisible() ) if( HasVisibleParts() )
{ {
for( int i = 0; i < GAMESTATE->GetCurrentStyle()->m_iColsPerPlayer; ++i ) for( int i = 0; i < GAMESTATE->GetCurrentStyle()->m_iColsPerPlayer; ++i )
{ {
@@ -571,7 +569,9 @@ void Player::Update( float fDeltaTime )
const float fSongBeat = GAMESTATE->m_fSongBeat; const float fSongBeat = GAMESTATE->m_fSongBeat;
const int iSongRow = BeatToNoteRow( fSongBeat ); const int iSongRow = BeatToNoteRow( fSongBeat );
if( this->GetVisible() ) // Optimization: Don't spend time processing the things below that won't show
// if the Player doesn't show anything on the screen.
if( HasVisibleParts() )
{ {
if( m_pPlayerState->m_bAttackBeganThisUpdate ) if( m_pPlayerState->m_bAttackBeganThisUpdate )
m_soundAttackLaunch.Play(); m_soundAttackLaunch.Play();
+2 -2
View File
@@ -39,7 +39,7 @@ class Player: public ActorFrame
{ {
public: public:
// The passed in NoteData isn't touched until Load() is called. // The passed in NoteData isn't touched until Load() is called.
Player( NoteData &nd, bool bVisible = true ); Player( NoteData &nd, bool bVisibleParts = true );
~Player(); ~Player();
virtual void Update( float fDeltaTime ); virtual void Update( float fDeltaTime );
@@ -96,7 +96,7 @@ public:
static float GetMaxStepDistanceSeconds(); static float GetMaxStepDistanceSeconds();
static float GetWindowSeconds( TimingWindow tw ); static float GetWindowSeconds( TimingWindow tw );
const NoteData &GetNoteData() const { return m_NoteData; } const NoteData &GetNoteData() const { return m_NoteData; }
bool HasNoteField() const { return m_pNoteField != NULL; } bool HasVisibleParts() const { return m_pNoteField != NULL; }
void SetActorWithJudgmentPosition( Actor *pActor ) { m_pActorWithJudgmentPosition = pActor; } void SetActorWithJudgmentPosition( Actor *pActor ) { m_pActorWithJudgmentPosition = pActor; }
void SetActorWithComboPosition( Actor *pActor ) { m_pActorWithComboPosition = pActor; } void SetActorWithComboPosition( Actor *pActor ) { m_pActorWithComboPosition = pActor; }
+2 -2
View File
@@ -318,7 +318,7 @@ GetNextVisiblePlayerInfo( vector<PlayerInfo>::iterator iter, vector<PlayerInfo>
{ {
for( ; iter != v.end(); ++iter ) for( ; iter != v.end(); ++iter )
{ {
if( !iter->m_pPlayer->HasNoteField() ) if( !iter->m_pPlayer->HasVisibleParts() )
continue; continue;
return iter; return iter;
} }
@@ -476,7 +476,7 @@ void ScreenGameplay::Init()
FOREACH_EnabledPlayerInfoNotDummy( m_vPlayerInfo, pi ) FOREACH_EnabledPlayerInfoNotDummy( m_vPlayerInfo, pi )
{ {
if( pi->m_pPlayer->HasNoteField() ) if( pi->m_pPlayer->HasVisibleParts() )
{ {
pi->m_sprOniGameOver.Load( THEME->GetPathG(m_sName,"oni gameover") ); pi->m_sprOniGameOver.Load( THEME->GetPathG(m_sName,"oni gameover") );
pi->m_sprOniGameOver->SetName( ssprintf("OniGameOver%s",pi->GetName().c_str()) ); pi->m_sprOniGameOver->SetName( ssprintf("OniGameOver%s",pi->GetName().c_str()) );