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

@@ -165,22 +165,22 @@ PyAttributeDef SCA_RandomSensor::Attributes[] = {
{NULL} //Sentinel
};
PyObject* SCA_RandomSensor::_getattr(const STR_String& attr) {
PyObject* SCA_RandomSensor::_getattr(const char *attr) {
PyObject* object = _getattr_self(Attributes, this, attr);
if (object != NULL)
return object;
if (attr == "seed") {
if (!strcmp(attr,"seed")) {
return PyInt_FromLong(m_basegenerator->GetSeed());
}
_getattr_up(SCA_ISensor);
}
int SCA_RandomSensor::_setattr(const STR_String& attr, PyObject *value)
int SCA_RandomSensor::_setattr(const char *attr, PyObject *value)
{
int ret = _setattr_self(Attributes, this, attr, value);
if (ret >= 0)
return ret;
if (attr == "seed") {
if (!strcmp(attr,"seed")) {
if (PyInt_Check(value)) {
int ival = PyInt_AsLong(value);
m_basegenerator->SetSeed(ival);