diff options
author | Mitchell Stokes <mogurijin@gmail.com> | 2011-07-05 09:22:02 +0400 |
---|---|---|
committer | Mitchell Stokes <mogurijin@gmail.com> | 2011-07-05 09:22:02 +0400 |
commit | ceabc6d119caa8132182697bf655f595c468dc2e (patch) | |
tree | eb97faa07b43f9d638875cc07d2026d6c448748a /source/gameengine/Ketsji | |
parent | afd77d081aa9c9fb51e22961e962b13f90da6cd8 (diff) |
BGE Animations: Various fixes and bits of cleanup to get the action actuator to behave more like it did in trunk. The Pepper version is still more sensitive to pulses than the trunk version, but this is more accurate. I might try to address this, but I'm not sure.
Diffstat (limited to 'source/gameengine/Ketsji')
-rw-r--r-- | source/gameengine/Ketsji/BL_Action.cpp | 34 | ||||
-rw-r--r-- | source/gameengine/Ketsji/BL_Action.h | 2 | ||||
-rw-r--r-- | source/gameengine/Ketsji/BL_ActionManager.cpp | 6 | ||||
-rw-r--r-- | source/gameengine/Ketsji/BL_ActionManager.h | 2 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_GameObject.cpp | 5 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_GameObject.h | 6 |
6 files changed, 40 insertions, 15 deletions
diff --git a/source/gameengine/Ketsji/BL_Action.cpp b/source/gameengine/Ketsji/BL_Action.cpp index 04d05d87c06..f1b53fc4151 100644 --- a/source/gameengine/Ketsji/BL_Action.cpp +++ b/source/gameengine/Ketsji/BL_Action.cpp @@ -62,8 +62,7 @@ BL_Action::BL_Action(class KX_GameObject* gameobj) m_blendinpose(NULL), m_sg_contr(NULL), m_ptrrna(NULL), - m_done(true), - m_bcalc_local_time(true) + m_done(true) { if (m_obj->GetGameObjectType() == SCA_IObject::OBJ_ARMATURE) { @@ -197,6 +196,11 @@ void BL_Action::InitIPO() m_sg_contr->SetOption(SG_Controller::SG_CONTR_IPO_LOCAL, m_ipo_flags & ACT_IPOFLAG_LOCAL); } +bAction *BL_Action::GetAction() +{ + return (IsDone()) ? NULL : m_action; +} + float BL_Action::GetFrame() { return m_localtime; @@ -204,14 +208,24 @@ 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; + + if (m_endframe < m_startframe) + dt = -dt; - m_localtime = frame; - m_bcalc_local_time = false; + m_starttime -= dt / (KX_KetsjiEngine::GetAnimFrameRate()*m_speed); } void BL_Action::SetLocalTime(float curtime) @@ -263,16 +277,8 @@ void BL_Action::Update(float curtime) if (m_done) return; - // We only want to calculate the current time if we weren't given a frame (e.g., from SetFrame()) - if (m_bcalc_local_time) - { - curtime -= KX_KetsjiEngine::GetSuspendedDelta(); - SetLocalTime(curtime); - } - else - { - m_bcalc_local_time = true; - } + curtime -= KX_KetsjiEngine::GetSuspendedDelta(); + SetLocalTime(curtime); // Handle wrap around if (m_localtime < min(m_startframe, m_endframe) || m_localtime > max(m_startframe, m_endframe)) diff --git a/source/gameengine/Ketsji/BL_Action.h b/source/gameengine/Ketsji/BL_Action.h index eea00b15036..f7c5a811721 100644 --- a/source/gameengine/Ketsji/BL_Action.h +++ b/source/gameengine/Ketsji/BL_Action.h @@ -66,7 +66,6 @@ private: short m_ipo_flags; bool m_done; - bool m_bcalc_local_time; void InitIPO(); void SetLocalTime(float curtime); @@ -91,6 +90,7 @@ public: // Accessors float GetFrame(); + struct bAction *GetAction(); // Mutators void SetFrame(float frame); diff --git a/source/gameengine/Ketsji/BL_ActionManager.cpp b/source/gameengine/Ketsji/BL_ActionManager.cpp index 8d862c38961..c3b4dc5d4db 100644 --- a/source/gameengine/Ketsji/BL_ActionManager.cpp +++ b/source/gameengine/Ketsji/BL_ActionManager.cpp @@ -56,6 +56,12 @@ void BL_ActionManager::SetActionFrame(short layer, float frame) m_layers[layer]->SetFrame(frame); } +struct bAction *BL_ActionManager::GetCurrentAction(short layer) +{ + if (m_layers[layer]) + return m_layers[layer]->GetAction(); +} + bool BL_ActionManager::PlayAction(const char* name, float start, float end, diff --git a/source/gameengine/Ketsji/BL_ActionManager.h b/source/gameengine/Ketsji/BL_ActionManager.h index 3836c6b59d2..c527c7bbd3a 100644 --- a/source/gameengine/Ketsji/BL_ActionManager.h +++ b/source/gameengine/Ketsji/BL_ActionManager.h @@ -56,6 +56,8 @@ public: float GetActionFrame(short layer); void SetActionFrame(short layer, float frame); + struct bAction *GetCurrentAction(short layer); + void StopAction(short layer); bool IsActionDone(short layer); void Update(float); diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index 334868d283a..3404cd227f0 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -399,6 +399,11 @@ void KX_GameObject::SetActionFrame(short layer, float frame) GetActionManager()->SetActionFrame(layer, frame); } +bAction *KX_GameObject::GetCurrentAction(short layer) +{ + return GetActionManager()->GetCurrentAction(layer); +} + void KX_GameObject::ProcessReplica() { SCA_IObject::ProcessReplica(); diff --git a/source/gameengine/Ketsji/KX_GameObject.h b/source/gameengine/Ketsji/KX_GameObject.h index 96bd42ba702..6e22dc5fbc3 100644 --- a/source/gameengine/Ketsji/KX_GameObject.h +++ b/source/gameengine/Ketsji/KX_GameObject.h @@ -65,6 +65,7 @@ class PHY_IGraphicController; class PHY_IPhysicsEnvironment; class BL_ActionManager; struct Object; +struct bAction; #ifdef WITH_PYTHON /* utility conversion function */ @@ -233,6 +234,11 @@ public: void SetActionFrame(short layer, float frame); /** + * Gets the currently running action on the given layer + */ + bAction *GetCurrentAction(short layer); + + /** * Remove an action from the object's action manager */ void StopAction(short layer); |