diff options
-rw-r--r-- | source/gameengine/Ketsji/KX_GameObject.cpp | 47 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_GameObject.h | 5 | ||||
-rw-r--r-- | source/gameengine/PyDoc/KX_GameObject.py | 25 |
3 files changed, 73 insertions, 4 deletions
diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index dd38bdfb06f..6f4aa2bc71a 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -64,6 +64,7 @@ typedef unsigned long uint_ptr; #include "KX_PyMath.h" #include "SCA_IActuator.h" #include "SCA_ISensor.h" +#include "SCA_IController.h" #include "PyObjectPlus.h" /* python stuff */ @@ -1044,7 +1045,14 @@ PyAttributeDef KX_GameObject::Attributes[] = { KX_PYATTRIBUTE_RW_FUNCTION("timeOffset",KX_GameObject, pyattr_get_timeOffset,pyattr_set_timeOffset), KX_PYATTRIBUTE_RW_FUNCTION("state", KX_GameObject, pyattr_get_state, pyattr_set_state), KX_PYATTRIBUTE_RO_FUNCTION("meshes", KX_GameObject, pyattr_get_meshes), + KX_PYATTRIBUTE_RO_FUNCTION("__dict__", KX_GameObject, pyattr_get_dir_dict), + + /* Experemental, dont rely on these yet */ + KX_PYATTRIBUTE_RO_FUNCTION("sensors", KX_GameObject, pyattr_get_sensors), + KX_PYATTRIBUTE_RO_FUNCTION("controllers", KX_GameObject, pyattr_get_controllers), + KX_PYATTRIBUTE_RO_FUNCTION("actuators", KX_GameObject, pyattr_get_actuators), + {NULL} //Sentinel }; @@ -1431,6 +1439,44 @@ PyObject* KX_GameObject::pyattr_get_meshes(void *self_v, const KX_PYATTRIBUTE_DE } +/* experemental! */ +PyObject* KX_GameObject::pyattr_get_sensors(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_GameObject* self= static_cast<KX_GameObject*>(self_v); + SCA_SensorList& sensors= self->GetSensors(); + PyObject* resultlist = PyList_New(sensors.size()); + + for (unsigned int index=0;index<sensors.size();index++) + PyList_SET_ITEM(resultlist, index, sensors[index]->AddRef()); + + return resultlist; +} + +PyObject* KX_GameObject::pyattr_get_controllers(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_GameObject* self= static_cast<KX_GameObject*>(self_v); + SCA_ControllerList& controllers= self->GetControllers(); + PyObject* resultlist = PyList_New(controllers.size()); + + for (unsigned int index=0;index<controllers.size();index++) + PyList_SET_ITEM(resultlist, index, controllers[index]->AddRef()); + + return resultlist; +} + +PyObject* KX_GameObject::pyattr_get_actuators(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_GameObject* self= static_cast<KX_GameObject*>(self_v); + SCA_ActuatorList& actuators= self->GetActuators(); + PyObject* resultlist = PyList_New(actuators.size()); + + for (unsigned int index=0;index<actuators.size();index++) + PyList_SET_ITEM(resultlist, index, actuators[index]->AddRef()); + + return resultlist; +} + + /* __dict__ only for the purpose of giving useful dir() results */ PyObject* KX_GameObject::pyattr_get_dir_dict(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) { @@ -1458,6 +1504,7 @@ PyObject* KX_GameObject::pyattr_get_dir_dict(void *self_v, const KX_PYATTRIBUTE_ return dict; } + PyObject* KX_GameObject::py_getattro(PyObject *attr) { PyObject* object = py_getattro_self(Attributes, this, attr); diff --git a/source/gameengine/Ketsji/KX_GameObject.h b/source/gameengine/Ketsji/KX_GameObject.h index c2b0428240d..bc6b60102d6 100644 --- a/source/gameengine/Ketsji/KX_GameObject.h +++ b/source/gameengine/Ketsji/KX_GameObject.h @@ -826,7 +826,10 @@ public: /* for dir(), python3 uses __dir__() */ static PyObject* pyattr_get_dir_dict(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); - + /* Experemental! */ + static PyObject* pyattr_get_sensors(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_controllers(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_actuators(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); /* getitem/setitem */ static Py_ssize_t Map_Len(PyObject* self); diff --git a/source/gameengine/PyDoc/KX_GameObject.py b/source/gameengine/PyDoc/KX_GameObject.py index 12a395287b0..a8d37cbbe53 100644 --- a/source/gameengine/PyDoc/KX_GameObject.py +++ b/source/gameengine/PyDoc/KX_GameObject.py @@ -1,7 +1,13 @@ # $Id$ # Documentation for game objects -class KX_GameObject: +# from SCA_IObject import * +from SCA_ISensor import * +from SCA_IController import * +from SCA_IActuator import * + + +class KX_GameObject: # (SCA_IObject) """ All game objects are derived from this class. @@ -26,9 +32,22 @@ class KX_GameObject: @type timeOffset: float @ivar state: the game object's state bitmask. @type state: int - @ivar meshes: a list of L{KX_MeshProxy} objects. + @ivar meshes: a list meshes for this object. + B{Note}: Most objects use only 1 mesh. + B{Note}: Changes to this list will not update the KX_GameObject. + @type meshes: list of L{KX_MeshProxy} + @ivar sensors: a list of L{SCA_ISensor} objects. + B{Note}: This attribute is experemental and may be removed (but probably wont be). + B{Note}: Changes to this list will not update the KX_GameObject + @type sensors: list of L{SCA_ISensor} + @ivar controllers: a list of L{SCA_ISensor} objects. + B{Note}: This attribute is experemental and may be removed (but probably wont be). + B{Note}: Changes to this list will not update the KX_GameObject + @type controllers: list of L{SCA_IController} + @ivar the actuators assigned to this object. + B{Note}: This attribute is experemental and may be removed (but probably wont be). B{Note}: Changes to this list will not update the KX_GameObject - @type meshes: list + @type actuators: a list of L{SCA_IActuator} """ def endObject(visible): """ |