BGE: some more cleanup in GetReplica/ProcessReplica of deformers: make them consisten...
authorBenoit Bolsee <benoit.bolsee@online.be>
Wed, 22 Apr 2009 16:26:22 +0000 (16:26 +0000)
committerBenoit Bolsee <benoit.bolsee@online.be>
Wed, 22 Apr 2009 16:26:22 +0000 (16:26 +0000)
source/gameengine/Converter/BL_DeformableGameObject.cpp
source/gameengine/Converter/BL_MeshDeformer.h
source/gameengine/Converter/BL_ModifierDeformer.cpp
source/gameengine/Converter/BL_ModifierDeformer.h
source/gameengine/Converter/BL_ShapeDeformer.cpp
source/gameengine/Converter/BL_ShapeDeformer.h
source/gameengine/Converter/BL_SkinDeformer.cpp
source/gameengine/Converter/BL_SkinDeformer.h
source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp
source/gameengine/Rasterizer/RAS_Deformer.h

index 241ff8d2aaf8ebb8c8f397728413d7f7bbcd3541..a9d5b643fd4957468c3e489eb1f5ab22db369463 100644 (file)
@@ -46,7 +46,7 @@ void BL_DeformableGameObject::ProcessReplica()
        KX_GameObject::ProcessReplica();
 
        if (m_pDeformer)
-               m_pDeformer= (BL_MeshDeformer*)m_pDeformer->GetReplica(this);
+               m_pDeformer= (BL_MeshDeformer*)m_pDeformer->GetReplica();
 }
 
 CValue*                BL_DeformableGameObject::GetReplica()
index 8de59c1cdf3331e58bafd5d05f22520166d39d97..34944421b286c267f364687460079ccde10742b3 100644 (file)
@@ -64,7 +64,8 @@ public:
        virtual void SetSimulatedTime(double time){};
        virtual bool Apply(class RAS_IPolyMaterial *mat);
        virtual bool Update(void){ return false; };
-       virtual RAS_Deformer*   GetReplica(class KX_GameObject* replica){return NULL;};
+       virtual RAS_Deformer*   GetReplica(){return NULL;};
+       virtual void ProcessReplica() { };
        struct Mesh* GetMesh() { return m_bmesh; };
        //      virtual void InitDeform(double time){};
 
index 79ee6be47f0123fc0659772440353cc63217d513..09dbe966d0bf561134e342ca1a025ef2e0cc0cc9 100644 (file)
@@ -76,7 +76,7 @@ BL_ModifierDeformer::~BL_ModifierDeformer()
        }
 };
 
-RAS_Deformer *BL_ModifierDeformer::GetReplica(class KX_GameObject* replica)
+RAS_Deformer *BL_ModifierDeformer::GetReplica()
 {
        BL_ModifierDeformer *result;
 
index 0caaabf805592fe8682979be100eec8a4b595626..465c287a88bcc1a4fe59f7f62ffb17b4f65095c2 100644 (file)
@@ -73,7 +73,7 @@ public:
        };
 
        virtual void ProcessReplica();
-       virtual RAS_Deformer *GetReplica(class KX_GameObject* replica);
+       virtual RAS_Deformer *GetReplica();
        virtual ~BL_ModifierDeformer();
        virtual bool UseVertexArray()
        {
index 499732c7f70406ba68276af08732861b9ebd15f7..bf5eb5cbcb32755c5be47e9631700fb0c0ce99af 100644 (file)
@@ -68,7 +68,7 @@ BL_ShapeDeformer::~BL_ShapeDeformer()
 {
 };
 
-RAS_Deformer *BL_ShapeDeformer::GetReplica(class KX_GameObject* replica)
+RAS_Deformer *BL_ShapeDeformer::GetReplica()
 {
        BL_ShapeDeformer *result;
 
@@ -77,11 +77,6 @@ RAS_Deformer *BL_ShapeDeformer::GetReplica(class KX_GameObject* replica)
        return result;
 }
 
-void BL_ShapeDeformer::ProcessReplica()
-{
-       BL_SkinDeformer::ProcessReplica();
-}
-
 bool BL_ShapeDeformer::LoadShapeDrivers(Object* arma)
 {
        IpoCurve *icu;
index 901a1d8229534306b289137ff0510d361d239672..1ec7bfdf74a236de789b394ad7d81c1427eb9a05 100644 (file)
@@ -66,8 +66,7 @@ public:
        {
        };
 
-       virtual void ProcessReplica();
-       virtual RAS_Deformer *GetReplica(class KX_GameObject* replica);
+       virtual RAS_Deformer *GetReplica();
        virtual ~BL_ShapeDeformer();
 
        bool Update (void);
index 3267dbce410a3e8a863c4045396e5b53e932cfcc..d40776a645dbe4bf3c8a244ca50c7425367bf6fd 100644 (file)
@@ -108,7 +108,7 @@ void BL_SkinDeformer::Relink(GEN_Map<class GEN_HashedPtr, void*>*map)
                void **h_obj = (*map)[m_armobj];
 
                if (h_obj)
-                       SetArmature( (BL_ArmatureObject*)(*h_obj) );
+                       m_armobj = (BL_ArmatureObject*)(*h_obj);
                else
                        m_armobj=NULL;
        }
@@ -151,21 +151,16 @@ bool BL_SkinDeformer::Apply(RAS_IPolyMaterial *mat)
        return true;
 }
 
-RAS_Deformer *BL_SkinDeformer::GetReplica(class KX_GameObject* replica)
+RAS_Deformer *BL_SkinDeformer::GetReplica()
 {
        BL_SkinDeformer *result;
 
        result = new BL_SkinDeformer(*this);
-       /* Not inherited from PyObjectPlus so this isnt needed */
-       /* Just call a dummy function below, will be optimized out */
+       /* there is m_armobj that must be fixed but we cannot do it now, it will be done in Relink */
        result->ProcessReplica();
        return result;
 }
 
-void BL_SkinDeformer::ProcessReplica()
-{
-}
-
 //void where_is_pose (Object *ob);
 //void armature_deform_verts(Object *armOb, Object *target, float (*vertexCos)[3], int numVerts, int deformflag); 
 bool BL_SkinDeformer::Update(void)
index c93188b0c5ad72adbda49255d63d967e9eacd5c6..ee2405888512cd4ba23831432ff8ccef95fc38dc 100644 (file)
@@ -67,8 +67,7 @@ public:
                                        bool recalc_normal,
                                        BL_ArmatureObject* arma = NULL);
 
-       virtual void ProcessReplica();
-       virtual RAS_Deformer *GetReplica(class KX_GameObject* replica);
+       virtual RAS_Deformer *GetReplica();
        virtual ~BL_SkinDeformer();
        bool Update (void);
        bool Apply (class RAS_IPolyMaterial *polymat);
index 08e2ea30414ba380f6318cff3ac6a2f1ab7d4e95..f4f8ec9f91bf54ff73e3ef34895a122f20a9e1da 100644 (file)
@@ -34,7 +34,7 @@
 
 // defines USE_ODE to choose physics engine
 #include "KX_ConvertPhysicsObject.h"
-#include "KX_GameObject.h"
+#include "BL_DeformableGameObject.h"
 #include "RAS_MeshObject.h"
 #include "KX_Scene.h"
 #include "SYS_System.h"
@@ -670,11 +670,11 @@ void      KX_ConvertODEEngineObject(KX_GameObject* gameobj,
                                                        
        class KX_SoftBodyDeformer : public RAS_Deformer
        {
-               class RAS_MeshObject*   m_pMeshObject;
-               class KX_GameObject*    m_gameobj;
+               class RAS_MeshObject*                   m_pMeshObject;
+               class BL_DeformableGameObject*  m_gameobj;
 
        public:
-               KX_SoftBodyDeformer(RAS_MeshObject*     pMeshObject,KX_GameObject*      gameobj)
+               KX_SoftBodyDeformer(RAS_MeshObject*     pMeshObject,BL_DeformableGameObject*    gameobj)
                        :m_pMeshObject(pMeshObject),
                        m_gameobj(gameobj)
                {
@@ -687,7 +687,15 @@ void       KX_ConvertODEEngineObject(KX_GameObject* gameobj,
                };
                virtual void Relink(GEN_Map<class GEN_HashedPtr, void*>*map)
                {
-                       //printf("relink\n");
+                       void **h_obj = (*map)[m_gameobj];
+
+                       if (h_obj) {
+                               m_gameobj = (BL_DeformableGameObject*)(*h_obj);
+                               m_pMeshObject = m_gameobj->GetMesh(0);
+                       } else {
+                               m_gameobj = NULL;
+                               m_pMeshObject = NULL;
+                       }
                }
                virtual bool Apply(class RAS_IPolyMaterial *polymat)
                {
@@ -751,12 +759,16 @@ void      KX_ConvertODEEngineObject(KX_GameObject* gameobj,
                        //printf("update\n");
                        return true;//??
                }
-               virtual RAS_Deformer *GetReplica(class KX_GameObject* replica)
+               virtual RAS_Deformer *GetReplica()
                {
-                       KX_SoftBodyDeformer* deformer = new KX_SoftBodyDeformer(replica->GetMesh(0),replica);
+                       KX_SoftBodyDeformer* deformer = new KX_SoftBodyDeformer(*this);
+                       deformer->ProcessReplica();
                        return deformer;
                }
-
+               virtual void ProcessReplica()
+               {
+                       // we have two pointers to deal with but we cannot do it now, will be done in Relink
+               }
                virtual bool SkipVertexTransform()
                {
                        return true;
@@ -1187,9 +1199,8 @@ void      KX_ConvertBulletObject( class   KX_GameObject* gameobj,
                if (softBody && gameobj->GetMesh(0))//only the first mesh, if any
                {
                        //should be a mesh then, so add a soft body deformer
-                       KX_SoftBodyDeformer* softbodyDeformer = new KX_SoftBodyDeformer( gameobj->GetMesh(0),gameobj);
+                       KX_SoftBodyDeformer* softbodyDeformer = new KX_SoftBodyDeformer( gameobj->GetMesh(0),(BL_DeformableGameObject*)gameobj);
                        gameobj->SetDeformer(softbodyDeformer);
-                       
                }
        }
 
index dc5a49a0f9963942a10b75ca67ce58886894afb9..5a6bab4c82d3dd67edee8861db0e3f769deb28d5 100644 (file)
@@ -44,7 +44,8 @@ public:
        virtual void Relink(GEN_Map<class GEN_HashedPtr, void*>*map)=0;
        virtual bool Apply(class RAS_IPolyMaterial *polymat)=0;
        virtual bool Update(void)=0;
-       virtual RAS_Deformer *GetReplica(class KX_GameObject* replica)=0;
+       virtual RAS_Deformer *GetReplica()=0;
+       virtual void ProcessReplica()=0;
        virtual bool SkipVertexTransform()
        {
                return false;