[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [19524] trunk/blender/source/gameengine/ GameLogic: BGE API cleanup: RandomActuator.
Benoit Bolsee
benoit.bolsee at online.be
Fri Apr 3 21:09:52 CEST 2009
Revision: 19524
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=19524
Author: ben2610
Date: 2009-04-03 21:09:52 +0200 (Fri, 03 Apr 2009)
Log Message:
-----------
BGE API cleanup: RandomActuator.
Modified Paths:
--------------
trunk/blender/source/gameengine/GameLogic/SCA_RandomActuator.cpp
trunk/blender/source/gameengine/GameLogic/SCA_RandomActuator.h
Modified: trunk/blender/source/gameengine/GameLogic/SCA_RandomActuator.cpp
===================================================================
--- trunk/blender/source/gameengine/GameLogic/SCA_RandomActuator.cpp 2009-04-03 18:13:51 UTC (rev 19523)
+++ trunk/blender/source/gameengine/GameLogic/SCA_RandomActuator.cpp 2009-04-03 19:09:52 UTC (rev 19524)
@@ -348,16 +348,18 @@
{"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},
- {"setIntConst", (PyCFunction) SCA_RandomActuator::sPySetIntConst, METH_VARARGS, (PY_METHODCHAR)SetIntConst_doc},
- {"setIntUniform", (PyCFunction) SCA_RandomActuator::sPySetIntUniform, METH_VARARGS, (PY_METHODCHAR)SetIntUniform_doc},
- {"setIntPoisson", (PyCFunction) SCA_RandomActuator::sPySetIntPoisson, METH_VARARGS, (PY_METHODCHAR)SetIntPoisson_doc},
- {"setFloatConst", (PyCFunction) SCA_RandomActuator::sPySetFloatConst, METH_VARARGS, (PY_METHODCHAR)SetFloatConst_doc},
- {"setFloatUniform", (PyCFunction) SCA_RandomActuator::sPySetFloatUniform, METH_VARARGS, (PY_METHODCHAR)SetFloatUniform_doc},
- {"setFloatNormal", (PyCFunction) SCA_RandomActuator::sPySetFloatNormal, METH_VARARGS, (PY_METHODCHAR)SetFloatNormal_doc},
- {"setFloatNegativeExponential", (PyCFunction) SCA_RandomActuator::sPySetFloatNegativeExponential, METH_VARARGS, (PY_METHODCHAR)SetFloatNegativeExponential_doc},
+ KX_PYMETHODTABLE(SCA_RandomActuator, setBoolConst),
+ KX_PYMETHODTABLE_NOARGS(SCA_RandomActuator, setBoolUniform),
+ KX_PYMETHODTABLE(SCA_RandomActuator, setBoolBernouilli),
+
+ KX_PYMETHODTABLE(SCA_RandomActuator, setIntConst),
+ KX_PYMETHODTABLE(SCA_RandomActuator, setIntUniform),
+ KX_PYMETHODTABLE(SCA_RandomActuator, setIntPoisson),
+
+ KX_PYMETHODTABLE(SCA_RandomActuator, setFloatConst),
+ KX_PYMETHODTABLE(SCA_RandomActuator, setFloatUniform),
+ KX_PYMETHODTABLE(SCA_RandomActuator, setFloatNormal),
+ KX_PYMETHODTABLE(SCA_RandomActuator, setFloatNegativeExponential),
{NULL,NULL} //Sentinel
};
@@ -366,17 +368,33 @@
KX_PYATTRIBUTE_FLOAT_RO("para2",SCA_RandomActuator,m_parameter2),
KX_PYATTRIBUTE_ENUM_RO("distribution",SCA_RandomActuator,m_distribution),
KX_PYATTRIBUTE_STRING_RW_CHECK("property",0,100,false,SCA_RandomActuator,m_propname,CheckProperty),
+ KX_PYATTRIBUTE_RW_FUNCTION("seed",SCA_RandomActuator,pyattr_get_seed,pyattr_set_seed),
{ NULL } //Sentinel
};
+PyObject* SCA_RandomActuator::pyattr_get_seed(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
+{
+ SCA_RandomActuator* act = static_cast<SCA_RandomActuator*>(self);
+ return PyInt_FromLong(act->m_base->GetSeed());
+}
+
+int SCA_RandomActuator::pyattr_set_seed(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
+{
+ SCA_RandomActuator* act = static_cast<SCA_RandomActuator*>(self);
+ if (PyInt_Check(value)) {
+ int ival = PyInt_AsLong(value);
+ act->m_base->SetSeed(ival);
+ return 0;
+ } else {
+ PyErr_SetString(PyExc_TypeError, "expected an integer");
+ return 1;
+ }
+}
+
PyObject* SCA_RandomActuator::py_getattro(PyObject *attr) {
PyObject* object = py_getattro_self(Attributes, this, attr);
if (object != NULL)
return object;
- char *attr_str= PyString_AsString(attr);
- if (!strcmp(attr_str, "seed")) {
- return PyInt_FromLong(m_base->GetSeed());
- }
py_getattro_up(SCA_IActuator);
}
@@ -385,18 +403,6 @@
int ret = py_setattro_self(Attributes, this, attr, value);
if (ret >= 0)
return ret;
-
- char *attr_str= PyString_AsString(attr);
- if (!strcmp(attr_str, "seed")) {
- if (PyInt_Check(value)) {
- int ival = PyInt_AsLong(value);
- m_base->SetSeed(ival);
- return 0;
- } else {
- PyErr_SetString(PyExc_TypeError, "expected an integer");
- return 1;
- }
- }
return SCA_IActuator::py_setattro(attr, value);
}
@@ -494,13 +500,11 @@
}
/* 11. setBoolConst */
-const char SCA_RandomActuator::SetBoolConst_doc[] =
+KX_PYMETHODDEF_DOC_VARARGS(SCA_RandomActuator, setBoolConst,
"setBoolConst(value)\n"
"\t- value: 0 or 1\n"
-"\tSet this generator to produce a constant boolean value.\n";
-PyObject* SCA_RandomActuator::PySetBoolConst(PyObject* self,
- PyObject* args,
- PyObject* kwds) {
+"\tSet this generator to produce a constant boolean value.\n")
+{
int paraArg;
if(!PyArg_ParseTuple(args, "i", ¶Arg)) {
return NULL;
@@ -512,25 +516,21 @@
Py_RETURN_NONE;
}
/* 12. setBoolUniform, */
-const char SCA_RandomActuator::SetBoolUniform_doc[] =
+KX_PYMETHODDEF_DOC_NOARGS(SCA_RandomActuator, setBoolUniform,
"setBoolUniform()\n"
-"\tSet this generator to produce true and false, each with 50%% chance of occuring\n";
-PyObject* SCA_RandomActuator::PySetBoolUniform(PyObject* self,
- PyObject* args,
- PyObject* kwds) {
+"\tSet this generator to produce true and false, each with 50%% chance of occuring\n")
+{
/* no args */
m_distribution = KX_RANDOMACT_BOOL_UNIFORM;
enforceConstraints();
Py_RETURN_NONE;
}
/* 13. setBoolBernouilli, */
-const char SCA_RandomActuator::SetBoolBernouilli_doc[] =
+KX_PYMETHODDEF_DOC_VARARGS(SCA_RandomActuator, setBoolBernouilli,
"setBoolBernouilli(value)\n"
"\t- value: a float between 0 and 1\n"
-"\tReturn false value * 100%% of the time.\n";
-PyObject* SCA_RandomActuator::PySetBoolBernouilli(PyObject* self,
- PyObject* args,
- PyObject* kwds) {
+"\tReturn false value * 100%% of the time.\n")
+{
float paraArg;
if(!PyArg_ParseTuple(args, "f", ¶Arg)) {
return NULL;
@@ -542,13 +542,11 @@
Py_RETURN_NONE;
}
/* 14. setIntConst,*/
-const char SCA_RandomActuator::SetIntConst_doc[] =
+KX_PYMETHODDEF_DOC_VARARGS(SCA_RandomActuator, setIntConst,
"setIntConst(value)\n"
"\t- value: integer\n"
-"\tAlways return value\n";
-PyObject* SCA_RandomActuator::PySetIntConst(PyObject* self,
- PyObject* args,
- PyObject* kwds) {
+"\tAlways return value\n")
+{
int paraArg;
if(!PyArg_ParseTuple(args, "i", ¶Arg)) {
return NULL;
@@ -560,15 +558,13 @@
Py_RETURN_NONE;
}
/* 15. setIntUniform,*/
-const char SCA_RandomActuator::SetIntUniform_doc[] =
+KX_PYMETHODDEF_DOC_VARARGS(SCA_RandomActuator, setIntUniform,
"setIntUniform(lower_bound, upper_bound)\n"
"\t- lower_bound: integer\n"
"\t- upper_bound: integer\n"
"\tReturn a random integer between lower_bound and\n"
-"\tupper_bound. The boundaries are included.\n";
-PyObject* SCA_RandomActuator::PySetIntUniform(PyObject* self,
- PyObject* args,
- PyObject* kwds) {
+"\tupper_bound. The boundaries are included.\n")
+{
int paraArg1, paraArg2;
if(!PyArg_ParseTuple(args, "ii", ¶Arg1, ¶Arg2)) {
return NULL;
@@ -581,15 +577,13 @@
Py_RETURN_NONE;
}
/* 16. setIntPoisson, */
-const char SCA_RandomActuator::SetIntPoisson_doc[] =
+KX_PYMETHODDEF_DOC_VARARGS(SCA_RandomActuator, setIntPoisson,
"setIntPoisson(value)\n"
"\t- value: float\n"
"\tReturn a Poisson-distributed number. This performs a series\n"
"\tof Bernouilli tests with parameter value. It returns the\n"
-"\tnumber of tries needed to achieve succes.\n";
-PyObject* SCA_RandomActuator::PySetIntPoisson(PyObject* self,
- PyObject* args,
- PyObject* kwds) {
+"\tnumber of tries needed to achieve succes.\n")
+{
float paraArg;
if(!PyArg_ParseTuple(args, "f", ¶Arg)) {
return NULL;
@@ -600,14 +594,12 @@
enforceConstraints();
Py_RETURN_NONE;
}
-/* 17. setFloatConst,*/
-const char SCA_RandomActuator::SetFloatConst_doc[] =
+/* 17. setFloatConst */
+KX_PYMETHODDEF_DOC_VARARGS(SCA_RandomActuator, setFloatConst,
"setFloatConst(value)\n"
"\t- value: float\n"
-"\tAlways return value\n";
-PyObject* SCA_RandomActuator::PySetFloatConst(PyObject* self,
- PyObject* args,
- PyObject* kwds) {
+"\tAlways return value\n")
+{
float paraArg;
if(!PyArg_ParseTuple(args, "f", ¶Arg)) {
return NULL;
@@ -619,15 +611,13 @@
Py_RETURN_NONE;
}
/* 18. setFloatUniform, */
-const char SCA_RandomActuator::SetFloatUniform_doc[] =
+KX_PYMETHODDEF_DOC_VARARGS(SCA_RandomActuator, setFloatUniform,
"setFloatUniform(lower_bound, upper_bound)\n"
"\t- lower_bound: float\n"
"\t- upper_bound: float\n"
"\tReturn a random integer between lower_bound and\n"
-"\tupper_bound.\n";
-PyObject* SCA_RandomActuator::PySetFloatUniform(PyObject* self,
- PyObject* args,
- PyObject* kwds) {
+"\tupper_bound.\n")
+{
float paraArg1, paraArg2;
if(!PyArg_ParseTuple(args, "ff", ¶Arg1, ¶Arg2)) {
return NULL;
@@ -640,15 +630,13 @@
Py_RETURN_NONE;
}
/* 19. setFloatNormal, */
-const char SCA_RandomActuator::SetFloatNormal_doc[] =
+KX_PYMETHODDEF_DOC_VARARGS(SCA_RandomActuator, setFloatNormal,
"setFloatNormal(mean, standard_deviation)\n"
"\t- mean: float\n"
"\t- standard_deviation: float\n"
"\tReturn normal-distributed numbers. The average is mean, and the\n"
-"\tdeviation from the mean is characterized by standard_deviation.\n";
-PyObject* SCA_RandomActuator::PySetFloatNormal(PyObject* self,
- PyObject* args,
- PyObject* kwds) {
+"\tdeviation from the mean is characterized by standard_deviation.\n")
+{
float paraArg1, paraArg2;
if(!PyArg_ParseTuple(args, "ff", ¶Arg1, ¶Arg2)) {
return NULL;
@@ -661,14 +649,12 @@
Py_RETURN_NONE;
}
/* 20. setFloatNegativeExponential, */
-const char SCA_RandomActuator::SetFloatNegativeExponential_doc[] =
+KX_PYMETHODDEF_DOC_VARARGS(SCA_RandomActuator, setFloatNegativeExponential,
"setFloatNegativeExponential(half_life)\n"
"\t- half_life: float\n"
"\tReturn negative-exponentially distributed numbers. The half-life 'time'\n"
-"\tis characterized by half_life.\n";
-PyObject* SCA_RandomActuator::PySetFloatNegativeExponential(PyObject* self,
- PyObject* args,
- PyObject* kwds) {
+"\tis characterized by half_life.\n")
+{
float paraArg;
if(!PyArg_ParseTuple(args, "f", ¶Arg)) {
return NULL;
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list