Revision: 18270
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=18270
Author:   ben2610
Date:     2009-01-02 23:09:57 +0100 (Fri, 02 Jan 2009)

Log Message:
-----------
BGE API cleanup: more bricks converted to attributes.

Modified Paths:
--------------
    trunk/blender/source/gameengine/GameLogic/SCA_ILogicBrick.cpp
    trunk/blender/source/gameengine/GameLogic/SCA_ILogicBrick.h
    trunk/blender/source/gameengine/GameLogic/SCA_RandomSensor.cpp
    trunk/blender/source/gameengine/GameLogic/SCA_RandomSensor.h

Modified: trunk/blender/source/gameengine/GameLogic/SCA_ILogicBrick.cpp
===================================================================
--- trunk/blender/source/gameengine/GameLogic/SCA_ILogicBrick.cpp       
2009-01-02 19:22:43 UTC (rev 18269)
+++ trunk/blender/source/gameengine/GameLogic/SCA_ILogicBrick.cpp       
2009-01-02 22:09:57 UTC (rev 18270)
@@ -247,11 +247,18 @@
 
 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 @@
 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* args, 
                               PyObject* kwds)
 {
+       ShowDeprecationWarning("setExecutePriority()", "the executePriority 
property");
 
        int priority=0;
 
@@ -313,6 +331,7 @@
 
 PyObject* SCA_ILogicBrick::PyGetExecutePriority(PyObject* self)
 {
+       ShowDeprecationWarning("getExecutePriority()", "the executePriority 
property");
        return PyInt_FromLong(m_Execute_Ueber_Priority);
 }
 

Modified: trunk/blender/source/gameengine/GameLogic/SCA_ILogicBrick.h
===================================================================
--- trunk/blender/source/gameengine/GameLogic/SCA_ILogicBrick.h 2009-01-02 
19:22:43 UTC (rev 18269)
+++ trunk/blender/source/gameengine/GameLogic/SCA_ILogicBrick.h 2009-01-02 
22:09:57 UTC (rev 18270)
@@ -79,6 +79,7 @@
        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;
 

Modified: trunk/blender/source/gameengine/GameLogic/SCA_RandomSensor.cpp
===================================================================
--- trunk/blender/source/gameengine/GameLogic/SCA_RandomSensor.cpp      
2009-01-02 19:22:43 UTC (rev 18269)
+++ trunk/blender/source/gameengine/GameLogic/SCA_RandomSensor.cpp      
2009-01-02 22:09:57 UTC (rev 18270)
@@ -160,10 +160,39 @@
        {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 @@
 "\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 @@
 "\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 @@
 "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);
 }
 

Modified: trunk/blender/source/gameengine/GameLogic/SCA_RandomSensor.h
===================================================================
--- trunk/blender/source/gameengine/GameLogic/SCA_RandomSensor.h        
2009-01-02 19:22:43 UTC (rev 18269)
+++ trunk/blender/source/gameengine/GameLogic/SCA_RandomSensor.h        
2009-01-02 22:09:57 UTC (rev 18270)
@@ -61,6 +61,7 @@
        /* 
--------------------------------------------------------------------- */
 
        virtual PyObject* _getattr(const STR_String& attr);
+       virtual int _setattr(const STR_String& attr, PyObject *value);
 
        /* 1. setSeed                                                           
 */
        KX_PYMETHOD_DOC(SCA_RandomSensor,SetSeed);


_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to