[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [18152] trunk/blender/source/gameengine: First batch of GE API cleanup.
Benoit Bolsee
benoit.bolsee at online.be
Mon Dec 29 17:36:58 CET 2008
Revision: 18152
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=18152
Author: ben2610
Date: 2008-12-29 17:36:58 +0100 (Mon, 29 Dec 2008)
Log Message:
-----------
First batch of GE API cleanup.
The principle is to replace most get/set methods of logic bricks by direct property access.
To make porting of game code easier, the properties have usually the same type and use than
the return values/parameters of the get/set methods.
More details on http://wiki.blender.org/index.php/GameEngineDev/Python_API_Clean_Up
Old methods are still available but will produce deprecation warnings on the console:
"<method> is deprecated, use the <property> property instead"
You can avoid these messages by turning on the "Ignore deprecation warnings" option in Game menu.
PyDoc is updated to include the new properties and display a deprecation warning
for the get/set methods that are being deprecated.
Modified Paths:
--------------
trunk/blender/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
trunk/blender/source/gameengine/Expressions/PyObjectPlus.h
trunk/blender/source/gameengine/Expressions/Value.cpp
trunk/blender/source/gameengine/Expressions/Value.h
trunk/blender/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp
trunk/blender/source/gameengine/GameLogic/SCA_ActuatorSensor.h
trunk/blender/source/gameengine/GameLogic/SCA_DelaySensor.cpp
trunk/blender/source/gameengine/GameLogic/SCA_DelaySensor.h
trunk/blender/source/gameengine/GameLogic/SCA_ISensor.cpp
trunk/blender/source/gameengine/GameLogic/SCA_ISensor.h
trunk/blender/source/gameengine/GameLogic/SCA_JoystickSensor.cpp
trunk/blender/source/gameengine/GameLogic/SCA_JoystickSensor.h
trunk/blender/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp
trunk/blender/source/gameengine/GameLogic/SCA_KeyboardSensor.h
trunk/blender/source/gameengine/GameLogic/SCA_MouseSensor.cpp
trunk/blender/source/gameengine/GameLogic/SCA_MouseSensor.h
trunk/blender/source/gameengine/GameLogic/SCA_PropertyActuator.cpp
trunk/blender/source/gameengine/GameLogic/SCA_PropertyActuator.h
trunk/blender/source/gameengine/GameLogic/SCA_PropertySensor.cpp
trunk/blender/source/gameengine/GameLogic/SCA_PropertySensor.h
trunk/blender/source/gameengine/GameLogic/SCA_PythonController.cpp
trunk/blender/source/gameengine/GameLogic/SCA_PythonController.h
trunk/blender/source/gameengine/GameLogic/SCA_RandomActuator.cpp
trunk/blender/source/gameengine/GameLogic/SCA_RandomActuator.h
trunk/blender/source/gameengine/GamePlayer/ghost/GPG_Application.cpp
trunk/blender/source/gameengine/Ketsji/KX_PolyProxy.cpp
trunk/blender/source/gameengine/PyDoc/KX_ActuatorSensor.py
trunk/blender/source/gameengine/PyDoc/SCA_DelaySensor.py
trunk/blender/source/gameengine/PyDoc/SCA_ILogicBrick.py
trunk/blender/source/gameengine/PyDoc/SCA_ISensor.py
trunk/blender/source/gameengine/PyDoc/SCA_JoystickSensor.py
trunk/blender/source/gameengine/PyDoc/SCA_KeyboardSensor.py
trunk/blender/source/gameengine/PyDoc/SCA_MouseSensor.py
trunk/blender/source/gameengine/PyDoc/SCA_PropertyActuator.py
trunk/blender/source/gameengine/PyDoc/SCA_PropertySensor.py
trunk/blender/source/gameengine/PyDoc/SCA_PythonController.py
trunk/blender/source/gameengine/PyDoc/SCA_RandomActuator.py
Modified: trunk/blender/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
===================================================================
--- trunk/blender/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp 2008-12-29 14:26:36 UTC (rev 18151)
+++ trunk/blender/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp 2008-12-29 16:36:58 UTC (rev 18152)
@@ -81,6 +81,7 @@
/***/
#include "GPU_extensions.h"
+#include "Value.h"
#ifdef __cplusplus
extern "C" {
@@ -139,6 +140,7 @@
bool frameRate = (SYS_GetCommandLineInt(syshandle, "show_framerate", 0) != 0);
bool game2ipo = (SYS_GetCommandLineInt(syshandle, "game2ipo", 0) != 0);
bool displaylists = (SYS_GetCommandLineInt(syshandle, "displaylists", 0) != 0);
+ bool nodepwarnings = (SYS_GetCommandLineInt(syshandle, "ignore_deprecation_warnings", 0) != 0);
// create the canvas, rasterizer and rendertools
RAS_ICanvas* canvas = new KX_BlenderCanvas(area);
@@ -195,7 +197,9 @@
ketsjiengine->SetUseFixedTime(usefixed);
ketsjiengine->SetTimingDisplay(frameRate, profile, properties);
+ CValue::SetDeprecationWarnings(nodepwarnings);
+
//lock frame and camera enabled - storing global values
int tmp_lay= G.scene->lay;
Object *tmp_camera = G.scene->camera;
Modified: trunk/blender/source/gameengine/Expressions/PyObjectPlus.h
===================================================================
--- trunk/blender/source/gameengine/Expressions/PyObjectPlus.h 2008-12-29 14:26:36 UTC (rev 18151)
+++ trunk/blender/source/gameengine/Expressions/PyObjectPlus.h 2008-12-29 16:36:58 UTC (rev 18152)
@@ -185,7 +185,10 @@
#define KX_PYMETHODTABLE(class_name, method_name) \
{#method_name , (PyCFunction) class_name::sPy##method_name, METH_VARARGS, (PY_METHODCHAR)class_name::method_name##_doc}
-#define KX_PYMETHODTABLE_NOARG(class_name, method_name) \
+#define KX_PYMETHODTABLE_O(class_name, method_name) \
+ {#method_name , (PyCFunction) class_name::sPy##method_name, METH_O, (PY_METHODCHAR)class_name::method_name##_doc}
+
+#define KX_PYMETHODTABLE_NOARGS(class_name, method_name) \
{#method_name , (PyCFunction) class_name::sPy##method_name, METH_NOARGS, (PY_METHODCHAR)class_name::method_name##_doc}
/**
@@ -195,8 +198,16 @@
const char class_name::method_name##_doc[] = doc_string; \
PyObject* class_name::Py##method_name(PyObject*, PyObject* args, PyObject*)
-#define KX_PYMETHODDEF_DOC_NOARG(class_name, method_name, doc_string) \
+#define KX_PYMETHODDEF_DOC_VARARGS(class_name, method_name, doc_string) \
const char class_name::method_name##_doc[] = doc_string; \
+PyObject* class_name::Py##method_name(PyObject*, PyObject* args)
+
+#define KX_PYMETHODDEF_DOC_O(class_name, method_name, doc_string) \
+const char class_name::method_name##_doc[] = doc_string; \
+PyObject* class_name::Py##method_name(PyObject*, PyObject* value)
+
+#define KX_PYMETHODDEF_DOC_NOARGS(class_name, method_name, doc_string) \
+const char class_name::method_name##_doc[] = doc_string; \
PyObject* class_name::Py##method_name(PyObject*)
/*------------------------------
Modified: trunk/blender/source/gameengine/Expressions/Value.cpp
===================================================================
--- trunk/blender/source/gameengine/Expressions/Value.cpp 2008-12-29 14:26:36 UTC (rev 18151)
+++ trunk/blender/source/gameengine/Expressions/Value.cpp 2008-12-29 16:36:58 UTC (rev 18152)
@@ -32,6 +32,7 @@
//////////////////////////////////////////////////////////////////////
double CValue::m_sZeroVec[3] = {0.0,0.0,0.0};
+bool CValue::m_ignore_deprecation_warnings(false);
#ifndef NO_EXP_PYTHON_EMBEDDING
@@ -849,4 +850,15 @@
}
///////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////
+/* deprecation warning management */
+void CValue::SetDeprecationWarnings(bool ignoreDeprecationWarnings)
+{
+ m_ignore_deprecation_warnings = ignoreDeprecationWarnings;
+}
+void CValue::ShowDeprecationWarning(const char* old_way,const char* new_way)
+{
+ if (!m_ignore_deprecation_warnings)
+ printf("Method %s is deprecated, please use %s instead.\n", old_way, new_way);
+}
+
Modified: trunk/blender/source/gameengine/Expressions/Value.h
===================================================================
--- trunk/blender/source/gameengine/Expressions/Value.h 2008-12-29 14:26:36 UTC (rev 18151)
+++ trunk/blender/source/gameengine/Expressions/Value.h 2008-12-29 16:36:58 UTC (rev 18152)
@@ -318,6 +318,10 @@
STR_String op2str(VALUE_OPERATOR op);
+ /** enable/disable display of deprecation warnings */
+ static void SetDeprecationWarnings(bool ignoreDeprecationWarnings);
+ /** Shows a deprecation warning */
+ static void ShowDeprecationWarning(const char* method,const char* prop);
// setting / getting flags
inline void SetSelected(bool bSelected) { m_ValFlags.Selected = bSelected; }
@@ -349,6 +353,7 @@
ValueFlags m_ValFlags; // Frequently used flags in a bitfield (low memoryusage)
int m_refcount; // Reference Counter
static double m_sZeroVec[3];
+ static bool m_ignore_deprecation_warnings;
};
Modified: trunk/blender/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp
===================================================================
--- trunk/blender/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp 2008-12-29 14:26:36 UTC (rev 18151)
+++ trunk/blender/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp 2008-12-29 16:36:58 UTC (rev 18152)
@@ -149,21 +149,44 @@
};
PyMethodDef SCA_ActuatorSensor::Methods[] = {
+ //Deprecated functions ------>
{"getActuator", (PyCFunction) SCA_ActuatorSensor::sPyGetActuator, METH_NOARGS, (PY_METHODCHAR)GetActuator_doc},
{"setActuator", (PyCFunction) SCA_ActuatorSensor::sPySetActuator, METH_VARARGS, (PY_METHODCHAR)SetActuator_doc},
+ //<----- Deprecated
{NULL,NULL} //Sentinel
};
PyObject* SCA_ActuatorSensor::_getattr(const STR_String& attr) {
+ if (attr == "actuator") {
+ return PyString_FromString(m_checkactname);
+ }
_getattr_up(SCA_ISensor); /* implicit return! */
}
+int SCA_ActuatorSensor::_setattr(const STR_String& attr, PyObject *value) {
+ if (PyString_Check(value)) {
+ char* sval = PyString_AsString(value);
+ if (attr == "actuator") {
+ SCA_IActuator* act = GetParent()->FindActuator(STR_String(sval));
+ if (act) {
+ m_checkactname = sval;
+ m_actuator = act;
+ return 0;
+ }
+ PyErr_SetString(PyExc_AttributeError, "string does not correspond to an actuator");
+ return 1;
+ }
+ }
+ return SCA_ISensor::_setattr(attr, value);
+}
+
/* 3. getActuator */
const char SCA_ActuatorSensor::GetActuator_doc[] =
"getActuator()\n"
"\tReturn the Actuator with which the sensor operates.\n";
PyObject* SCA_ActuatorSensor::PyGetActuator(PyObject* self)
{
+ ShowDeprecationWarning("getActuator()", "the actuator property");
return PyString_FromString(m_checkactname);
}
@@ -175,6 +198,7 @@
"\tof this name, the call is ignored.\n";
PyObject* SCA_ActuatorSensor::PySetActuator(PyObject* self, PyObject* args, PyObject* kwds)
{
+ ShowDeprecationWarning("setActuator()", "the actuator property");
/* We should query whether the name exists. Or should we create a prop */
/* on the fly? */
char *actNameArg = NULL;
Modified: trunk/blender/source/gameengine/GameLogic/SCA_ActuatorSensor.h
===================================================================
--- trunk/blender/source/gameengine/GameLogic/SCA_ActuatorSensor.h 2008-12-29 14:26:36 UTC (rev 18151)
+++ trunk/blender/source/gameengine/GameLogic/SCA_ActuatorSensor.h 2008-12-29 16:36:58 UTC (rev 18152)
@@ -62,6 +62,7 @@
/* --------------------------------------------------------------------- */
virtual PyObject* _getattr(const STR_String& attr);
+ virtual int _setattr(const STR_String& attr, PyObject *value);
/* 3. setProperty */
KX_PYMETHOD_DOC(SCA_ActuatorSensor,SetActuator);
Modified: trunk/blender/source/gameengine/GameLogic/SCA_DelaySensor.cpp
===================================================================
--- trunk/blender/source/gameengine/GameLogic/SCA_DelaySensor.cpp 2008-12-29 14:26:36 UTC (rev 18151)
+++ trunk/blender/source/gameengine/GameLogic/SCA_DelaySensor.cpp 2008-12-29 16:36:58 UTC (rev 18152)
@@ -158,6 +158,7 @@
};
PyMethodDef SCA_DelaySensor::Methods[] = {
+ //Deprecated functions ------>
/* setProperty */
{"setDelay", (PyCFunction) SCA_DelaySensor::sPySetDelay, METH_VARARGS, (PY_METHODCHAR)SetDelay_doc},
{"setDuration", (PyCFunction) SCA_DelaySensor::sPySetDuration, METH_VARARGS, (PY_METHODCHAR)SetDuration_doc},
@@ -166,13 +167,51 @@
{"getDelay", (PyCFunction) SCA_DelaySensor::sPyGetDelay, METH_NOARGS, (PY_METHODCHAR)GetDelay_doc},
{"getDuration", (PyCFunction) SCA_DelaySensor::sPyGetDuration, METH_NOARGS, (PY_METHODCHAR)GetDuration_doc},
{"getRepeat", (PyCFunction) SCA_DelaySensor::sPyGetRepeat, METH_NOARGS, (PY_METHODCHAR)GetRepeat_doc},
+ //<----- Deprecated
{NULL,NULL} //Sentinel
};
PyObject* SCA_DelaySensor::_getattr(const STR_String& attr) {
+ if (attr == "delay") {
+ return PyInt_FromLong(m_delay);
+ }
+ if (attr == "duration") {
+ return PyInt_FromLong(m_duration);
+ }
+ if (attr == "repeat") {
+ return PyInt_FromLong(m_repeat);
+ }
_getattr_up(SCA_ISensor);
}
+int SCA_DelaySensor::_setattr(const STR_String& attr, PyObject *value) {
+ if (PyInt_Check(value)) {
+ int ival = PyInt_AsLong(value);
+ if (attr == "delay") {
+ if (ival < 0) {
+ PyErr_SetString(PyExc_ValueError, "Delay cannot be negative");
+ return 1;
+ }
+ m_delay = ival;
+ return 0;
+ }
+ if (attr == "duration") {
+ if (ival < 0) {
+ PyErr_SetString(PyExc_ValueError, "Duration cannot be negative");
+ return 1;
+ }
+ m_duration = ival;
+ return 0;
+ }
+ if (attr == "repeat") {
+ m_repeat = (ival != 0);
+ return 0;
+ }
+ }
+ return SCA_ISensor::_setattr(attr, value);
+}
+
+
const char SCA_DelaySensor::SetDelay_doc[] =
"setDelay(delay)\n"
"\t- delay: length of the initial OFF period as number of frame\n"
@@ -180,6 +219,7 @@
"\tSet the initial delay before the positive trigger\n";
PyObject* SCA_DelaySensor::PySetDelay(PyObject* self, PyObject* args, PyObject* kwds)
{
+ ShowDeprecationWarning("setDelay()", "the delay property");
int delay;
if(!PyArg_ParseTuple(args, "i", &delay)) {
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list