moved more attributes from getattr into PyAttributeDef's
authorCampbell Barton <ideasman42@gmail.com>
Sat, 4 Apr 2009 02:57:35 +0000 (02:57 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sat, 4 Apr 2009 02:57:35 +0000 (02:57 +0000)
16 files changed:
source/gameengine/Converter/BL_ActionActuator.cpp
source/gameengine/Converter/BL_ActionActuator.h
source/gameengine/Converter/BL_ShapeActionActuator.cpp
source/gameengine/Converter/BL_ShapeActionActuator.h
source/gameengine/GameLogic/SCA_ISensor.cpp
source/gameengine/GameLogic/SCA_ISensor.h
source/gameengine/GameLogic/SCA_JoystickSensor.cpp
source/gameengine/GameLogic/SCA_JoystickSensor.h
source/gameengine/GameLogic/SCA_PythonController.cpp
source/gameengine/GameLogic/SCA_PythonController.h
source/gameengine/GameLogic/SCA_RandomSensor.cpp
source/gameengine/GameLogic/SCA_RandomSensor.h
source/gameengine/Ketsji/KX_CameraActuator.cpp
source/gameengine/Ketsji/KX_CameraActuator.h
source/gameengine/Ketsji/KX_TouchSensor.cpp
source/gameengine/Ketsji/KX_TouchSensor.h

index 943bb68f6f28c16c298cf306671ee3d58644a0bf..b7a961d6a9d3b7909f05f60a3fd3dd97ee3f3849 100644 (file)
@@ -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;
+
+}
index 7160dd4dad0a9cc82acb56a823ab9cead0bcfe3d..d5b5762d9e71070dda896eaac996945224aa1988 100644 (file)
@@ -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);
index c53be4653ca1ef0f96d060b6559b3f2fcce9e486..3c0ce0918f273ffa6a030dc8697a4f0f00d83215 100644 (file)
@@ -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;
+
+}
index ea25d66e0503ae2b8a2e90b2ef2be9e1a2cb317c..162580fca85f8cb7e697e866f3dda687164ceaec 100644 (file)
@@ -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);
index 8a40c0c35f3a99ecbfc10a73630df5c347f4a485..a4f493d82c851456e4c1bdf47380de7a810583e8 100644 (file)
@@ -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 */
index ce7b66df1cda4b8c81df235dd1adee16e189bde3..cfc956820897ad3f75b4571d9c5f3082bc6c9330 100644 (file)
@@ -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
index 0cfd6843c1b965e438cd01e520a1c31ea947f69d..2744d7f66095dd29fbbfe18dbd8e19c82c0c8b93 100644 (file)
@@ -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 );
+}
index ccdd2107b218e5028753559a4a40a2ce876b7d4f..f8a3eb8756aecee2d9b3d8fa2e6d74b4744f9b05 100644 (file)
@@ -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*)
        {
index 2d200e0a2380adb5f24777843509d8b3c0af199e..4b9248a908fd7ac3f4a569c4ccae752b3da68bbd 100644 (file)
@@ -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 */
index 3348071c00fdd12d64828c569b675a06f598bdb8..f10c4e47ebb0f194c3711a5388295345092efa7b 100644 (file)
@@ -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);
+       
 
 };
 
index 84a9ef95e843333a708edb95d6b87978a79326eb..bdee64430fac75140af74e97352db81b2bac7217 100644 (file)
@@ -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 */
index 39d072dd3161758d91452fb35eb3efcfbb203f3c..844552f0b64cff110381b0e60c02cc57027a5ae3 100644 (file)
@@ -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);
 
 };
 
index 354143f1e69fd63d6d09a823a77510325713c7f3..526c2dc404b2df4854ad0dbeb9f6fab592af567c 100644 (file)
@@ -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 */
index 5d7473a5bf08b256920cb75f8086dda44f4f153b..d0aceb89aff976cbec459b651e7f17bcaed18ebb 100644 (file)
@@ -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);
 
 };
 
index 49d3d20dc3d43d90e4803a3ec34eb56e1cda88f4..c22885f36649c092e33dc6a3a3971d72e10950f8 100644 (file)
@@ -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 */
index 93fadef4abd116c0948cb35919e8e03849ca6b6a..15ef653c1b25e6cceab986104bf0f90604fec316 100644 (file)
@@ -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