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.
This commit is contained in:
2009-02-19 13:42:07 +00:00
parent c597863783
commit cdec2b3d15
127 changed files with 392 additions and 403 deletions

View File

@@ -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)