From 8883702f8a3b57d0316811e9412bd46ce0dd9c0d Mon Sep 17 00:00:00 2001 From: Mitchell Stokes Date: Mon, 8 Aug 2011 04:28:30 +0000 Subject: BGE Animations: Various compatibility fixes: * Blendin for Loop End works even after a negative pulse. Flipper could still use some work in this area. * Continuous works a lot better. * BL_Action::SetFrame() should work a little smoother. --- source/gameengine/Ketsji/BL_Action.cpp | 43 ++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 12 deletions(-) (limited to 'source/gameengine/Ketsji/BL_Action.cpp') diff --git a/source/gameengine/Ketsji/BL_Action.cpp b/source/gameengine/Ketsji/BL_Action.cpp index caffd3cd8ca..4cf6f982006 100644 --- a/source/gameengine/Ketsji/BL_Action.cpp +++ b/source/gameengine/Ketsji/BL_Action.cpp @@ -67,7 +67,8 @@ BL_Action::BL_Action(class KX_GameObject* gameobj) m_priority(0), m_playmode(0), m_ipo_flags(0), - m_done(true) + m_done(true), + m_calc_localtime(true) { if (m_obj->GetGameObjectType() == SCA_IObject::OBJ_ARMATURE) { @@ -215,24 +216,25 @@ float BL_Action::GetFrame() void BL_Action::SetFrame(float frame) { - float dt; - // Clamp the frame to the start and end frame if (frame < min(m_startframe, m_endframe)) frame = min(m_startframe, m_endframe); else if (frame > max(m_startframe, m_endframe)) frame = max(m_startframe, m_endframe); - // We don't set m_localtime directly since it's recalculated - // in the next update. So, we modify the value (m_starttime) - // used to calculate m_localtime the next time SetLocalTime() is called. - - dt = frame-m_startframe; + m_localtime = frame; + m_calc_localtime = false; +} - if (m_endframe < m_startframe) - dt = -dt; +void BL_Action::SetPlayMode(short play_mode) +{ + m_playmode = play_mode; +} - m_starttime -= dt / (KX_KetsjiEngine::GetAnimFrameRate()*m_speed); +void BL_Action::SetTimes(float start, float end) +{ + m_startframe = start; + m_endframe = end; } void BL_Action::SetLocalTime(float curtime) @@ -245,6 +247,16 @@ void BL_Action::SetLocalTime(float curtime) m_localtime = m_startframe + dt; } +void BL_Action::ResetStartTime(float curtime) +{ + float dt = m_localtime - m_startframe; + + m_starttime = curtime - dt / (KX_KetsjiEngine::GetAnimFrameRate()*m_speed); + printf("Before: %f, ", m_localtime); + SetLocalTime(curtime); + printf("After: %f\n", m_localtime); +} + void BL_Action::IncrementBlending(float curtime) { // Setup m_blendstart if we need to @@ -285,7 +297,14 @@ void BL_Action::Update(float curtime) return; curtime -= KX_KetsjiEngine::GetSuspendedDelta(); - SetLocalTime(curtime); + + if (m_calc_localtime) + SetLocalTime(curtime); + else + { + ResetStartTime(curtime); + m_calc_localtime = true; + } // Handle wrap around if (m_localtime < min(m_startframe, m_endframe) || m_localtime > max(m_startframe, m_endframe)) -- cgit v1.2.3