BGE API cleanup: more bricks converted to attributes.
authorBenoit Bolsee <benoit.bolsee@online.be>
Fri, 2 Jan 2009 22:09:57 +0000 (22:09 +0000)
committerBenoit Bolsee <benoit.bolsee@online.be>
Fri, 2 Jan 2009 22:09:57 +0000 (22:09 +0000)
source/gameengine/GameLogic/SCA_ILogicBrick.cpp
source/gameengine/GameLogic/SCA_ILogicBrick.h
source/gameengine/GameLogic/SCA_RandomSensor.cpp
source/gameengine/GameLogic/SCA_RandomSensor.h

index 37658480c0569572acf74b517d3d9ba7f4fabc6b..8286c0829a7e7e9bc801d92373ce7cbcd2ae0b5e 100644 (file)
@@ -247,11 +247,18 @@ PyParentObject SCA_ILogicBrick::Parents[] = {
 
 PyMethodDef SCA_ILogicBrick::Methods[] = {
   {"getOwner", (PyCFunction) SCA_ILogicBrick::sPyGetOwner, METH_NOARGS},
+  // --> Deprecated
   {"getExecutePriority", (PyCFunction) SCA_ILogicBrick::sPyGetExecutePriority, METH_NOARGS},
   {"setExecutePriority", (PyCFunction) SCA_ILogicBrick::sPySetExecutePriority, METH_VARARGS},
+  // <-- Deprecated
   {NULL,NULL} //Sentinel
 };
 
+PyAttributeDef SCA_ILogicBrick::Attributes[] = {
+       KX_PYATTRIBUTE_INT_RW("executePriority",0,100000,false,SCA_ILogicBrick,m_Execute_Ueber_Priority),
+       {NULL} //Sentinel
+};
+
 int SCA_ILogicBrick::CheckProperty(void *self, const PyAttributeDef *attrdef)
 {
        if (attrdef->m_type != KX_PYATTRIBUTE_TYPE_STRING || attrdef->m_length != 1) {
@@ -273,9 +280,19 @@ int SCA_ILogicBrick::CheckProperty(void *self, const PyAttributeDef *attrdef)
 PyObject*
 SCA_ILogicBrick::_getattr(const STR_String& attr)
 {
+       PyObject* object = _getattr_self(Attributes, this, attr);
+       if (object != NULL)
+               return object;
   _getattr_up(CValue);
 }
 
+int SCA_ILogicBrick::_setattr(const STR_String& attr, PyObject *value)
+{
+       int ret = _setattr_self(Attributes, this, attr, value);
+       if (ret >= 0)
+               return ret;
+       return CValue::_setattr(attr, value);
+}
 
 
 PyObject* SCA_ILogicBrick::PyGetOwner(PyObject* self)
@@ -297,6 +314,7 @@ PyObject* SCA_ILogicBrick::PySetExecutePriority(PyObject* self,
                               PyObject* args, 
                               PyObject* kwds)
 {
+       ShowDeprecationWarning("setExecutePriority()", "the executePriority property");
 
        int priority=0;
 
@@ -313,6 +331,7 @@ PyObject* SCA_ILogicBrick::PySetExecutePriority(PyObject* self,
 
 PyObject* SCA_ILogicBrick::PyGetExecutePriority(PyObject* self)
 {
+       ShowDeprecationWarning("getExecutePriority()", "the executePriority property");
        return PyInt_FromLong(m_Execute_Ueber_Priority);
 }
 
index 38ec80d4096536d33a29919d25b51025ca228460..772bd65d57728dd4a5a2eb054e8ba01140454f22 100644 (file)
@@ -79,6 +79,7 @@ public:
        virtual bool            LessComparedTo(SCA_ILogicBrick* other);
        
        virtual PyObject* _getattr(const STR_String& attr);
+       virtual int _setattr(const STR_String& attr, PyObject *value);
 
        static class SCA_LogicManager*  m_sCurrentLogicManager;
 
index 202fd6382e6698c8fe3a73f366ae79d0f86f13b1..8fae0bbeaba6d9c26029246d0f1ac5d06c9a9e8a 100644 (file)
@@ -160,10 +160,39 @@ PyMethodDef SCA_RandomSensor::Methods[] = {
        {NULL,NULL} //Sentinel
 };
 
+PyAttributeDef SCA_RandomSensor::Attributes[] = {
+       KX_PYATTRIBUTE_BOOL_RO("lastDraw",SCA_RandomSensor,m_lastdraw),
+       {NULL} //Sentinel
+};
+
 PyObject* SCA_RandomSensor::_getattr(const STR_String& attr) {
+       PyObject* object = _getattr_self(Attributes, this, attr);
+       if (object != NULL)
+               return object;
+       if (attr == "seed") {
+               return PyInt_FromLong(m_basegenerator->GetSeed());
+       }
        _getattr_up(SCA_ISensor);
 }
 
+int SCA_RandomSensor::_setattr(const STR_String& attr, PyObject *value)
+{
+       int ret = _setattr_self(Attributes, this, attr, value);
+       if (ret >= 0)
+               return ret;
+       if (attr == "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::_setattr(attr, value);
+}
+
 /* 1. setSeed                                                            */
 const char SCA_RandomSensor::SetSeed_doc[] = 
 "setSeed(seed)\n"
@@ -172,6 +201,7 @@ const char SCA_RandomSensor::SetSeed_doc[] =
 "\tequal series. If the seed is 0, the generator will produce\n"
 "\tthe same value on every call.\n";
 PyObject* SCA_RandomSensor::PySetSeed(PyObject* self, PyObject* args, PyObject* kwds) {
+       ShowDeprecationWarning("setSeed()", "the seed property");
        long seedArg;
        if(!PyArg_ParseTuple(args, "i", &seedArg)) {
                return NULL;
@@ -188,6 +218,7 @@ const char SCA_RandomSensor::GetSeed_doc[] =
 "\tReturns the initial seed of the generator. Equal seeds produce\n"
 "\tequal series.\n";
 PyObject* SCA_RandomSensor::PyGetSeed(PyObject* self, PyObject* args, PyObject* kwds) {
+       ShowDeprecationWarning("getSeed()", "the seed property");
        return PyInt_FromLong(m_basegenerator->GetSeed());
 }
 
@@ -196,6 +227,7 @@ const char SCA_RandomSensor::GetLastDraw_doc[] =
 "getLastDraw()\n"
 "\tReturn the last value that was drawn.\n";
 PyObject* SCA_RandomSensor::PyGetLastDraw(PyObject* self, PyObject* args, PyObject* kwds) {
+       ShowDeprecationWarning("getLastDraw()", "the lastDraw property");
        return PyInt_FromLong(m_lastdraw);
 }
 
index d29bfb6837a69e798ef3e7fd7376fd36e28716e6..009efc32aacaf77ab833109453789a5276943f4b 100644 (file)
@@ -61,6 +61,7 @@ public:
        /* --------------------------------------------------------------------- */
 
        virtual PyObject* _getattr(const STR_String& attr);
+       virtual int _setattr(const STR_String& attr, PyObject *value);
 
        /* 1. setSeed                                                            */
        KX_PYMETHOD_DOC(SCA_RandomSensor,SetSeed);