From 14fceb64cc4e7e1a3f9f6e01b7db52f77fa95b2b Mon Sep 17 00:00:00 2001 From: Ines Almeida Date: Wed, 4 Jun 2014 09:17:52 +0100 Subject: [PATCH] BGE: python API initialization cleanup -Removing unused parameters -Updating some parts to match bpy_interface.c initialization --- source/gameengine/Ketsji/KX_PythonInit.cpp | 34 ++++++++++++---------- source/gameengine/Ketsji/KX_PythonInit.h | 7 ++--- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index 234d03ab618..fc669272f7c 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -1960,7 +1960,7 @@ static struct _inittab bge_internal_modules[] = { * Python is not initialized. * see bpy_interface.c's BPY_python_start() which shares the same functionality in blender. */ -PyObject *initGamePlayerPythonScripting(const STR_String& progname, TPythonSecurityLevel level, Main *maggie, int argc, char** argv) +PyObject *initGamePlayerPythonScripting(Main *maggie, int argc, char** argv) { /* Yet another gotcha in the py api * Cant run PySys_SetArgv more than once because this adds the @@ -1969,16 +1969,22 @@ PyObject *initGamePlayerPythonScripting(const STR_String& progname, TPythonSecur * somehow it remembers the sys.path - Campbell */ static bool first_time = true; - const char * const py_path_bundle = BLI_get_folder(BLENDER_SYSTEM_PYTHON, NULL); + const char * const py_path_bundle = BLI_get_folder(BLENDER_SYSTEM_PYTHON, NULL); -#if 0 // TODO - py3 - STR_String pname = progname; - Py_SetProgramName(pname.Ptr()); -#endif + /* not essential but nice to set our name */ + static wchar_t program_path_wchar[FILE_MAX]; /* python holds a reference */ + BLI_strncpy_wchar_from_utf8(program_path_wchar, BLI_program_path(), sizeof(program_path_wchar) / sizeof(wchar_t)); + Py_SetProgramName(program_path_wchar); + /* Update, Py3.3 resolves attempting to parse non-existing header */ + #if 0 + /* Python 3.2 now looks for '2.xx/python/include/python3.2d/pyconfig.h' to + * parse from the 'sysconfig' module which is used by 'site', + * so for now disable site. alternatively we could copy the file. */ if (py_path_bundle != NULL) { Py_NoSiteFlag = 1; } + #endif Py_FrozenFlag = 1; @@ -2064,12 +2070,12 @@ void exitGamePlayerPythonScripting() /** * Python is already initialized. */ -PyObject *initGamePythonScripting(const STR_String& progname, TPythonSecurityLevel level, Main *maggie) +PyObject *initGamePythonScripting(Main *maggie) { -#if 0 // XXX TODO Py3 - STR_String pname = progname; - Py_SetProgramName(pname.Ptr()); -#endif + /* not essential but nice to set our name */ + static wchar_t program_path_wchar[FILE_MAX]; /* python holds a reference */ + BLI_strncpy_wchar_from_utf8(program_path_wchar, BLI_program_path(), sizeof(program_path_wchar) / sizeof(wchar_t)); + Py_SetProgramName(program_path_wchar); #ifdef WITH_AUDASPACE /* accessing a SoundActuator's sound results in a crash if aud is not initialized... */ @@ -2119,9 +2125,9 @@ void setupGamePython(KX_KetsjiEngine* ketsjiengine, KX_Scene *startscene, Main * PyObject *dictionaryobject; if (argv) /* player only */ - dictionaryobject= initGamePlayerPythonScripting("Ketsji", psl_Lowest, blenderdata, argc, argv); + dictionaryobject= initGamePlayerPythonScripting(blenderdata, argc, argv); else - dictionaryobject= initGamePythonScripting("Ketsji", psl_Lowest, blenderdata); + dictionaryobject= initGamePythonScripting(blenderdata); ketsjiengine->SetPyNamespace(dictionaryobject); initRasterizer(ketsjiengine->GetRasterizer(), ketsjiengine->GetCanvas()); @@ -2175,8 +2181,6 @@ PyObject *initRasterizer(RAS_IRasterizer* rasty,RAS_ICanvas* canvas) { gp_Canvas = canvas; gp_Rasterizer = rasty; - - PyObject *m; PyObject *d; PyObject *item; diff --git a/source/gameengine/Ketsji/KX_PythonInit.h b/source/gameengine/Ketsji/KX_PythonInit.h index 719a74ee219..e9c94a05b3d 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.h +++ b/source/gameengine/Ketsji/KX_PythonInit.h @@ -47,10 +47,9 @@ extern bool gUseVisibilityTemp; PyObject *initGameLogic(class KX_KetsjiEngine *engine, class KX_Scene *ketsjiscene); PyObject *initGameKeys(); PyObject *initRasterizer(class RAS_IRasterizer *rasty,class RAS_ICanvas *canvas); -PyObject *initGamePlayerPythonScripting(const STR_String &progname, TPythonSecurityLevel level, - struct Main *maggie, int argc, char **argv); -PyObject *initVideoTexture(void); -PyObject *initGamePythonScripting(const STR_String &progname, TPythonSecurityLevel level, struct Main *maggie); +PyObject *initVideoTexture(void); +PyObject *initGamePlayerPythonScripting(struct Main *maggie, int argc, char **argv); +PyObject *initGamePythonScripting(struct Main *maggie); void exitGamePlayerPythonScripting(); void exitGamePythonScripting();