Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2009-05-10 05:48:14 +0400
committerCampbell Barton <ideasman42@gmail.com>2009-05-10 05:48:14 +0400
commit136d4c34badc12b72f5c3541fcdaf2b1459af408 (patch)
tree2fc2952fb508234c74f9b1f1151dfea6dc242303 /source/gameengine/Ketsji/KX_GameObject.cpp
parentf155da0039104af88379bb354674e32ef2595960 (diff)
deprecate controller.getActuator(name) and controller.getSensor(name) for
controller.actuators[name] and controller.sensors[name] Made a read-only sequence type for logic brick sensors and actuators which can access single items or be used like a list or dictionary. We could use a python dictionary or CValueList but that would be slower to create. So you can do... for s in controller.sensors: print s print controller.sensors["Sensor"] print controller.sensors[0] sensors = list(controller.sensors) This sequence type keeps a reference to the proxy it came from and will raise an error on access if the proxy has been removed.
Diffstat (limited to 'source/gameengine/Ketsji/KX_GameObject.cpp')
-rw-r--r--source/gameengine/Ketsji/KX_GameObject.cpp28
1 files changed, 4 insertions, 24 deletions
diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp
index c2216fd3514..2f5b5631761 100644
--- a/source/gameengine/Ketsji/KX_GameObject.cpp
+++ b/source/gameengine/Ketsji/KX_GameObject.cpp
@@ -63,6 +63,7 @@ typedef unsigned long uint_ptr;
#include "KX_RayCast.h"
#include "KX_PythonInit.h"
#include "KX_PyMath.h"
+#include "KX_PythonSeq.h"
#include "SCA_IActuator.h"
#include "SCA_ISensor.h"
#include "SCA_IController.h"
@@ -1735,38 +1736,17 @@ 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]->GetProxy());
-
- return resultlist;
+ return KX_PythonSeq_CreatePyObject((static_cast<KX_GameObject*>(self_v))->m_proxy, KX_PYGENSEQ_OB_TYPE_SENSORS);
}
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]->GetProxy());
-
- return resultlist;
+ return KX_PythonSeq_CreatePyObject((static_cast<KX_GameObject*>(self_v))->m_proxy, KX_PYGENSEQ_OB_TYPE_CONTROLLERS);
}
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]->GetProxy());
-
- return resultlist;
+ return KX_PythonSeq_CreatePyObject((static_cast<KX_GameObject*>(self_v))->m_proxy, KX_PYGENSEQ_OB_TYPE_ACTUATORS);
}
PyObject* KX_GameObject::pyattr_get_attrDict(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)