added experimental KX_GameObject attributes "sensors", "controllers" and "actuators"
authorCampbell Barton <ideasman42@gmail.com>
Sun, 5 Apr 2009 08:48:51 +0000 (08:48 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sun, 5 Apr 2009 08:48:51 +0000 (08:48 +0000)
source/gameengine/Ketsji/KX_GameObject.cpp
source/gameengine/Ketsji/KX_GameObject.h
source/gameengine/PyDoc/KX_GameObject.py

index dd38bdfb06f4cc7bc3b4b03586b12aa30d5852b5..6f4aa2bc71add3b526053085db6e712c5d1a5cd0 100644 (file)
@@ -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);
index c2b0428240d681535dad6fdabf76c41f288c2e66..bc6b60102d6b50a64870a3d91a1d0c46eeace2a7 100644 (file)
@@ -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);
index 12a395287b03787220fa25d8ed3049d89060de38..a8d37cbbe53f5788d7c3c012166ff306f245a84d 100644 (file)
@@ -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):
                """