diff options
author | Campbell Barton <ideasman42@gmail.com> | 2009-04-04 06:57:35 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2009-04-04 06:57:35 +0400 |
commit | 6be69211843ee37ab9be763df0621db94dbfd69b (patch) | |
tree | e4efbb5bc2b60986bac5276881e11e54fdd5fb7d | |
parent | 29f5c7dd5d0871835e4d50b2b3018b9a24a93350 (diff) |
moved more attributes from getattr into PyAttributeDef's
-rw-r--r-- | source/gameengine/Converter/BL_ActionActuator.cpp | 64 | ||||
-rw-r--r-- | source/gameengine/Converter/BL_ActionActuator.h | 8 | ||||
-rw-r--r-- | source/gameengine/Converter/BL_ShapeActionActuator.cpp | 68 | ||||
-rw-r--r-- | source/gameengine/Converter/BL_ShapeActionActuator.h | 6 | ||||
-rw-r--r-- | source/gameengine/GameLogic/SCA_ISensor.cpp | 35 | ||||
-rw-r--r-- | source/gameengine/GameLogic/SCA_ISensor.h | 3 | ||||
-rw-r--r-- | source/gameengine/GameLogic/SCA_JoystickSensor.cpp | 77 | ||||
-rw-r--r-- | source/gameengine/GameLogic/SCA_JoystickSensor.h | 7 | ||||
-rw-r--r-- | source/gameengine/GameLogic/SCA_PythonController.cpp | 65 | ||||
-rw-r--r-- | source/gameengine/GameLogic/SCA_PythonController.h | 4 | ||||
-rw-r--r-- | source/gameengine/GameLogic/SCA_RandomSensor.cpp | 35 | ||||
-rw-r--r-- | source/gameengine/GameLogic/SCA_RandomSensor.h | 3 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_CameraActuator.cpp | 55 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_CameraActuator.h | 3 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_TouchSensor.cpp | 33 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_TouchSensor.h | 4 |
16 files changed, 276 insertions, 194 deletions
diff --git a/source/gameengine/Converter/BL_ActionActuator.cpp b/source/gameengine/Converter/BL_ActionActuator.cpp index 943bb68f6f2..b7a961d6a9d 100644 --- a/source/gameengine/Converter/BL_ActionActuator.cpp +++ b/source/gameengine/Converter/BL_ActionActuator.cpp @@ -1025,6 +1025,7 @@ PyAttributeDef BL_ActionActuator::Attributes[] = { KX_PYATTRIBUTE_FLOAT_RW("start", 0, MAXFRAMEF, BL_ActionActuator, m_startframe), KX_PYATTRIBUTE_FLOAT_RW("end", 0, MAXFRAMEF, BL_ActionActuator, m_endframe), KX_PYATTRIBUTE_FLOAT_RW("blendin", 0, MAXFRAMEF, BL_ActionActuator, m_blendin), + KX_PYATTRIBUTE_RW_FUNCTION("action", BL_ActionActuator, pyattr_get_action, pyattr_set_action), KX_PYATTRIBUTE_SHORT_RW("priority", 0, 100, false, BL_ActionActuator, m_priority), KX_PYATTRIBUTE_FLOAT_RW_CHECK("frame", 0, MAXFRAMEF, BL_ActionActuator, m_localtime, CheckFrame), KX_PYATTRIBUTE_STRING_RW("property", 0, 31, false, BL_ActionActuator, m_propname), @@ -1036,10 +1037,6 @@ PyAttributeDef BL_ActionActuator::Attributes[] = { }; PyObject* BL_ActionActuator::py_getattro(PyObject *attr) { - char *attr_str= PyString_AsString(attr); - if (!strcmp(attr_str, "action")) - return PyString_FromString(m_action->id.name+2); - PyObject* object = py_getattro_self(Attributes, this, attr); if (object != NULL) return object; @@ -1047,39 +1044,44 @@ PyObject* BL_ActionActuator::py_getattro(PyObject *attr) { } int BL_ActionActuator::py_setattro(PyObject *attr, PyObject* value) { - char *attr_str= PyString_AsString(attr); - if (!strcmp(attr_str, "action")) - { - if (!PyString_Check(value)) - { - PyErr_SetString(PyExc_ValueError, "expected a string"); - return 1; - } + int ret = py_setattro_self(Attributes, this, attr, value); + if (ret >= 0) + return ret; + return SCA_IActuator::py_setattro(attr, value); +} - STR_String val = PyString_AsString(value); - - if (val == "") - { - m_action = NULL; - return 0; - } - bAction *action; - - action = (bAction*)SCA_ILogicBrick::m_sCurrentLogicManager->GetActionByName(val); - +PyObject* BL_ActionActuator::pyattr_get_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + BL_ActionActuator* self= static_cast<BL_ActionActuator*>(self_v); + return PyString_FromString(self->GetAction()->id.name+2); +} + +int BL_ActionActuator::pyattr_set_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) +{ + BL_ActionActuator* self= static_cast<BL_ActionActuator*>(self_v); + + if (!PyString_Check(value)) + { + PyErr_SetString(PyExc_ValueError, "expected the string name of the action"); + return -1; + } + + bAction *action= NULL; + STR_String val = PyString_AsString(value); + + if (val != "") + { + (bAction*)SCA_ILogicBrick::m_sCurrentLogicManager->GetActionByName(val); if (!action) { PyErr_SetString(PyExc_ValueError, "action not found!"); return 1; } - - m_action = action; - return 0; } - int ret = py_setattro_self(Attributes, this, attr, value); - if (ret >= 0) - return ret; - return SCA_IActuator::py_setattro(attr, value); -}
\ No newline at end of file + + self->SetAction(action); + return 0; + +} diff --git a/source/gameengine/Converter/BL_ActionActuator.h b/source/gameengine/Converter/BL_ActionActuator.h index 7160dd4dad0..d5b5762d9e7 100644 --- a/source/gameengine/Converter/BL_ActionActuator.h +++ b/source/gameengine/Converter/BL_ActionActuator.h @@ -81,6 +81,9 @@ public: virtual void ProcessReplica(); void SetBlendTime (float newtime); + + bAction* GetAction() { return m_action; } + void SetAction(bAction* act) { m_action= act; } //Deprecated -----> KX_PYMETHOD_DOC(BL_ActionActuator,SetAction); @@ -113,6 +116,9 @@ public: virtual PyObject* py_getattro(PyObject* attr); virtual int py_setattro(PyObject* attr, PyObject* value); + static PyObject* pyattr_get_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static int pyattr_set_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + /* attribute check */ static int CheckFrame(void *self, const PyAttributeDef*) { @@ -151,8 +157,8 @@ public: PyErr_SetString(PyExc_ValueError, "invalid type supplied"); return 1; } - } + protected: void SetStartTime(float curtime); diff --git a/source/gameengine/Converter/BL_ShapeActionActuator.cpp b/source/gameengine/Converter/BL_ShapeActionActuator.cpp index c53be4653ca..3c0ce0918f2 100644 --- a/source/gameengine/Converter/BL_ShapeActionActuator.cpp +++ b/source/gameengine/Converter/BL_ShapeActionActuator.cpp @@ -474,6 +474,7 @@ PyAttributeDef BL_ShapeActionActuator::Attributes[] = { KX_PYATTRIBUTE_FLOAT_RW("start", 0, MAXFRAMEF, BL_ShapeActionActuator, m_startframe), KX_PYATTRIBUTE_FLOAT_RW("end", 0, MAXFRAMEF, BL_ShapeActionActuator, m_endframe), KX_PYATTRIBUTE_FLOAT_RW("blendin", 0, MAXFRAMEF, BL_ShapeActionActuator, m_blendin), + KX_PYATTRIBUTE_RW_FUNCTION("action", BL_ShapeActionActuator, pyattr_get_action, pyattr_set_action), KX_PYATTRIBUTE_SHORT_RW("priority", 0, 100, false, BL_ShapeActionActuator, m_priority), KX_PYATTRIBUTE_FLOAT_RW_CHECK("frame", 0, MAXFRAMEF, BL_ShapeActionActuator, m_localtime, CheckFrame), KX_PYATTRIBUTE_STRING_RW("property", 0, 31, false, BL_ShapeActionActuator, m_propname), @@ -485,9 +486,6 @@ PyAttributeDef BL_ShapeActionActuator::Attributes[] = { PyObject* BL_ShapeActionActuator::py_getattro(PyObject* attr) { - char *attr_str= PyString_AsString(attr); - if (!strcmp(attr_str, "action")) - return PyString_FromString(m_action->id.name+2); PyObject* object = py_getattro_self(Attributes, this, attr); if (object != NULL) return object; @@ -495,37 +493,6 @@ PyObject* BL_ShapeActionActuator::py_getattro(PyObject* attr) { } int BL_ShapeActionActuator::py_setattro(PyObject *attr, PyObject* value) { - char *attr_str= PyString_AsString(attr); - if (!strcmp(attr_str, "action")) - { - if (!PyString_Check(value)) - { - PyErr_SetString(PyExc_ValueError, "expected a string"); - return 1; - } - - STR_String val = PyString_AsString(value); - - if (val == "") - { - m_action = NULL; - return 0; - } - - bAction *action; - - action = (bAction*)SCA_ILogicBrick::m_sCurrentLogicManager->GetActionByName(val); - - - if (!action) - { - PyErr_SetString(PyExc_ValueError, "action not found!"); - return 1; - } - - m_action = action; - return 0; - } int ret = py_setattro_self(Attributes, this, attr, value); if (ret >= 0) return ret; @@ -916,3 +883,36 @@ PyObject* BL_ShapeActionActuator::PySetType(PyObject* self, Py_RETURN_NONE; } +PyObject* BL_ShapeActionActuator::pyattr_get_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + BL_ShapeActionActuator* self= static_cast<BL_ShapeActionActuator*>(self_v); + return PyString_FromString(self->GetAction()->id.name+2); +} + +int BL_ShapeActionActuator::pyattr_set_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) +{ + BL_ShapeActionActuator* self= static_cast<BL_ShapeActionActuator*>(self_v); + /* exact copy of BL_ActionActuator's function from here down */ + if (!PyString_Check(value)) + { + PyErr_SetString(PyExc_ValueError, "expected the string name of the action"); + return -1; + } + + bAction *action= NULL; + STR_String val = PyString_AsString(value); + + if (val != "") + { + (bAction*)SCA_ILogicBrick::m_sCurrentLogicManager->GetActionByName(val); + if (action==NULL) + { + PyErr_SetString(PyExc_ValueError, "action not found!"); + return 1; + } + } + + self->SetAction(action); + return 0; + +} diff --git a/source/gameengine/Converter/BL_ShapeActionActuator.h b/source/gameengine/Converter/BL_ShapeActionActuator.h index ea25d66e050..162580fca85 100644 --- a/source/gameengine/Converter/BL_ShapeActionActuator.h +++ b/source/gameengine/Converter/BL_ShapeActionActuator.h @@ -79,6 +79,9 @@ public: void SetBlendTime (float newtime); void BlendShape(struct Key* key, float weigth); + + bAction* GetAction() { return m_action; } + void SetAction(bAction* act) { m_action= act; } KX_PYMETHOD_DOC(BL_ShapeActionActuator,SetAction); KX_PYMETHOD_DOC(BL_ShapeActionActuator,SetBlendin); @@ -106,6 +109,9 @@ public: virtual PyObject* py_getattro(PyObject* attr); virtual int py_setattro(PyObject* attr, PyObject* value); + static PyObject* pyattr_get_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static int pyattr_set_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + static int CheckBlendTime(void *self, const PyAttributeDef*) { BL_ShapeActionActuator* act = reinterpret_cast<BL_ShapeActionActuator*>(self); diff --git a/source/gameengine/GameLogic/SCA_ISensor.cpp b/source/gameengine/GameLogic/SCA_ISensor.cpp index 8a40c0c35f3..a4f493d82c8 100644 --- a/source/gameengine/GameLogic/SCA_ISensor.cpp +++ b/source/gameengine/GameLogic/SCA_ISensor.cpp @@ -454,9 +454,8 @@ 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 py_getattro - KX_PYATTRIBUTE_DUMMY("triggered"), - KX_PYATTRIBUTE_DUMMY("positive"), + KX_PYATTRIBUTE_RO_FUNCTION("triggered", SCA_ISensor, pyattr_get_triggered), + KX_PYATTRIBUTE_RO_FUNCTION("positive", SCA_ISensor, pyattr_get_positive), { NULL } //Sentinel }; @@ -466,20 +465,6 @@ SCA_ISensor::py_getattro(PyObject *attr) PyObject* object = py_getattro_self(Attributes, this, attr); if (object != NULL) return object; - - 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_str, "positive")) - { - int retval = IsPositiveTrigger(); - return PyInt_FromLong(retval); - } py_getattro_up(SCA_ILogicBrick); } @@ -490,4 +475,20 @@ int SCA_ISensor::py_setattro(PyObject *attr, PyObject *value) return ret; return SCA_ILogicBrick::py_setattro(attr, value); } + +PyObject* SCA_ISensor::pyattr_get_triggered(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + SCA_ISensor* self= static_cast<SCA_ISensor*>(self_v); + int retval = 0; + if (SCA_PythonController::m_sCurrentController) + retval = SCA_PythonController::m_sCurrentController->IsTriggered(self); + return PyInt_FromLong(retval); +} + +PyObject* SCA_ISensor::pyattr_get_positive(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + SCA_ISensor* self= static_cast<SCA_ISensor*>(self_v); + return PyInt_FromLong(self->IsPositiveTrigger()); +} + /* eof */ diff --git a/source/gameengine/GameLogic/SCA_ISensor.h b/source/gameengine/GameLogic/SCA_ISensor.h index ce7b66df1cd..cfc95682089 100644 --- a/source/gameengine/GameLogic/SCA_ISensor.h +++ b/source/gameengine/GameLogic/SCA_ISensor.h @@ -154,6 +154,9 @@ public: KX_PYMETHOD_DOC(SCA_ISensor,SetLevel); //<------ KX_PYMETHOD_DOC_NOARGS(SCA_ISensor,reset); + + static PyObject* pyattr_get_triggered(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_positive(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); }; #endif //__SCA_ISENSOR diff --git a/source/gameengine/GameLogic/SCA_JoystickSensor.cpp b/source/gameengine/GameLogic/SCA_JoystickSensor.cpp index 0cfd6843c1b..2744d7f6609 100644 --- a/source/gameengine/GameLogic/SCA_JoystickSensor.cpp +++ b/source/gameengine/GameLogic/SCA_JoystickSensor.cpp @@ -333,38 +333,18 @@ 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 py_setattro - // you still need to defined them in py_getattro - KX_PYATTRIBUTE_DUMMY("axisPosition"), - KX_PYATTRIBUTE_DUMMY("numAxis"), - KX_PYATTRIBUTE_DUMMY("numButtons"), - KX_PYATTRIBUTE_DUMMY("numHats"), - KX_PYATTRIBUTE_DUMMY("connected"), + KX_PYATTRIBUTE_RO_FUNCTION("axisPosition", SCA_JoystickSensor, pyattr_get_axis_position), + KX_PYATTRIBUTE_RO_FUNCTION("numAxis", SCA_JoystickSensor, pyattr_get_num_axis), + KX_PYATTRIBUTE_RO_FUNCTION("numButtons", SCA_JoystickSensor, pyattr_get_num_buttons), + KX_PYATTRIBUTE_RO_FUNCTION("numHats", SCA_JoystickSensor, pyattr_get_num_hats), + KX_PYATTRIBUTE_RO_FUNCTION("connected", SCA_JoystickSensor, pyattr_get_connected), + + { NULL } //Sentinel }; -PyObject* SCA_JoystickSensor::py_getattro(PyObject *attr) { - SCA_Joystick *joy = m_pJoystickMgr->GetJoystickDevice(m_joyindex); - 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_str, "numAxis")) { - return PyInt_FromLong( joy ? joy->GetNumberOfAxes() : 0 ); - } - if (!strcmp(attr_str, "numButtons")) { - return PyInt_FromLong( joy ? joy->GetNumberOfButtons() : 0 ); - } - if (!strcmp(attr_str, "numHats")) { - return PyInt_FromLong( joy ? joy->GetNumberOfHats() : 0 ); - } - if (!strcmp(attr_str, "connected")) { - return PyBool_FromLong( joy ? joy->Connected() : 0 ); - } +PyObject* SCA_JoystickSensor::py_getattro(PyObject *attr) +{ PyObject* object = py_getattro_self(Attributes, this, attr); if (object != NULL) return object; @@ -532,7 +512,6 @@ const char SCA_JoystickSensor::GetButtonStatus_doc[] = "\tReturns a bool of the current pressed state of the specified button.\n"; PyObject* SCA_JoystickSensor::PyGetButtonStatus( PyObject* self, PyObject* args ) { SCA_Joystick *joy = m_pJoystickMgr->GetJoystickDevice(m_joyindex); - PyObject *value; int index; if(!PyArg_ParseTuple(args, "i", &index)){ @@ -609,3 +588,41 @@ PyObject* SCA_JoystickSensor::PyConnected( PyObject* self ) { SCA_Joystick *joy = m_pJoystickMgr->GetJoystickDevice(m_joyindex); return PyBool_FromLong( joy ? joy->Connected() : 0 ); } + + +PyObject* SCA_JoystickSensor::pyattr_get_axis_position(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + SCA_JoystickSensor* self= static_cast<SCA_JoystickSensor*>(self_v); + SCA_Joystick *joy = self->m_pJoystickMgr->GetJoystickDevice(self->m_joyindex); + + if(joy) return Py_BuildValue("[iiii]", joy->GetAxis10(), joy->GetAxis11(), joy->GetAxis20(), joy->GetAxis21()); + else return Py_BuildValue("[iiii]", 0, 0, 0, 0); +} + +PyObject* SCA_JoystickSensor::pyattr_get_num_axis(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + SCA_JoystickSensor* self= static_cast<SCA_JoystickSensor*>(self_v); + SCA_Joystick *joy = self->m_pJoystickMgr->GetJoystickDevice(self->m_joyindex); + return PyInt_FromLong( joy ? joy->GetNumberOfAxes() : 0 ); +} + +PyObject* SCA_JoystickSensor::pyattr_get_num_buttons(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + SCA_JoystickSensor* self= static_cast<SCA_JoystickSensor*>(self_v); + SCA_Joystick *joy = self->m_pJoystickMgr->GetJoystickDevice(self->m_joyindex); + return PyInt_FromLong( joy ? joy->GetNumberOfButtons() : 0 ); +} + +PyObject* SCA_JoystickSensor::pyattr_get_num_hats(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + SCA_JoystickSensor* self= static_cast<SCA_JoystickSensor*>(self_v); + SCA_Joystick *joy = self->m_pJoystickMgr->GetJoystickDevice(self->m_joyindex); + return PyInt_FromLong( joy ? joy->GetNumberOfHats() : 0 ); +} + +PyObject* SCA_JoystickSensor::pyattr_get_connected(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + SCA_JoystickSensor* self= static_cast<SCA_JoystickSensor*>(self_v); + SCA_Joystick *joy = self->m_pJoystickMgr->GetJoystickDevice(self->m_joyindex); + return PyBool_FromLong( joy ? joy->Connected() : 0 ); +} diff --git a/source/gameengine/GameLogic/SCA_JoystickSensor.h b/source/gameengine/GameLogic/SCA_JoystickSensor.h index ccdd2107b21..f8a3eb8756a 100644 --- a/source/gameengine/GameLogic/SCA_JoystickSensor.h +++ b/source/gameengine/GameLogic/SCA_JoystickSensor.h @@ -148,6 +148,13 @@ public: KX_PYMETHOD_DOC_NOARGS(SCA_JoystickSensor,NumberOfHats); KX_PYMETHOD_DOC_NOARGS(SCA_JoystickSensor,Connected); + static PyObject* pyattr_get_axis_position(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_num_axis(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_num_buttons(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_num_hats(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_connected(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + + /* attribute check */ static int CheckAxis(void *self, const PyAttributeDef*) { diff --git a/source/gameengine/GameLogic/SCA_PythonController.cpp b/source/gameengine/GameLogic/SCA_PythonController.cpp index 2d200e0a238..4b9248a908f 100644 --- a/source/gameengine/GameLogic/SCA_PythonController.cpp +++ b/source/gameengine/GameLogic/SCA_PythonController.cpp @@ -265,6 +265,8 @@ PyMethodDef SCA_PythonController::Methods[] = { }; PyAttributeDef SCA_PythonController::Attributes[] = { + KX_PYATTRIBUTE_RO_FUNCTION("state", SCA_PythonController, pyattr_get_state), + KX_PYATTRIBUTE_RW_FUNCTION("script", SCA_PythonController, pyattr_get_script, pyattr_set_script), { NULL } //Sentinel }; @@ -374,37 +376,19 @@ void SCA_PythonController::Trigger(SCA_LogicManager* logicmgr) PyObject* SCA_PythonController::py_getattro(PyObject *attr) { - char *attr_str= PyString_AsString(attr); - if (!strcmp(attr_str,"state")) { - return PyInt_FromLong(m_statemask); - } - if (!strcmp(attr_str,"script")) { - return PyString_FromString(m_scriptText); - } + PyObject* object = py_getattro_self(Attributes, this, attr); + if (object != NULL) + return object; + py_getattro_up(SCA_IController); } int SCA_PythonController::py_setattro(PyObject *attr, PyObject *value) { - char *attr_str= PyString_AsString(attr); - if (!strcmp(attr_str,"state")) { - PyErr_SetString(PyExc_AttributeError, "state is read only"); - return 1; - } - if (!strcmp(attr_str,"script")) { - char *scriptArg = PyString_AsString(value); - - if (scriptArg==NULL) { - PyErr_SetString(PyExc_TypeError, "expected a string (script name)"); - return -1; - } + int ret = py_setattro_self(Attributes, this, attr, value); + if (ret >= 0) + return ret; - /* 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::py_setattro(attr, value); } @@ -548,4 +532,35 @@ PyObject* SCA_PythonController::PyGetState(PyObject* self) return PyInt_FromLong(m_statemask); } +PyObject* SCA_PythonController::pyattr_get_state(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + SCA_PythonController* self= static_cast<SCA_PythonController*>(self_v); + return PyInt_FromLong(self->m_statemask); +} + +PyObject* SCA_PythonController::pyattr_get_script(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + SCA_PythonController* self= static_cast<SCA_PythonController*>(self_v); + return PyString_FromString(self->m_scriptText); +} + +int SCA_PythonController::pyattr_set_script(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) +{ + SCA_PythonController* self= static_cast<SCA_PythonController*>(self_v); + + 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 */ + self->SetScriptText(scriptArg); + + return 0; +} + + /* eof */ diff --git a/source/gameengine/GameLogic/SCA_PythonController.h b/source/gameengine/GameLogic/SCA_PythonController.h index 3348071c00f..f10c4e47ebb 100644 --- a/source/gameengine/GameLogic/SCA_PythonController.h +++ b/source/gameengine/GameLogic/SCA_PythonController.h @@ -92,6 +92,10 @@ class SCA_PythonController : public SCA_IController KX_PYMETHOD_NOARGS(SCA_PythonController,GetScript); KX_PYMETHOD_NOARGS(SCA_PythonController,GetState); + static PyObject* pyattr_get_state(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_script(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static int pyattr_set_script(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + }; diff --git a/source/gameengine/GameLogic/SCA_RandomSensor.cpp b/source/gameengine/GameLogic/SCA_RandomSensor.cpp index 84a9ef95e84..bdee64430fa 100644 --- a/source/gameengine/GameLogic/SCA_RandomSensor.cpp +++ b/source/gameengine/GameLogic/SCA_RandomSensor.cpp @@ -162,6 +162,7 @@ PyMethodDef SCA_RandomSensor::Methods[] = { PyAttributeDef SCA_RandomSensor::Attributes[] = { KX_PYATTRIBUTE_BOOL_RO("lastDraw",SCA_RandomSensor,m_lastdraw), + KX_PYATTRIBUTE_RW_FUNCTION("seed", SCA_RandomSensor, pyattr_get_seed, pyattr_set_seed), {NULL} //Sentinel }; @@ -169,11 +170,6 @@ PyObject* SCA_RandomSensor::py_getattro(PyObject *attr) { PyObject* object = py_getattro_self(Attributes, this, attr); if (object != NULL) return object; - - char *attr_str= PyString_AsString(attr); - if (!strcmp(attr_str,"seed")) { - return PyInt_FromLong(m_basegenerator->GetSeed()); - } py_getattro_up(SCA_ISensor); } @@ -182,17 +178,6 @@ int SCA_RandomSensor::py_setattro(PyObject *attr, PyObject *value) int ret = py_setattro_self(Attributes, this, attr, value); if (ret >= 0) return ret; - char *attr_str= PyString_AsString(attr); - if (!strcmp(attr_str,"seed")) { - if (PyInt_Check(value)) { - int ival = PyInt_AsLong(value); - m_basegenerator->SetSeed(ival); - return 0; - } else { - PyErr_SetString(PyExc_TypeError, "expected an integer"); - return 1; - } - } return SCA_ISensor::py_setattro(attr, value); } @@ -234,4 +219,22 @@ PyObject* SCA_RandomSensor::PyGetLastDraw(PyObject* self, PyObject* args, PyObje return PyInt_FromLong(m_lastdraw); } + +PyObject* SCA_RandomSensor::pyattr_get_seed(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + SCA_RandomSensor* self= static_cast<SCA_RandomSensor*>(self_v); + return PyInt_FromLong(self->m_basegenerator->GetSeed()); +} + +int SCA_RandomSensor::pyattr_set_seed(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) +{ + SCA_RandomSensor* self= static_cast<SCA_RandomSensor*>(self_v); + if (!PyInt_Check(value)) { + PyErr_SetString(PyExc_TypeError, "expected an integer"); + return -1; + } + self->m_basegenerator->SetSeed(PyInt_AsLong(value)); + return 0; +} + /* eof */ diff --git a/source/gameengine/GameLogic/SCA_RandomSensor.h b/source/gameengine/GameLogic/SCA_RandomSensor.h index 39d072dd316..844552f0b64 100644 --- a/source/gameengine/GameLogic/SCA_RandomSensor.h +++ b/source/gameengine/GameLogic/SCA_RandomSensor.h @@ -69,6 +69,9 @@ public: KX_PYMETHOD_DOC(SCA_RandomSensor,GetSeed); /* 3. getSeed */ KX_PYMETHOD_DOC(SCA_RandomSensor,GetLastDraw); + + static PyObject* pyattr_get_seed(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static int pyattr_set_seed(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); }; diff --git a/source/gameengine/Ketsji/KX_CameraActuator.cpp b/source/gameengine/Ketsji/KX_CameraActuator.cpp index 354143f1e69..526c2dc404b 100644 --- a/source/gameengine/Ketsji/KX_CameraActuator.cpp +++ b/source/gameengine/Ketsji/KX_CameraActuator.cpp @@ -417,19 +417,12 @@ PyAttributeDef KX_CameraActuator::Attributes[] = { KX_PYATTRIBUTE_FLOAT_RW("max",-MAXFLOAT,MAXFLOAT,KX_CameraActuator,m_maxHeight), KX_PYATTRIBUTE_FLOAT_RW("height",-MAXFLOAT,MAXFLOAT,KX_CameraActuator,m_height), KX_PYATTRIBUTE_BOOL_RW("xy",KX_CameraActuator,m_x), - KX_PYATTRIBUTE_DUMMY("object"), + KX_PYATTRIBUTE_RW_FUNCTION("object", KX_CameraActuator, pyattr_get_object, pyattr_set_object), {NULL} }; PyObject* KX_CameraActuator::py_getattro(PyObject *attr) { - PyObject* object; - char *attr_str= PyString_AsString(attr); - if (!strcmp(attr_str, "object")) { - if (!m_ob) Py_RETURN_NONE; - else return m_ob->AddRef(); - } - - object = py_getattro_self(Attributes, this, attr); + PyObject* object = py_getattro_self(Attributes, this, attr); if (object != NULL) return object; py_getattro_up(SCA_IActuator); @@ -437,24 +430,6 @@ PyObject* KX_CameraActuator::py_getattro(PyObject *attr) { int KX_CameraActuator::py_setattro(PyObject *attr, PyObject* value) { int ret; - char *attr_str= PyString_AsString(attr); - if (!strcmp(attr_str, "object")) { - KX_GameObject *gameobj; - - if (!ConvertPythonToGameObject(value, &gameobj, true)) - return 1; // ConvertPythonToGameObject sets the error - - if (m_ob != NULL) - m_ob->UnregisterActuator(this); - - m_ob = (SCA_IObject*)gameobj; - - if (m_ob) - m_ob->RegisterActuator(this); - - return 0; - } - ret = py_setattro_self(Attributes, this, attr, value); if (ret >= 0) return ret; @@ -623,4 +598,30 @@ PyObject* KX_CameraActuator::PyGetXY(PyObject* self, return PyInt_FromLong(m_x); } +PyObject* KX_CameraActuator::pyattr_get_object(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_CameraActuator* self= static_cast<KX_CameraActuator*>(self_v); + if (self->m_ob==NULL) + Py_RETURN_NONE; + else + return self->m_ob->AddRef(); +} + +int KX_CameraActuator::pyattr_set_object(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) +{ + KX_CameraActuator* self= static_cast<KX_CameraActuator*>(self_v); + KX_GameObject *gameobj; + + if (!ConvertPythonToGameObject(value, &gameobj, true)) + return 1; // ConvertPythonToGameObject sets the error + + if (self->m_ob) + self->m_ob->UnregisterActuator(self); + + if (self->m_ob = (SCA_IObject*)gameobj) + self->m_ob->RegisterActuator(self); + + return 0; +} + /* eof */ diff --git a/source/gameengine/Ketsji/KX_CameraActuator.h b/source/gameengine/Ketsji/KX_CameraActuator.h index 5d7473a5bf0..d0aceb89aff 100644 --- a/source/gameengine/Ketsji/KX_CameraActuator.h +++ b/source/gameengine/Ketsji/KX_CameraActuator.h @@ -135,6 +135,9 @@ private : KX_PYMETHOD_DOC(KX_CameraActuator,GetHeight); KX_PYMETHOD_DOC(KX_CameraActuator,SetXY); KX_PYMETHOD_DOC(KX_CameraActuator,GetXY); + + static PyObject* pyattr_get_object(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static int pyattr_set_object(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); }; diff --git a/source/gameengine/Ketsji/KX_TouchSensor.cpp b/source/gameengine/Ketsji/KX_TouchSensor.cpp index 49d3d20dc3d..c22885f3664 100644 --- a/source/gameengine/Ketsji/KX_TouchSensor.cpp +++ b/source/gameengine/Ketsji/KX_TouchSensor.cpp @@ -286,8 +286,8 @@ PyAttributeDef KX_TouchSensor::Attributes[] = { KX_PYATTRIBUTE_STRING_RW("property",0,100,false,KX_TouchSensor,m_touchedpropname), KX_PYATTRIBUTE_BOOL_RW("useMaterial",KX_TouchSensor,m_bFindMaterial), KX_PYATTRIBUTE_BOOL_RW("pulseCollisions",KX_TouchSensor,m_bTouchPulse), - KX_PYATTRIBUTE_DUMMY("objectHit"), - KX_PYATTRIBUTE_DUMMY("objectHitList"), + KX_PYATTRIBUTE_RO_FUNCTION("objectHit", KX_TouchSensor, pyattr_get_object_hit), + KX_PYATTRIBUTE_RO_FUNCTION("objectHitList", KX_TouchSensor, pyattr_get_object_hit_list), { NULL } //Sentinel }; @@ -295,17 +295,7 @@ PyObject* KX_TouchSensor::py_getattro(PyObject *attr) { PyObject* object= py_getattro_self(Attributes, this, attr); if (object != NULL) - return object; - - char *attr_str= PyString_AsString(attr); - if (!strcmp(attr_str, "objectHit")) { - if (m_hitObject) return m_hitObject->AddRef(); - else Py_RETURN_NONE; - } - if (!strcmp(attr_str, "objectHitList")) { - return m_colliders->AddRef(); - } - + return object; py_getattro_up(SCA_ISensor); } @@ -412,4 +402,21 @@ PyObject* KX_TouchSensor::PySetTouchMaterial(PyObject* self, PyObject *value) } #endif +PyObject* KX_TouchSensor::pyattr_get_object_hit(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_TouchSensor* self= static_cast<KX_TouchSensor*>(self_v); + + if (self->m_hitObject) + return self->m_hitObject->AddRef(); + else + Py_RETURN_NONE; +} + +PyObject* KX_TouchSensor::pyattr_get_object_hit_list(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_TouchSensor* self= static_cast<KX_TouchSensor*>(self_v); + return self->m_colliders->AddRef(); +} + + /* eof */ diff --git a/source/gameengine/Ketsji/KX_TouchSensor.h b/source/gameengine/Ketsji/KX_TouchSensor.h index 93fadef4abd..15ef653c1b2 100644 --- a/source/gameengine/Ketsji/KX_TouchSensor.h +++ b/source/gameengine/Ketsji/KX_TouchSensor.h @@ -140,6 +140,10 @@ public: #endif //<----- + static PyObject* pyattr_get_object_hit(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_object_hit_list(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + + }; #endif //__KX_TOUCHSENSOR |