diff options
author | Campbell Barton <ideasman42@gmail.com> | 2009-02-19 16:42:07 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2009-02-19 16:42:07 +0300 |
commit | cdec2b3d15ab0448e4df70496285ed95681e5972 (patch) | |
tree | f6d2d49a28c45d035c0c047c9488d687a75d459b /source/gameengine/GameLogic/SCA_JoystickSensor.cpp | |
parent | c597863783e1001dca599e6dcbc28048f0ef4ce1 (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_JoystickSensor.cpp')
-rw-r--r-- | source/gameengine/GameLogic/SCA_JoystickSensor.cpp | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/source/gameengine/GameLogic/SCA_JoystickSensor.cpp b/source/gameengine/GameLogic/SCA_JoystickSensor.cpp index 694bca9bac5..17a8710ed48 100644 --- a/source/gameengine/GameLogic/SCA_JoystickSensor.cpp +++ b/source/gameengine/GameLogic/SCA_JoystickSensor.cpp @@ -343,24 +343,24 @@ PyAttributeDef SCA_JoystickSensor::Attributes[] = { { NULL } //Sentinel }; -PyObject* SCA_JoystickSensor::_getattr(const STR_String& attr) { +PyObject* SCA_JoystickSensor::_getattr(const char *attr) { SCA_Joystick *joy = m_pJoystickMgr->GetJoystickDevice(m_joyindex); - if (attr == "axisPosition") { + if (!strcmp(attr, "axisPosition")) { if(joy) return Py_BuildValue("[iiii]", joy->GetAxis10(), joy->GetAxis11(), joy->GetAxis20(), joy->GetAxis21()); else return Py_BuildValue("[iiii]", 0, 0, 0, 0); } - if (attr == "numAxis") { + if (!strcmp(attr, "numAxis")) { return PyInt_FromLong( joy ? joy->GetNumberOfAxes() : 0 ); } - if (attr == "numButtons") { + if (!strcmp(attr, "numButtons")) { return PyInt_FromLong( joy ? joy->GetNumberOfButtons() : 0 ); } - if (attr == "numHats") { + if (!strcmp(attr, "numHats")) { return PyInt_FromLong( joy ? joy->GetNumberOfHats() : 0 ); } - if (attr == "connected") { + if (!strcmp(attr, "connected")) { return PyBool_FromLong( joy ? joy->Connected() : 0 ); } PyObject* object = _getattr_self(Attributes, this, attr); @@ -369,7 +369,7 @@ PyObject* SCA_JoystickSensor::_getattr(const STR_String& attr) { _getattr_up(SCA_ISensor); } -int SCA_JoystickSensor::_setattr(const STR_String& attr, PyObject *value) +int SCA_JoystickSensor::_setattr(const char *attr, PyObject *value) { int ret = _setattr_self(Attributes, this, attr, value); if (ret >= 0) |