From a12b841a4fdd9b1b5ef75120774e0bbf2b5f3518 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Tue, 23 Sep 2003 23:56:15 +0000 Subject: [PATCH] cleanup add GetUndisplayedBeats --- stepmania/src/GameState.cpp | 26 ++++++++++++++++---------- stepmania/src/GameState.h | 2 ++ stepmania/src/NoteField.cpp | 4 +--- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/stepmania/src/GameState.cpp b/stepmania/src/GameState.cpp index db7b7ffb28..2a18f2a34b 100644 --- a/stepmania/src/GameState.cpp +++ b/stepmania/src/GameState.cpp @@ -551,7 +551,18 @@ void GameState::ResetNoteSkins() } /* From NoteField: */ -extern float g_fNoteFieldLastBeatToDraw[NUM_PLAYERS]; + +void GameState::GetUndisplayedBeats( PlayerNumber pn, float TotalSeconds, float &StartBeat, float &EndBeat ) +{ + /* If reasonable, push the attack forward so notes on screen don't change suddenly. */ + StartBeat = min( this->m_fSongBeat+BEATS_PER_MEASURE*2, m_fLastDrawnBeat[pn] ); + StartBeat = truncf(StartBeat)+1; + + const float StartSecond = this->m_pCurSong->GetElapsedTimeFromBeat( StartBeat ); + const float EndSecond = StartSecond + TotalSeconds; + EndBeat = this->m_pCurSong->GetBeatFromElapsedTime( EndSecond ); + EndBeat = truncf(EndBeat)+1; +} void GameState::LaunchAttack( PlayerNumber target, Attack a ) { @@ -574,13 +585,8 @@ void GameState::LaunchAttack( PlayerNumber target, Attack a ) map &BeatToNoteSkin = m_BeatToNoteSkin[target]; /* Add it in the future, past what's currently on screen, so new arrows will scroll * on screen with this skin. */ - const float CurBeat = this->m_fSongBeat; - /* If reasonable, push the attack forward so notes on screen don't change suddenly. */ - const float AddBeat = min( CurBeat+16, g_fNoteFieldLastBeatToDraw[target] ); - - const float AddSecond = this->m_pCurSong->GetElapsedTimeFromBeat( CurBeat ); - const float EndSecond = AddSecond + a.fSecsRemaining; - const float EndBeat = this->m_pCurSong->GetBeatFromElapsedTime( EndSecond ); + float StartBeat, EndBeat; + GetUndisplayedBeats( target, a.fSecsRemaining, StartBeat, EndBeat ); /* If there are any note skins after the point we're adding, remove them. We probably * have overlapping note skin attacks. */ @@ -589,7 +595,7 @@ void GameState::LaunchAttack( PlayerNumber target, Attack a ) { map::iterator next = it; ++next; - if( it->first >= AddBeat ) + if( it->first >= StartBeat ) { LOG->Trace( "erase old %f", it->first ); BeatToNoteSkin.erase( it ); @@ -598,7 +604,7 @@ void GameState::LaunchAttack( PlayerNumber target, Attack a ) } /* Add the skin to m_BeatToNoteSkin. */ - BeatToNoteSkin[AddBeat] = po.m_sNoteSkin; + BeatToNoteSkin[StartBeat] = po.m_sNoteSkin; /* Return to the default note skin after the duration. */ BeatToNoteSkin[EndBeat] = GAMESTATE->m_PlayerOptions[target].m_sNoteSkin; diff --git a/stepmania/src/GameState.h b/stepmania/src/GameState.h index 731220d6c9..3482c44366 100644 --- a/stepmania/src/GameState.h +++ b/stepmania/src/GameState.h @@ -154,6 +154,7 @@ public: float m_fCurBPS; bool m_bFreeze; // in the middle of a freeze bool m_bPastHereWeGo; + float m_fLastDrawnBeat[NUM_PLAYERS]; // set by NoteField map m_BeatToNoteSkin[NUM_PLAYERS]; int m_BeatToNoteSkinRev; /* hack: incremented whenever m_BeatToNoteSkin changes */ @@ -192,6 +193,7 @@ public: float m_fSuperMeter[NUM_PLAYERS]; // between 0 and NUM_ATTACK_LEVELS bool m_bActiveAttackEndedThisUpdate[NUM_PLAYERS]; // flag for other objects to watch (play sounds) + void GetUndisplayedBeats( PlayerNumber pn, float TotalSeconds, float &StartBeat, float &EndBeat ); // only meaningful when a NoteField is in use void LaunchAttack( PlayerNumber target, Attack aa ); void RebuildPlayerOptionsFromActiveAttacks( PlayerNumber pn ); void RemoveAllActiveAttacks() // called on end of song diff --git a/stepmania/src/NoteField.cpp b/stepmania/src/NoteField.cpp index a96cdfcb45..615bcb880f 100644 --- a/stepmania/src/NoteField.cpp +++ b/stepmania/src/NoteField.cpp @@ -346,7 +346,6 @@ float FindLastDisplayedBeat( PlayerNumber pn, int iLastPixelToDraw ) return fLastBeatToDraw; } -float g_fNoteFieldLastBeatToDraw[NUM_PLAYERS] = { -1, -1 }; void NoteField::DrawPrimitives() { @@ -376,8 +375,7 @@ void NoteField::DrawPrimitives() float fFirstBeatToDraw = FindFirstDisplayedBeat( m_PlayerNumber, iFirstPixelToDraw ); float fLastBeatToDraw = FindLastDisplayedBeat( m_PlayerNumber, iLastPixelToDraw ); - /* Hack: */ - g_fNoteFieldLastBeatToDraw[m_PlayerNumber] = fLastBeatToDraw; + GAMESTATE->m_fLastDrawnBeat[m_PlayerNumber] = fLastBeatToDraw; const int iFirstIndexToDraw = BeatToNoteRow(fFirstBeatToDraw); const int iLastIndexToDraw = BeatToNoteRow(fLastBeatToDraw);