From ce5ba1f7f0d25095b69479e648c6b331335abbc4 Mon Sep 17 00:00:00 2001 From: Porteries Tristan Date: Mon, 12 Sep 2016 17:13:38 +0000 Subject: [PATCH] UPBGE: Fix animations update and shadows. Previously since 1d81d517530e53e8545a160078f6a386dc83ead9 (again) the animations updated during a shaodw render wasn't in the final render. This was because BL_ActionManager::Update was always called for culled and non-culled objects. But this same function used a variable named m_prevUpdate to avoid double update for the same animation time. The case creating the bug was when an object culled during the shadow render updates its animation, then the m_prevUpdate is set to the current time and after in the final render, when trying to update the animation the comparaison with m_prevUpdate discard the update as exepted for the same object even if is it non-culled. To solve this issue we have to know if the action was applied to the object (similar to if the object is non-culled) and in this case allow discarding the animation update thanks to m_prevUpdate. To do it the m_prevUpdate was moved in BL_Action to access to the m_appliedToObject value in the function BL_Action::Update. --- source/gameengine/Ketsji/BL_Action.cpp | 12 +++++++++--- source/gameengine/Ketsji/BL_Action.h | 3 +++ source/gameengine/Ketsji/BL_ActionManager.cpp | 7 +------ source/gameengine/Ketsji/BL_ActionManager.h | 3 --- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/source/gameengine/Ketsji/BL_Action.cpp b/source/gameengine/Ketsji/BL_Action.cpp index adbfd1b5ec73..ccafa4233eda 100644 --- a/source/gameengine/Ketsji/BL_Action.cpp +++ b/source/gameengine/Ketsji/BL_Action.cpp @@ -78,7 +78,8 @@ BL_Action::BL_Action(class KX_GameObject* gameobj) m_ipo_flags(0), m_done(true), m_appliedToObject(true), - m_calc_localtime(true) + m_calc_localtime(true), + m_prevUpdate(-1.0f) { } @@ -259,6 +260,8 @@ bool BL_Action::Play(const char* name, m_done = false; m_appliedToObject = false; + m_prevUpdate = -1.0f; + return true; } @@ -379,10 +382,13 @@ void BL_Action::BlendShape(Key* key, float srcweight, std::vector& blends void BL_Action::Update(float curtime, bool applyToObject) { - // Don't bother if we're done with the animation and if the animation was already applied to the object. - if (m_done && m_appliedToObject) { + /* Don't bother if we're done with the animation and if the animation was already applied to the object. + * of if the animation made a double update for the same time and that it was applied to the object. + */ + if ((m_done && m_appliedToObject) || (m_prevUpdate == curtime && m_appliedToObject)) { return; } + m_prevUpdate = curtime; curtime -= (float)KX_KetsjiEngine::GetSuspendedDelta(); diff --git a/source/gameengine/Ketsji/BL_Action.h b/source/gameengine/Ketsji/BL_Action.h index f0e5b9977cd4..dbf4b225b4d3 100644 --- a/source/gameengine/Ketsji/BL_Action.h +++ b/source/gameengine/Ketsji/BL_Action.h @@ -74,6 +74,9 @@ class BL_Action bool m_appliedToObject; bool m_calc_localtime; + // The last update time to avoid double animation update. + float m_prevUpdate; + void ClearControllerList(); void InitIPO(); void SetLocalTime(float curtime); diff --git a/source/gameengine/Ketsji/BL_ActionManager.cpp b/source/gameengine/Ketsji/BL_ActionManager.cpp index a606f46de3c0..458d6f86c427 100644 --- a/source/gameengine/Ketsji/BL_ActionManager.cpp +++ b/source/gameengine/Ketsji/BL_ActionManager.cpp @@ -31,8 +31,7 @@ #define IS_TAGGED(_id) ((_id) && (((ID *)_id)->tag & LIB_TAG_DOIT)) BL_ActionManager::BL_ActionManager(class KX_GameObject *obj): - m_obj(obj), - m_prevUpdate(-1.0f) + m_obj(obj) { } @@ -150,10 +149,6 @@ bool BL_ActionManager::IsActionDone(short layer) void BL_ActionManager::Update(float curtime, bool applyToObject) { - if (m_prevUpdate == curtime) - return; - m_prevUpdate = curtime; - BL_ActionMap::iterator it; for (it = m_layers.begin(); it != m_layers.end(); ++it) { it->second->Update(curtime, applyToObject); diff --git a/source/gameengine/Ketsji/BL_ActionManager.h b/source/gameengine/Ketsji/BL_ActionManager.h index e65e829afb46..ef4b7ee0c744 100644 --- a/source/gameengine/Ketsji/BL_ActionManager.h +++ b/source/gameengine/Ketsji/BL_ActionManager.h @@ -51,9 +51,6 @@ class BL_ActionManager class KX_GameObject* m_obj; BL_ActionMap m_layers; - // The last update time to avoid double animation update. - float m_prevUpdate; - /** * Check if an action exists */