Fix for T41536: 2.71 getActionFrame no longer returns frames accurately
authorMitchell Stokes <mogurijin@gmail.com>
Wed, 7 Oct 2015 05:16:22 +0000 (22:16 -0700)
committerMitchell Stokes <mogurijin@gmail.com>
Wed, 7 Oct 2015 05:22:47 +0000 (22:22 -0700)
We now keep actions around when they are finished playing so scripts can
still get access to information such as the current frame. Playing a new
action in the same layer still overwrites the previous action as before this
commit. Using an explicit KX_GameObject.stopAction() will free the memory. The
action is also freed when the KX_GameObject is freed as before.

source/gameengine/Ketsji/BL_Action.cpp
source/gameengine/Ketsji/BL_Action.h
source/gameengine/Ketsji/BL_ActionManager.cpp
source/gameengine/Ketsji/BL_ActionManager.h

index 12a1caee22150056e1922b1af0f95625b0d1367b..507476dbd0eb9a2afde958da196f95d0f5cbd568 100644 (file)
@@ -268,11 +268,6 @@ bool BL_Action::Play(const char* name,
        return true;
 }
 
-void BL_Action::Stop()
-{
-       m_done = true;
-}
-
 bool BL_Action::IsDone()
 {
        return m_done;
index 379dd52df5b1272449b23a47e6e5b6cfdda4ec75..7a404416758767587cec7f779f820dfc1a555b93 100644 (file)
@@ -93,10 +93,6 @@ public:
                        short ipo_flags,
                        float playback_speed,
                        short blend_mode);
-       /**
-        * Stop playing the action
-        */
-       void Stop();
        /**
         * Whether or not the action is still playing
         */
index 9e4690548d38c930dc15959df10b70f021614e93..4249db55b4515dff695b0a5ca28eeb8717982ef2 100644 (file)
@@ -53,14 +53,6 @@ BL_Action *BL_ActionManager::GetAction(short layer)
        return (it != m_layers.end()) ? it->second : 0;
 }
 
-BL_Action* BL_ActionManager::AddAction(short layer)
-{
-       BL_Action *action = new BL_Action(m_obj);
-       m_layers[layer] = action;
-
-       return action;
-}
-
 float BL_ActionManager::GetActionFrame(short layer)
 {
        BL_Action *action = GetAction(layer);
@@ -116,8 +108,10 @@ bool BL_ActionManager::PlayAction(const char* name,
 {
        // Only this method will create layer if non-existent
        BL_Action *action = GetAction(layer);
-       if (!action)
-               action = AddAction(layer);
+       if (!action) {
+               action = new BL_Action(m_obj);
+               m_layers[layer] = action;
+       }
 
        // Disable layer blending on the first layer
        if (layer == 0) layer_weight = -1.f;
@@ -129,7 +123,10 @@ void BL_ActionManager::StopAction(short layer)
 {
        BL_Action *action = GetAction(layer);
 
-       if (action) action->Stop();
+       if (action) {
+               m_layers.erase(layer);
+               delete action;
+       }
 }
 
 void BL_ActionManager::RemoveTaggedActions()
@@ -158,15 +155,10 @@ void BL_ActionManager::Update(float curtime)
        m_prevUpdate = curtime;
 
        BL_ActionMap::iterator it;
-       for (it = m_layers.begin(); it != m_layers.end(); )
+       for (it = m_layers.begin(); it != m_layers.end(); ++it)
        {
-               if (it->second->IsDone()) {
-                       delete it->second;
-                       m_layers.erase(it++);
-               }
-               else {
+               if (!it->second->IsDone()) {
                        it->second->Update(curtime);
-                       ++it;
                }
        }
 }
index 97d6d88cf22d4b850c101d88084e86bbcb16efd6..1292938d8f4182f64612f41701612d7eaeb95f1f 100644 (file)
@@ -59,11 +59,6 @@ private:
         */
        BL_Action* GetAction(short layer);
 
-       /**
-        * Add new action with given layer
-        */
-       BL_Action* AddAction(short layer);
-
 public:
        BL_ActionManager(class KX_GameObject* obj);
        ~BL_ActionManager();