code cleanup: function naming, use BKE_*type* prefix.
[blender.git] / source / gameengine / Converter / BL_ShapeDeformer.cpp
index 82c73529a9413ebff22b3075a5a02eaf2d98a39e..b93d731c5e6bfcdac49011a5a9ffa80b62886df6 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id$
- *
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
  * This program is free software; you can redistribute it and/or
@@ -52,6 +50,8 @@
 #include "DNA_meshdata_types.h"
 #include "BKE_armature.h"
 #include "BKE_action.h"
+#include "BKE_global.h"
+#include "BKE_main.h"
 #include "BKE_key.h"
 #include "BKE_ipo.h"
 #include "MT_Point3.h"
@@ -69,15 +69,15 @@ extern "C"{
 //#undef __NLA_DEFNORMALS
 
 BL_ShapeDeformer::BL_ShapeDeformer(BL_DeformableGameObject *gameobj,
-                    Object *bmeshobj,
-                    RAS_MeshObject *mesh)
-                               :       
-                                       BL_SkinDeformer(gameobj,bmeshobj, mesh),
-                                       m_lastShapeUpdate(-1),
-                                       m_useShapeDrivers(false)
+                                   Object *bmeshobj,
+                                   RAS_MeshObject *mesh)
+    :
+      BL_SkinDeformer(gameobj,bmeshobj, mesh),
+      m_useShapeDrivers(false),
+      m_lastShapeUpdate(-1)
 {
        m_key = m_bmesh->key;
-       m_bmesh->key = copy_key(m_key);
+       m_bmesh->key = BKE_key_copy(m_key);
 };
 
 /* this second constructor is needed for making a mesh deformable on the fly. */
@@ -90,19 +90,22 @@ BL_ShapeDeformer::BL_ShapeDeformer(BL_DeformableGameObject *gameobj,
                                BL_ArmatureObject* arma)
                                :
                                        BL_SkinDeformer(gameobj, bmeshobj_old, bmeshobj_new, mesh, release_object, recalc_normal, arma),
-                                       m_lastShapeUpdate(-1),
-                                       m_useShapeDrivers(false)
+                                       m_useShapeDrivers(false),
+                                       m_lastShapeUpdate(-1)
 {
        m_key = m_bmesh->key;
-       m_bmesh->key = copy_key(m_key);
+       m_bmesh->key = BKE_key_copy(m_key);
 };
 
 BL_ShapeDeformer::~BL_ShapeDeformer()
 {
-       if (m_key && m_bmesh->key)
+       if (m_key && m_bmesh->key && m_key != m_bmesh->key)
        {
-               free_key(m_bmesh->key);
+               BKE_key_free(m_bmesh->key);
+               BLI_remlink_safe(&G.main->key, m_bmesh->key);
+               MEM_freeN(m_bmesh->key);
                m_bmesh->key = m_key;
+               m_key = NULL;
        }
 };