BGE API cleanup: RandomActuator.
authorBenoit Bolsee <benoit.bolsee@online.be>
Fri, 3 Apr 2009 19:09:52 +0000 (19:09 +0000)
committerBenoit Bolsee <benoit.bolsee@online.be>
Fri, 3 Apr 2009 19:09:52 +0000 (19:09 +0000)
source/gameengine/GameLogic/SCA_RandomActuator.cpp
source/gameengine/GameLogic/SCA_RandomActuator.h

index a9a664b0686e4e7c200799344d5569b20b71fa16..7af116fad992b1f5cc17d031e9fadf374cabafe1 100644 (file)
@@ -348,16 +348,18 @@ PyMethodDef SCA_RandomActuator::Methods[] = {
        {"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 @@ PyAttributeDef SCA_RandomActuator::Attributes[] = {
        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 SCA_RandomActuator::py_setattro(PyObject *attr, PyObject *value)
        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 @@ PyObject* SCA_RandomActuator::PyGetProperty(PyObject* self, PyObject* args, PyOb
 }
 
 /* 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", &paraArg)) {
                return NULL;
@@ -512,25 +516,21 @@ PyObject* SCA_RandomActuator::PySetBoolConst(PyObject* self,
        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", &paraArg)) {
                return NULL;
@@ -542,13 +542,11 @@ PyObject* SCA_RandomActuator::PySetBoolBernouilli(PyObject* self,
        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", &paraArg)) {
                return NULL;
@@ -560,15 +558,13 @@ PyObject* SCA_RandomActuator::PySetIntConst(PyObject* self,
        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", &paraArg1, &paraArg2)) {
                return NULL;
@@ -581,15 +577,13 @@ PyObject* SCA_RandomActuator::PySetIntUniform(PyObject* self,
        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", &paraArg)) {
                return NULL;
@@ -600,14 +594,12 @@ PyObject* SCA_RandomActuator::PySetIntPoisson(PyObject* self,
        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", &paraArg)) {
                return NULL;
@@ -619,15 +611,13 @@ PyObject* SCA_RandomActuator::PySetFloatConst(PyObject* self,
        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", &paraArg1, &paraArg2)) {
                return NULL;
@@ -640,15 +630,13 @@ PyObject* SCA_RandomActuator::PySetFloatUniform(PyObject* self,
        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", &paraArg1, &paraArg2)) {
                return NULL;
@@ -661,14 +649,12 @@ PyObject* SCA_RandomActuator::PySetFloatNormal(PyObject* self,
        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", &paraArg)) {
                return NULL;
index 96ca353257f1f937e467de8ebe2d23c54efe148e..fbafbb69c017b6c5b75a9d4c99436374afa211ff 100644 (file)
@@ -99,43 +99,29 @@ class SCA_RandomActuator : public SCA_IActuator
        virtual PyObject* py_getattro(PyObject *attr);
        virtual int py_setattro(PyObject *attr, PyObject *value);
 
-       /* 1. setSeed                                                            */
+       static PyObject* pyattr_get_seed(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
+       static int pyattr_set_seed(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
+
+       // Deprecated methods ----->
        KX_PYMETHOD_DOC(SCA_RandomActuator,SetSeed);
-       /* 2. getSeed                                                            */
        KX_PYMETHOD_DOC(SCA_RandomActuator,GetSeed);
-       /* 3. setPara1 -removed-                                                 */
-       /* 4. getPara1                                                           */
        KX_PYMETHOD_DOC(SCA_RandomActuator,GetPara1);
-       /* 5. setPara2 -removed-                                                 */
-       /* 6. getPara2                                                           */
        KX_PYMETHOD_DOC(SCA_RandomActuator,GetPara2);
-       /* 7. setDistribution -removed-                                          */
-       /* 8. getDistribution                                                    */
        KX_PYMETHOD_DOC(SCA_RandomActuator,GetDistribution);
-       /* 9. setProperty                                                        */
        KX_PYMETHOD_DOC(SCA_RandomActuator,SetProperty);
-       /* 10. getProperty                                                       */
        KX_PYMETHOD_DOC(SCA_RandomActuator,GetProperty);
-       /* 11. setBoolConst                                                      */
-       KX_PYMETHOD_DOC(SCA_RandomActuator,SetBoolConst);
-       /* 12. setBoolUniform, */
-       KX_PYMETHOD_DOC(SCA_RandomActuator,SetBoolUniform);
-       /* 13. setBoolBernouilli,  */
-       KX_PYMETHOD_DOC(SCA_RandomActuator,SetBoolBernouilli);
-       /* 14. setIntConst,*/
-       KX_PYMETHOD_DOC(SCA_RandomActuator,SetIntConst);
-       /* 15. setIntUniform,*/
-       KX_PYMETHOD_DOC(SCA_RandomActuator,SetIntUniform);
-       /* 16. setIntPoisson,           */
-       KX_PYMETHOD_DOC(SCA_RandomActuator,SetIntPoisson);
-       /* 17. setFloatConst,*/
-       KX_PYMETHOD_DOC(SCA_RandomActuator,SetFloatConst);
-       /* 18. setFloatUniform, */
-       KX_PYMETHOD_DOC(SCA_RandomActuator,SetFloatUniform);
-       /* 19. setFloatNormal, */
-       KX_PYMETHOD_DOC(SCA_RandomActuator,SetFloatNormal);
-       /* 20. setFloatNegativeExponential, */
-       KX_PYMETHOD_DOC(SCA_RandomActuator,SetFloatNegativeExponential);
+       // <-----
+
+       KX_PYMETHOD_DOC_VARARGS(SCA_RandomActuator, setBoolConst);
+       KX_PYMETHOD_DOC_NOARGS(SCA_RandomActuator, setBoolUniform);
+       KX_PYMETHOD_DOC_VARARGS(SCA_RandomActuator, setBoolBernouilli);
+       KX_PYMETHOD_DOC_VARARGS(SCA_RandomActuator, setIntConst);
+       KX_PYMETHOD_DOC_VARARGS(SCA_RandomActuator, setIntUniform);
+       KX_PYMETHOD_DOC_VARARGS(SCA_RandomActuator, setIntPoisson);
+       KX_PYMETHOD_DOC_VARARGS(SCA_RandomActuator, setFloatConst);
+       KX_PYMETHOD_DOC_VARARGS(SCA_RandomActuator, setFloatUniform);
+       KX_PYMETHOD_DOC_VARARGS(SCA_RandomActuator, setFloatNormal);
+       KX_PYMETHOD_DOC_VARARGS(SCA_RandomActuator, setFloatNegativeExponential);
 }; /* end of class KX_EditObjectActuator : public SCA_PropertyActuator */
 
 #endif