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-02-19 16:42:07 +0300
committerCampbell Barton <ideasman42@gmail.com>2009-02-19 16:42:07 +0300
commitcdec2b3d15ab0448e4df70496285ed95681e5972 (patch)
treef6d2d49a28c45d035c0c047c9488d687a75d459b /source/gameengine/GameLogic/SCA_PythonController.cpp
parentc597863783e1001dca599e6dcbc28048f0ef4ce1 (diff)
BGE Python API
Use 'const char *' rather then the C++ 'STR_String' type for the attribute identifier of python attributes. Each attribute and method access from python was allocating and freeing the string. A simple test with getting an attribute a loop shows this speeds up attribute lookups a bit over 2x.
Diffstat (limited to 'source/gameengine/GameLogic/SCA_PythonController.cpp')
-rw-r--r--source/gameengine/GameLogic/SCA_PythonController.cpp35
1 files changed, 24 insertions, 11 deletions
diff --git a/source/gameengine/GameLogic/SCA_PythonController.cpp b/source/gameengine/GameLogic/SCA_PythonController.cpp
index e879481a444..2fff21f22fb 100644
--- a/source/gameengine/GameLogic/SCA_PythonController.cpp
+++ b/source/gameengine/GameLogic/SCA_PythonController.cpp
@@ -233,8 +233,8 @@ PyMethodDef SCA_PythonController::Methods[] = {
{"getActuator", (PyCFunction) SCA_PythonController::sPyGetActuator, METH_O, (PY_METHODCHAR)SCA_PythonController::GetActuator_doc},
{"getSensors", (PyCFunction) SCA_PythonController::sPyGetSensors, METH_NOARGS, (PY_METHODCHAR)SCA_PythonController::GetSensors_doc},
{"getSensor", (PyCFunction) SCA_PythonController::sPyGetSensor, METH_O, (PY_METHODCHAR)SCA_PythonController::GetSensor_doc},
- {"setScript", (PyCFunction) SCA_PythonController::sPySetScript, METH_O},
//Deprecated functions ------>
+ {"setScript", (PyCFunction) SCA_PythonController::sPySetScript, METH_O},
{"getScript", (PyCFunction) SCA_PythonController::sPyGetScript, METH_NOARGS},
{"getState", (PyCFunction) SCA_PythonController::sPyGetState, METH_NOARGS},
//<----- Deprecated
@@ -329,25 +329,35 @@ void SCA_PythonController::Trigger(SCA_LogicManager* logicmgr)
-PyObject* SCA_PythonController::_getattr(const STR_String& attr)
+PyObject* SCA_PythonController::_getattr(const char *attr)
{
- if (attr == "script") {
- return PyString_FromString(m_scriptText);
- }
- if (attr == "state") {
+ if (!strcmp(attr,"state")) {
return PyInt_FromLong(m_statemask);
}
+ if (!strcmp(attr,"script")) {
+ return PyString_FromString(m_scriptText);
+ }
_getattr_up(SCA_IController);
}
-int SCA_PythonController::_setattr(const STR_String& attr, PyObject *value)
+int SCA_PythonController::_setattr(const char *attr, PyObject *value)
{
- if (attr == "script") {
- PyErr_SetString(PyExc_AttributeError, "script is read only, use setScript() to update the script");
+ if (!strcmp(attr,"state")) {
+ PyErr_SetString(PyExc_AttributeError, "state is read only");
return 1;
}
- if (attr == "state") {
- PyErr_SetString(PyExc_AttributeError, "state is read only");
+ if (!strcmp(attr,"script")) {
+ char *scriptArg = PyString_AsString(value);
+
+ if (scriptArg==NULL) {
+ PyErr_SetString(PyExc_TypeError, "expected a string (script name)");
+ return -1;
+ }
+
+ /* set scripttext sets m_bModified to true,
+ so next time the script is needed, a reparse into byte code is done */
+ this->SetScriptText(scriptArg);
+
return 1;
}
return SCA_IController::_setattr(attr, value);
@@ -448,6 +458,9 @@ PyObject* SCA_PythonController::PyGetScript(PyObject* self)
PyObject* SCA_PythonController::PySetScript(PyObject* self, PyObject* value)
{
char *scriptArg = PyString_AsString(value);
+
+ ShowDeprecationWarning("setScript()", "the script property");
+
if (scriptArg==NULL) {
PyErr_SetString(PyExc_TypeError, "expected a string (script name)");
return NULL;