improve tween synchronization
This commit is contained in:
+39
-35
@@ -203,48 +203,52 @@ void Actor::EndDraw()
|
|||||||
|
|
||||||
void Actor::UpdateTweening( float fDeltaTime )
|
void Actor::UpdateTweening( float fDeltaTime )
|
||||||
{
|
{
|
||||||
// update tweening
|
while( 1 )
|
||||||
if( m_TweenStates.empty() )
|
|
||||||
return;
|
|
||||||
|
|
||||||
// we are performing a tween
|
|
||||||
TweenState &TS = m_TweenStates[0]; // earliest tween
|
|
||||||
TweenInfo &TI = m_TweenInfo[0]; // earliest tween
|
|
||||||
|
|
||||||
if( TI.m_fTimeLeftInTween == TI.m_fTweenTime ) // we are just beginning this tween
|
|
||||||
{
|
{
|
||||||
// set the start position
|
if( m_TweenStates.empty() ) // nothing to do
|
||||||
m_start = m_current;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
TI.m_fTimeLeftInTween -= fDeltaTime;
|
if( fDeltaTime == 0 ) // nothing will change
|
||||||
|
return;
|
||||||
|
|
||||||
if( TI.m_fTimeLeftInTween <= 0 ) // The tweening is over. Stop the tweening
|
// update current tween state
|
||||||
{
|
TweenState &TS = m_TweenStates[0]; // earliest tween
|
||||||
m_current = TS;
|
TweenInfo &TI = m_TweenInfo[0]; // earliest tween
|
||||||
|
|
||||||
// delete the head tween
|
if( TI.m_fTimeLeftInTween == TI.m_fTweenTime ) // we are just beginning this tween
|
||||||
m_TweenStates.erase( m_TweenStates.begin() );
|
m_start = m_current; // set the start position
|
||||||
m_TweenInfo.erase( m_TweenInfo.begin() );
|
|
||||||
}
|
|
||||||
else // in the middle of tweening. Recalcute the current position.
|
|
||||||
{
|
|
||||||
const float fPercentThroughTween = 1-(TI.m_fTimeLeftInTween / TI.m_fTweenTime);
|
|
||||||
|
|
||||||
// distort the percentage if appropriate
|
float fSecsToSubtract = min( TI.m_fTimeLeftInTween, fDeltaTime );
|
||||||
float fPercentAlongPath = 0.f;
|
TI.m_fTimeLeftInTween -= fSecsToSubtract;
|
||||||
switch( TI.m_TweenType )
|
fDeltaTime -= fSecsToSubtract;
|
||||||
|
|
||||||
|
if( TI.m_fTimeLeftInTween == 0 ) // Current tween is over. Stop.
|
||||||
{
|
{
|
||||||
case TWEEN_LINEAR: fPercentAlongPath = fPercentThroughTween; break;
|
m_current = TS;
|
||||||
case TWEEN_ACCELERATE: fPercentAlongPath = fPercentThroughTween * fPercentThroughTween; break;
|
|
||||||
case TWEEN_DECELERATE: fPercentAlongPath = 1 - (1-fPercentThroughTween) * (1-fPercentThroughTween); break;
|
|
||||||
case TWEEN_BOUNCE_BEGIN:fPercentAlongPath = 1 - sinf( 1.1f + fPercentThroughTween*(PI-1.1f) ) / 0.89f; break;
|
|
||||||
case TWEEN_BOUNCE_END: fPercentAlongPath = sinf( 1.1f + (1-fPercentThroughTween)*(PI-1.1f) ) / 0.89f; break;
|
|
||||||
case TWEEN_SPRING: fPercentAlongPath = 1 - cosf( fPercentThroughTween*PI*2.5f )/(1+fPercentThroughTween*3); break;
|
|
||||||
default: ASSERT(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
TweenState::MakeWeightedAverage( m_current, m_start, TS, fPercentAlongPath );
|
// delete the head tween
|
||||||
|
m_TweenStates.erase( m_TweenStates.begin() );
|
||||||
|
m_TweenInfo.erase( m_TweenInfo.begin() );
|
||||||
|
}
|
||||||
|
else // in the middle of tweening. Recalcute the current position.
|
||||||
|
{
|
||||||
|
const float fPercentThroughTween = 1-(TI.m_fTimeLeftInTween / TI.m_fTweenTime);
|
||||||
|
|
||||||
|
// distort the percentage if appropriate
|
||||||
|
float fPercentAlongPath = 0.f;
|
||||||
|
switch( TI.m_TweenType )
|
||||||
|
{
|
||||||
|
case TWEEN_LINEAR: fPercentAlongPath = fPercentThroughTween; break;
|
||||||
|
case TWEEN_ACCELERATE: fPercentAlongPath = fPercentThroughTween * fPercentThroughTween; break;
|
||||||
|
case TWEEN_DECELERATE: fPercentAlongPath = 1 - (1-fPercentThroughTween) * (1-fPercentThroughTween); break;
|
||||||
|
case TWEEN_BOUNCE_BEGIN:fPercentAlongPath = 1 - sinf( 1.1f + fPercentThroughTween*(PI-1.1f) ) / 0.89f; break;
|
||||||
|
case TWEEN_BOUNCE_END: fPercentAlongPath = sinf( 1.1f + (1-fPercentThroughTween)*(PI-1.1f) ) / 0.89f; break;
|
||||||
|
case TWEEN_SPRING: fPercentAlongPath = 1 - cosf( fPercentThroughTween*PI*2.5f )/(1+fPercentThroughTween*3); break;
|
||||||
|
default: ASSERT(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TweenState::MakeWeightedAverage( m_current, m_start, TS, fPercentAlongPath );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user