synched with trunk at revision 36569
[blender.git] / source / gameengine / Ketsji / KX_GameObject.cpp
index 93d67e9..d4ef462 100644 (file)
@@ -73,6 +73,7 @@ typedef unsigned long uint_ptr;
 #include "SCA_ISensor.h"
 #include "SCA_IController.h"
 #include "NG_NetworkScene.h" //Needed for sendMessage()
+#include "KX_ObstacleSimulation.h"
 
 #include "PyObjectPlus.h" /* python stuff */
 
@@ -107,7 +108,8 @@ KX_GameObject::KX_GameObject(
        m_pGraphicController(NULL),
        m_xray(false),
        m_pHitObject(NULL),
-       m_isDeformable(false)
+       m_isDeformable(false),
+       m_pObstacleSimulation(NULL)
 #ifdef WITH_PYTHON
        , m_attr_dict(NULL)
 #endif
@@ -154,9 +156,15 @@ KX_GameObject::~KX_GameObject()
        {
                delete m_pGraphicController;
        }
+
+       if (m_pObstacleSimulation)
+       {
+               m_pObstacleSimulation->DestroyObstacleForObj(this);
+       }
+
 #ifdef WITH_PYTHON
        if (m_attr_dict) {
-               PyDict_Clear(m_attr_dict); /* incase of circular refs or other weired cases */
+               PyDict_Clear(m_attr_dict); /* incase of circular refs or other weird cases */
                /* Py_CLEAR: Py_DECREF's and NULL's */
                Py_CLEAR(m_attr_dict);
        }
@@ -355,6 +363,14 @@ void KX_GameObject::ProcessReplica()
        m_pClient_info->m_gameobject = this;
        m_state = 0;
 
+       KX_Scene* scene = KX_GetActiveScene();
+       KX_ObstacleSimulation* obssimulation = scene->GetObstacleSimulation();
+       struct Object* blenderobject = GetBlenderObject();
+       if (obssimulation && (blenderobject->gameflag & OB_HASOBSTACLE))
+       {
+               obssimulation->AddObstacleForObj(this);
+       }
+
 #ifdef WITH_PYTHON
        if(m_attr_dict)
                m_attr_dict= PyDict_Copy(m_attr_dict);
@@ -1224,7 +1240,7 @@ CListValue* KX_GameObject::GetChildrenRecursive()
 /* ---------------------------------------------------------------------
  * Some stuff taken from the header
  * --------------------------------------------------------------------- */
-void KX_GameObject::Relink(GEN_Map<GEN_HashedPtr, void*> *map_parameter)
+void KX_GameObject::Relink(CTR_Map<CTR_HashedPtr, void*> *map_parameter)
 {
        // we will relink the sensors and actuators that use object references
        // if the object is part of the replicated hierarchy, use the new
@@ -1263,16 +1279,16 @@ static int mathutils_kxgameob_generic_check(BaseMathObject *bmo)
 {
        KX_GameObject* self= static_cast<KX_GameObject*>BGE_PROXY_REF(bmo->cb_user);
        if(self==NULL)
-               return 0;
+               return -1;
        
-       return 1;
+       return 0;
 }
 
 static int mathutils_kxgameob_vector_get(BaseMathObject *bmo, int subtype)
 {
        KX_GameObject* self= static_cast<KX_GameObject*>BGE_PROXY_REF(bmo->cb_user);
        if(self==NULL)
-               return 0;
+               return -1;
 
 #define PHYS_ERR(attr) PyErr_SetString(PyExc_AttributeError, "KX_GameObject." attr ", is missing a physics controller")
 
@@ -1290,26 +1306,26 @@ static int mathutils_kxgameob_vector_get(BaseMathObject *bmo, int subtype)
                        self->NodeGetWorldScaling().getValue(bmo->data);
                        break;
                case MATHUTILS_VEC_CB_INERTIA_LOCAL:
-                       if(!self->GetPhysicsController()) return PHYS_ERR("localInertia"), 0;
+                       if(!self->GetPhysicsController()) return PHYS_ERR("localInertia"), -1;
                        self->GetPhysicsController()->GetLocalInertia().getValue(bmo->data);
                        break;
                case MATHUTILS_VEC_CB_OBJECT_COLOR:
                        self->GetObjectColor().getValue(bmo->data);
                        break;
                case MATHUTILS_VEC_CB_LINVEL_LOCAL:
-                       if(!self->GetPhysicsController()) return PHYS_ERR("localLinearVelocity"), 0;
+                       if(!self->GetPhysicsController()) return PHYS_ERR("localLinearVelocity"), -1;
                        self->GetLinearVelocity(true).getValue(bmo->data);
                        break;
                case MATHUTILS_VEC_CB_LINVEL_GLOBAL:
-                       if(!self->GetPhysicsController()) return PHYS_ERR("worldLinearVelocity"), 0;
+                       if(!self->GetPhysicsController()) return PHYS_ERR("worldLinearVelocity"), -1;
                        self->GetLinearVelocity(false).getValue(bmo->data);
                        break;
                case MATHUTILS_VEC_CB_ANGVEL_LOCAL:
-                       if(!self->GetPhysicsController()) return PHYS_ERR("localLinearVelocity"), 0;
+                       if(!self->GetPhysicsController()) return PHYS_ERR("localLinearVelocity"), -1;
                        self->GetAngularVelocity(true).getValue(bmo->data);
                        break;
                case MATHUTILS_VEC_CB_ANGVEL_GLOBAL:
-                       if(!self->GetPhysicsController()) return PHYS_ERR("worldLinearVelocity"), 0;
+                       if(!self->GetPhysicsController()) return PHYS_ERR("worldLinearVelocity"), -1;
                        self->GetAngularVelocity(false).getValue(bmo->data);
                        break;
                        
@@ -1317,14 +1333,14 @@ static int mathutils_kxgameob_vector_get(BaseMathObject *bmo, int subtype)
        
 #undef PHYS_ERR
        
-       return 1;
+       return 0;
 }
 
 static int mathutils_kxgameob_vector_set(BaseMathObject *bmo, int subtype)
 {
        KX_GameObject* self= static_cast<KX_GameObject*>BGE_PROXY_REF(bmo->cb_user);
        if(self==NULL)
-               return 0;
+               return -1;
        
        switch(subtype) {
                case MATHUTILS_VEC_CB_POS_LOCAL:
@@ -1341,7 +1357,7 @@ static int mathutils_kxgameob_vector_set(BaseMathObject *bmo, int subtype)
                        break;
                case MATHUTILS_VEC_CB_SCALE_GLOBAL:
                        PyErr_SetString(PyExc_AttributeError, "KX_GameObject.worldScale is read-only");
-                       return 0;
+                       return -1;
                case MATHUTILS_VEC_CB_INERTIA_LOCAL:
                        /* read only */
                        break;
@@ -1362,15 +1378,15 @@ static int mathutils_kxgameob_vector_set(BaseMathObject *bmo, int subtype)
                        break;
        }
        
-       return 1;
+       return 0;
 }
 
 static int mathutils_kxgameob_vector_get_index(BaseMathObject *bmo, int subtype, int index)
 {
        /* lazy, avoid repeteing the case statement */
-       if(!mathutils_kxgameob_vector_get(bmo, subtype))
-               return 0;
-       return 1;
+       if(mathutils_kxgameob_vector_get(bmo, subtype) == -1)
+               return -1;
+       return 0;
 }
 
 static int mathutils_kxgameob_vector_set_index(BaseMathObject *bmo, int subtype, int index)
@@ -1378,8 +1394,8 @@ static int mathutils_kxgameob_vector_set_index(BaseMathObject *bmo, int subtype,
        float f= bmo->data[index];
        
        /* lazy, avoid repeteing the case statement */
-       if(!mathutils_kxgameob_vector_get(bmo, subtype))
-               return 0;
+       if(mathutils_kxgameob_vector_get(bmo, subtype) == -1)
+               return -1;
        
        bmo->data[index]= f;
        return mathutils_kxgameob_vector_set(bmo, subtype);
@@ -1403,7 +1419,7 @@ static int mathutils_kxgameob_matrix_get(BaseMathObject *bmo, int subtype)
 {
        KX_GameObject* self= static_cast<KX_GameObject*>BGE_PROXY_REF(bmo->cb_user);
        if(self==NULL)
-               return 0;
+               return -1;
 
        switch(subtype) {
                case MATHUTILS_MAT_CB_ORI_LOCAL:
@@ -1414,7 +1430,7 @@ static int mathutils_kxgameob_matrix_get(BaseMathObject *bmo, int subtype)
                        break;
        }
        
-       return 1;
+       return 0;
 }
 
 
@@ -1422,7 +1438,7 @@ static int mathutils_kxgameob_matrix_set(BaseMathObject *bmo, int subtype)
 {
        KX_GameObject* self= static_cast<KX_GameObject*>BGE_PROXY_REF(bmo->cb_user);
        if(self==NULL)
-               return 0;
+               return -1;
        
        MT_Matrix3x3 mat3x3;
        switch(subtype) {
@@ -1438,7 +1454,7 @@ static int mathutils_kxgameob_matrix_set(BaseMathObject *bmo, int subtype)
                        break;
        }
        
-       return 1;
+       return 0;
 }
 
 Mathutils_Callback mathutils_kxgameob_matrix_cb = {