From 10702bf93f14441066ceba3204f932a5ba099c2e Mon Sep 17 00:00:00 2001 From: Benoit Bolsee Date: Fri, 2 Jan 2009 22:09:57 +0000 Subject: BGE API cleanup: more bricks converted to attributes. --- source/gameengine/GameLogic/SCA_ILogicBrick.cpp | 19 ++++++++++++++ source/gameengine/GameLogic/SCA_ILogicBrick.h | 1 + source/gameengine/GameLogic/SCA_RandomSensor.cpp | 32 ++++++++++++++++++++++++ source/gameengine/GameLogic/SCA_RandomSensor.h | 1 + 4 files changed, 53 insertions(+) (limited to 'source/gameengine') diff --git a/source/gameengine/GameLogic/SCA_ILogicBrick.cpp b/source/gameengine/GameLogic/SCA_ILogicBrick.cpp index 37658480c05..8286c0829a7 100644 --- a/source/gameengine/GameLogic/SCA_ILogicBrick.cpp +++ b/source/gameengine/GameLogic/SCA_ILogicBrick.cpp @@ -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); } diff --git a/source/gameengine/GameLogic/SCA_ILogicBrick.h b/source/gameengine/GameLogic/SCA_ILogicBrick.h index 38ec80d4096..772bd65d577 100644 --- a/source/gameengine/GameLogic/SCA_ILogicBrick.h +++ b/source/gameengine/GameLogic/SCA_ILogicBrick.h @@ -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; diff --git a/source/gameengine/GameLogic/SCA_RandomSensor.cpp b/source/gameengine/GameLogic/SCA_RandomSensor.cpp index 202fd6382e6..8fae0bbeaba 100644 --- a/source/gameengine/GameLogic/SCA_RandomSensor.cpp +++ b/source/gameengine/GameLogic/SCA_RandomSensor.cpp @@ -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); } diff --git a/source/gameengine/GameLogic/SCA_RandomSensor.h b/source/gameengine/GameLogic/SCA_RandomSensor.h index d29bfb6837a..009efc32aac 100644 --- a/source/gameengine/GameLogic/SCA_RandomSensor.h +++ b/source/gameengine/GameLogic/SCA_RandomSensor.h @@ -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); -- cgit v1.2.3