From 481b4842cf1f1feae8b0c777eb56275400047074 Mon Sep 17 00:00:00 2001 From: Mitchell Stokes Date: Tue, 22 Mar 2011 08:35:56 +0000 Subject: [PATCH] Blenderplayer: Fixing import issues. Using PyImport_ExtendInittab() for the Blender modules allows them to be imported in the Blenderplayer. --- source/gameengine/Ketsji/KX_PythonInit.cpp | 36 +++++++--------------- source/gameengine/Ketsji/KX_PythonInit.h | 4 --- 2 files changed, 11 insertions(+), 29 deletions(-) diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index ad3f4b06323..d274b3e4eac 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -1917,6 +1917,15 @@ static void restorePySysObjects(void) // PyObject_Print(sys_path, stderr, 0); } +// Copied from bpy_interface.c +static struct _inittab bpy_internal_modules[]= { + {"mathutils", BPyInit_mathutils}, + {"bgl", BPyInit_bgl}, + {"blf", BPyInit_blf}, + {"aud", AUD_initPython}, + {NULL, NULL} +}; + /** * Python is not initialised. */ @@ -1957,6 +1966,8 @@ PyObject* initGamePlayerPythonScripting(const STR_String& progname, TPythonSecur bpy_import_main_set(maggie); initPySysObjects(maggie); + + PyImport_ExtendInittab(bpy_internal_modules); first_time = false; @@ -2045,11 +2056,6 @@ void setupGamePython(KX_KetsjiEngine* ketsjiengine, KX_Scene* startscene, Main * initGameKeys(); initPythonConstraintBinding(); - initMathutils(); - initGeometry(); - initBGL(); - initBLF(); - AUD_initPython(); initVideoTexture(); /* could be done a lot more nicely, but for now a quick way to get bge.* working */ @@ -2358,26 +2364,6 @@ PyObject* initGameKeys() return d; } -PyObject* initMathutils() -{ - return BPyInit_mathutils(); -} - -PyObject* initGeometry() -{ - return BPyInit_mathutils_geometry(); -} - -PyObject* initBGL() -{ - return BPyInit_bgl(); -} - -PyObject* initBLF() -{ - return BPyInit_blf(); -} - // utility function for loading and saving the globalDict int saveGamePythonConfig( char **marshal_buffer) { diff --git a/source/gameengine/Ketsji/KX_PythonInit.h b/source/gameengine/Ketsji/KX_PythonInit.h index f062aa2d661..1b172c35eff 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.h +++ b/source/gameengine/Ketsji/KX_PythonInit.h @@ -49,10 +49,6 @@ PyObject* initGameLogic(class KX_KetsjiEngine *engine, class KX_Scene* ketsjisce 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* initMathutils(); -PyObject* initGeometry(); -PyObject* initBGL(); -PyObject* initBLF(); PyObject* initVideoTexture(void); void exitGamePlayerPythonScripting(); PyObject* initGamePythonScripting(const STR_String& progname, TPythonSecurityLevel level, struct Main *maggie);