svn merge https://svn.blender.org/svnroot/bf-blender/trunk/blender -r22701:22704
[blender-staging.git] / source / gameengine / GameLogic / SCA_KeyboardSensor.cpp
index a5581f0d9876f1b97ca7702356a1d1235e4e7056..13b32b5446c94dfa60a1b3ceabd4f4e71a65b86f 100644 (file)
@@ -48,9 +48,8 @@ SCA_KeyboardSensor::SCA_KeyboardSensor(SCA_KeyboardManager* keybdmgr,
                                                                           bool bAllKeys,
                                                                           const STR_String& targetProp,
                                                                           const STR_String& toggleProp,
-                                                                          SCA_IObject* gameobj,
-                                                                          PyTypeObject* T )
-       :SCA_ISensor(gameobj,keybdmgr,T),
+                                                                          SCA_IObject* gameobj)
+       :SCA_ISensor(gameobj,keybdmgr),
         m_hotkey(hotkey),
         m_qual(qual),
         m_qual2(qual2),
@@ -417,7 +416,7 @@ const char SCA_KeyboardSensor::GetKey_doc[] =
 PyObject* SCA_KeyboardSensor::PyGetKey()
 {
        ShowDeprecationWarning("getKey()", "the key property");
-       return PyInt_FromLong(m_hotkey);
+       return PyLong_FromSsize_t(m_hotkey);
 }
 
 /** 2. SetKey: change the key to look at */
@@ -449,7 +448,7 @@ const char SCA_KeyboardSensor::GetHold1_doc[] =
 PyObject* SCA_KeyboardSensor::PyGetHold1()
 {
        ShowDeprecationWarning("getHold1()", "the hold1 property");
-       return PyInt_FromLong(m_qual);
+       return PyLong_FromSsize_t(m_qual);
 }
 
 /** 4. SetHold1: change the first bucky bit */
@@ -481,7 +480,7 @@ const char SCA_KeyboardSensor::GetHold2_doc[] =
 PyObject* SCA_KeyboardSensor::PyGetHold2()
 {
        ShowDeprecationWarning("getHold2()", "the hold2 property");
-       return PyInt_FromLong(m_qual2);
+       return PyLong_FromSsize_t(m_qual2);
 }
 
 /** 6. SetHold2: change the second bucky bit */
@@ -531,8 +530,8 @@ PyObject* SCA_KeyboardSensor::PyGetPressedKeys()
                                || (inevent.m_status == SCA_InputEvent::KX_JUSTRELEASED))
                        {
                                PyObject* keypair = PyList_New(2);
-                               PyList_SET_ITEM(keypair,0,PyInt_FromLong(i));
-                               PyList_SET_ITEM(keypair,1,PyInt_FromLong(inevent.m_status));
+                               PyList_SET_ITEM(keypair,0,PyLong_FromSsize_t(i));
+                               PyList_SET_ITEM(keypair,1,PyLong_FromSsize_t(inevent.m_status));
                                PyList_SET_ITEM(resultlist,index,keypair);
                                index++;
                                
@@ -571,8 +570,8 @@ PyObject* SCA_KeyboardSensor::PyGetCurrentlyPressedKeys()
                                 || (inevent.m_status == SCA_InputEvent::KX_JUSTACTIVATED))
                        {
                                PyObject* keypair = PyList_New(2);
-                               PyList_SET_ITEM(keypair,0,PyInt_FromLong(i));
-                               PyList_SET_ITEM(keypair,1,PyInt_FromLong(inevent.m_status));
+                               PyList_SET_ITEM(keypair,0,PyLong_FromSsize_t(i));
+                               PyList_SET_ITEM(keypair,1,PyLong_FromSsize_t(inevent.m_status));
                                PyList_SET_ITEM(resultlist,index,keypair);
                                index++;
                                
@@ -591,12 +590,12 @@ KX_PYMETHODDEF_DOC_O(SCA_KeyboardSensor, getKeyStatus,
 "getKeyStatus(keycode)\n"
 "\tGet the given key's status (KX_NO_INPUTSTATUS, KX_JUSTACTIVATED, KX_ACTIVE or KX_JUSTRELEASED).\n")
 {
-       if (!PyInt_Check(value)) {
+       if (!PyLong_Check(value)) {
                PyErr_SetString(PyExc_ValueError, "sensor.getKeyStatus(int): Keyboard Sensor, expected an int");
                return NULL;
        }
        
-       int keycode = PyInt_AsLong(value);
+       int keycode = PyLong_AsSsize_t(value);
        
        if ((keycode < SCA_IInputDevice::KX_BEGINKEY)
                || (keycode > SCA_IInputDevice::KX_ENDKEY)){
@@ -606,7 +605,7 @@ KX_PYMETHODDEF_DOC_O(SCA_KeyboardSensor, getKeyStatus,
        
        SCA_IInputDevice* inputdev = ((SCA_KeyboardManager *)m_eventmgr)->GetInputDevice();
        const SCA_InputEvent & inevent = inputdev->GetEventValue((SCA_IInputDevice::KX_EnumInputs) keycode);
-       return PyInt_FromLong(inevent.m_status);
+       return PyLong_FromSsize_t(inevent.m_status);
 }
 
 /* ------------------------------------------------------------------------- */
@@ -614,13 +613,7 @@ KX_PYMETHODDEF_DOC_O(SCA_KeyboardSensor, getKeyStatus,
 /* ------------------------------------------------------------------------- */
 
 PyTypeObject SCA_KeyboardSensor::Type = {
-#if (PY_VERSION_HEX >= 0x02060000)
        PyVarObject_HEAD_INIT(NULL, 0)
-#else
-       /* python 2.5 and below */
-       PyObject_HEAD_INIT( NULL )  /* required py macro */
-       0,                          /* ob_size */
-#endif
        "SCA_KeyboardSensor",
        sizeof(PyObjectPlus_Proxy),
        0,
@@ -630,31 +623,27 @@ PyTypeObject SCA_KeyboardSensor::Type = {
        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_KeyboardSensor::Parents[] = {
-       &SCA_KeyboardSensor::Type,
+       Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
+       0,0,0,0,0,0,0,
+       Methods,
+       0,
+       0,
        &SCA_ISensor::Type,
-       &SCA_ILogicBrick::Type,
-       &CValue::Type,
-       NULL
+       0,0,0,0,0,0,
+       py_base_new
 };
 
 PyMethodDef SCA_KeyboardSensor::Methods[] = {
        //Deprecated functions ------>
-       {"getKey", (PyCFunction) SCA_KeyboardSensor::sPyGetKey, METH_NOARGS, (PY_METHODCHAR)GetKey_doc},
-       {"setKey", (PyCFunction) SCA_KeyboardSensor::sPySetKey, METH_VARARGS, (PY_METHODCHAR)SetKey_doc},
-       {"getHold1", (PyCFunction) SCA_KeyboardSensor::sPyGetHold1, METH_NOARGS, (PY_METHODCHAR)GetHold1_doc},
-       {"setHold1", (PyCFunction) SCA_KeyboardSensor::sPySetHold1, METH_VARARGS, (PY_METHODCHAR)SetHold1_doc},
-       {"getHold2", (PyCFunction) SCA_KeyboardSensor::sPyGetHold2, METH_NOARGS, (PY_METHODCHAR)GetHold2_doc},
-       {"setHold2", (PyCFunction) SCA_KeyboardSensor::sPySetHold2, METH_VARARGS, (PY_METHODCHAR)SetHold2_doc},
-       {"getPressedKeys", (PyCFunction) SCA_KeyboardSensor::sPyGetPressedKeys, METH_NOARGS, (PY_METHODCHAR)GetPressedKeys_doc},
-       {"getCurrentlyPressedKeys", (PyCFunction) SCA_KeyboardSensor::sPyGetCurrentlyPressedKeys, METH_NOARGS, (PY_METHODCHAR)GetCurrentlyPressedKeys_doc},
+       {"getKey", (PyCFunction) SCA_KeyboardSensor::sPyGetKey, METH_NOARGS, (const char *)GetKey_doc},
+       {"setKey", (PyCFunction) SCA_KeyboardSensor::sPySetKey, METH_VARARGS, (const char *)SetKey_doc},
+       {"getHold1", (PyCFunction) SCA_KeyboardSensor::sPyGetHold1, METH_NOARGS, (const char *)GetHold1_doc},
+       {"setHold1", (PyCFunction) SCA_KeyboardSensor::sPySetHold1, METH_VARARGS, (const char *)SetHold1_doc},
+       {"getHold2", (PyCFunction) SCA_KeyboardSensor::sPyGetHold2, METH_NOARGS, (const char *)GetHold2_doc},
+       {"setHold2", (PyCFunction) SCA_KeyboardSensor::sPySetHold2, METH_VARARGS, (const char *)SetHold2_doc},
+       {"getPressedKeys", (PyCFunction) SCA_KeyboardSensor::sPyGetPressedKeys, METH_NOARGS, (const char *)GetPressedKeys_doc},
+       {"getCurrentlyPressedKeys", (PyCFunction) SCA_KeyboardSensor::sPyGetCurrentlyPressedKeys, METH_NOARGS, (const char *)GetCurrentlyPressedKeys_doc},
        //<----- Deprecated
        KX_PYMETHODTABLE_O(SCA_KeyboardSensor, getKeyStatus),
        {NULL,NULL} //Sentinel
@@ -671,20 +660,6 @@ PyAttributeDef SCA_KeyboardSensor::Attributes[] = {
        { NULL }        //Sentinel
 };
 
-PyObject* SCA_KeyboardSensor::py_getattro(PyObject *attr)
-{
-  py_getattro_up(SCA_ISensor);
-}
-
-PyObject* SCA_KeyboardSensor::py_getattro_dict() {
-       py_getattro_dict_up(SCA_ISensor);
-}
-
-int SCA_KeyboardSensor::py_setattro(PyObject *attr, PyObject *value)
-{
-       py_setattro_up(SCA_ISensor);
-}
-
 
 PyObject* SCA_KeyboardSensor::pyattr_get_events(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
 {
@@ -700,8 +675,8 @@ PyObject* SCA_KeyboardSensor::pyattr_get_events(void *self_v, const KX_PYATTRIBU
                if (inevent.m_status != SCA_InputEvent::KX_NO_INPUTSTATUS)
                {
                        PyObject* keypair = PyList_New(2);
-                       PyList_SET_ITEM(keypair,0,PyInt_FromLong(i));
-                       PyList_SET_ITEM(keypair,1,PyInt_FromLong(inevent.m_status));
+                       PyList_SET_ITEM(keypair,0,PyLong_FromSsize_t(i));
+                       PyList_SET_ITEM(keypair,1,PyLong_FromSsize_t(inevent.m_status));
                        PyList_Append(resultlist,keypair);
                }
        }