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.
This commit is contained in:
2008-12-29 16:36:58 +00:00
parent d91daaa5f6
commit 1c663bbc7e
37 changed files with 1184 additions and 249 deletions

View File

@@ -339,6 +339,7 @@ PyParentObject SCA_RandomActuator::Parents[] = {
};
PyMethodDef SCA_RandomActuator::Methods[] = {
//Deprecated functions ------>
{"setSeed", (PyCFunction) SCA_RandomActuator::sPySetSeed, METH_VARARGS, (PY_METHODCHAR)SetSeed_doc},
{"getSeed", (PyCFunction) SCA_RandomActuator::sPyGetSeed, METH_VARARGS, (PY_METHODCHAR)GetSeed_doc},
{"getPara1", (PyCFunction) SCA_RandomActuator::sPyGetPara1, METH_VARARGS, (PY_METHODCHAR)GetPara1_doc},
@@ -346,6 +347,7 @@ PyMethodDef SCA_RandomActuator::Methods[] = {
{"getDistribution", (PyCFunction) SCA_RandomActuator::sPyGetDistribution, METH_VARARGS, (PY_METHODCHAR)GetDistribution_doc},
{"setProperty", (PyCFunction) SCA_RandomActuator::sPySetProperty, METH_VARARGS, (PY_METHODCHAR)SetProperty_doc},
{"getProperty", (PyCFunction) SCA_RandomActuator::sPyGetProperty, METH_VARARGS, (PY_METHODCHAR)GetProperty_doc},
//<----- Deprecated
{"setBoolConst", (PyCFunction) SCA_RandomActuator::sPySetBoolConst, METH_VARARGS, (PY_METHODCHAR)SetBoolConst_doc},
{"setBoolUniform", (PyCFunction) SCA_RandomActuator::sPySetBoolUniform, METH_VARARGS, (PY_METHODCHAR)SetBoolUniform_doc},
{"setBoolBernouilli",(PyCFunction) SCA_RandomActuator::sPySetBoolBernouilli, METH_VARARGS, (PY_METHODCHAR)SetBoolBernouilli_doc},
@@ -360,9 +362,60 @@ PyMethodDef SCA_RandomActuator::Methods[] = {
};
PyObject* SCA_RandomActuator::_getattr(const STR_String& attr) {
if (attr == "seed") {
return PyInt_FromLong(m_base->GetSeed());
}
if (attr == "para1") {
return PyFloat_FromDouble(m_parameter1);
}
if (attr == "para2") {
return PyFloat_FromDouble(m_parameter2);
}
if (attr == "distribution") {
return PyInt_FromLong(m_distribution);
}
if (attr == "property") {
return PyString_FromString(m_propname);
}
_getattr_up(SCA_IActuator);
}
int SCA_RandomActuator::_setattr(const STR_String& attr, PyObject *value)
{
if (attr == "para1") {
PyErr_SetString(PyExc_AttributeError, "para1 is read only");
}
if (attr == "para2") {
PyErr_SetString(PyExc_AttributeError, "para2 is read only");
}
if (attr == "distribution") {
PyErr_SetString(PyExc_AttributeError, "distribution is read only");
}
if (PyInt_Check(value)) {
int ival = PyInt_AsLong(value);
if (attr == "seed") {
m_base->SetSeed(ival);
}
return 0;
}
if (PyString_Check(value)) {
char* sval = PyString_AsString(value);
if (attr == "property") {
CValue* prop = GetParent()->FindIdentifier(sval);
bool error = prop->IsError();
prop->Release();
if (!prop->IsError()) {
m_propname = sval;
return 0;
} else {
PyErr_SetString(PyExc_ValueError, "string does not correspond to a property");
return 1;
}
}
}
return SCA_IActuator::_setattr(attr, value);
}
/* 1. setSeed */
const char SCA_RandomActuator::SetSeed_doc[] =
"setSeed(seed)\n"
@@ -371,6 +424,7 @@ const char SCA_RandomActuator::SetSeed_doc[] =
"\tequal series. If the seed is 0, the generator will produce\n"
"\tthe same value on every call.\n";
PyObject* SCA_RandomActuator::PySetSeed(PyObject* self, PyObject* args, PyObject* kwds) {
ShowDeprecationWarning("setSeed()", "the seed property");
long seedArg;
if(!PyArg_ParseTuple(args, "i", &seedArg)) {
return NULL;
@@ -386,6 +440,7 @@ const char SCA_RandomActuator::GetSeed_doc[] =
"\tReturns the initial seed of the generator. Equal seeds produce\n"
"\tequal series.\n";
PyObject* SCA_RandomActuator::PyGetSeed(PyObject* self, PyObject* args, PyObject* kwds) {
ShowDeprecationWarning("getSeed()", "the seed property");
return PyInt_FromLong(m_base->GetSeed());
}
@@ -396,6 +451,7 @@ const char SCA_RandomActuator::GetPara1_doc[] =
"\tto the documentation of the generator types for the meaning\n"
"\tof this value.";
PyObject* SCA_RandomActuator::PyGetPara1(PyObject* self, PyObject* args, PyObject* kwds) {
ShowDeprecationWarning("getPara1()", "the para1 property");
return PyFloat_FromDouble(m_parameter1);
}
@@ -406,6 +462,7 @@ const char SCA_RandomActuator::GetPara2_doc[] =
"\tto the documentation of the generator types for the meaning\n"
"\tof this value.";
PyObject* SCA_RandomActuator::PyGetPara2(PyObject* self, PyObject* args, PyObject* kwds) {
ShowDeprecationWarning("getPara2()", "the para2 property");
return PyFloat_FromDouble(m_parameter2);
}
@@ -414,6 +471,7 @@ const char SCA_RandomActuator::GetDistribution_doc[] =
"getDistribution()\n"
"\tReturns the type of the active distribution.\n";
PyObject* SCA_RandomActuator::PyGetDistribution(PyObject* self, PyObject* args, PyObject* kwds) {
ShowDeprecationWarning("getDistribution()", "the distribution property");
return PyInt_FromLong(m_distribution);
}
@@ -424,6 +482,7 @@ const char SCA_RandomActuator::SetProperty_doc[] =
"\tSet the property to which the random value is assigned. If the \n"
"\tgenerator and property types do not match, the assignment is ignored.\n";
PyObject* SCA_RandomActuator::PySetProperty(PyObject* self, PyObject* args, PyObject* kwds) {
ShowDeprecationWarning("setProperty()", "the 'property' property");
char *nameArg;
if (!PyArg_ParseTuple(args, "s", &nameArg)) {
return NULL;
@@ -446,6 +505,7 @@ const char SCA_RandomActuator::GetProperty_doc[] =
"\tReturn the property to which the random value is assigned. If the \n"
"\tgenerator and property types do not match, the assignment is ignored.\n";
PyObject* SCA_RandomActuator::PyGetProperty(PyObject* self, PyObject* args, PyObject* kwds) {
ShowDeprecationWarning("getProperty()", "the 'property' property");
return PyString_FromString(m_propname);
}
@@ -463,9 +523,7 @@ PyObject* SCA_RandomActuator::PySetBoolConst(PyObject* self,
}
m_distribution = KX_RANDOMACT_BOOL_CONST;
if (paraArg) {
m_parameter1 = 1;
}
m_parameter1 = (paraArg) ? 1.0 : 0.0;
Py_Return;
}