BGE Animations: Removing unused code and adding some more comments.
authorMitchell Stokes <mogurijin@gmail.com>
Thu, 7 Jul 2011 03:53:24 +0000 (03:53 +0000)
committerMitchell Stokes <mogurijin@gmail.com>
Thu, 7 Jul 2011 03:53:24 +0000 (03:53 +0000)
source/gameengine/Converter/BL_ActionActuator.cpp
source/gameengine/Converter/BL_ActionActuator.h
source/gameengine/Ketsji/BL_Action.cpp
source/gameengine/Ketsji/BL_Action.h
source/gameengine/Ketsji/BL_ActionManager.cpp
source/gameengine/Ketsji/BL_ActionManager.h
source/gameengine/Ketsji/KX_GameObject.h

index f52f8387a6d7ddceb20f884ec6ac7d4a298dc80e..7bfe87c773ecaa21d3210eb0bdc10186d75764c1 100644 (file)
@@ -135,59 +135,6 @@ CValue* BL_ActionActuator::GetReplica() {
        return replica;
 }
 
-#if 0
-bool BL_ActionActuator::ClampLocalTime()
-{
-       if (m_startframe < m_endframe)
-       {
-               if (m_localtime < m_startframe)
-               {
-                       m_localtime = m_startframe;
-                       return true;
-               } 
-               else if (m_localtime > m_endframe)
-               {
-                       m_localtime = m_endframe;
-                       return true;
-               }
-       } else {
-               if (m_localtime > m_startframe)
-               {
-                       m_localtime = m_startframe;
-                       return true;
-               }
-               else if (m_localtime < m_endframe)
-               {
-                       m_localtime = m_endframe;
-                       return true;
-               }
-       }
-       return false;
-}
-
-void BL_ActionActuator::SetStartTime(float curtime)
-{
-       float direction = m_startframe < m_endframe ? 1.0 : -1.0;
-       
-       if (!(m_flag & ACT_FLAG_REVERSE))
-               m_starttime = curtime - direction*(m_localtime - m_startframe)/KX_KetsjiEngine::GetAnimFrameRate();
-       else
-               m_starttime = curtime - direction*(m_endframe - m_localtime)/KX_KetsjiEngine::GetAnimFrameRate();
-}
-
-void BL_ActionActuator::SetLocalTime(float curtime)
-{
-       float delta_time = (curtime - m_starttime)*KX_KetsjiEngine::GetAnimFrameRate();
-       
-       if (m_endframe < m_startframe)
-               delta_time = -delta_time;
-
-       if (!(m_flag & ACT_FLAG_REVERSE))
-               m_localtime = m_startframe + delta_time;
-       else
-               m_localtime = m_endframe - delta_time;
-}
-#endif
 bool BL_ActionActuator::Update(double curtime, bool frame)
 {
        bool bNegativeEvent = false;
@@ -309,314 +256,6 @@ bool BL_ActionActuator::Update(double curtime, bool frame)
        return true;
 }
 
-#if 0 // Kept around as reference for now
-bool BL_ActionActuator::Update(double curtime, bool frame)
-{
-       bool bNegativeEvent = false;
-       bool bPositiveEvent = false;
-       bool keepgoing = true;
-       bool wrap = false;
-       bool apply=true;
-       int     priority;
-       float newweight;
-
-       curtime -= KX_KetsjiEngine::GetSuspendedDelta();
-       
-       // result = true if animation has to be continued, false if animation stops
-       // maybe there are events for us in the queue !
-       if (frame)
-       {
-               bNegativeEvent = m_negevent;
-               bPositiveEvent = m_posevent;
-               RemoveAllEvents();
-               
-               if (bPositiveEvent)
-                       m_flag |= ACT_FLAG_ACTIVE;
-               
-               if (bNegativeEvent)
-               {
-                       // dont continue where we left off when restarting
-                       if (m_end_reset) {
-                               m_flag &= ~ACT_FLAG_LOCKINPUT;
-                       }
-                       
-                       if (!(m_flag & ACT_FLAG_ACTIVE))
-                               return false;
-                       m_flag &= ~ACT_FLAG_ACTIVE;
-               }
-       }
-       
-       /*      We know that action actuators have been discarded from all non armature objects:
-       if we're being called, we're attached to a BL_ArmatureObject */
-       BL_ArmatureObject *obj = (BL_ArmatureObject*)GetParent();
-       float length = m_endframe - m_startframe;
-       
-       priority = m_priority;
-       
-       /* Determine pre-incrementation behaviour and set appropriate flags */
-       switch (m_playtype){
-       case ACT_ACTION_MOTION:
-               if (bNegativeEvent){
-                       keepgoing=false;
-                       apply=false;
-               };
-               break;
-       case ACT_ACTION_FROM_PROP:
-               if (bNegativeEvent){
-                       apply=false;
-                       keepgoing=false;
-               }
-               break;
-       case ACT_ACTION_LOOP_END:
-               if (bPositiveEvent){
-                       if (!(m_flag & ACT_FLAG_LOCKINPUT)){
-                               m_flag &= ~ACT_FLAG_KEYUP;
-                               m_flag &= ~ACT_FLAG_REVERSE;
-                               m_flag |= ACT_FLAG_LOCKINPUT;
-                               m_localtime = m_startframe;
-                               m_starttime = curtime;
-                       }
-               }
-               if (bNegativeEvent){
-                       m_flag |= ACT_FLAG_KEYUP;
-               }
-               break;
-       case ACT_ACTION_LOOP_STOP:
-               if (bPositiveEvent){
-                       if (!(m_flag & ACT_FLAG_LOCKINPUT)){
-                               m_flag &= ~ACT_FLAG_REVERSE;
-                               m_flag &= ~ACT_FLAG_KEYUP;
-                               m_flag |= ACT_FLAG_LOCKINPUT;
-                               SetStartTime(curtime);
-                       }
-               }
-               if (bNegativeEvent){
-                       m_flag |= ACT_FLAG_KEYUP;
-                       m_flag &= ~ACT_FLAG_LOCKINPUT;
-                       keepgoing=false;
-                       apply=false;
-               }
-               break;
-       case ACT_ACTION_PINGPONG:
-               if (bPositiveEvent){
-                       if (!(m_flag & ACT_FLAG_LOCKINPUT)){
-                               m_flag &= ~ACT_FLAG_KEYUP;
-                               m_localtime = m_starttime;
-                               m_starttime = curtime;
-                               m_flag |= ACT_FLAG_LOCKINPUT;
-                       }
-               }
-               break;
-       case ACT_ACTION_FLIPPER:
-               if (bPositiveEvent){
-                       if (!(m_flag & ACT_FLAG_LOCKINPUT)){
-                               m_flag &= ~ACT_FLAG_REVERSE;
-                               m_flag |= ACT_FLAG_LOCKINPUT;
-                               SetStartTime(curtime);
-                       }
-               }
-               else if (bNegativeEvent){
-                       m_flag |= ACT_FLAG_REVERSE;
-                       m_flag &= ~ACT_FLAG_LOCKINPUT;
-                       SetStartTime(curtime);
-               }
-               break;
-       case ACT_ACTION_PLAY:
-               if (bPositiveEvent){
-                       if (!(m_flag & ACT_FLAG_LOCKINPUT)){
-                               m_flag &= ~ACT_FLAG_REVERSE;
-                               m_localtime = m_starttime;
-                               m_starttime = curtime;
-                               m_flag |= ACT_FLAG_LOCKINPUT;
-                       }
-               }
-               break;
-       default:
-               break;
-       }
-       
-       /* Perform increment */
-       if (keepgoing){
-               if (m_playtype == ACT_ACTION_MOTION){
-                       MT_Point3       newpos;
-                       MT_Point3       deltapos;
-                       
-                       newpos = obj->NodeGetWorldPosition();
-                       
-                       /* Find displacement */
-                       deltapos = newpos-m_lastpos;
-                       m_localtime += (length/m_stridelength) * deltapos.length();
-                       m_lastpos = newpos;
-               }
-               else{
-                       SetLocalTime(curtime);
-               }
-       }
-       
-       /* Check if a wrapping response is needed */
-       if (length){
-               if (m_localtime < m_startframe || m_localtime > m_endframe)
-               {
-                       m_localtime = m_startframe + fmod(m_localtime, length);
-                       wrap = true;
-               }
-       }
-       else
-               m_localtime = m_startframe;
-       
-       /* Perform post-increment tasks */
-       switch (m_playtype){
-       case ACT_ACTION_FROM_PROP:
-               {
-                       CValue* propval = GetParent()->GetProperty(m_propname);
-                       if (propval)
-                               m_localtime = propval->GetNumber();
-                       
-                       if (bNegativeEvent){
-                               keepgoing=false;
-                       }
-               }
-               break;
-       case ACT_ACTION_MOTION:
-               break;
-       case ACT_ACTION_LOOP_STOP:
-               break;
-       case ACT_ACTION_PINGPONG:
-               if (wrap){
-                       if (!(m_flag & ACT_FLAG_REVERSE))
-                               m_localtime = m_endframe;
-                       else 
-                               m_localtime = m_startframe;
-
-                       m_flag &= ~ACT_FLAG_LOCKINPUT;
-                       m_flag ^= ACT_FLAG_REVERSE; //flip direction
-                       keepgoing = false;
-               }
-               break;
-       case ACT_ACTION_FLIPPER:
-               if (wrap){
-                       if (!(m_flag & ACT_FLAG_REVERSE)){
-                               m_localtime=m_endframe;
-                               //keepgoing = false;
-                       }
-                       else {
-                               m_localtime=m_startframe;
-                               keepgoing = false;
-                       }
-               }
-               break;
-       case ACT_ACTION_LOOP_END:
-               if (wrap){
-                       if (m_flag & ACT_FLAG_KEYUP){
-                               keepgoing = false;
-                               m_localtime = m_endframe;
-                               m_flag &= ~ACT_FLAG_LOCKINPUT;
-                       }
-                       SetStartTime(curtime);
-               }
-               break;
-       case ACT_ACTION_PLAY:
-               if (wrap){
-                       m_localtime = m_endframe;
-                       keepgoing = false;
-                       m_flag &= ~ACT_FLAG_LOCKINPUT;
-               }
-               break;
-       default:
-               keepgoing = false;
-               break;
-       }
-       
-       /* Set the property if its defined */
-       if (m_framepropname[0] != '\0') {
-               CValue* propowner = GetParent();
-               CValue* oldprop = propowner->GetProperty(m_framepropname);
-               CValue* newval = new CFloatValue(m_localtime);
-               if (oldprop) {
-                       oldprop->SetValue(newval);
-               } else {
-                       propowner->SetProperty(m_framepropname, newval);
-               }
-               newval->Release();
-       }
-       
-       if (bNegativeEvent)
-               m_blendframe=0.0;
-       
-       /* Apply the pose if necessary*/
-       if (apply){
-
-               /* Priority test */
-               if (obj->SetActiveAction(this, priority, curtime)){
-                       
-                       /* Get the underlying pose from the armature */
-                       obj->GetPose(&m_pose);
-
-// 2.4x function, 
-                       /* Override the necessary channels with ones from the action */
-                       // XXX extract_pose_from_action(m_pose, m_action, m_localtime);
-                       
-                       
-// 2.5x - replacement for extract_pose_from_action(...) above.
-                       {
-                               struct PointerRNA id_ptr;
-                               Object *arm= obj->GetArmatureObject();
-                               bPose *pose_back= arm->pose;
-                               
-                               arm->pose= m_pose;
-                               RNA_id_pointer_create((ID *)arm, &id_ptr);
-                               animsys_evaluate_action(&id_ptr, m_action, NULL, m_localtime);
-                               
-                               arm->pose= pose_back;
-                       
-// 2.5x - could also do this but looks too high level, constraints use this, it works ok.
-//                             Object workob; /* evaluate using workob */
-//                             what_does_obaction(obj->GetArmatureObject(), &workob, m_pose, m_action, NULL, m_localtime);
-                       }
-
-                       // done getting the pose from the action
-                       
-                       /* Perform the user override (if any) */
-                       if (m_userpose){
-                               extract_pose_from_pose(m_pose, m_userpose);
-                               game_free_pose(m_userpose); //cant use MEM_freeN(m_userpose) because the channels need freeing too.
-                               m_userpose = NULL;
-                       }
-#if 1
-                       /* Handle blending */
-                       if (m_blendin && (m_blendframe<m_blendin)){
-                               /* If this is the start of a blending sequence... */
-                               if ((m_blendframe==0.0) || (!m_blendpose)){
-                                       obj->GetMRDPose(&m_blendpose);
-                                       m_blendstart = curtime;
-                               }
-                               
-                               /* Find percentages */
-                               newweight = (m_blendframe/(float)m_blendin);
-                               game_blend_poses(m_pose, m_blendpose, 1.0 - newweight);
-
-                               /* Increment current blending percentage */
-                               m_blendframe = (curtime - m_blendstart)*KX_KetsjiEngine::GetAnimFrameRate();
-                               if (m_blendframe>m_blendin)
-                                       m_blendframe = m_blendin;
-                               
-                       }
-#endif
-                       m_lastUpdate = m_localtime;
-                       obj->SetPose (m_pose);
-               }
-               else{
-                       m_blendframe = 0.0;
-               }
-       }
-       
-       if (!keepgoing){
-               m_blendframe = 0.0;
-       }
-       return keepgoing;
-};
-#endif
-
 #ifdef WITH_PYTHON
 
 /* ------------------------------------------------------------------------- */
index 7b4200fa19b8ae480a08993a0cfdb5dbe101e152..ee8599a90524ca9519ef6c8a43f0197af180782a 100644 (file)
@@ -122,11 +122,6 @@ public:
 #endif // WITH_PYTHON
        
 protected:
-
-       //void SetStartTime(float curtime);
-       //void SetLocalTime(float curtime);
-       //bool ClampLocalTime();
-
        MT_Point3       m_lastpos;
        float   m_blendframe;
        int             m_flag;
@@ -156,6 +151,9 @@ protected:
        STR_String      m_framepropname;
 };
 
+// The first values are not used in BL_ActionActuator anymore,
+// but BL_ShapeActionActuator still uses them, so we keep them around
+// for now.
 enum {
        ACT_FLAG_REVERSE        = 1<<0,
        ACT_FLAG_LOCKINPUT      = 1<<1,
index f1b53fc4151aff81eb0d2c5dcba696849189a365..8ed6a33696a6cbea6ed13e809928f4a9d39edbed 100644 (file)
  * ***** END GPL LICENSE BLOCK *****
  */
 
+/** \file BL_Action.cpp
+ *  \ingroup ketsji
+ */
+
 #include <cstdlib>
 
 #include "BL_Action.h"
index f7c5a81172159056b9e17de498e871dc588d34eb..14312e158c015684090ceb4a7ffd5f45066b11fb 100644 (file)
  *
  * ***** END GPL LICENSE BLOCK *****
  */
+
+/** \file BL_Action.h
+ *  \ingroup ketsji
+ */
+
 #ifndef __BL_ACTION
 #define __BL_ACTION
 
@@ -75,6 +80,9 @@ public:
        BL_Action(class KX_GameObject* gameobj);
        ~BL_Action();
 
+       /**
+        * Play an action
+        */
        bool Play(const char* name,
                        float start,
                        float end,
@@ -84,8 +92,17 @@ public:
                        float layer_weight,
                        short ipo_flags,
                        float playback_speed);
+       /**
+        * Stop playing the action
+        */
        void Stop();
+       /**
+        * Whether or not the action is still playing
+        */
        bool IsDone();
+       /**
+        * Update the action's frame, etc.
+        */
        void Update(float curtime);
 
        // Accessors
index c3b4dc5d4db50019d53d6bf24db4e08f399c6a92..0586c515c659b810f25215d26c00c24a2967d6ff 100644 (file)
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
+ * Contributor(s): Mitchell Stokes.
  *
  * ***** END GPL LICENSE BLOCK *****
  */
 
+/** \file BL_ActionManager.cpp
+ *  \ingroup ketsji
+ */
+
 #include "BL_ActionManager.h"
 
 BL_ActionManager::BL_ActionManager(class KX_GameObject *obj)
index c527c7bbd3aaacd92b8607658ef91b119afb2d08..3818f643b1cf8a87a9f82139dc9956297f2c24c0 100644 (file)
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
+ * Contributor(s): Mitchell Stokes.
  *
  * ***** END GPL LICENSE BLOCK *****
  */
+
+/** \file BL_ActionManager.cpp
+ *  \ingroup ketsji
+ */
+
 #ifndef __BL_ACTIONMANAGER
 #define __BL_ACTIONMANAGER
 
@@ -33,6 +33,9 @@
 
 #define MAX_ACTION_LAYERS 4
 
+/**
+ * BL_ActionManager is responsible for handling a KX_GameObject's actions.
+ */
 class BL_ActionManager
 {
 private:
@@ -52,14 +55,34 @@ public:
                                        float layer_weight=0.f,
                                        short ipo_flags=0,
                                        float playback_speed=1.f);
-       
+       /**
+        * Gets the current frame of an action
+        */
        float GetActionFrame(short layer);
-       void SetActionFrame(short layer, float frame);
 
+       /**
+        * Sets the current frame of an action
+        */
+       void SetActionFrame(short layer, float frame);
+       
+       /**
+        * Gets the currently running action on the given layer
+        */
        struct bAction *GetCurrentAction(short layer);
 
+       /**
+        * Stop playing the action on the given layer
+        */
        void StopAction(short layer);
+
+       /**
+        * Check if an action has finished playing
+        */
        bool IsActionDone(short layer);
+
+       /**
+        * Update any running actions
+        */
        void Update(float);
 
 #ifdef WITH_CXX_GUARDEDALLOC
index 6e22dc5fbc3f4d70990e070d9e73dfd6a75c0bcf..7e052e6d05789a53aa5b905e34ea1b4989f5db1c 100644 (file)
@@ -239,7 +239,7 @@ public:
        bAction *GetCurrentAction(short layer);
 
        /**
-        * Remove an action from the object's action manager
+        * Stop playing the action on the given layer
         */
        void StopAction(short layer);