synched with trunk at revision 36569
[blender.git] / source / gameengine / Ketsji / KX_GameObject.cpp
index 8cab7c1..d4ef462 100644 (file)
@@ -1,4 +1,4 @@
-/**
+/*
  * $Id$
  *
  * ***** BEGIN GPL LICENSE BLOCK *****
  * Game object wrapper
  */
 
+/** \file gameengine/Ketsji/KX_GameObject.cpp
+ *  \ingroup ketsji
+ */
+
+
 #if defined(_WIN64)
 typedef unsigned __int64 uint_ptr;
 #else
@@ -159,8 +164,9 @@ KX_GameObject::~KX_GameObject()
 
 #ifdef WITH_PYTHON
        if (m_attr_dict) {
-               PyDict_Clear(m_attr_dict); /* incase of circular refs or other weired cases */
-               Py_DECREF(m_attr_dict);
+               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);
        }
 #endif // WITH_PYTHON
 }
@@ -1234,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
@@ -1273,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")
 
@@ -1300,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;
                        
@@ -1327,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:
@@ -1351,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;
@@ -1372,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)
@@ -1388,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);
@@ -1413,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:
@@ -1424,7 +1430,7 @@ static int mathutils_kxgameob_matrix_get(BaseMathObject *bmo, int subtype)
                        break;
        }
        
-       return 1;
+       return 0;
 }
 
 
@@ -1432,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) {
@@ -1448,7 +1454,7 @@ static int mathutils_kxgameob_matrix_set(BaseMathObject *bmo, int subtype)
                        break;
        }
        
-       return 1;
+       return 0;
 }
 
 Mathutils_Callback mathutils_kxgameob_matrix_cb = {