diff options
Diffstat (limited to 'source/gameengine/GameLogic/SCA_KeyboardSensor.cpp')
-rw-r--r-- | source/gameengine/GameLogic/SCA_KeyboardSensor.cpp | 241 |
1 files changed, 14 insertions, 227 deletions
diff --git a/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp b/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp index a5581f0d987..d2e3871fec2 100644 --- a/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp +++ b/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp @@ -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), @@ -409,194 +408,16 @@ void SCA_KeyboardSensor::LogKeystrokes(void) /* Python Functions */ /* ------------------------------------------------------------------------- */ -//Deprecated -----> -/** 1. GetKey : check which key this sensor looks at */ -const char SCA_KeyboardSensor::GetKey_doc[] = -"getKey()\n" -"\tReturn the code of the key this sensor is listening to.\n" ; -PyObject* SCA_KeyboardSensor::PyGetKey() -{ - ShowDeprecationWarning("getKey()", "the key property"); - return PyInt_FromLong(m_hotkey); -} - -/** 2. SetKey: change the key to look at */ -const char SCA_KeyboardSensor::SetKey_doc[] = -"setKey(keycode)\n" -"\t- keycode: any code from GameKeys\n" -"\tSet the key this sensor should listen to.\n" ; -PyObject* SCA_KeyboardSensor::PySetKey(PyObject* args) -{ - ShowDeprecationWarning("setKey()", "the key property"); - int keyCode; - - if(!PyArg_ParseTuple(args, "i:setKey", &keyCode)) { - return NULL; - } - - /* Since we have symbolic constants for this in Python, we don't guard */ - /* anything. It's up to the user to provide a sensible number. */ - m_hotkey = keyCode; - - Py_RETURN_NONE; -} - -/** 3. GetHold1 : set the first bucky bit */ -const char SCA_KeyboardSensor::GetHold1_doc[] = -"getHold1()\n" -"\tReturn the code of the first key modifier to the key this \n" -"\tsensor is listening to.\n" ; -PyObject* SCA_KeyboardSensor::PyGetHold1() -{ - ShowDeprecationWarning("getHold1()", "the hold1 property"); - return PyInt_FromLong(m_qual); -} - -/** 4. SetHold1: change the first bucky bit */ -const char SCA_KeyboardSensor::SetHold1_doc[] = -"setHold1(keycode)\n" -"\t- keycode: any code from GameKeys\n" -"\tSet the first modifier to the key this sensor should listen to.\n" ; -PyObject* SCA_KeyboardSensor::PySetHold1(PyObject* args) -{ - ShowDeprecationWarning("setHold1()", "the hold1 property"); - int keyCode; - - if(!PyArg_ParseTuple(args, "i:setHold1", &keyCode)) { - return NULL; - } - - /* Since we have symbolic constants for this in Python, we don't guard */ - /* anything. It's up to the user to provide a sensible number. */ - m_qual = keyCode; - - Py_RETURN_NONE; -} - -/** 5. GetHold2 : get the second bucky bit */ -const char SCA_KeyboardSensor::GetHold2_doc[] = -"getHold2()\n" -"\tReturn the code of the second key modifier to the key this \n" -"\tsensor is listening to.\n" ; -PyObject* SCA_KeyboardSensor::PyGetHold2() -{ - ShowDeprecationWarning("getHold2()", "the hold2 property"); - return PyInt_FromLong(m_qual2); -} - -/** 6. SetHold2: change the second bucky bit */ -const char SCA_KeyboardSensor::SetHold2_doc[] = -"setHold2(keycode)\n" -"\t- keycode: any code from GameKeys\n" -"\tSet the first modifier to the key this sensor should listen to.\n" ; -PyObject* SCA_KeyboardSensor::PySetHold2(PyObject* args) -{ - ShowDeprecationWarning("setHold2()", "the hold2 property"); - int keyCode; - - if(!PyArg_ParseTuple(args, "i:setHold2", &keyCode)) { - return NULL; - } - - /* Since we have symbolic constants for this in Python, we don't guard */ - /* anything. It's up to the user to provide a sensible number. */ - m_qual2 = keyCode; - - Py_RETURN_NONE; -} - - -const char SCA_KeyboardSensor::GetPressedKeys_doc[] = -"getPressedKeys()\n" -"\tGet a list of pressed keys that have either been pressed, or just released this frame.\n" ; - -PyObject* SCA_KeyboardSensor::PyGetPressedKeys() -{ - ShowDeprecationWarning("getPressedKeys()", "events"); - - SCA_IInputDevice* inputdev = ((SCA_KeyboardManager *)m_eventmgr)->GetInputDevice(); - - int num = inputdev->GetNumJustEvents(); - PyObject* resultlist = PyList_New(num); - - if (num > 0) - { - - int index = 0; - - for (int i=SCA_IInputDevice::KX_BEGINKEY ; i<= SCA_IInputDevice::KX_ENDKEY;i++) - { - const SCA_InputEvent & inevent = inputdev->GetEventValue((SCA_IInputDevice::KX_EnumInputs) i); - if ((inevent.m_status == SCA_InputEvent::KX_JUSTACTIVATED) - || (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(resultlist,index,keypair); - index++; - - if (index >= num) /* should not happen */ - break; - } - } - } - - return resultlist; -} - - - -const char SCA_KeyboardSensor::GetCurrentlyPressedKeys_doc[] = -"getCurrentlyPressedKeys()\n" -"\tGet a list of keys that are currently pressed.\n" ; - -PyObject* SCA_KeyboardSensor::PyGetCurrentlyPressedKeys() -{ - ShowDeprecationWarning("getCurrentlyPressedKeys()", "events"); - - SCA_IInputDevice* inputdev = ((SCA_KeyboardManager *)m_eventmgr)->GetInputDevice(); - - int num = inputdev->GetNumActiveEvents(); - PyObject* resultlist = PyList_New(num); - - if (num > 0) - { - int index = 0; - - for (int i=SCA_IInputDevice::KX_BEGINKEY ; i<= SCA_IInputDevice::KX_ENDKEY;i++) - { - const SCA_InputEvent & inevent = inputdev->GetEventValue((SCA_IInputDevice::KX_EnumInputs) i); - if ( (inevent.m_status == SCA_InputEvent::KX_ACTIVE) - || (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(resultlist,index,keypair); - index++; - - if (index >= num) /* should never happen */ - break; - } - } - } - - return resultlist; -} - -//<---- Deprecated - 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 +427,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 +435,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,32 +445,18 @@ 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}, - //<----- Deprecated KX_PYMETHODTABLE_O(SCA_KeyboardSensor, getKeyStatus), {NULL,NULL} //Sentinel }; @@ -671,20 +472,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 +487,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); } } |