Skip to content

Commit

Permalink
UPBGE: Fix animations update and shadows.
Browse files Browse the repository at this point in the history
Previously since 1d81d51 (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.
  • Loading branch information
panzergame committed Sep 12, 2016
1 parent d984423 commit ce5ba1f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
12 changes: 9 additions & 3 deletions source/gameengine/Ketsji/BL_Action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}

Expand Down Expand Up @@ -259,6 +260,8 @@ bool BL_Action::Play(const char* name,
m_done = false;
m_appliedToObject = false;

m_prevUpdate = -1.0f;

return true;
}

Expand Down Expand Up @@ -379,10 +382,13 @@ void BL_Action::BlendShape(Key* key, float srcweight, std::vector<float>& 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();

Expand Down
3 changes: 3 additions & 0 deletions source/gameengine/Ketsji/BL_Action.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 1 addition & 6 deletions source/gameengine/Ketsji/BL_ActionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}

Expand Down Expand Up @@ -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);
Expand Down
3 changes: 0 additions & 3 deletions source/gameengine/Ketsji/BL_ActionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit ce5ba1f

Please sign in to comment.