From 12b777c12a7acd2646a89dc4997dad7aa533942b Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sat, 16 Oct 2004 02:15:18 +0000 Subject: [PATCH] Sprites now follow the effect clock; you can sync an animated sprite to the beat. This can be used to implement things like the receptor row in .sprites. (This is minor; it's actually just a tangent of another change which I havn't committed yet ...) --- stepmania/src/Sprite.cpp | 25 ++++++++++++++++++++++--- stepmania/src/Sprite.h | 1 + 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/stepmania/src/Sprite.cpp b/stepmania/src/Sprite.cpp index cb27d8fce4..e963f50dd0 100644 --- a/stepmania/src/Sprite.cpp +++ b/stepmania/src/Sprite.cpp @@ -18,7 +18,7 @@ Sprite::Sprite() m_pTexture = NULL; m_bDrawIfTextureNull = false; m_iCurState = 0; - m_fSecsIntoState = 0.0; + m_fSecsIntoState = m_fLastTime = 0.0f; m_bUsingCustomTexCoords = false; m_fRememberedClipWidth = -1; @@ -283,7 +283,26 @@ void Sprite::Update( float fDelta ) if( !m_pTexture ) // no texture, nothing to animate return; - m_fSecsIntoState += fDelta; + float fTimePassed = 0; + switch( m_EffectClock ) + { + case CLOCK_TIMER: + fTimePassed = fDelta; + break; + + case CLOCK_BGM_BEAT: + fTimePassed = g_fCurrentBGMBeat - m_fLastTime; + m_fLastTime = g_fCurrentBGMBeat; + break; + + case CLOCK_BGM_TIME: + fTimePassed = g_fCurrentBGMTime - m_fLastTime; + m_fLastTime = g_fCurrentBGMTime; + break; + default: FAIL_M( ssprintf("%i",m_EffectClock) ); + } + + m_fSecsIntoState += fTimePassed; UpdateAnimationState(); // @@ -627,7 +646,7 @@ void Sprite::SetState( int iNewState ) CLAMP(iNewState, 0, (int)m_States.size()-1); m_iCurState = iNewState; - m_fSecsIntoState = 0.0; + m_fSecsIntoState = m_fLastTime = 0.0f; } float Sprite::GetAnimationLengthSeconds() const diff --git a/stepmania/src/Sprite.h b/stepmania/src/Sprite.h index 37f1e57592..d80b460039 100644 --- a/stepmania/src/Sprite.h +++ b/stepmania/src/Sprite.h @@ -79,6 +79,7 @@ protected: vector m_States; int m_iCurState; float m_fSecsIntoState; // number of seconds that have elapsed since we switched to this frame + float m_fLastTime; bool m_bUsingCustomTexCoords; float m_CustomTexCoords[8]; // (x,y) * 4: top left, bottom left, bottom right, top right