diff options
author | Campbell Barton <ideasman42@gmail.com> | 2009-04-03 18:51:06 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2009-04-03 18:51:06 +0400 |
commit | fd2b1156783d52dbb7c93c53fe008d9e14cbffdd (patch) | |
tree | 3578443cee384e883450b35480244a0c46aaf34b /source/gameengine/GameLogic | |
parent | e30cb79aaa8d9a25b66c57aa08fb79bf591b6be4 (diff) |
Python BGE API
- Initialize python types with PyType_Ready, which adds methods to the type dictionary.
- use Pythons get/setattro (uses a python string for the attribute rather then char*). Using basic C strings seems nice but internally python converts them to python strings and discards them for most functions that accept char arrays.
- Method lookups use the PyTypes dictionary (should be faster then Py_FindMethod)
- Renamed __getattr -> py_base_getattro, _getattr -> py_getattro, __repr -> py_base_repr, py_delattro, py_getattro_self etc.
From here is possible to put all the parent classes methods into each python types dictionary to avoid nested lookups (api has 4 levels of lookups in some places), tested this but its not ready yet.
Simple tests for getting a method within a loop show this to be between 0.5 and 3.2x faster then using Py_FindMethod()
Diffstat (limited to 'source/gameengine/GameLogic')
43 files changed, 332 insertions, 257 deletions
diff --git a/source/gameengine/GameLogic/SCA_2DFilterActuator.cpp b/source/gameengine/GameLogic/SCA_2DFilterActuator.cpp index 0b410728512..9d4dc1f33d6 100644 --- a/source/gameengine/GameLogic/SCA_2DFilterActuator.cpp +++ b/source/gameengine/GameLogic/SCA_2DFilterActuator.cpp @@ -80,18 +80,21 @@ bool SCA_2DFilterActuator::Update() PyTypeObject SCA_2DFilterActuator::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "SCA_2DFilterActuator", sizeof(SCA_2DFilterActuator), 0, - PyDestructor, - 0, - __getattr, - __setattr, - 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + PyDestructor, + 0, + 0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -114,6 +117,6 @@ PyAttributeDef SCA_2DFilterActuator::Attributes[] = { { NULL } //Sentinel }; -PyObject* SCA_2DFilterActuator::_getattr(const char *attr) { - _getattr_up(SCA_IActuator); +PyObject* SCA_2DFilterActuator::py_getattro(PyObject *attr) { + py_getattro_up(SCA_IActuator); } diff --git a/source/gameengine/GameLogic/SCA_2DFilterActuator.h b/source/gameengine/GameLogic/SCA_2DFilterActuator.h index 9da0500afff..f69c680b774 100644 --- a/source/gameengine/GameLogic/SCA_2DFilterActuator.h +++ b/source/gameengine/GameLogic/SCA_2DFilterActuator.h @@ -38,7 +38,7 @@ public: virtual bool Update(); virtual CValue* GetReplica(); - virtual PyObject* _getattr(const char *attr); + virtual PyObject* py_getattro(PyObject *attr); }; #endif diff --git a/source/gameengine/GameLogic/SCA_ANDController.cpp b/source/gameengine/GameLogic/SCA_ANDController.cpp index de67037b64a..cb62e2b5a1d 100644 --- a/source/gameengine/GameLogic/SCA_ANDController.cpp +++ b/source/gameengine/GameLogic/SCA_ANDController.cpp @@ -107,18 +107,21 @@ CValue* SCA_ANDController::GetReplica() /* Integration hooks ------------------------------------------------------- */ PyTypeObject SCA_ANDController::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "SCA_ANDController", sizeof(SCA_ANDController), 0, PyDestructor, 0, - __getattr, - __setattr, 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -138,8 +141,8 @@ PyAttributeDef SCA_ANDController::Attributes[] = { { NULL } //Sentinel }; -PyObject* SCA_ANDController::_getattr(const char *attr) { - _getattr_up(SCA_IController); +PyObject* SCA_ANDController::py_getattro(PyObject *attr) { + py_getattro_up(SCA_IController); } /* eof */ diff --git a/source/gameengine/GameLogic/SCA_ANDController.h b/source/gameengine/GameLogic/SCA_ANDController.h index eba7e1b545a..fdb93d0fc42 100644 --- a/source/gameengine/GameLogic/SCA_ANDController.h +++ b/source/gameengine/GameLogic/SCA_ANDController.h @@ -48,7 +48,7 @@ public: /* Python interface ---------------------------------------------------- */ /* --------------------------------------------------------------------- */ - virtual PyObject* _getattr(const char *attr); + virtual PyObject* py_getattro(PyObject *attr); }; diff --git a/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp b/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp index d5c3e1960fe..ed7aa66d04b 100644 --- a/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp +++ b/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp @@ -122,18 +122,21 @@ void SCA_ActuatorSensor::Update() /* Integration hooks ------------------------------------------------------- */ PyTypeObject SCA_ActuatorSensor::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "SCA_ActuatorSensor", sizeof(SCA_ActuatorSensor), 0, PyDestructor, 0, - __getattr, - __setattr, 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -158,11 +161,11 @@ PyAttributeDef SCA_ActuatorSensor::Attributes[] = { { NULL } //Sentinel }; -PyObject* SCA_ActuatorSensor::_getattr(const char *attr) { - PyObject* object = _getattr_self(Attributes, this, attr); +PyObject* SCA_ActuatorSensor::py_getattro(PyObject *attr) { + PyObject* object = py_getattro_self(Attributes, this, attr); if (object != NULL) return object; - _getattr_up(SCA_ISensor); /* implicit return! */ + py_getattro_up(SCA_ISensor); /* implicit return! */ } int SCA_ActuatorSensor::CheckActuator(void *self, const PyAttributeDef*) @@ -177,11 +180,11 @@ int SCA_ActuatorSensor::CheckActuator(void *self, const PyAttributeDef*) return 1; } -int SCA_ActuatorSensor::_setattr(const char *attr, PyObject *value) { - int ret = _setattr_self(Attributes, this, attr, value); +int SCA_ActuatorSensor::py_setattro(PyObject *attr, PyObject *value) { + int ret = py_setattro_self(Attributes, this, attr, value); if (ret >= 0) return ret; - return SCA_ISensor::_setattr(attr, value); + return SCA_ISensor::py_setattro(attr, value); } /* 3. getActuator */ diff --git a/source/gameengine/GameLogic/SCA_ActuatorSensor.h b/source/gameengine/GameLogic/SCA_ActuatorSensor.h index 75ee08f42d6..9bc873e4ee1 100644 --- a/source/gameengine/GameLogic/SCA_ActuatorSensor.h +++ b/source/gameengine/GameLogic/SCA_ActuatorSensor.h @@ -61,8 +61,8 @@ public: /* Python interface ---------------------------------------------------- */ /* --------------------------------------------------------------------- */ - virtual PyObject* _getattr(const char *attr); - virtual int _setattr(const char *attr, PyObject *value); + virtual PyObject* py_getattro(PyObject *attr); + virtual int py_setattro(PyObject *attr, PyObject *value); /* 3. setProperty */ KX_PYMETHOD_DOC(SCA_ActuatorSensor,SetActuator); diff --git a/source/gameengine/GameLogic/SCA_AlwaysSensor.cpp b/source/gameengine/GameLogic/SCA_AlwaysSensor.cpp index e2125b8b08d..a7b0e5a14d2 100644 --- a/source/gameengine/GameLogic/SCA_AlwaysSensor.cpp +++ b/source/gameengine/GameLogic/SCA_AlwaysSensor.cpp @@ -105,18 +105,21 @@ bool SCA_AlwaysSensor::Evaluate(CValue* event) /* Integration hooks ------------------------------------------------------- */ PyTypeObject SCA_AlwaysSensor::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "SCA_AlwaysSensor", sizeof(SCA_AlwaysSensor), 0, PyDestructor, 0, - __getattr, - __setattr, - 0, //&MyPyCompare, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -136,8 +139,8 @@ PyAttributeDef SCA_AlwaysSensor::Attributes[] = { { NULL } //Sentinel }; -PyObject* SCA_AlwaysSensor::_getattr(const char *attr) { - _getattr_up(SCA_ISensor); +PyObject* SCA_AlwaysSensor::py_getattro(PyObject *attr) { + py_getattro_up(SCA_ISensor); } /* eof */ diff --git a/source/gameengine/GameLogic/SCA_AlwaysSensor.h b/source/gameengine/GameLogic/SCA_AlwaysSensor.h index ebe6ba80208..87949babf59 100644 --- a/source/gameengine/GameLogic/SCA_AlwaysSensor.h +++ b/source/gameengine/GameLogic/SCA_AlwaysSensor.h @@ -52,7 +52,7 @@ public: /* Python interface ---------------------------------------------------- */ /* --------------------------------------------------------------------- */ - virtual PyObject* _getattr(const char *attr); + virtual PyObject* py_getattro(PyObject *attr); }; diff --git a/source/gameengine/GameLogic/SCA_DelaySensor.cpp b/source/gameengine/GameLogic/SCA_DelaySensor.cpp index 733057017a7..5082caacfd5 100644 --- a/source/gameengine/GameLogic/SCA_DelaySensor.cpp +++ b/source/gameengine/GameLogic/SCA_DelaySensor.cpp @@ -131,18 +131,21 @@ bool SCA_DelaySensor::Evaluate(CValue* event) /* Integration hooks ------------------------------------------------------- */ PyTypeObject SCA_DelaySensor::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "SCA_DelaySensor", sizeof(SCA_DelaySensor), 0, PyDestructor, 0, - __getattr, - __setattr, - 0, //&MyPyCompare, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -175,18 +178,18 @@ PyAttributeDef SCA_DelaySensor::Attributes[] = { { NULL } //Sentinel }; -PyObject* SCA_DelaySensor::_getattr(const char *attr) { - PyObject* object = _getattr_self(Attributes, this, attr); +PyObject* SCA_DelaySensor::py_getattro(PyObject *attr) { + PyObject* object = py_getattro_self(Attributes, this, attr); if (object != NULL) return object; - _getattr_up(SCA_ISensor); + py_getattro_up(SCA_ISensor); } -int SCA_DelaySensor::_setattr(const char *attr, PyObject *value) { - int ret = _setattr_self(Attributes, this, attr, value); +int SCA_DelaySensor::py_setattro(PyObject *attr, PyObject *value) { + int ret = py_setattro_self(Attributes, this, attr, value); if (ret >= 0) return ret; - return SCA_ISensor::_setattr(attr, value); + return SCA_ISensor::py_setattro(attr, value); } diff --git a/source/gameengine/GameLogic/SCA_DelaySensor.h b/source/gameengine/GameLogic/SCA_DelaySensor.h index 491eee61da8..f9e3d619198 100644 --- a/source/gameengine/GameLogic/SCA_DelaySensor.h +++ b/source/gameengine/GameLogic/SCA_DelaySensor.h @@ -60,8 +60,8 @@ public: /* Python interface ---------------------------------------------------- */ /* --------------------------------------------------------------------- */ - virtual PyObject* _getattr(const char *attr); - virtual int _setattr(const char *attr, PyObject *value); + virtual PyObject* py_getattro(PyObject *attr); + virtual int py_setattro(PyObject *attr, PyObject *value); /* setProperty */ KX_PYMETHOD_DOC(SCA_DelaySensor,SetDelay); diff --git a/source/gameengine/GameLogic/SCA_ExpressionController.h b/source/gameengine/GameLogic/SCA_ExpressionController.h index 79c26eea1e7..2936742be19 100644 --- a/source/gameengine/GameLogic/SCA_ExpressionController.h +++ b/source/gameengine/GameLogic/SCA_ExpressionController.h @@ -59,7 +59,7 @@ public: /* Python interface ---------------------------------------------------- */ /* --------------------------------------------------------------------- */ -// virtual PyObject* _getattr(const char *attr); +// virtual PyObject* py_getattro(PyObject *attr); }; diff --git a/source/gameengine/GameLogic/SCA_ILogicBrick.cpp b/source/gameengine/GameLogic/SCA_ILogicBrick.cpp index 3cefe638726..45ebd874ea5 100644 --- a/source/gameengine/GameLogic/SCA_ILogicBrick.cpp +++ b/source/gameengine/GameLogic/SCA_ILogicBrick.cpp @@ -217,18 +217,21 @@ CValue* SCA_ILogicBrick::GetEvent() /* python stuff */ PyTypeObject SCA_ILogicBrick::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "SCA_ILogicBrick", sizeof(SCA_ILogicBrick), 0, PyDestructor, 0, - __getattr, - __setattr, - 0, //&MyPyCompare, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -275,20 +278,20 @@ int SCA_ILogicBrick::CheckProperty(void *self, const PyAttributeDef *attrdef) } PyObject* -SCA_ILogicBrick::_getattr(const char *attr) +SCA_ILogicBrick::py_getattro(PyObject *attr) { - PyObject* object = _getattr_self(Attributes, this, attr); + PyObject* object = py_getattro_self(Attributes, this, attr); if (object != NULL) return object; - _getattr_up(CValue); + py_getattro_up(CValue); } -int SCA_ILogicBrick::_setattr(const char *attr, PyObject *value) +int SCA_ILogicBrick::py_setattro(PyObject *attr, PyObject *value) { - int ret = _setattr_self(Attributes, this, attr, value); + int ret = py_setattro_self(Attributes, this, attr, value); if (ret >= 0) return ret; - return CValue::_setattr(attr, value); + return CValue::py_setattro(attr, value); } diff --git a/source/gameengine/GameLogic/SCA_ILogicBrick.h b/source/gameengine/GameLogic/SCA_ILogicBrick.h index 70d49941613..c098f9dfd8a 100644 --- a/source/gameengine/GameLogic/SCA_ILogicBrick.h +++ b/source/gameengine/GameLogic/SCA_ILogicBrick.h @@ -79,8 +79,8 @@ public: virtual bool LessComparedTo(SCA_ILogicBrick* other); - virtual PyObject* _getattr(const char *attr); - virtual int _setattr(const char *attr, PyObject *value); + virtual PyObject* py_getattro(PyObject *attr); + virtual int py_setattro(PyObject *attr, PyObject *value); static class SCA_LogicManager* m_sCurrentLogicManager; diff --git a/source/gameengine/GameLogic/SCA_IObject.cpp b/source/gameengine/GameLogic/SCA_IObject.cpp index 976665a3ccd..d1ce377316b 100644 --- a/source/gameengine/GameLogic/SCA_IObject.cpp +++ b/source/gameengine/GameLogic/SCA_IObject.cpp @@ -375,18 +375,21 @@ void SCA_IObject::SetState(unsigned int state) /* Integration hooks ------------------------------------------------------- */ PyTypeObject SCA_IObject::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "SCA_IObject", sizeof(SCA_IObject), 0, PyDestructor, 0, - __getattr, - __setattr, - 0, //&MyPyCompare, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -411,7 +414,7 @@ PyAttributeDef SCA_IObject::Attributes[] = { }; -PyObject* SCA_IObject::_getattr(const char *attr) { - _getattr_up(CValue); +PyObject* SCA_IObject::py_getattro(PyObject *attr) { + py_getattro_up(CValue); } diff --git a/source/gameengine/GameLogic/SCA_IObject.h b/source/gameengine/GameLogic/SCA_IObject.h index d47353b1ac0..44ed3c8f3fe 100644 --- a/source/gameengine/GameLogic/SCA_IObject.h +++ b/source/gameengine/GameLogic/SCA_IObject.h @@ -145,7 +145,7 @@ public: // const class MT_Point3& ConvertPythonPylist(PyObject* pylist); // here come the python forwarded methods - virtual PyObject* _getattr(const char *attr); + virtual PyObject* py_getattro(PyObject *attr); virtual int GetGameObjectType() {return -1;} diff --git a/source/gameengine/GameLogic/SCA_ISensor.cpp b/source/gameengine/GameLogic/SCA_ISensor.cpp index 0d7dffca17a..8a40c0c35f3 100644 --- a/source/gameengine/GameLogic/SCA_ISensor.cpp +++ b/source/gameengine/GameLogic/SCA_ISensor.cpp @@ -393,18 +393,21 @@ KX_PYMETHODDEF_DOC_NOARGS(SCA_ISensor, reset, /* ----------------------------------------------- */ PyTypeObject SCA_ISensor::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "SCA_ISensor", sizeof(SCA_ISensor), 0, PyDestructor, 0, - __getattr, - __setattr, 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -451,38 +454,40 @@ PyAttributeDef SCA_ISensor::Attributes[] = { KX_PYATTRIBUTE_INT_RW("frequency",0,100000,true,SCA_ISensor,m_pulse_frequency), KX_PYATTRIBUTE_BOOL_RW("invert",SCA_ISensor,m_invert), KX_PYATTRIBUTE_BOOL_RW("level",SCA_ISensor,m_level), - // make these properties read-only in _setaddr, must still implement them in _getattr + // make these properties read-only in _setaddr, must still implement them in py_getattro KX_PYATTRIBUTE_DUMMY("triggered"), KX_PYATTRIBUTE_DUMMY("positive"), { NULL } //Sentinel }; PyObject* -SCA_ISensor::_getattr(const char *attr) +SCA_ISensor::py_getattro(PyObject *attr) { - PyObject* object = _getattr_self(Attributes, this, attr); + PyObject* object = py_getattro_self(Attributes, this, attr); if (object != NULL) return object; - if (!strcmp(attr, "triggered")) + + char *attr_str= PyString_AsString(attr); + if (!strcmp(attr_str, "triggered")) { int retval = 0; if (SCA_PythonController::m_sCurrentController) retval = SCA_PythonController::m_sCurrentController->IsTriggered(this); return PyInt_FromLong(retval); } - if (!strcmp(attr, "positive")) + if (!strcmp(attr_str, "positive")) { int retval = IsPositiveTrigger(); return PyInt_FromLong(retval); } - _getattr_up(SCA_ILogicBrick); + py_getattro_up(SCA_ILogicBrick); } -int SCA_ISensor::_setattr(const char *attr, PyObject *value) +int SCA_ISensor::py_setattro(PyObject *attr, PyObject *value) { - int ret = _setattr_self(Attributes, this, attr, value); + int ret = py_setattro_self(Attributes, this, attr, value); if (ret >= 0) return ret; - return SCA_ILogicBrick::_setattr(attr, value); + return SCA_ILogicBrick::py_setattro(attr, value); } /* eof */ diff --git a/source/gameengine/GameLogic/SCA_ISensor.h b/source/gameengine/GameLogic/SCA_ISensor.h index 23f2c76c19f..ce7b66df1cd 100644 --- a/source/gameengine/GameLogic/SCA_ISensor.h +++ b/source/gameengine/GameLogic/SCA_ISensor.h @@ -136,8 +136,8 @@ public: /* Python functions: */ - virtual PyObject* _getattr(const char *attr); - virtual int _setattr(const char *attr, PyObject *value); + virtual PyObject* py_getattro(PyObject *attr); + virtual int py_setattro(PyObject *attr, PyObject *value); //Deprecated functions -----> KX_PYMETHOD_DOC_NOARGS(SCA_ISensor,IsPositive); diff --git a/source/gameengine/GameLogic/SCA_JoystickSensor.cpp b/source/gameengine/GameLogic/SCA_JoystickSensor.cpp index 6b8779ee37a..0cfd6843c1b 100644 --- a/source/gameengine/GameLogic/SCA_JoystickSensor.cpp +++ b/source/gameengine/GameLogic/SCA_JoystickSensor.cpp @@ -275,18 +275,21 @@ bool SCA_JoystickSensor::isValid(SCA_JoystickSensor::KX_JOYSENSORMODE m) /* Integration hooks ------------------------------------------------------- */ PyTypeObject SCA_JoystickSensor::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "SCA_JoystickSensor", sizeof(SCA_JoystickSensor), 0, PyDestructor, 0, - __getattr, - __setattr, - 0, //&MyPyCompare, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -330,8 +333,8 @@ PyAttributeDef SCA_JoystickSensor::Attributes[] = { KX_PYATTRIBUTE_INT_RW("button",0,100,false,SCA_JoystickSensor,m_button), KX_PYATTRIBUTE_INT_LIST_RW_CHECK("axis",0,3,true,SCA_JoystickSensor,m_axis,2,CheckAxis), KX_PYATTRIBUTE_INT_LIST_RW_CHECK("hat",0,12,true,SCA_JoystickSensor,m_hat,2,CheckHat), - // dummy attributes will just be read-only in _setattr - // you still need to defined them in _getattr + // dummy attributes will just be read-only in py_setattro + // you still need to defined them in py_getattro KX_PYATTRIBUTE_DUMMY("axisPosition"), KX_PYATTRIBUTE_DUMMY("numAxis"), KX_PYATTRIBUTE_DUMMY("numButtons"), @@ -340,38 +343,40 @@ PyAttributeDef SCA_JoystickSensor::Attributes[] = { { NULL } //Sentinel }; -PyObject* SCA_JoystickSensor::_getattr(const char *attr) { +PyObject* SCA_JoystickSensor::py_getattro(PyObject *attr) { SCA_Joystick *joy = m_pJoystickMgr->GetJoystickDevice(m_joyindex); - if (!strcmp(attr, "axisPosition")) { + char *attr_str= PyString_AsString(attr); + + if (!strcmp(attr_str, "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 (!strcmp(attr, "numAxis")) { + if (!strcmp(attr_str, "numAxis")) { return PyInt_FromLong( joy ? joy->GetNumberOfAxes() : 0 ); } - if (!strcmp(attr, "numButtons")) { + if (!strcmp(attr_str, "numButtons")) { return PyInt_FromLong( joy ? joy->GetNumberOfButtons() : 0 ); } - if (!strcmp(attr, "numHats")) { + if (!strcmp(attr_str, "numHats")) { return PyInt_FromLong( joy ? joy->GetNumberOfHats() : 0 ); } - if (!strcmp(attr, "connected")) { + if (!strcmp(attr_str, "connected")) { return PyBool_FromLong( joy ? joy->Connected() : 0 ); } - PyObject* object = _getattr_self(Attributes, this, attr); + PyObject* object = py_getattro_self(Attributes, this, attr); if (object != NULL) return object; - _getattr_up(SCA_ISensor); + py_getattro_up(SCA_ISensor); } -int SCA_JoystickSensor::_setattr(const char *attr, PyObject *value) +int SCA_JoystickSensor::py_setattro(PyObject *attr, PyObject *value) { - int ret = _setattr_self(Attributes, this, attr, value); + int ret = py_setattro_self(Attributes, this, attr, value); if (ret >= 0) return ret; - return SCA_ISensor::_setattr(attr, value); + return SCA_ISensor::py_setattro(attr, value); } diff --git a/source/gameengine/GameLogic/SCA_JoystickSensor.h b/source/gameengine/GameLogic/SCA_JoystickSensor.h index 49d220c056d..ccdd2107b21 100644 --- a/source/gameengine/GameLogic/SCA_JoystickSensor.h +++ b/source/gameengine/GameLogic/SCA_JoystickSensor.h @@ -121,8 +121,8 @@ public: /* Python interface ---------------------------------------------------- */ /* --------------------------------------------------------------------- */ - virtual PyObject* _getattr(const char *attr); - virtual int _setattr(const char *attr, PyObject *value); + virtual PyObject* py_getattro(PyObject *attr); + virtual int py_setattro(PyObject *attr, PyObject *value); /* Joystick Index */ KX_PYMETHOD_DOC_NOARGS(SCA_JoystickSensor,GetIndex); diff --git a/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp b/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp index bf470daa349..fc1b5be3540 100644 --- a/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp +++ b/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp @@ -778,18 +778,21 @@ KX_PYMETHODDEF_DOC_O(SCA_KeyboardSensor, getKeyStatus, /* ------------------------------------------------------------------------- */ PyTypeObject SCA_KeyboardSensor::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "SCA_KeyboardSensor", sizeof(SCA_KeyboardSensor), 0, PyDestructor, 0, - __getattr, - __setattr, - 0, //&MyPyCompare, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -828,18 +831,18 @@ PyAttributeDef SCA_KeyboardSensor::Attributes[] = { }; PyObject* -SCA_KeyboardSensor::_getattr(const char *attr) +SCA_KeyboardSensor::py_getattro(PyObject *attr) { - PyObject* object = _getattr_self(Attributes, this, attr); + PyObject* object = py_getattro_self(Attributes, this, attr); if (object != NULL) return object; - _getattr_up(SCA_ISensor); + py_getattro_up(SCA_ISensor); } -int SCA_KeyboardSensor::_setattr(const char *attr, PyObject *value) +int SCA_KeyboardSensor::py_setattro(PyObject *attr, PyObject *value) { - int ret = _setattr_self(Attributes, this, attr, value); + int ret = py_setattro_self(Attributes, this, attr, value); if (ret >= 0) return ret; - return SCA_ISensor::_setattr(attr, value); + return SCA_ISensor::py_setattro(attr, value); } diff --git a/source/gameengine/GameLogic/SCA_KeyboardSensor.h b/source/gameengine/GameLogic/SCA_KeyboardSensor.h index bc2f86327a5..c579b6a82f8 100644 --- a/source/gameengine/GameLogic/SCA_KeyboardSensor.h +++ b/source/gameengine/GameLogic/SCA_KeyboardSensor.h @@ -126,8 +126,8 @@ public: /* Python interface ---------------------------------------------------- */ /* --------------------------------------------------------------------- */ - virtual PyObject* _getattr(const char *attr); - virtual int _setattr(const char *attr, PyObject *value); + virtual PyObject* py_getattro(PyObject *attr); + virtual int py_setattro(PyObject *attr, PyObject *value); //Deprecated functions -----> /** 1. GetKey : check which key this sensor looks at */ diff --git a/source/gameengine/GameLogic/SCA_MouseSensor.cpp b/source/gameengine/GameLogic/SCA_MouseSensor.cpp index 19365fbbb88..c5f6fdabbe8 100644 --- a/source/gameengine/GameLogic/SCA_MouseSensor.cpp +++ b/source/gameengine/GameLogic/SCA_MouseSensor.cpp @@ -102,7 +102,7 @@ int SCA_MouseSensor::UpdateHotkey(void *self, const PyAttributeDef*) default: ; /* ignore, no hotkey */ } - // return value is used in _setattr(), + // return value is used in py_setattro(), // 0=attribute checked ok (see Attributes array definition) return 0; } @@ -300,18 +300,21 @@ KX_PYMETHODDEF_DOC_O(SCA_MouseSensor, getButtonStatus, /* ------------------------------------------------------------------------- */ PyTypeObject SCA_MouseSensor::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "SCA_MouseSensor", sizeof(SCA_MouseSensor), 0, PyDestructor, 0, - __getattr, - __setattr, 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -338,20 +341,20 @@ PyAttributeDef SCA_MouseSensor::Attributes[] = { { NULL } //Sentinel }; -PyObject* SCA_MouseSensor::_getattr(const char *attr) +PyObject* SCA_MouseSensor::py_getattro(PyObject *attr) { - PyObject* object = _getattr_self(Attributes, this, attr); + PyObject* object = py_getattro_self(Attributes, this, attr); if (object != NULL) return object; - _getattr_up(SCA_ISensor); + py_getattro_up(SCA_ISensor); } -int SCA_MouseSensor::_setattr(const char *attr, PyObject *value) +int SCA_MouseSensor::py_setattro(PyObject *attr, PyObject *value) { - int ret = _setattr_self(Attributes, this, attr, value); + int ret = py_setattro_self(Attributes, this, attr, value); if (ret >= 0) return ret; - return SCA_ISensor::_setattr(attr, value); + return SCA_ISensor::py_setattro(attr, value); } /* eof */ diff --git a/source/gameengine/GameLogic/SCA_MouseSensor.h b/source/gameengine/GameLogic/SCA_MouseSensor.h index 30b43fe53cc..73410569cc2 100644 --- a/source/gameengine/GameLogic/SCA_MouseSensor.h +++ b/source/gameengine/GameLogic/SCA_MouseSensor.h @@ -109,8 +109,8 @@ class SCA_MouseSensor : public SCA_ISensor /* Python interface ---------------------------------------------------- */ /* --------------------------------------------------------------------- */ - virtual PyObject* _getattr(const char *attr); - virtual int _setattr(const char *attr, PyObject *value); + virtual PyObject* py_getattro(PyObject *attr); + virtual int py_setattro(PyObject *attr, PyObject *value); //Deprecated functions -----> /* read x-coordinate */ diff --git a/source/gameengine/GameLogic/SCA_NANDController.cpp b/source/gameengine/GameLogic/SCA_NANDController.cpp index 2bc6a3ef1d6..bddd5f4d3ab 100644 --- a/source/gameengine/GameLogic/SCA_NANDController.cpp +++ b/source/gameengine/GameLogic/SCA_NANDController.cpp @@ -107,18 +107,21 @@ CValue* SCA_NANDController::GetReplica() /* Integration hooks ------------------------------------------------------- */ PyTypeObject SCA_NANDController::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "SCA_NANDController", sizeof(SCA_NANDController), 0, PyDestructor, 0, - __getattr, - __setattr, 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -138,8 +141,8 @@ PyAttributeDef SCA_NANDController::Attributes[] = { { NULL } //Sentinel }; -PyObject* SCA_NANDController::_getattr(const char *attr) { - _getattr_up(SCA_IController); +PyObject* SCA_NANDController::py_getattro(PyObject *attr) { + py_getattro_up(SCA_IController); } /* eof */ diff --git a/source/gameengine/GameLogic/SCA_NANDController.h b/source/gameengine/GameLogic/SCA_NANDController.h index d88504cfc0d..11600914a1a 100644 --- a/source/gameengine/GameLogic/SCA_NANDController.h +++ b/source/gameengine/GameLogic/SCA_NANDController.h @@ -48,7 +48,7 @@ public: /* Python interface ---------------------------------------------------- */ /* --------------------------------------------------------------------- */ - virtual PyObject* _getattr(const char *attr); + virtual PyObject* py_getattro(PyObject *attr); }; diff --git a/source/gameengine/GameLogic/SCA_NORController.cpp b/source/gameengine/GameLogic/SCA_NORController.cpp index 98ba77df54c..3ee073523c3 100644 --- a/source/gameengine/GameLogic/SCA_NORController.cpp +++ b/source/gameengine/GameLogic/SCA_NORController.cpp @@ -107,18 +107,21 @@ CValue* SCA_NORController::GetReplica() /* Integration hooks ------------------------------------------------------- */ PyTypeObject SCA_NORController::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "SCA_NORController", sizeof(SCA_NORController), 0, PyDestructor, 0, - __getattr, - __setattr, 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -138,8 +141,8 @@ PyAttributeDef SCA_NORController::Attributes[] = { { NULL } //Sentinel }; -PyObject* SCA_NORController::_getattr(const char *attr) { - _getattr_up(SCA_IController); +PyObject* SCA_NORController::py_getattro(PyObject *attr) { + py_getattro_up(SCA_IController); } /* eof */ diff --git a/source/gameengine/GameLogic/SCA_NORController.h b/source/gameengine/GameLogic/SCA_NORController.h index 45b639f3f3f..fc814e28d37 100644 --- a/source/gameengine/GameLogic/SCA_NORController.h +++ b/source/gameengine/GameLogic/SCA_NORController.h @@ -48,7 +48,7 @@ public: /* Python interface ---------------------------------------------------- */ /* --------------------------------------------------------------------- */ - virtual PyObject* _getattr(const char *attr); + virtual PyObject* py_getattro(PyObject *attr); }; diff --git a/source/gameengine/GameLogic/SCA_ORController.cpp b/source/gameengine/GameLogic/SCA_ORController.cpp index ba616402ac9..91d5e56d4f3 100644 --- a/source/gameengine/GameLogic/SCA_ORController.cpp +++ b/source/gameengine/GameLogic/SCA_ORController.cpp @@ -99,18 +99,21 @@ void SCA_ORController::Trigger(SCA_LogicManager* logicmgr) /* Integration hooks ------------------------------------------------------- */ PyTypeObject SCA_ORController::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "SCA_ORController", sizeof(SCA_ORController), 0, PyDestructor, 0, - __getattr, - __setattr, - 0, //&MyPyCompare, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -131,8 +134,8 @@ PyAttributeDef SCA_ORController::Attributes[] = { }; -PyObject* SCA_ORController::_getattr(const char *attr) { - _getattr_up(SCA_IController); +PyObject* SCA_ORController::py_getattro(PyObject *attr) { + py_getattro_up(SCA_IController); } /* eof */ diff --git a/source/gameengine/GameLogic/SCA_ORController.h b/source/gameengine/GameLogic/SCA_ORController.h index 9a6e9e75022..fdc81486e74 100644 --- a/source/gameengine/GameLogic/SCA_ORController.h +++ b/source/gameengine/GameLogic/SCA_ORController.h @@ -49,7 +49,7 @@ public: /* Python interface ---------------------------------------------------- */ /* --------------------------------------------------------------------- */ - virtual PyObject* _getattr(const char *attr); + virtual PyObject* py_getattro(PyObject *attr); }; #endif //__KX_ORCONTROLLER diff --git a/source/gameengine/GameLogic/SCA_PropertyActuator.cpp b/source/gameengine/GameLogic/SCA_PropertyActuator.cpp index 28a3b6b822a..e1f303430ec 100644 --- a/source/gameengine/GameLogic/SCA_PropertyActuator.cpp +++ b/source/gameengine/GameLogic/SCA_PropertyActuator.cpp @@ -218,18 +218,21 @@ void SCA_PropertyActuator::Relink(GEN_Map<GEN_HashedPtr, void*> *obj_map) /* Integration hooks ------------------------------------------------------- */ PyTypeObject SCA_PropertyActuator::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "SCA_PropertyActuator", sizeof(SCA_PropertyActuator), 0, PyDestructor, 0, - __getattr, - __setattr, 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -257,18 +260,18 @@ PyAttributeDef SCA_PropertyActuator::Attributes[] = { { NULL } //Sentinel }; -PyObject* SCA_PropertyActuator::_getattr(const char *attr) { - PyObject* object = _getattr_self(Attributes, this, attr); +PyObject* SCA_PropertyActuator::py_getattro(PyObject *attr) { + PyObject* object = py_getattro_self(Attributes, this, attr); if (object != NULL) return object; - _getattr_up(SCA_IActuator); + py_getattro_up(SCA_IActuator); } -int SCA_PropertyActuator::_setattr(const char *attr, PyObject *value) { - int ret = _setattr_self(Attributes, this, attr, value); +int SCA_PropertyActuator::py_setattro(PyObject *attr, PyObject *value) { + int ret = py_setattro_self(Attributes, this, attr, value); if (ret >= 0) return ret; - return SCA_IActuator::_setattr(attr, value); + return SCA_IActuator::py_setattro(attr, value); } /* 1. setProperty */ diff --git a/source/gameengine/GameLogic/SCA_PropertyActuator.h b/source/gameengine/GameLogic/SCA_PropertyActuator.h index 444d9285796..6a975716ed0 100644 --- a/source/gameengine/GameLogic/SCA_PropertyActuator.h +++ b/source/gameengine/GameLogic/SCA_PropertyActuator.h @@ -85,8 +85,8 @@ public: /* Python interface ---------------------------------------------------- */ /* --------------------------------------------------------------------- */ - virtual PyObject* _getattr(const char *attr); - virtual int _setattr(const char *attr, PyObject *value); + virtual PyObject* py_getattro(PyObject *attr); + virtual int py_setattro(PyObject *attr, PyObject *value); // python wrapped methods KX_PYMETHOD_DOC(SCA_PropertyActuator,SetProperty); diff --git a/source/gameengine/GameLogic/SCA_PropertySensor.cpp b/source/gameengine/GameLogic/SCA_PropertySensor.cpp index ef3dbe7e049..659823f6fba 100644 --- a/source/gameengine/GameLogic/SCA_PropertySensor.cpp +++ b/source/gameengine/GameLogic/SCA_PropertySensor.cpp @@ -306,18 +306,21 @@ int SCA_PropertySensor::validValueForProperty(void *self, const PyAttributeDef*) /* Integration hooks ------------------------------------------------------- */ PyTypeObject SCA_PropertySensor::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "SCA_PropertySensor", sizeof(SCA_PropertySensor), 0, PyDestructor, 0, - __getattr, - __setattr, 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -349,18 +352,18 @@ PyAttributeDef SCA_PropertySensor::Attributes[] = { }; -PyObject* SCA_PropertySensor::_getattr(const char *attr) { - PyObject* object = _getattr_self(Attributes, this, attr); +PyObject* SCA_PropertySensor::py_getattro(PyObject *attr) { + PyObject* object = py_getattro_self(Attributes, this, attr); if (object != NULL) return object; - _getattr_up(SCA_ISensor); /* implicit return! */ + py_getattro_up(SCA_ISensor); /* implicit return! */ } -int SCA_PropertySensor::_setattr(const char *attr, PyObject *value) { - int ret = _setattr_self(Attributes, this, attr, value); +int SCA_PropertySensor::py_setattro(PyObject *attr, PyObject *value) { + int ret = py_setattro_self(Attributes, this, attr, value); if (ret >= 0) return ret; - return SCA_ISensor::_setattr(attr, value); + return SCA_ISensor::py_setattro(attr, value); } /* 1. getType */ diff --git a/source/gameengine/GameLogic/SCA_PropertySensor.h b/source/gameengine/GameLogic/SCA_PropertySensor.h index 2594e3fca9d..076c1ae51ec 100644 --- a/source/gameengine/GameLogic/SCA_PropertySensor.h +++ b/source/gameengine/GameLogic/SCA_PropertySensor.h @@ -89,8 +89,8 @@ public: /* Python interface ---------------------------------------------------- */ /* --------------------------------------------------------------------- */ - virtual PyObject* _getattr(const char *attr); - virtual int _setattr(const char *attr, PyObject *value); + virtual PyObject* py_getattro(PyObject *attr); + virtual int py_setattro(PyObject *attr, PyObject *value); /* 1. getType */ KX_PYMETHOD_DOC(SCA_PropertySensor,GetType); diff --git a/source/gameengine/GameLogic/SCA_PythonController.cpp b/source/gameengine/GameLogic/SCA_PythonController.cpp index 4ad3f135d31..2d200e0a238 100644 --- a/source/gameengine/GameLogic/SCA_PythonController.cpp +++ b/source/gameengine/GameLogic/SCA_PythonController.cpp @@ -224,18 +224,21 @@ const char* SCA_PythonController::sPyAddActiveActuator__doc__= "addActiveActuato const char SCA_PythonController::GetActuators_doc[] = "getActuator"; PyTypeObject SCA_PythonController::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "SCA_PythonController", sizeof(SCA_PythonController), 0, PyDestructor, 0, - __getattr, - __setattr, - 0, //&MyPyCompare, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -369,24 +372,26 @@ void SCA_PythonController::Trigger(SCA_LogicManager* logicmgr) -PyObject* SCA_PythonController::_getattr(const char *attr) +PyObject* SCA_PythonController::py_getattro(PyObject *attr) { - if (!strcmp(attr,"state")) { + char *attr_str= PyString_AsString(attr); + if (!strcmp(attr_str,"state")) { return PyInt_FromLong(m_statemask); } - if (!strcmp(attr,"script")) { + if (!strcmp(attr_str,"script")) { return PyString_FromString(m_scriptText); } - _getattr_up(SCA_IController); + py_getattro_up(SCA_IController); } -int SCA_PythonController::_setattr(const char *attr, PyObject *value) +int SCA_PythonController::py_setattro(PyObject *attr, PyObject *value) { - if (!strcmp(attr,"state")) { + char *attr_str= PyString_AsString(attr); + if (!strcmp(attr_str,"state")) { PyErr_SetString(PyExc_AttributeError, "state is read only"); return 1; } - if (!strcmp(attr,"script")) { + if (!strcmp(attr_str,"script")) { char *scriptArg = PyString_AsString(value); if (scriptArg==NULL) { @@ -400,7 +405,7 @@ int SCA_PythonController::_setattr(const char *attr, PyObject *value) return 1; } - return SCA_IController::_setattr(attr, value); + return SCA_IController::py_setattro(attr, value); } PyObject* SCA_PythonController::PyActivate(PyObject* self, PyObject *value) diff --git a/source/gameengine/GameLogic/SCA_PythonController.h b/source/gameengine/GameLogic/SCA_PythonController.h index 4ec18f32c23..3348071c00f 100644 --- a/source/gameengine/GameLogic/SCA_PythonController.h +++ b/source/gameengine/GameLogic/SCA_PythonController.h @@ -78,8 +78,8 @@ class SCA_PythonController : public SCA_IController static PyObject* sPyAddActiveActuator(PyObject* self, PyObject* args); static SCA_IActuator* LinkedActuatorFromPy(PyObject *value); - virtual PyObject* _getattr(const char *attr); - virtual int _setattr(const char *attr, PyObject *value); + virtual PyObject* py_getattro(PyObject *attr); + virtual int py_setattro(PyObject *attr, PyObject *value); KX_PYMETHOD_O(SCA_PythonController,Activate); diff --git a/source/gameengine/GameLogic/SCA_RandomActuator.cpp b/source/gameengine/GameLogic/SCA_RandomActuator.cpp index 78614f9ace3..a9a664b0686 100644 --- a/source/gameengine/GameLogic/SCA_RandomActuator.cpp +++ b/source/gameengine/GameLogic/SCA_RandomActuator.cpp @@ -312,18 +312,21 @@ void SCA_RandomActuator::enforceConstraints() { /* Integration hooks ------------------------------------------------------- */ PyTypeObject SCA_RandomActuator::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "SCA_RandomActuator", sizeof(SCA_RandomActuator), 0, PyDestructor, 0, - __getattr, - __setattr, 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -366,22 +369,25 @@ PyAttributeDef SCA_RandomActuator::Attributes[] = { { NULL } //Sentinel }; -PyObject* SCA_RandomActuator::_getattr(const char *attr) { - PyObject* object = _getattr_self(Attributes, this, attr); +PyObject* SCA_RandomActuator::py_getattro(PyObject *attr) { + PyObject* object = py_getattro_self(Attributes, this, attr); if (object != NULL) return object; - if (!strcmp(attr, "seed")) { + char *attr_str= PyString_AsString(attr); + if (!strcmp(attr_str, "seed")) { return PyInt_FromLong(m_base->GetSeed()); } - _getattr_up(SCA_IActuator); + py_getattro_up(SCA_IActuator); } -int SCA_RandomActuator::_setattr(const char *attr, PyObject *value) +int SCA_RandomActuator::py_setattro(PyObject *attr, PyObject *value) { - int ret = _setattr_self(Attributes, this, attr, value); + int ret = py_setattro_self(Attributes, this, attr, value); if (ret >= 0) return ret; - if (!strcmp(attr, "seed")) { + + char *attr_str= PyString_AsString(attr); + if (!strcmp(attr_str, "seed")) { if (PyInt_Check(value)) { int ival = PyInt_AsLong(value); m_base->SetSeed(ival); @@ -391,7 +397,7 @@ int SCA_RandomActuator::_setattr(const char *attr, PyObject *value) return 1; } } - return SCA_IActuator::_setattr(attr, value); + return SCA_IActuator::py_setattro(attr, value); } /* 1. setSeed */ diff --git a/source/gameengine/GameLogic/SCA_RandomActuator.h b/source/gameengine/GameLogic/SCA_RandomActuator.h index 0d404fa8a9f..96ca353257f 100644 --- a/source/gameengine/GameLogic/SCA_RandomActuator.h +++ b/source/gameengine/GameLogic/SCA_RandomActuator.h @@ -96,8 +96,8 @@ class SCA_RandomActuator : public SCA_IActuator /* Python interface ---------------------------------------------------- */ /* --------------------------------------------------------------------- */ - virtual PyObject* _getattr(const char *attr); - virtual int _setattr(const char *attr, PyObject *value); + virtual PyObject* py_getattro(PyObject *attr); + virtual int py_setattro(PyObject *attr, PyObject *value); /* 1. setSeed */ KX_PYMETHOD_DOC(SCA_RandomActuator,SetSeed); diff --git a/source/gameengine/GameLogic/SCA_RandomSensor.cpp b/source/gameengine/GameLogic/SCA_RandomSensor.cpp index d88f8f500c0..84a9ef95e84 100644 --- a/source/gameengine/GameLogic/SCA_RandomSensor.cpp +++ b/source/gameengine/GameLogic/SCA_RandomSensor.cpp @@ -127,18 +127,21 @@ bool SCA_RandomSensor::Evaluate(CValue* event) /* Integration hooks ------------------------------------------------------- */ PyTypeObject SCA_RandomSensor::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "SCA_RandomSensor", sizeof(SCA_RandomSensor), 0, PyDestructor, 0, - __getattr, - __setattr, 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -162,22 +165,25 @@ PyAttributeDef SCA_RandomSensor::Attributes[] = { {NULL} //Sentinel }; -PyObject* SCA_RandomSensor::_getattr(const char *attr) { - PyObject* object = _getattr_self(Attributes, this, attr); +PyObject* SCA_RandomSensor::py_getattro(PyObject *attr) { + PyObject* object = py_getattro_self(Attributes, this, attr); if (object != NULL) return object; - if (!strcmp(attr,"seed")) { + + char *attr_str= PyString_AsString(attr); + if (!strcmp(attr_str,"seed")) { return PyInt_FromLong(m_basegenerator->GetSeed()); } - _getattr_up(SCA_ISensor); + py_getattro_up(SCA_ISensor); } -int SCA_RandomSensor::_setattr(const char *attr, PyObject *value) +int SCA_RandomSensor::py_setattro(PyObject *attr, PyObject *value) { - int ret = _setattr_self(Attributes, this, attr, value); + int ret = py_setattro_self(Attributes, this, attr, value); if (ret >= 0) return ret; - if (!strcmp(attr,"seed")) { + char *attr_str= PyString_AsString(attr); + if (!strcmp(attr_str,"seed")) { if (PyInt_Check(value)) { int ival = PyInt_AsLong(value); m_basegenerator->SetSeed(ival); @@ -187,7 +193,7 @@ int SCA_RandomSensor::_setattr(const char *attr, PyObject *value) return 1; } } - return SCA_ISensor::_setattr(attr, value); + return SCA_ISensor::py_setattro(attr, value); } /* 1. setSeed */ diff --git a/source/gameengine/GameLogic/SCA_RandomSensor.h b/source/gameengine/GameLogic/SCA_RandomSensor.h index d808db07536..39d072dd316 100644 --- a/source/gameengine/GameLogic/SCA_RandomSensor.h +++ b/source/gameengine/GameLogic/SCA_RandomSensor.h @@ -60,8 +60,8 @@ public: /* Python interface ---------------------------------------------------- */ /* --------------------------------------------------------------------- */ - virtual PyObject* _getattr(const char *attr); - virtual int _setattr(const char *attr, PyObject *value); + virtual PyObject* py_getattro(PyObject *attr); + virtual int py_setattro(PyObject *attr, PyObject *value); /* 1. setSeed */ KX_PYMETHOD_DOC(SCA_RandomSensor,SetSeed); diff --git a/source/gameengine/GameLogic/SCA_XNORController.cpp b/source/gameengine/GameLogic/SCA_XNORController.cpp index a9fe906f54e..10757e1c935 100644 --- a/source/gameengine/GameLogic/SCA_XNORController.cpp +++ b/source/gameengine/GameLogic/SCA_XNORController.cpp @@ -111,18 +111,21 @@ CValue* SCA_XNORController::GetReplica() /* Integration hooks ------------------------------------------------------- */ PyTypeObject SCA_XNORController::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "SCA_XNORController", sizeof(SCA_XNORController), 0, PyDestructor, 0, - __getattr, - __setattr, 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -142,8 +145,8 @@ PyAttributeDef SCA_XNORController::Attributes[] = { { NULL } //Sentinel }; -PyObject* SCA_XNORController::_getattr(const char *attr) { - _getattr_up(SCA_IController); +PyObject* SCA_XNORController::py_getattro(PyObject *attr) { + py_getattro_up(SCA_IController); } /* eof */ diff --git a/source/gameengine/GameLogic/SCA_XNORController.h b/source/gameengine/GameLogic/SCA_XNORController.h index a431a72c177..c992d5f1834 100644 --- a/source/gameengine/GameLogic/SCA_XNORController.h +++ b/source/gameengine/GameLogic/SCA_XNORController.h @@ -48,7 +48,7 @@ public: /* Python interface ---------------------------------------------------- */ /* --------------------------------------------------------------------- */ - virtual PyObject* _getattr(const char *attr); + virtual PyObject* py_getattro(PyObject *attr); }; diff --git a/source/gameengine/GameLogic/SCA_XORController.cpp b/source/gameengine/GameLogic/SCA_XORController.cpp index b0053ca17fb..d2290fe207a 100644 --- a/source/gameengine/GameLogic/SCA_XORController.cpp +++ b/source/gameengine/GameLogic/SCA_XORController.cpp @@ -111,18 +111,21 @@ CValue* SCA_XORController::GetReplica() /* Integration hooks ------------------------------------------------------- */ PyTypeObject SCA_XORController::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "SCA_XORController", sizeof(SCA_XORController), 0, PyDestructor, 0, - __getattr, - __setattr, 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -142,8 +145,8 @@ PyAttributeDef SCA_XORController::Attributes[] = { { NULL } //Sentinel }; -PyObject* SCA_XORController::_getattr(const char *attr) { - _getattr_up(SCA_IController); +PyObject* SCA_XORController::py_getattro(PyObject *attr) { + py_getattro_up(SCA_IController); } /* eof */ diff --git a/source/gameengine/GameLogic/SCA_XORController.h b/source/gameengine/GameLogic/SCA_XORController.h index 2fbc7866ecf..065b31fd901 100644 --- a/source/gameengine/GameLogic/SCA_XORController.h +++ b/source/gameengine/GameLogic/SCA_XORController.h @@ -48,7 +48,7 @@ public: /* Python interface ---------------------------------------------------- */ /* --------------------------------------------------------------------- */ - virtual PyObject* _getattr(const char *attr); + virtual PyObject* py_getattro(PyObject *attr); }; |