diff options
author | Benoit Bolsee <benoit.bolsee@online.be> | 2009-04-01 01:03:15 +0400 |
---|---|---|
committer | Benoit Bolsee <benoit.bolsee@online.be> | 2009-04-01 01:03:15 +0400 |
commit | f6f47a08eba8991419853f66ade3b1ad44f5b3e4 (patch) | |
tree | 3f2ad50e807de670fb7d6ec70c187c894f27e502 /source/gameengine/Ketsji | |
parent | 1f0e5f5807f796a6c90aadf9e86916bd69c89a23 (diff) |
BGE API cleanup: DynamicActuator, ReplaceMeshActuator, TrackToActuator.
Diffstat (limited to 'source/gameengine/Ketsji')
-rw-r--r-- | source/gameengine/Ketsji/KX_PythonInit.cpp | 8 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp | 18 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_SCA_DynamicActuator.h | 11 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp | 47 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.h | 7 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_TrackToActuator.cpp | 67 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_TrackToActuator.h | 6 |
7 files changed, 134 insertions, 30 deletions
diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index bf41f3a555f..7ddfbb0d5fe 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -49,6 +49,7 @@ #include "KX_KetsjiEngine.h" #include "KX_RadarSensor.h" #include "KX_RaySensor.h" +#include "KX_SCA_DynamicActuator.h" #include "SCA_IInputDevice.h" #include "SCA_PropertySensor.h" @@ -1079,6 +1080,13 @@ PyObject* initGameLogic(KX_KetsjiEngine *engine, KX_Scene* scene) // quick hack KX_MACRO_addTypesToDict(d, KX_RAY_AXIS_NEG_Y, KX_RaySensor::KX_RAY_AXIS_NEG_X); KX_MACRO_addTypesToDict(d, KX_RAY_AXIS_NEG_Z, KX_RaySensor::KX_RAY_AXIS_NEG_Z); + /* Dynamic actuator */ + KX_MACRO_addTypesToDict(d, KX_DYN_RESTORE_DYNAMICS, KX_SCA_DynamicActuator::KX_DYN_RESTORE_DYNAMICS); + KX_MACRO_addTypesToDict(d, KX_DYN_DISABLE_DYNAMICS, KX_SCA_DynamicActuator::KX_DYN_DISABLE_DYNAMICS); + KX_MACRO_addTypesToDict(d, KX_DYN_ENABLE_RIGID_BODY, KX_SCA_DynamicActuator::KX_DYN_ENABLE_RIGID_BODY); + KX_MACRO_addTypesToDict(d, KX_DYN_DISABLE_RIGID_BODY, KX_SCA_DynamicActuator::KX_DYN_DISABLE_RIGID_BODY); + KX_MACRO_addTypesToDict(d, KX_DYN_SET_MASS, KX_SCA_DynamicActuator::KX_DYN_SET_MASS); + // Check for errors if (PyErr_Occurred()) { diff --git a/source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp b/source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp index 394bb667728..8df3af61721 100644 --- a/source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp +++ b/source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp @@ -36,6 +36,7 @@ // Please look here for revision history. #include "KX_SCA_DynamicActuator.h" +#include "blendef.h" #ifdef HAVE_CONFIG_H #include <config.h> @@ -80,21 +81,34 @@ PyParentObject KX_SCA_DynamicActuator::Parents[] = { PyMethodDef KX_SCA_DynamicActuator::Methods[] = { + // ---> deprecated KX_PYMETHODTABLE(KX_SCA_DynamicActuator, setOperation), KX_PYMETHODTABLE(KX_SCA_DynamicActuator, getOperation), {NULL,NULL} //Sentinel }; PyAttributeDef KX_SCA_DynamicActuator::Attributes[] = { + KX_PYATTRIBUTE_SHORT_RW("operation",0,4,false,KX_SCA_DynamicActuator,m_dyn_operation), + KX_PYATTRIBUTE_FLOAT_RW("mass",0.0,MAXFLOAT,KX_SCA_DynamicActuator,m_setmass), { NULL } //Sentinel }; PyObject* KX_SCA_DynamicActuator::_getattr(const char *attr) { - _getattr_up(SCA_IActuator); + PyObject* object = _getattr_self(Attributes, this, attr); + if (object != NULL) + return object; + _getattr_up(SCA_IActuator); } +int KX_SCA_DynamicActuator::_setattr(const char *attr, PyObject* value) +{ + int ret = _setattr_self(Attributes, this, attr, value); + if (ret >= 0) + return ret; + return SCA_IActuator::_setattr(attr, value); +} /* 1. setOperation */ @@ -107,6 +121,7 @@ KX_PYMETHODDEF_DOC(KX_SCA_DynamicActuator, setOperation, "\t 3 = disable rigid body\n" "Change the dynamic status of the parent object.\n") { + ShowDeprecationWarning("setOperation()", "the operation property"); int dyn_operation; if (!PyArg_ParseTuple(args, "i", &dyn_operation)) @@ -126,6 +141,7 @@ KX_PYMETHODDEF_DOC(KX_SCA_DynamicActuator, getOperation, "Returns the operation type of this actuator.\n" ) { + ShowDeprecationWarning("getOperation()", "the operation property"); return PyInt_FromLong((long)m_dyn_operation); } diff --git a/source/gameengine/Ketsji/KX_SCA_DynamicActuator.h b/source/gameengine/Ketsji/KX_SCA_DynamicActuator.h index a82cddd66a7..082fcd72035 100644 --- a/source/gameengine/Ketsji/KX_SCA_DynamicActuator.h +++ b/source/gameengine/Ketsji/KX_SCA_DynamicActuator.h @@ -64,7 +64,18 @@ class KX_SCA_DynamicActuator : public SCA_IActuator virtual bool Update(); + //Python Interface + enum DynamicOperation { + KX_DYN_RESTORE_DYNAMICS = 0, + KX_DYN_DISABLE_DYNAMICS, + KX_DYN_ENABLE_RIGID_BODY, + KX_DYN_DISABLE_RIGID_BODY, + KX_DYN_SET_MASS, + }; + + virtual PyObject* _getattr(const char *attr); + virtual int _setattr(const char *attr, PyObject *value); /* 1. setOperation */ KX_PYMETHOD_DOC(KX_SCA_DynamicActuator,setOperation); diff --git a/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp b/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp index 502990b2b27..2f971084a39 100644 --- a/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp +++ b/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp @@ -82,23 +82,62 @@ PyParentObject KX_SCA_ReplaceMeshActuator::Parents[] = { PyMethodDef KX_SCA_ReplaceMeshActuator::Methods[] = { - {"setMesh", (PyCFunction) KX_SCA_ReplaceMeshActuator::sPySetMesh, METH_O, (PY_METHODCHAR)SetMesh_doc}, - KX_PYMETHODTABLE(KX_SCA_ReplaceMeshActuator, instantReplaceMesh), + // Deprecated -----> + {"setMesh", (PyCFunction) KX_SCA_ReplaceMeshActuator::sPySetMesh, METH_O, (PY_METHODCHAR)SetMesh_doc}, KX_PYMETHODTABLE(KX_SCA_ReplaceMeshActuator, getMesh), {NULL,NULL} //Sentinel }; PyAttributeDef KX_SCA_ReplaceMeshActuator::Attributes[] = { + KX_PYATTRIBUTE_RW_FUNCTION("mesh", KX_SCA_ReplaceMeshActuator, pyattr_get_mesh, pyattr_set_mesh), { NULL } //Sentinel }; PyObject* KX_SCA_ReplaceMeshActuator::_getattr(const char *attr) { - _getattr_up(SCA_IActuator); + PyObject* object = _getattr_self(Attributes, this, attr); + if (object != NULL) + return object; + _getattr_up(SCA_IActuator); } +int KX_SCA_ReplaceMeshActuator::_setattr(const char *attr, PyObject* value) +{ + int ret = _setattr_self(Attributes, this, attr, value); + if (ret >= 0) + return ret; + return SCA_IActuator::_setattr(attr, value); +} +PyObject* KX_SCA_ReplaceMeshActuator::pyattr_get_mesh(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_SCA_ReplaceMeshActuator* actuator = static_cast<KX_SCA_ReplaceMeshActuator*>(self); + if (!actuator->m_mesh) + Py_RETURN_NONE; + return PyString_FromString(const_cast<char *>(actuator->m_mesh->GetName().ReadPtr())); +} + +int KX_SCA_ReplaceMeshActuator::pyattr_set_mesh(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) +{ + KX_SCA_ReplaceMeshActuator* actuator = static_cast<KX_SCA_ReplaceMeshActuator*>(self); + if (value == Py_None) { + actuator->m_mesh = NULL; + } else { + char* meshname = PyString_AsString(value); + if (!meshname) { + PyErr_SetString(PyExc_ValueError, "Expected the name of a mesh or None"); + return 1; + } + void* mesh = SCA_ILogicBrick::m_sCurrentLogicManager->GetMeshByName(STR_String(meshname)); + if (mesh==NULL) { + PyErr_SetString(PyExc_ValueError, "The mesh name given does not exist"); + return 1; + } + actuator->m_mesh= (class RAS_MeshObject*)mesh; + } + return 0; +} /* 1. setMesh */ const char KX_SCA_ReplaceMeshActuator::SetMesh_doc[] = @@ -108,6 +147,7 @@ const char KX_SCA_ReplaceMeshActuator::SetMesh_doc[] = PyObject* KX_SCA_ReplaceMeshActuator::PySetMesh(PyObject* self, PyObject* value) { + ShowDeprecationWarning("setMesh()", "the mesh property"); if (value == Py_None) { m_mesh = NULL; } else { @@ -133,6 +173,7 @@ KX_PYMETHODDEF_DOC(KX_SCA_ReplaceMeshActuator, getMesh, "Returns the name of the mesh to be substituted.\n" ) { + ShowDeprecationWarning("getMesh()", "the mesh property"); if (!m_mesh) Py_RETURN_NONE; diff --git a/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.h b/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.h index 0ba60650683..ba43975bd51 100644 --- a/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.h +++ b/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.h @@ -69,9 +69,14 @@ class KX_SCA_ReplaceMeshActuator : public SCA_IActuator virtual bool Update(); - virtual PyObject* _getattr(const char *attr); void InstantReplaceMesh(); + virtual PyObject* _getattr(const char *attr); + virtual int _setattr(const char *attr, PyObject* value); + + static PyObject* pyattr_get_mesh(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); + static int pyattr_set_mesh(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + /* 1. setMesh */ KX_PYMETHOD_DOC_O(KX_SCA_ReplaceMeshActuator,SetMesh); KX_PYMETHOD_DOC(KX_SCA_ReplaceMeshActuator,getMesh); diff --git a/source/gameengine/Ketsji/KX_TrackToActuator.cpp b/source/gameengine/Ketsji/KX_TrackToActuator.cpp index 8637bc92d39..e54528c7bd4 100644 --- a/source/gameengine/Ketsji/KX_TrackToActuator.cpp +++ b/source/gameengine/Ketsji/KX_TrackToActuator.cpp @@ -402,7 +402,7 @@ bool KX_TrackToActuator::Update(double curtime, bool frame) // set the models tranformation properties curobj->NodeSetLocalOrientation(mat); curobj->NodeSetLocalPosition(localpos); - curobj->UpdateTransform(); + //curobj->UpdateTransform(); } else { @@ -456,12 +456,11 @@ PyParentObject KX_TrackToActuator::Parents[] = { PyMethodDef KX_TrackToActuator::Methods[] = { + // ---> deprecated {"setTime", (PyCFunction) KX_TrackToActuator::sPySetTime, METH_VARARGS, (PY_METHODCHAR)SetTime_doc}, {"getTime", (PyCFunction) KX_TrackToActuator::sPyGetTime, METH_VARARGS, (PY_METHODCHAR)GetTime_doc}, {"setUse3D", (PyCFunction) KX_TrackToActuator::sPySetUse3D, METH_VARARGS, (PY_METHODCHAR)SetUse3D_doc}, {"getUse3D", (PyCFunction) KX_TrackToActuator::sPyGetUse3D, METH_VARARGS, (PY_METHODCHAR)GetUse3D_doc}, - - // ---> deprecated {"setObject", (PyCFunction) KX_TrackToActuator::sPySetObject, METH_O, (PY_METHODCHAR)SetObject_doc}, {"getObject", (PyCFunction) KX_TrackToActuator::sPyGetObject, METH_VARARGS, (PY_METHODCHAR)GetObject_doc}, @@ -469,39 +468,55 @@ PyMethodDef KX_TrackToActuator::Methods[] = { }; PyAttributeDef KX_TrackToActuator::Attributes[] = { + KX_PYATTRIBUTE_INT_RW("time",0,1000,true,KX_TrackToActuator,m_time), + KX_PYATTRIBUTE_BOOL_RW("user3D",KX_TrackToActuator,m_allow3D), + KX_PYATTRIBUTE_RW_FUNCTION("object", KX_TrackToActuator, pyattr_get_object, pyattr_set_object), + { NULL } //Sentinel }; - -PyObject* KX_TrackToActuator::_getattr(const char *attr) +PyObject* KX_TrackToActuator::pyattr_get_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) { - if (!strcmp(attr, "object")) { - if (!m_object) Py_RETURN_NONE; - else return m_object->AddRef(); - } - - _getattr_up(SCA_IActuator); + KX_TrackToActuator* actuator = static_cast<KX_TrackToActuator*>(self); + if (!actuator->m_object) + Py_RETURN_NONE; + else + return actuator->m_object->AddRef(); } -int KX_TrackToActuator::_setattr(const char *attr, PyObject* value) +int KX_TrackToActuator::pyattr_set_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) { - if (!strcmp(attr, "object")) { - KX_GameObject *gameobj; + KX_TrackToActuator* actuator = static_cast<KX_TrackToActuator*>(self); + KX_GameObject *gameobj; - if (!ConvertPythonToGameObject(value, &gameobj, true)) - return 1; // ConvertPythonToGameObject sets the error + if (!ConvertPythonToGameObject(value, &gameobj, true)) + return 1; // ConvertPythonToGameObject sets the error - if (m_object != NULL) - m_object->UnregisterActuator(this); + if (actuator->m_object != NULL) + actuator->m_object->UnregisterActuator(actuator); - m_object = (SCA_IObject*)gameobj; + actuator->m_object = (SCA_IObject*) gameobj; - if (m_object) - m_object->RegisterActuator(this); + if (actuator->m_object) + actuator->m_object->RegisterActuator(actuator); - return 0; - } - + return 0; +} + + +PyObject* KX_TrackToActuator::_getattr(const char *attr) +{ + PyObject* object = _getattr_self(Attributes, this, attr); + if (object != NULL) + return object; + _getattr_up(SCA_IActuator); +} + +int KX_TrackToActuator::_setattr(const char *attr, PyObject* value) +{ + int ret = _setattr_self(Attributes, this, attr, value); + if (ret >= 0) + return ret; return SCA_IActuator::_setattr(attr, value); } @@ -563,6 +578,7 @@ const char KX_TrackToActuator::SetTime_doc[] = "\tSet the time in frames with which to delay the tracking motion.\n"; PyObject* KX_TrackToActuator::PySetTime(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setTime()", "the timer property"); int timeArg; if (!PyArg_ParseTuple(args, "i", &timeArg)) @@ -584,6 +600,7 @@ const char KX_TrackToActuator::GetTime_doc[] = "\tReturn the time in frames with which the tracking motion is delayed.\n"; PyObject* KX_TrackToActuator::PyGetTime(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("getTime()", "the timer property"); return PyInt_FromLong(m_time); } @@ -595,6 +612,7 @@ const char KX_TrackToActuator::GetUse3D_doc[] = "\tReturns 1 if the motion is allowed to extend in the z-direction.\n"; PyObject* KX_TrackToActuator::PyGetUse3D(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setTime()", "the use3D property"); return PyInt_FromLong(!(m_allow3D == 0)); } @@ -608,6 +626,7 @@ const char KX_TrackToActuator::SetUse3D_doc[] = "\tset to 0 to lock the tracking motion to the x-y plane.\n"; PyObject* KX_TrackToActuator::PySetUse3D(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setTime()", "the use3D property"); int boolArg; if (!PyArg_ParseTuple(args, "i", &boolArg)) { diff --git a/source/gameengine/Ketsji/KX_TrackToActuator.h b/source/gameengine/Ketsji/KX_TrackToActuator.h index 392e55402f1..f81958dfb33 100644 --- a/source/gameengine/Ketsji/KX_TrackToActuator.h +++ b/source/gameengine/Ketsji/KX_TrackToActuator.h @@ -74,7 +74,11 @@ class KX_TrackToActuator : public SCA_IActuator /* Python part */ virtual PyObject* _getattr(const char *attr); virtual int _setattr(const char *attr, PyObject* value); - + + /* These are used to get and set m_ob */ + static PyObject* pyattr_get_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); + static int pyattr_set_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + /* 1. setObject */ KX_PYMETHOD_DOC_O(KX_TrackToActuator,SetObject); /* 2. getObject */ |