remove python2.x support
[blender.git] / source / gameengine / GameLogic / SCA_RandomActuator.cpp
index d5d993c4ba61c80f9c65d9095c2cb02670f80cbf..2b10f49137807116c7f5ff915af0cdf73eda837f 100644 (file)
@@ -50,15 +50,13 @@ SCA_RandomActuator::SCA_RandomActuator(SCA_IObject *gameobj,
                                                                         SCA_RandomActuator::KX_RANDOMACT_MODE mode,
                                                                         float para1,
                                                                         float para2,
-                                                                        const STR_String &propName,
-                                                                        PyTypeObject* T)
-       : SCA_IActuator(gameobj, T),
+                                                                        const STR_String &propName)
+       : SCA_IActuator(gameobj),
          m_propname(propName),
          m_parameter1(para1),
          m_parameter2(para2),
          m_distribution(mode)
 {
-       // m_base is never deleted, probably a memory leak!
        m_base = new SCA_RandomNumberGenerator(seed);
        m_counter = 0;
        enforceConstraints();
@@ -68,7 +66,7 @@ SCA_RandomActuator::SCA_RandomActuator(SCA_IObject *gameobj,
 
 SCA_RandomActuator::~SCA_RandomActuator()
 {
-       /* intentionally empty */ 
+       m_base->Release();
 } 
 
 
@@ -78,11 +76,16 @@ CValue* SCA_RandomActuator::GetReplica()
        SCA_RandomActuator* replica = new SCA_RandomActuator(*this);
        // replication just copy the m_base pointer => common random generator
        replica->ProcessReplica();
-       CValue::AddDataToReplica(replica);
-
        return replica;
 }
 
+void SCA_RandomActuator::ProcessReplica()
+{
+       SCA_IActuator::ProcessReplica();
+       // increment reference count so that we can release the generator at the end
+       m_base->AddRef();
+}
+
 
 
 bool SCA_RandomActuator::Update()
@@ -312,41 +315,36 @@ void SCA_RandomActuator::enforceConstraints() {
 
 /* Integration hooks ------------------------------------------------------- */
 PyTypeObject SCA_RandomActuator::Type = {
-       PyObject_HEAD_INIT(NULL)
-       0,
+       PyVarObject_HEAD_INIT(NULL, 0)
        "SCA_RandomActuator",
-       sizeof(SCA_RandomActuator),
+       sizeof(PyObjectPlus_Proxy),
        0,
-       PyDestructor,
+       py_base_dealloc,
        0,
        0,
        0,
        0,
        py_base_repr,
-       0,0,0,0,0,0,
-       py_base_getattro,
-       py_base_setattro,
        0,0,0,0,0,0,0,0,0,
-       Methods
-};
-
-PyParentObject SCA_RandomActuator::Parents[] = {
-       &SCA_RandomActuator::Type,
+       Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
+       0,0,0,0,0,0,0,
+       Methods,
+       0,
+       0,
        &SCA_IActuator::Type,
-       &SCA_ILogicBrick::Type,
-       &CValue::Type,
-       NULL
+       0,0,0,0,0,0,
+       py_base_new
 };
 
 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},
-       {"getPara2",        (PyCFunction) SCA_RandomActuator::sPyGetPara2, METH_VARARGS, (PY_METHODCHAR)GetPara2_doc},
-       {"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},
+       {"setSeed",         (PyCFunction) SCA_RandomActuator::sPySetSeed, METH_VARARGS, (const char *)SetSeed_doc},
+       {"getSeed",         (PyCFunction) SCA_RandomActuator::sPyGetSeed, METH_NOARGS, (const char *)GetSeed_doc},
+       {"getPara1",        (PyCFunction) SCA_RandomActuator::sPyGetPara1, METH_NOARGS, (const char *)GetPara1_doc},
+       {"getPara2",        (PyCFunction) SCA_RandomActuator::sPyGetPara2, METH_NOARGS, (const char *)GetPara2_doc},
+       {"getDistribution", (PyCFunction) SCA_RandomActuator::sPyGetDistribution, METH_NOARGS, (const char *)GetDistribution_doc},
+       {"setProperty",     (PyCFunction) SCA_RandomActuator::sPySetProperty, METH_VARARGS, (const char *)SetProperty_doc},
+       {"getProperty",     (PyCFunction) SCA_RandomActuator::sPyGetProperty, METH_NOARGS, (const char *)GetProperty_doc},
        //<----- Deprecated
        KX_PYMETHODTABLE(SCA_RandomActuator, setBoolConst),
        KX_PYMETHODTABLE_NOARGS(SCA_RandomActuator, setBoolUniform),
@@ -367,7 +365,7 @@ PyAttributeDef SCA_RandomActuator::Attributes[] = {
        KX_PYATTRIBUTE_FLOAT_RO("para1",SCA_RandomActuator,m_parameter1),
        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_STRING_RW_CHECK("propName",0,100,false,SCA_RandomActuator,m_propname,CheckProperty),
        KX_PYATTRIBUTE_RW_FUNCTION("seed",SCA_RandomActuator,pyattr_get_seed,pyattr_set_seed),
        { NULL }        //Sentinel
 };     
@@ -375,31 +373,22 @@ PyAttributeDef SCA_RandomActuator::Attributes[] = {
 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());
+       return PyLong_FromSsize_t(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);
+       if (PyLong_Check(value))        {
+               int ival = PyLong_AsSsize_t(value);
                act->m_base->SetSeed(ival);
-               return 0;
+               return PY_SET_ATTR_SUCCESS;
        } else {
-               PyErr_SetString(PyExc_TypeError, "expected an integer");
-               return 1;
+               PyErr_SetString(PyExc_TypeError, "actuator.seed = int: Random Actuator, expected an integer");
+               return PY_SET_ATTR_FAIL;
        }
 }
 
-PyObject* SCA_RandomActuator::py_getattro(PyObject *attr) {
-       py_getattro_up(SCA_IActuator);
-}
-
-int SCA_RandomActuator::py_setattro(PyObject *attr, PyObject *value)
-{
-       py_setattro_up(SCA_IActuator);
-}
-
 /* 1. setSeed                                                            */
 const char SCA_RandomActuator::SetSeed_doc[] = 
 "setSeed(seed)\n"
@@ -407,7 +396,7 @@ const char SCA_RandomActuator::SetSeed_doc[] =
 "\tSet the initial seed of the generator. Equal seeds produce\n"
 "\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) {
+PyObject* SCA_RandomActuator::PySetSeed(PyObject* args) {
        ShowDeprecationWarning("setSeed()", "the seed property");
        long seedArg;
        if(!PyArg_ParseTuple(args, "i:setSeed", &seedArg)) {
@@ -423,9 +412,10 @@ const char SCA_RandomActuator::GetSeed_doc[] =
 "getSeed()\n"
 "\tReturns the initial seed of the generator. Equal seeds produce\n"
 "\tequal series.\n";
-PyObject* SCA_RandomActuator::PyGetSeed(PyObject* self, PyObject* args, PyObject* kwds) {
+PyObject* SCA_RandomActuator::PyGetSeed()
+{
        ShowDeprecationWarning("getSeed()", "the seed property");
-       return PyInt_FromLong(m_base->GetSeed());
+       return PyLong_FromSsize_t(m_base->GetSeed());
 }
 
 /* 4. getPara1                                                           */
@@ -434,7 +424,8 @@ const char SCA_RandomActuator::GetPara1_doc[] =
 "\tReturns the first parameter of the active distribution. Refer\n"
 "\tto the documentation of the generator types for the meaning\n"
 "\tof this value.";
-PyObject* SCA_RandomActuator::PyGetPara1(PyObject* self, PyObject* args, PyObject* kwds) {
+PyObject* SCA_RandomActuator::PyGetPara1()
+{
        ShowDeprecationWarning("getPara1()", "the para1 property");
        return PyFloat_FromDouble(m_parameter1);
 }
@@ -445,7 +436,8 @@ const char SCA_RandomActuator::GetPara2_doc[] =
 "\tReturns the first parameter of the active distribution. Refer\n"
 "\tto the documentation of the generator types for the meaning\n"
 "\tof this value.";
-PyObject* SCA_RandomActuator::PyGetPara2(PyObject* self, PyObject* args, PyObject* kwds) {
+PyObject* SCA_RandomActuator::PyGetPara2()
+{
        ShowDeprecationWarning("getPara2()", "the para2 property");
        return PyFloat_FromDouble(m_parameter2);
 }
@@ -454,9 +446,10 @@ PyObject* SCA_RandomActuator::PyGetPara2(PyObject* self, PyObject* args, PyObjec
 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) {
+PyObject* SCA_RandomActuator::PyGetDistribution()
+{
        ShowDeprecationWarning("getDistribution()", "the distribution property");
-       return PyInt_FromLong(m_distribution);
+       return PyLong_FromSsize_t(m_distribution);
 }
 
 /* 9. setProperty                                                        */
@@ -465,8 +458,8 @@ const char SCA_RandomActuator::SetProperty_doc[] =
 "\t- name: string\n"
 "\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");
+PyObject* SCA_RandomActuator::PySetProperty(PyObject* args) {
+       ShowDeprecationWarning("setProperty()", "the 'propName' property");
        char *nameArg;
        if (!PyArg_ParseTuple(args, "s:setProperty", &nameArg)) {
                return NULL;
@@ -488,9 +481,10 @@ const char SCA_RandomActuator::GetProperty_doc[] =
 "getProperty(name)\n"
 "\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);
+PyObject* SCA_RandomActuator::PyGetProperty()
+{
+       ShowDeprecationWarning("getProperty()", "the 'propName' property");
+       return PyUnicode_FromString(m_propname);
 }
 
 /* 11. setBoolConst */