diff options
author | Benoit Bolsee <benoit.bolsee@online.be> | 2009-03-01 00:00:27 +0300 |
---|---|---|
committer | Benoit Bolsee <benoit.bolsee@online.be> | 2009-03-01 00:00:27 +0300 |
commit | 6c409ed541d84b662d16ee34e9128cc64d27d0d8 (patch) | |
tree | a7d89dd5a0e0bcf98cb4faf436268464d326c852 /source/gameengine/Ketsji | |
parent | 541d49bc2c2ad9f26314df0fa4a6c96cfdf2852e (diff) |
BGE API cleanup: apply patch from Moguri: Near, Radar, Touch sensor updated.
Diffstat (limited to 'source/gameengine/Ketsji')
-rw-r--r-- | source/gameengine/Ketsji/KX_NearSensor.cpp | 41 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_NearSensor.h | 27 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_PythonInit.cpp | 9 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_RadarSensor.cpp | 119 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_RadarSensor.h | 22 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_TouchSensor.cpp | 9 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_TouchSensor.h | 2 |
7 files changed, 171 insertions, 58 deletions
diff --git a/source/gameengine/Ketsji/KX_NearSensor.cpp b/source/gameengine/Ketsji/KX_NearSensor.cpp index 066387abb93..993a6b3d86c 100644 --- a/source/gameengine/Ketsji/KX_NearSensor.cpp +++ b/source/gameengine/Ketsji/KX_NearSensor.cpp @@ -42,8 +42,8 @@ #endif KX_NearSensor::KX_NearSensor(SCA_EventManager* eventmgr, KX_GameObject* gameobj, - double margin, - double resetmargin, + float margin, + float resetmargin, bool bFindMaterial, const STR_String& touchedpropname, class KX_Scene* scene, @@ -276,8 +276,16 @@ bool KX_NearSensor::NewHandleCollision(void* obj1,void* obj2,const PHY_CollData } +/* ------------------------------------------------------------------------- */ +/* Python Functions */ +/* ------------------------------------------------------------------------- */ + +//No methods + +/* ------------------------------------------------------------------------- */ +/* Python Integration Hooks */ +/* ------------------------------------------------------------------------- */ -// python embedding PyTypeObject KX_NearSensor::Type = { PyObject_HEAD_INIT(&PyType_Type) 0, @@ -311,20 +319,31 @@ PyParentObject KX_NearSensor::Parents[] = { PyMethodDef KX_NearSensor::Methods[] = { - {"setProperty", (PyCFunction) KX_NearSensor::sPySetProperty, METH_O, (PY_METHODCHAR)SetProperty_doc}, - {"getProperty", (PyCFunction) KX_NearSensor::sPyGetProperty, METH_NOARGS, (PY_METHODCHAR)GetProperty_doc}, - {"getHitObject",(PyCFunction) KX_NearSensor::sPyGetHitObject, METH_NOARGS, (PY_METHODCHAR)GetHitObject_doc}, - {"getHitObjectList", (PyCFunction) KX_NearSensor::sPyGetHitObjectList, METH_NOARGS, (PY_METHODCHAR)GetHitObjectList_doc}, + //No methods {NULL,NULL} //Sentinel }; PyAttributeDef KX_NearSensor::Attributes[] = { - { NULL } //Sentinel + KX_PYATTRIBUTE_FLOAT_RW_CHECK("distance", 0, 100, KX_NearSensor, m_Margin, CheckResetDistance), + KX_PYATTRIBUTE_FLOAT_RW_CHECK("resetDistance", 0, 100, KX_NearSensor, m_ResetMargin, CheckResetDistance), + {NULL} //Sentinel }; -PyObject* -KX_NearSensor::_getattr(const char *attr) + +PyObject* KX_NearSensor::_getattr(const char *attr) { - _getattr_up(KX_TouchSensor); + PyObject* object = _getattr_self(Attributes, this, attr); + if (object != NULL) + return object; + + _getattr_up(KX_TouchSensor); } +int KX_NearSensor::_setattr(const char *attr, PyObject* value) +{ + int ret = _setattr_self(Attributes, this, attr, value); + if (ret >= 0) + return ret; + + return KX_TouchSensor::_setattr(attr, value); +} diff --git a/source/gameengine/Ketsji/KX_NearSensor.h b/source/gameengine/Ketsji/KX_NearSensor.h index 58c7cc7da91..ee03992e734 100644 --- a/source/gameengine/Ketsji/KX_NearSensor.h +++ b/source/gameengine/Ketsji/KX_NearSensor.h @@ -42,15 +42,15 @@ class KX_NearSensor : public KX_TouchSensor { Py_Header; protected: - double m_Margin; - double m_ResetMargin; + float m_Margin; + float m_ResetMargin; KX_Scene* m_scene; KX_ClientObjectInfo* m_client_info; public: KX_NearSensor(class SCA_EventManager* eventmgr, class KX_GameObject* gameobj, - double margin, - double resetmargin, + float margin, + float resetmargin, bool bFindMaterial, const STR_String& touchedpropname, class KX_Scene* scene, @@ -78,8 +78,25 @@ public: virtual bool BroadPhaseFilterCollision(void*obj1,void*obj2); virtual void RegisterSumo(KX_TouchEventManager *touchman); virtual void UnregisterSumo(KX_TouchEventManager* touchman); - + + /* --------------------------------------------------------------------- */ + /* Python interface ---------------------------------------------------- */ + /* --------------------------------------------------------------------- */ virtual PyObject* _getattr(const char *attr); + virtual int _setattr(const char *attr, PyObject* value); + + //No methods + + //This method is used to make sure the distance does not exceed the reset distance + static int CheckResetDistance(void *self, const PyAttributeDef*) + { + KX_NearSensor* sensor = reinterpret_cast<KX_NearSensor*>(self); + + if (sensor->m_Margin > sensor->m_ResetMargin) + sensor->m_ResetMargin = sensor->m_Margin; + + return 0; + } }; diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index 93f57986181..d974d67bf33 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -47,6 +47,7 @@ #include "KX_PyConstraintBinding.h" #include "KX_KetsjiEngine.h" +#include "KX_RadarSensor.h" #include "SCA_IInputDevice.h" #include "SCA_PropertySensor.h" @@ -1060,6 +1061,14 @@ PyObject* initGameLogic(KX_KetsjiEngine *engine, KX_Scene* scene) // quick hack KX_MACRO_addTypesToDict(d, KX_STATE29, (1<<28)); KX_MACRO_addTypesToDict(d, KX_STATE30, (1<<29)); + /* Radar Sensor */ + KX_MACRO_addTypesToDict(d, KX_RADAR_AXIS_POS_X, KX_RadarSensor::KX_RADAR_AXIS_POS_X); + KX_MACRO_addTypesToDict(d, KX_RADAR_AXIS_POS_Y, KX_RadarSensor::KX_RADAR_AXIS_POS_Y); + KX_MACRO_addTypesToDict(d, KX_RADAR_AXIS_POS_Z, KX_RadarSensor::KX_RADAR_AXIS_POS_Z); + KX_MACRO_addTypesToDict(d, KX_RADAR_AXIS_NEG_X, KX_RadarSensor::KX_RADAR_AXIS_NEG_Y); + KX_MACRO_addTypesToDict(d, KX_RADAR_AXIS_NEG_Y, KX_RadarSensor::KX_RADAR_AXIS_NEG_X); + KX_MACRO_addTypesToDict(d, KX_RADAR_AXIS_NEG_Z, KX_RadarSensor::KX_RADAR_AXIS_NEG_Z); + // Check for errors if (PyErr_Occurred()) { diff --git a/source/gameengine/Ketsji/KX_RadarSensor.cpp b/source/gameengine/Ketsji/KX_RadarSensor.cpp index c347faaee1a..fa8998cd81d 100644 --- a/source/gameengine/Ketsji/KX_RadarSensor.cpp +++ b/source/gameengine/Ketsji/KX_RadarSensor.cpp @@ -171,8 +171,18 @@ void KX_RadarSensor::SynchronizeTransform() { } } - m_cone_origin = trans.getOrigin(); - m_cone_target = trans(MT_Point3(0, -m_coneheight/2.0 ,0)); + + //Using a temp variable to translate MT_Point3 to float[3]. + //float[3] works better for the Python interface. + MT_Point3 temp = trans.getOrigin(); + m_cone_origin[0] = temp[0]; + m_cone_origin[1] = temp[1]; + m_cone_origin[2] = temp[2]; + + temp = trans(MT_Point3(0, -m_coneheight/2.0 ,0)); + m_cone_target[0] = temp[0]; + m_cone_target[1] = temp[1]; + m_cone_target[2] = temp[2]; if (m_physCtrl) @@ -187,10 +197,58 @@ void KX_RadarSensor::SynchronizeTransform() } /* ------------------------------------------------------------------------- */ -/* Python functions */ +/* Python Functions */ /* ------------------------------------------------------------------------- */ -/* Integration hooks ------------------------------------------------------- */ +//Deprecated -----> +/* getConeOrigin */ +const char KX_RadarSensor::GetConeOrigin_doc[] = +"getConeOrigin()\n" +"\tReturns the origin of the cone with which to test. The origin\n" +"\tis in the middle of the cone."; +PyObject* KX_RadarSensor::PyGetConeOrigin(PyObject* self) { + ShowDeprecationWarning("getConeOrigin()", "the coneOrigin property"); + + PyObject *retVal = PyList_New(3); + + PyList_SetItem(retVal, 0, PyFloat_FromDouble(m_cone_origin[0])); + PyList_SetItem(retVal, 1, PyFloat_FromDouble(m_cone_origin[1])); + PyList_SetItem(retVal, 2, PyFloat_FromDouble(m_cone_origin[2])); + + return retVal; +} + +/* getConeOrigin */ +const char KX_RadarSensor::GetConeTarget_doc[] = +"getConeTarget()\n" +"\tReturns the center of the bottom face of the cone with which to test.\n"; +PyObject* KX_RadarSensor::PyGetConeTarget(PyObject* self) { + ShowDeprecationWarning("getConeTarget()", "the coneTarget property"); + + PyObject *retVal = PyList_New(3); + + PyList_SetItem(retVal, 0, PyFloat_FromDouble(m_cone_target[0])); + PyList_SetItem(retVal, 1, PyFloat_FromDouble(m_cone_target[1])); + PyList_SetItem(retVal, 2, PyFloat_FromDouble(m_cone_target[2])); + + return retVal; +} + +/* getConeHeight */ +const char KX_RadarSensor::GetConeHeight_doc[] = +"getConeHeight()\n" +"\tReturns the height of the cone with which to test.\n"; +PyObject* KX_RadarSensor::PyGetConeHeight(PyObject* self) { + + ShowDeprecationWarning("getConeHeight()", "the distance property"); + + return PyFloat_FromDouble(m_coneheight); +} +//<----- Deprecated + +/* ------------------------------------------------------------------------- */ +/* Python Integration Hooks */ +/* ------------------------------------------------------------------------- */ PyTypeObject KX_RadarSensor::Type = { PyObject_HEAD_INIT(&PyType_Type) 0, @@ -221,46 +279,39 @@ PyParentObject KX_RadarSensor::Parents[] = { }; PyMethodDef KX_RadarSensor::Methods[] = { + //Deprecated -----> {"getConeOrigin", (PyCFunction) KX_RadarSensor::sPyGetConeOrigin, - METH_NOARGS, (PY_METHODCHAR)GetConeOrigin_doc}, + METH_VARARGS, (PY_METHODCHAR)GetConeOrigin_doc}, {"getConeTarget", (PyCFunction) KX_RadarSensor::sPyGetConeTarget, - METH_NOARGS, (PY_METHODCHAR)GetConeTarget_doc}, + METH_VARARGS, (PY_METHODCHAR)GetConeTarget_doc}, {"getConeHeight", (PyCFunction) KX_RadarSensor::sPyGetConeHeight, - METH_NOARGS, (PY_METHODCHAR)GetConeHeight_doc}, - {NULL,NULL,NULL,NULL} //Sentinel + METH_VARARGS, (PY_METHODCHAR)GetConeHeight_doc}, + //<----- + {NULL} //Sentinel }; PyAttributeDef KX_RadarSensor::Attributes[] = { - { NULL } //Sentinel + KX_PYATTRIBUTE_FLOAT_ARRAY_RO("coneOrigin", KX_RadarSensor, m_cone_origin, 3), + KX_PYATTRIBUTE_FLOAT_ARRAY_RO("coneTarget", KX_RadarSensor, m_cone_target, 3), + KX_PYATTRIBUTE_FLOAT_RW("angle", 0, 360, KX_RadarSensor, m_coneradius), + KX_PYATTRIBUTE_INT_RW("axis", 0, 5, true, KX_RadarSensor, m_axis), + {NULL} //Sentinel }; -PyObject* KX_RadarSensor::_getattr(const char *attr) { - _getattr_up(KX_TouchSensor); -} +PyObject* KX_RadarSensor::_getattr(const char *attr) +{ + PyObject* object = _getattr_self(Attributes, this, attr); + if (object != NULL) + return object; -/* getConeOrigin */ -const char KX_RadarSensor::GetConeOrigin_doc[] = -"getConeOrigin()\n" -"\tReturns the origin of the cone with which to test. The origin\n" -"\tis in the middle of the cone."; -PyObject* KX_RadarSensor::PyGetConeOrigin(PyObject* self) { - return PyObjectFrom(m_cone_origin); + _getattr_up(KX_NearSensor); } -/* getConeOrigin */ -const char KX_RadarSensor::GetConeTarget_doc[] = -"getConeTarget()\n" -"\tReturns the center of the bottom face of the cone with which to test.\n"; -PyObject* KX_RadarSensor::PyGetConeTarget(PyObject* self) { - return PyObjectFrom(m_cone_target); -} +int KX_RadarSensor::_setattr(const char *attr, PyObject* value) +{ + int ret = _setattr_self(Attributes, this, attr, value); + if (ret >= 0) + return ret; -/* getConeOrigin */ -const char KX_RadarSensor::GetConeHeight_doc[] = -"getConeHeight()\n" -"\tReturns the height of the cone with which to test.\n"; -PyObject* KX_RadarSensor::PyGetConeHeight(PyObject* self) { - return PyFloat_FromDouble(m_coneheight); + return KX_NearSensor::_setattr(attr, value); } - - diff --git a/source/gameengine/Ketsji/KX_RadarSensor.h b/source/gameengine/Ketsji/KX_RadarSensor.h index e4c6d73f22d..6dfe0c42f5d 100644 --- a/source/gameengine/Ketsji/KX_RadarSensor.h +++ b/source/gameengine/Ketsji/KX_RadarSensor.h @@ -40,23 +40,23 @@ class KX_RadarSensor : public KX_NearSensor protected: Py_Header; - MT_Scalar m_coneradius; + float m_coneradius; /** * Height of the cone. */ - MT_Scalar m_coneheight; + float m_coneheight; int m_axis; /** * The previous position of the origin of the cone. */ - MT_Point3 m_cone_origin; + float m_cone_origin[3]; /** * The previous direction of the cone (origin to bottom plane). */ - MT_Point3 m_cone_target; + float m_cone_target[3]; public: @@ -80,13 +80,23 @@ public: /* --------------------------------------------------------------------- */ /* Python interface ---------------------------------------------------- */ /* --------------------------------------------------------------------- */ - + enum RadarAxis { + KX_RADAR_AXIS_POS_X = 0, + KX_RADAR_AXIS_POS_Y, + KX_RADAR_AXIS_POS_Z, + KX_RADAR_AXIS_NEG_X, + KX_RADAR_AXIS_NEG_Y, + KX_RADAR_AXIS_NEG_Z + }; + virtual PyObject* _getattr(const char *attr); + virtual int _setattr(const char *attr, PyObject* value); + //Deprecated -----> KX_PYMETHOD_DOC_NOARGS(KX_RadarSensor,GetConeOrigin); KX_PYMETHOD_DOC_NOARGS(KX_RadarSensor,GetConeTarget); KX_PYMETHOD_DOC_NOARGS(KX_RadarSensor,GetConeHeight); - + //<----- }; #endif //__KX_RADAR_SENSOR_H diff --git a/source/gameengine/Ketsji/KX_TouchSensor.cpp b/source/gameengine/Ketsji/KX_TouchSensor.cpp index 32fcc148395..705b54edd37 100644 --- a/source/gameengine/Ketsji/KX_TouchSensor.cpp +++ b/source/gameengine/Ketsji/KX_TouchSensor.cpp @@ -269,6 +269,7 @@ PyParentObject KX_TouchSensor::Parents[] = { }; PyMethodDef KX_TouchSensor::Methods[] = { + //Deprecated -----> {"setProperty", (PyCFunction) KX_TouchSensor::sPySetProperty, METH_O, (PY_METHODCHAR)SetProperty_doc}, {"getProperty", @@ -277,12 +278,13 @@ PyMethodDef KX_TouchSensor::Methods[] = { (PyCFunction) KX_TouchSensor::sPyGetHitObject, METH_NOARGS, (PY_METHODCHAR)GetHitObject_doc}, {"getHitObjectList", (PyCFunction) KX_TouchSensor::sPyGetHitObjectList, METH_NOARGS, (PY_METHODCHAR)GetHitObjectList_doc}, + //<----- {NULL,NULL} //Sentinel }; PyAttributeDef KX_TouchSensor::Attributes[] = { - KX_PYATTRIBUTE_STRING_RW("propertyName",0,100,false,KX_TouchSensor,m_touchedpropname), - KX_PYATTRIBUTE_BOOL_RW("materialCheck",KX_TouchSensor,m_bFindMaterial), + KX_PYATTRIBUTE_STRING_RW("property",0,100,false,KX_TouchSensor,m_touchedpropname), + KX_PYATTRIBUTE_BOOL_RW("useMaterial",KX_TouchSensor,m_bFindMaterial), KX_PYATTRIBUTE_BOOL_RW("pulseCollisions",KX_TouchSensor,m_bTouchPulse), KX_PYATTRIBUTE_DUMMY("objectHit"), KX_PYATTRIBUTE_DUMMY("objectHitList"), @@ -372,6 +374,9 @@ PyObject* KX_TouchSensor::PyGetHitObjectList(PyObject* self) return m_colliders->AddRef(); } +/*getTouchMaterial and setTouchMaterial were never added to the api, +they can probably be removed with out anyone noticing*/ + /* 5. getTouchMaterial */ const char KX_TouchSensor::GetTouchMaterial_doc[] = "getTouchMaterial()\n" diff --git a/source/gameengine/Ketsji/KX_TouchSensor.h b/source/gameengine/Ketsji/KX_TouchSensor.h index c523736967b..18ce9406a9b 100644 --- a/source/gameengine/Ketsji/KX_TouchSensor.h +++ b/source/gameengine/Ketsji/KX_TouchSensor.h @@ -123,6 +123,7 @@ public: virtual PyObject* _getattr(const char *attr); virtual int _setattr(const char *attr, PyObject *value); + //Deprecated -----> /* 1. setProperty */ KX_PYMETHOD_DOC_O(KX_TouchSensor,SetProperty); /* 2. getProperty */ @@ -137,6 +138,7 @@ public: /* 6. setTouchMaterial */ KX_PYMETHOD_DOC_O(KX_TouchSensor,SetTouchMaterial); #endif + //<----- }; |