[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [19543] trunk/blender/source/gameengine: added experimental KX_GameObject attributes "sensors", "controllers" and " actuators"
Campbell Barton
ideasman42 at gmail.com
Sun Apr 5 10:48:53 CEST 2009
Revision: 19543
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=19543
Author: campbellbarton
Date: 2009-04-05 10:48:51 +0200 (Sun, 05 Apr 2009)
Log Message:
-----------
added experimental KX_GameObject attributes "sensors", "controllers" and "actuators"
Modified Paths:
--------------
trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp
trunk/blender/source/gameengine/Ketsji/KX_GameObject.h
trunk/blender/source/gameengine/PyDoc/KX_GameObject.py
Modified: trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp 2009-04-05 07:41:03 UTC (rev 19542)
+++ trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp 2009-04-05 08:48:51 UTC (rev 19543)
@@ -64,6 +64,7 @@
#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 @@
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 @@
}
+/* 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 @@
return dict;
}
+
PyObject* KX_GameObject::py_getattro(PyObject *attr)
{
PyObject* object = py_getattro_self(Attributes, this, attr);
Modified: trunk/blender/source/gameengine/Ketsji/KX_GameObject.h
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_GameObject.h 2009-04-05 07:41:03 UTC (rev 19542)
+++ trunk/blender/source/gameengine/Ketsji/KX_GameObject.h 2009-04-05 08:48:51 UTC (rev 19543)
@@ -826,8 +826,11 @@
/* 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);
static PyMappingMethods Mapping;
Modified: trunk/blender/source/gameengine/PyDoc/KX_GameObject.py
===================================================================
--- trunk/blender/source/gameengine/PyDoc/KX_GameObject.py 2009-04-05 07:41:03 UTC (rev 19542)
+++ trunk/blender/source/gameengine/PyDoc/KX_GameObject.py 2009-04-05 08:48:51 UTC (rev 19543)
@@ -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 @@
@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 meshes: list
+ @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 actuators: a list of L{SCA_IActuator}
"""
def endObject(visible):
"""
More information about the Bf-blender-cvs
mailing list