use const for readonly strings and set some functions to static
[blender.git] / source / gameengine / Converter / BL_ShapeActionActuator.cpp
index 81ce9ff6154420468e4b1c352a65707b9b9dddf7..ecf9427eddd5573eb9da79e8527d4e1a1f610de1 100644 (file)
@@ -1,6 +1,4 @@
-/**
-* $Id$
-*
+/*
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
  * This program is free software; you can redistribute it and/or
@@ -15,7 +13,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * 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.
  * Contributor(s): none yet.
  *
  * ***** END GPL LICENSE BLOCK *****
-*/
+ */
+
+/** \file gameengine/Converter/BL_ShapeActionActuator.cpp
+ *  \ingroup bgeconv
+ */
+
 
-#if defined (__sgi)
-#include <math.h>
-#else
 #include <cmath>
-#endif
 
 #include "SCA_LogicManager.h"
 #include "BL_ShapeActionActuator.h"
 #include "DNA_armature_types.h"
 #include "MEM_guardedalloc.h"
 #include "BLI_blenlib.h"
-#include "BLI_arithb.h"
+#include "BLI_math.h"
 #include "MT_Matrix4x4.h"
-#include "BKE_utildefines.h"
+
 #include "FloatValue.h"
 #include "PyObjectPlus.h"
 
 extern "C" {
        #include "BKE_animsys.h"
+       #include "BKE_key.h"
+       #include "RNA_access.h"
 }
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
+BL_ShapeActionActuator::BL_ShapeActionActuator(SCA_IObject* gameobj,
+                                       const STR_String& propname,
+                                       const STR_String& framepropname,
+                                       float starttime,
+                                       float endtime,
+                                       struct bAction *action,
+                                       short   playtype,
+                                       short   blendin,
+                                       short   priority,
+                                       float   stride) 
+       : SCA_IActuator(gameobj, KX_ACT_SHAPEACTION),
+               
+       m_lastpos(0, 0, 0),
+       m_blendframe(0),
+       m_flag(0),
+       m_startframe (starttime),
+       m_endframe(endtime) ,
+       m_starttime(0),
+       m_localtime(starttime),
+       m_lastUpdate(-1),
+       m_blendin(blendin),
+       m_blendstart(0),
+       m_stridelength(stride),
+       m_playtype(playtype),
+       m_priority(priority),
+       m_action(action),
+       m_framepropname(framepropname), 
+       m_propname(propname)
+{
+       m_idptr = new PointerRNA();
+       BL_DeformableGameObject *obj = (BL_DeformableGameObject*)GetParent();
+       BL_ShapeDeformer *shape_deformer = dynamic_cast<BL_ShapeDeformer*>(obj->GetDeformer());
+       RNA_id_pointer_create(&shape_deformer->GetKey()->id, m_idptr);
+};
 
 BL_ShapeActionActuator::~BL_ShapeActionActuator()
 {
+       if (m_idptr)
+               delete m_idptr;
 }
 
 void BL_ShapeActionActuator::ProcessReplica()
@@ -230,6 +264,16 @@ bool BL_ShapeActionActuator::Update(double curtime, bool frame)
                        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)){
@@ -304,6 +348,18 @@ bool BL_ShapeActionActuator::Update(double curtime, bool frame)
                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)){
@@ -359,7 +415,11 @@ bool BL_ShapeActionActuator::Update(double curtime, bool frame)
 
                /* Priority test */
                if (obj->SetActiveAction(this, priority, curtime)){
-                       Key *key = obj->GetKey();
+                       BL_ShapeDeformer *shape_deformer = dynamic_cast<BL_ShapeDeformer*>(obj->GetDeformer());
+                       Key *key = NULL;
+
+                       if (shape_deformer)
+                               key = shape_deformer->GetKey();
 
                        if (!key) {
                                // this could happen if the mesh was changed in the middle of an action
@@ -374,10 +434,14 @@ bool BL_ShapeActionActuator::Update(double curtime, bool frame)
                                        obj->GetShape(m_blendshape);
                                        m_blendstart = curtime;
                                }
-                               // only interested in shape channel
 
-                               // in 2.4x was // extract_ipochannels_from_action(&tchanbase, &key->id, m_action, "Shape", m_localtime);
-                               BKE_animsys_evaluate_animdata(&key->id, key->adt, m_localtime, ADT_RECALC_ANIM);
+                               KeyBlock *kb;
+                               // We go through and clear out the keyblocks so there isn't any interference
+                               // from other shape actions
+                               for (kb=(KeyBlock*)key->block.first; kb; kb=(KeyBlock*)kb->next)
+                                       kb->curval = 0.f;
+
+                               animsys_evaluate_action(m_idptr, m_action, NULL, m_localtime);
 
                                // XXX - in 2.5 theres no way to do this. possibly not that important to support - Campbell
                                if (0) { // XXX !execute_ipochannels(&tchanbase)) {
@@ -412,6 +476,8 @@ bool BL_ShapeActionActuator::Update(double curtime, bool frame)
        return keepgoing;
 };
 
+#ifdef WITH_PYTHON
+
 /* ------------------------------------------------------------------------- */
 /* Python functions                                                          */
 /* ------------------------------------------------------------------------- */
@@ -492,3 +558,5 @@ int BL_ShapeActionActuator::pyattr_set_action(void *self_v, const KX_PYATTRIBUTE
        return PY_SET_ATTR_SUCCESS;
 
 }
+
+#endif // WITH_PYTHON