diff options
Diffstat (limited to 'source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp')
-rw-r--r-- | source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp | 157 |
1 files changed, 94 insertions, 63 deletions
diff --git a/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp b/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp index 68b704f4889..c45d89a2815 100644 --- a/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp +++ b/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp @@ -38,7 +38,6 @@ #include "SCA_IScene.h" #include "KX_GameObject.h" #include "KX_IPhysicsController.h" - #include "PyObjectPlus.h" #ifdef HAVE_CONFIG_H @@ -53,9 +52,9 @@ KX_SCA_AddObjectActuator::KX_SCA_AddObjectActuator(SCA_IObject *gameobj, SCA_IObject *original, int time, SCA_IScene* scene, - const MT_Vector3& linvel, + const float *linvel, bool linv_local, - const MT_Vector3& angvel, + const float *angvel, bool angv_local, PyTypeObject* T) : @@ -63,12 +62,16 @@ KX_SCA_AddObjectActuator::KX_SCA_AddObjectActuator(SCA_IObject *gameobj, m_OriginalObject(original), m_scene(scene), - m_linear_velocity(linvel), m_localLinvFlag(linv_local), - - m_angular_velocity(angvel), m_localAngvFlag(angv_local) { + m_linear_velocity[0] = linvel[0]; + m_linear_velocity[1] = linvel[1]; + m_linear_velocity[2] = linvel[2]; + m_angular_velocity[0] = angvel[0]; + m_angular_velocity[1] = angvel[1]; + m_angular_velocity[2] = angvel[2]; + if (m_OriginalObject) m_OriginalObject->RegisterActuator(this); @@ -163,31 +166,33 @@ void KX_SCA_AddObjectActuator::Relink(GEN_Map<GEN_HashedPtr, void*> *obj_map) /* Integration hooks ------------------------------------------------------- */ PyTypeObject KX_SCA_AddObjectActuator::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "KX_SCA_AddObjectActuator", - sizeof(KX_SCA_AddObjectActuator), - 0, - PyDestructor, + sizeof(PyObjectPlus_Proxy), 0, - __getattr, - __setattr, - 0, - __repr, + py_base_dealloc, 0, 0, 0, 0, - 0 + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, + Methods }; PyParentObject KX_SCA_AddObjectActuator::Parents[] = { + &KX_SCA_AddObjectActuator::Type, &SCA_IActuator::Type, &SCA_ILogicBrick::Type, &CValue::Type, NULL }; PyMethodDef KX_SCA_AddObjectActuator::Methods[] = { + // ---> deprecated {"setTime", (PyCFunction) KX_SCA_AddObjectActuator::sPySetTime, METH_O, (PY_METHODCHAR)SetTime_doc}, {"getTime", (PyCFunction) KX_SCA_AddObjectActuator::sPyGetTime, METH_NOARGS, (PY_METHODCHAR)GetTime_doc}, {"getLinearVelocity", (PyCFunction) KX_SCA_AddObjectActuator::sPyGetLinearVelocity, METH_NOARGS, (PY_METHODCHAR)GetLinearVelocity_doc}, @@ -196,8 +201,6 @@ PyMethodDef KX_SCA_AddObjectActuator::Methods[] = { {"setAngularVelocity", (PyCFunction) KX_SCA_AddObjectActuator::sPySetAngularVelocity, METH_VARARGS, (PY_METHODCHAR)SetAngularVelocity_doc}, {"getLastCreatedObject", (PyCFunction) KX_SCA_AddObjectActuator::sPyGetLastCreatedObject, METH_NOARGS,"getLastCreatedObject() : get the object handle to the last created object\n"}, {"instantAddObject", (PyCFunction) KX_SCA_AddObjectActuator::sPyInstantAddObject, METH_NOARGS,"instantAddObject() : immediately add object without delay\n"}, - - // ---> deprecated {"setObject", (PyCFunction) KX_SCA_AddObjectActuator::sPySetObject, METH_O, (PY_METHODCHAR)SetObject_doc}, {"getObject", (PyCFunction) KX_SCA_AddObjectActuator::sPyGetObject, METH_VARARGS, (PY_METHODCHAR)GetObject_doc}, @@ -205,42 +208,60 @@ PyMethodDef KX_SCA_AddObjectActuator::Methods[] = { }; PyAttributeDef KX_SCA_AddObjectActuator::Attributes[] = { + KX_PYATTRIBUTE_RW_FUNCTION("object",KX_SCA_AddObjectActuator,pyattr_get_object,pyattr_set_object), + KX_PYATTRIBUTE_RO_FUNCTION("objectLastCreated",KX_SCA_AddObjectActuator,pyattr_get_objectLastCreated), + KX_PYATTRIBUTE_INT_RW("time",0,2000,true,KX_SCA_AddObjectActuator,m_timeProp), + KX_PYATTRIBUTE_FLOAT_ARRAY_RW("linearVelocity",-FLT_MAX,FLT_MAX,KX_SCA_AddObjectActuator,m_linear_velocity,3), + KX_PYATTRIBUTE_FLOAT_ARRAY_RW("angularVelocity",-FLT_MAX,FLT_MAX,KX_SCA_AddObjectActuator,m_angular_velocity,3), { NULL } //Sentinel }; -PyObject* KX_SCA_AddObjectActuator::_getattr(const char *attr) +PyObject* KX_SCA_AddObjectActuator::pyattr_get_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) { - if (!strcmp(attr, "object")) { - if (!m_OriginalObject) Py_RETURN_NONE; - else return m_OriginalObject->AddRef(); - } else if (!strcmp(attr, "objectLastCreated")) { - if (!m_OriginalObject) Py_RETURN_NONE; - else return m_lastCreatedObject->AddRef(); - } - - _getattr_up(SCA_IActuator); + KX_SCA_AddObjectActuator* actuator = static_cast<KX_SCA_AddObjectActuator*>(self); + if (!actuator->m_OriginalObject) + Py_RETURN_NONE; + else + return actuator->m_OriginalObject->GetProxy(); } -int KX_SCA_AddObjectActuator::_setattr(const char *attr, PyObject* value) { - - if (!strcmp(attr, "object")) { - KX_GameObject *gameobj; +int KX_SCA_AddObjectActuator::pyattr_set_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) +{ + KX_SCA_AddObjectActuator* actuator = static_cast<KX_SCA_AddObjectActuator*>(self); + KX_GameObject *gameobj; - if (!ConvertPythonToGameObject(value, &gameobj, true)) - return 1; // ConvertPythonToGameObject sets the error + if (!ConvertPythonToGameObject(value, &gameobj, true, "actuator.object = value: KX_SCA_AddObjectActuator")) + return 1; // ConvertPythonToGameObject sets the error - if (m_OriginalObject != NULL) - m_OriginalObject->UnregisterActuator(this); + if (actuator->m_OriginalObject != NULL) + actuator->m_OriginalObject->UnregisterActuator(actuator); - m_OriginalObject = (SCA_IObject*)gameobj; + actuator->m_OriginalObject = (SCA_IObject*)gameobj; - if (m_OriginalObject) - m_OriginalObject->RegisterActuator(this); + if (actuator->m_OriginalObject) + actuator->m_OriginalObject->RegisterActuator(actuator); - return 0; - } - - return SCA_IActuator::_setattr(attr, value); + return 0; +} + +PyObject* KX_SCA_AddObjectActuator::pyattr_get_objectLastCreated(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_SCA_AddObjectActuator* actuator = static_cast<KX_SCA_AddObjectActuator*>(self); + if (!actuator->m_lastCreatedObject) + Py_RETURN_NONE; + else + return actuator->m_lastCreatedObject->GetProxy(); +} + + +PyObject* KX_SCA_AddObjectActuator::py_getattro(PyObject *attr) +{ + py_getattro_up(SCA_IActuator); +} + +int KX_SCA_AddObjectActuator::py_setattro(PyObject *attr, PyObject* value) +{ + py_setattro_up(SCA_IActuator); } /* 1. setObject */ @@ -249,13 +270,13 @@ const char KX_SCA_AddObjectActuator::SetObject_doc[] = "\t- object: KX_GameObject, string or None\n" "\tSets the object that will be added. There has to be an object\n" "\tof this name. If not, this function does nothing.\n"; -PyObject* KX_SCA_AddObjectActuator::PySetObject(PyObject* self, PyObject* value) +PyObject* KX_SCA_AddObjectActuator::PySetObject(PyObject* value) { KX_GameObject *gameobj; ShowDeprecationWarning("setObject()", "the object property"); - if (!ConvertPythonToGameObject(value, &gameobj, true)) + if (!ConvertPythonToGameObject(value, &gameobj, true, "actuator.setObject(value): KX_SCA_AddObjectActuator")) return NULL; // ConvertPythonToGameObject sets the error if (m_OriginalObject != NULL) @@ -278,8 +299,9 @@ const char KX_SCA_AddObjectActuator::SetTime_doc[] = "\tIf the duration is negative, it is set to 0.\n"; -PyObject* KX_SCA_AddObjectActuator::PySetTime(PyObject* self, PyObject* value) +PyObject* KX_SCA_AddObjectActuator::PySetTime(PyObject* value) { + ShowDeprecationWarning("setTime()", "the time property"); int deltatime = PyInt_AsLong(value); if (deltatime==-1 && PyErr_Occurred()) { PyErr_SetString(PyExc_TypeError, "expected an int"); @@ -296,12 +318,13 @@ PyObject* KX_SCA_AddObjectActuator::PySetTime(PyObject* self, PyObject* value) /* 3. getTime */ const char KX_SCA_AddObjectActuator::GetTime_doc[] = -"GetTime()\n" +"getTime()\n" "\tReturns the lifetime of the object that will be added.\n"; -PyObject* KX_SCA_AddObjectActuator::PyGetTime(PyObject* self) +PyObject* KX_SCA_AddObjectActuator::PyGetTime() { + ShowDeprecationWarning("getTime()", "the time property"); return PyInt_FromLong(m_timeProp); } @@ -311,13 +334,13 @@ const char KX_SCA_AddObjectActuator::GetObject_doc[] = "getObject(name_only = 1)\n" "name_only - optional arg, when true will return the KX_GameObject rather then its name\n" "\tReturns the name of the object that will be added.\n"; -PyObject* KX_SCA_AddObjectActuator::PyGetObject(PyObject* self, PyObject* args) +PyObject* KX_SCA_AddObjectActuator::PyGetObject(PyObject* args) { int ret_name_only = 1; ShowDeprecationWarning("getObject()", "the object property"); - if (!PyArg_ParseTuple(args, "|i", &ret_name_only)) + if (!PyArg_ParseTuple(args, "|i:getObject", &ret_name_only)) return NULL; if (!m_OriginalObject) @@ -326,7 +349,7 @@ PyObject* KX_SCA_AddObjectActuator::PyGetObject(PyObject* self, PyObject* args) if (ret_name_only) return PyString_FromString(m_OriginalObject->GetName()); else - return m_OriginalObject->AddRef(); + return m_OriginalObject->GetProxy(); } @@ -337,8 +360,9 @@ const char KX_SCA_AddObjectActuator::GetLinearVelocity_doc[] = "\tReturns the linear velocity that will be assigned to \n" "\tthe created object.\n"; -PyObject* KX_SCA_AddObjectActuator::PyGetLinearVelocity(PyObject* self) +PyObject* KX_SCA_AddObjectActuator::PyGetLinearVelocity() { + ShowDeprecationWarning("getLinearVelocity()", "the linearVelocity property"); PyObject *retVal = PyList_New(3); PyList_SET_ITEM(retVal, 0, PyFloat_FromDouble(m_linear_velocity[0])); @@ -359,14 +383,17 @@ const char KX_SCA_AddObjectActuator::SetLinearVelocity_doc[] = "\t- local: bool\n" "\tAssign this velocity to the created object. \n"; -PyObject* KX_SCA_AddObjectActuator::PySetLinearVelocity(PyObject* self, PyObject* args) +PyObject* KX_SCA_AddObjectActuator::PySetLinearVelocity(PyObject* args) { + ShowDeprecationWarning("setLinearVelocity()", "the linearVelocity property"); float vecArg[3]; - if (!PyArg_ParseTuple(args, "fff", &vecArg[0], &vecArg[1], &vecArg[2])) + if (!PyArg_ParseTuple(args, "fff:setLinearVelocity", &vecArg[0], &vecArg[1], &vecArg[2])) return NULL; - m_linear_velocity.setValue(vecArg); + m_linear_velocity[0] = vecArg[0]; + m_linear_velocity[1] = vecArg[1]; + m_linear_velocity[2] = vecArg[2]; Py_RETURN_NONE; } @@ -376,8 +403,9 @@ const char KX_SCA_AddObjectActuator::GetAngularVelocity_doc[] = "\tReturns the angular velocity that will be assigned to \n" "\tthe created object.\n"; -PyObject* KX_SCA_AddObjectActuator::PyGetAngularVelocity(PyObject* self) +PyObject* KX_SCA_AddObjectActuator::PyGetAngularVelocity() { + ShowDeprecationWarning("getAngularVelocity()", "the angularVelocity property"); PyObject *retVal = PyList_New(3); PyList_SET_ITEM(retVal, 0, PyFloat_FromDouble(m_angular_velocity[0])); @@ -398,14 +426,17 @@ const char KX_SCA_AddObjectActuator::SetAngularVelocity_doc[] = "\t- local: bool\n" "\tAssign this angular velocity to the created object. \n"; -PyObject* KX_SCA_AddObjectActuator::PySetAngularVelocity(PyObject* self, PyObject* args) +PyObject* KX_SCA_AddObjectActuator::PySetAngularVelocity(PyObject* args) { + ShowDeprecationWarning("setAngularVelocity()", "the angularVelocity property"); float vecArg[3]; - if (!PyArg_ParseTuple(args, "fff", &vecArg[0], &vecArg[1], &vecArg[2])) + if (!PyArg_ParseTuple(args, "fff:setAngularVelocity", &vecArg[0], &vecArg[1], &vecArg[2])) return NULL; - m_angular_velocity.setValue(vecArg); + m_angular_velocity[0] = vecArg[0]; + m_angular_velocity[1] = vecArg[1]; + m_angular_velocity[2] = vecArg[2]; Py_RETURN_NONE; } @@ -417,7 +448,7 @@ void KX_SCA_AddObjectActuator::InstantAddObject() // Now it needs to be added to the current scene. SCA_IObject* replica = m_scene->AddReplicaObject(m_OriginalObject,GetParent(),m_timeProp ); KX_GameObject * game_obj = static_cast<KX_GameObject *>(replica); - game_obj->setLinearVelocity(m_linear_velocity,m_localLinvFlag); + game_obj->setLinearVelocity(m_linear_velocity ,m_localLinvFlag); game_obj->setAngularVelocity(m_angular_velocity,m_localAngvFlag); game_obj->ResolveCombinedVelocities(m_linear_velocity, m_angular_velocity, m_localLinvFlag, m_localAngvFlag); @@ -436,7 +467,7 @@ void KX_SCA_AddObjectActuator::InstantAddObject() } } -PyObject* KX_SCA_AddObjectActuator::PyInstantAddObject(PyObject* self) +PyObject* KX_SCA_AddObjectActuator::PyInstantAddObject() { InstantAddObject(); @@ -451,16 +482,16 @@ const char KX_SCA_AddObjectActuator::GetLastCreatedObject_doc[] = "\tReturn the last created object. \n"; -PyObject* KX_SCA_AddObjectActuator::PyGetLastCreatedObject(PyObject* self) +PyObject* KX_SCA_AddObjectActuator::PyGetLastCreatedObject() { + ShowDeprecationWarning("getLastCreatedObject()", "the objectLastCreated property"); SCA_IObject* result = this->GetLastCreatedObject(); // if result->GetSGNode() is NULL // it means the object has ended, The BGE python api crashes in many places if the object is returned. if (result && (static_cast<KX_GameObject *>(result))->GetSGNode()) { - result->AddRef(); - return result; + return result->GetProxy(); } // don't return NULL to python anymore, it gives trouble in the scripts Py_RETURN_NONE; |