diff options
Diffstat (limited to 'source/gameengine/Ketsji/KX_GameObject.cpp')
-rw-r--r-- | source/gameengine/Ketsji/KX_GameObject.cpp | 56 |
1 files changed, 38 insertions, 18 deletions
diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index e955c344f0a..8cab7c17d8a 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -47,6 +47,7 @@ typedef unsigned long uint_ptr; #include "KX_GameObject.h" #include "KX_Camera.h" // only for their ::Type #include "KX_Light.h" // only for their ::Type +#include "KX_FontObject.h" // only for their ::Type #include "RAS_MeshObject.h" #include "KX_MeshProxy.h" #include "KX_PolyProxy.h" @@ -102,9 +103,9 @@ KX_GameObject::KX_GameObject( m_pGraphicController(NULL), m_xray(false), m_pHitObject(NULL), - m_pObstacleSimulation(NULL), - m_isDeformable(false) -#ifndef DISABLE_PYTHON + m_isDeformable(false), + m_pObstacleSimulation(NULL) +#ifdef WITH_PYTHON , m_attr_dict(NULL) #endif { @@ -156,12 +157,12 @@ KX_GameObject::~KX_GameObject() m_pObstacleSimulation->DestroyObstacleForObj(this); } -#ifndef DISABLE_PYTHON +#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); } -#endif // DISABLE_PYTHON +#endif // WITH_PYTHON } KX_GameObject* KX_GameObject::GetClientObject(KX_ClientObjectInfo* info) @@ -364,7 +365,7 @@ void KX_GameObject::ProcessReplica() obssimulation->AddObstacleForObj(this); } -#ifndef DISABLE_PYTHON +#ifdef WITH_PYTHON if(m_attr_dict) m_attr_dict= PyDict_Copy(m_attr_dict); #endif @@ -1038,7 +1039,7 @@ void KX_GameObject::NodeSetGlobalOrientation(const MT_Matrix3x3& rot) if (GetSGNode()->GetSGParent()) GetSGNode()->SetLocalOrientation(GetSGNode()->GetSGParent()->GetWorldOrientation().inverse()*rot); else - GetSGNode()->SetLocalOrientation(rot); + NodeSetLocalOrientation(rot); } void KX_GameObject::NodeSetLocalScale(const MT_Vector3& scale) @@ -1282,7 +1283,9 @@ 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; - + +#define PHYS_ERR(attr) PyErr_SetString(PyExc_AttributeError, "KX_GameObject." attr ", is missing a physics controller") + switch(subtype) { case MATHUTILS_VEC_CB_POS_LOCAL: self->NodeGetLocalPosition().getValue(bmo->data); @@ -1297,31 +1300,33 @@ 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 0; + if(!self->GetPhysicsController()) return PHYS_ERR("localInertia"), 0; 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 0; + if(!self->GetPhysicsController()) return PHYS_ERR("localLinearVelocity"), 0; self->GetLinearVelocity(true).getValue(bmo->data); break; case MATHUTILS_VEC_CB_LINVEL_GLOBAL: - if(!self->GetPhysicsController()) return 0; + if(!self->GetPhysicsController()) return PHYS_ERR("worldLinearVelocity"), 0; self->GetLinearVelocity(false).getValue(bmo->data); break; case MATHUTILS_VEC_CB_ANGVEL_LOCAL: - if(!self->GetPhysicsController()) return 0; + if(!self->GetPhysicsController()) return PHYS_ERR("localLinearVelocity"), 0; self->GetAngularVelocity(true).getValue(bmo->data); break; case MATHUTILS_VEC_CB_ANGVEL_GLOBAL: - if(!self->GetPhysicsController()) return 0; + if(!self->GetPhysicsController()) return PHYS_ERR("worldLinearVelocity"), 0; self->GetAngularVelocity(false).getValue(bmo->data); break; } +#undef PHYS_ERR + return 1; } @@ -1464,7 +1469,7 @@ void KX_GameObject_Mathutils_Callback_Init(void) #endif // USE_MATHUTILS -#ifndef DISABLE_PYTHON +#ifdef WITH_PYTHON /* ------- python stuff ---------------------------------------------------*/ PyMethodDef KX_GameObject::Methods[] = { {"applyForce", (PyCFunction) KX_GameObject::sPyApplyForce, METH_VARARGS}, @@ -1512,6 +1517,7 @@ PyMethodDef KX_GameObject::Methods[] = { PyAttributeDef KX_GameObject::Attributes[] = { KX_PYATTRIBUTE_RO_FUNCTION("name", KX_GameObject, pyattr_get_name), KX_PYATTRIBUTE_RO_FUNCTION("parent", KX_GameObject, pyattr_get_parent), + KX_PYATTRIBUTE_RO_FUNCTION("life", KX_GameObject, pyattr_get_life), KX_PYATTRIBUTE_RW_FUNCTION("mass", KX_GameObject, pyattr_get_mass, pyattr_set_mass), KX_PYATTRIBUTE_RW_FUNCTION("linVelocityMin", KX_GameObject, pyattr_get_lin_vel_min, pyattr_set_lin_vel_min), KX_PYATTRIBUTE_RW_FUNCTION("linVelocityMax", KX_GameObject, pyattr_get_lin_vel_max, pyattr_set_lin_vel_max), @@ -1590,11 +1596,11 @@ PyObject* KX_GameObject::PyReinstancePhysicsMesh(PyObject* args) ) { return NULL; } - +#ifdef USE_BULLET /* gameobj and mesh can be NULL */ if(KX_ReInstanceBulletShapeFromMesh(this, gameobj, mesh)) Py_RETURN_TRUE; - +#endif Py_RETURN_FALSE; } @@ -1803,6 +1809,19 @@ PyObject* KX_GameObject::pyattr_get_parent(void *self_v, const KX_PYATTRIBUTE_DE Py_RETURN_NONE; } +PyObject* KX_GameObject::pyattr_get_life(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_GameObject* self= static_cast<KX_GameObject*>(self_v); + + CValue *life = self->GetProperty("::timebomb"); + if (life) + // this convert the timebomb seconds to frames, hard coded 50.0 (assuming 50fps) + // value hardcoded in KX_Scene::AddReplicaObject() + return PyFloat_FromDouble(life->GetNumber() * 50.0); + else + Py_RETURN_NONE; +} + PyObject* KX_GameObject::pyattr_get_mass(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) { KX_GameObject* self= static_cast<KX_GameObject*>(self_v); @@ -3032,7 +3051,8 @@ bool ConvertPythonToGameObject(PyObject * value, KX_GameObject **object, bool py if ( PyObject_TypeCheck(value, &KX_GameObject::Type) || PyObject_TypeCheck(value, &KX_LightObject::Type) || - PyObject_TypeCheck(value, &KX_Camera::Type) ) + PyObject_TypeCheck(value, &KX_Camera::Type) || + PyObject_TypeCheck(value, &KX_FontObject::Type)) { *object = static_cast<KX_GameObject*>BGE_PROXY_REF(value); @@ -3055,4 +3075,4 @@ bool ConvertPythonToGameObject(PyObject * value, KX_GameObject **object, bool py return false; } -#endif // DISABLE_PYTHON +#endif // WITH_PYTHON |