diff options
Diffstat (limited to 'source/gameengine/Ketsji/KX_PythonInit.cpp')
-rw-r--r-- | source/gameengine/Ketsji/KX_PythonInit.cpp | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index 3a754f1f466..88993f20132 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -141,6 +141,8 @@ static char gp_GamePythonPathOrig[FILE_MAXDIR + FILE_MAXFILE] = ""; // not super static KX_Scene* gp_KetsjiScene = NULL; static KX_KetsjiEngine* gp_KetsjiEngine = NULL; static RAS_IRasterizer* gp_Rasterizer = NULL; +static SCA_PythonKeyboard* gp_PythonKeyboard = NULL; +static SCA_PythonMouse* gp_PythonMouse = NULL; void KX_SetActiveScene(class KX_Scene* scene) { @@ -1296,11 +1298,13 @@ PyObject* initGameLogic(KX_KetsjiEngine *engine, KX_Scene* scene) // quick hack PyDict_SetItemString(d, "globalDict", item=PyDict_New()); Py_DECREF(item); // Add keyboard and mouse attributes to this module - SCA_PythonKeyboard* pykeyb = new SCA_PythonKeyboard(gp_KetsjiEngine->GetKeyboardDevice()); - PyDict_SetItemString(d, "keyboard", pykeyb->NewProxy(true)); + MT_assert(!gp_PythonKeyboard); + gp_PythonKeyboard = new SCA_PythonKeyboard(gp_KetsjiEngine->GetKeyboardDevice()); + PyDict_SetItemString(d, "keyboard", gp_PythonKeyboard->NewProxy(true)); - SCA_PythonMouse* pymouse = new SCA_PythonMouse(gp_KetsjiEngine->GetMouseDevice(), gp_Canvas); - PyDict_SetItemString(d, "mouse", pymouse->NewProxy(true)); + MT_assert(!gp_PythonMouse); + gp_PythonMouse = new SCA_PythonMouse(gp_KetsjiEngine->GetMouseDevice(), gp_Canvas); + PyDict_SetItemString(d, "mouse", gp_PythonMouse->NewProxy(true)); ErrorObject = PyUnicode_FromString("GameLogic.error"); PyDict_SetItemString(d, "error", ErrorObject); @@ -1760,8 +1764,8 @@ static void setSandbox(TPythonSecurityLevel level) */ default: /* Allow importing internal text, from bpy_internal_import.py */ - PyDict_SetItemString(d, "reload", item=PyCFunction_New(bpy_reload_meth, NULL)); Py_DECREF(item); - PyDict_SetItemString(d, "__import__", item=PyCFunction_New(bpy_import_meth, NULL)); Py_DECREF(item); + PyDict_SetItemString(d, "reload", item=PyCFunction_New(&bpy_reload_meth, NULL)); Py_DECREF(item); + PyDict_SetItemString(d, "__import__", item=PyCFunction_New(&bpy_import_meth, NULL)); Py_DECREF(item); break; } } @@ -1926,6 +1930,13 @@ PyObject* initGamePlayerPythonScripting(const STR_String& progname, TPythonSecur void exitGamePlayerPythonScripting() { + /* Clean up the Python mouse and keyboard */ + delete gp_PythonKeyboard; + gp_PythonKeyboard = NULL; + + delete gp_PythonMouse; + gp_PythonMouse = NULL; + /* since python restarts we cant let the python backup of the sys.path hang around in a global pointer */ restorePySysObjects(); /* get back the original sys.path and clear the backup */ @@ -1962,6 +1973,13 @@ PyObject* initGamePythonScripting(const STR_String& progname, TPythonSecurityLev void exitGamePythonScripting() { + /* Clean up the Python mouse and keyboard */ + delete gp_PythonKeyboard; + gp_PythonKeyboard = NULL; + + delete gp_PythonMouse; + gp_PythonMouse = NULL; + restorePySysObjects(); /* get back the original sys.path and clear the backup */ bpy_import_main_set(NULL); PyObjectPlus::ClearDeprecationWarning(); @@ -2214,6 +2232,7 @@ PyObject* initGameKeys() KX_MACRO_addTypesToDict(d, ESCKEY, SCA_IInputDevice::KX_ESCKEY); KX_MACRO_addTypesToDict(d, TABKEY, SCA_IInputDevice::KX_TABKEY); KX_MACRO_addTypesToDict(d, RETKEY, SCA_IInputDevice::KX_RETKEY); + KX_MACRO_addTypesToDict(d, ENTERKEY, SCA_IInputDevice::KX_RETKEY); KX_MACRO_addTypesToDict(d, SPACEKEY, SCA_IInputDevice::KX_SPACEKEY); KX_MACRO_addTypesToDict(d, LINEFEEDKEY, SCA_IInputDevice::KX_LINEFEEDKEY); KX_MACRO_addTypesToDict(d, BACKSPACEKEY, SCA_IInputDevice::KX_BACKSPACEKEY); |