diff options
Diffstat (limited to 'source/gameengine/GamePlayer/ghost/GPG_Application.cpp')
-rw-r--r-- | source/gameengine/GamePlayer/ghost/GPG_Application.cpp | 113 |
1 files changed, 55 insertions, 58 deletions
diff --git a/source/gameengine/GamePlayer/ghost/GPG_Application.cpp b/source/gameengine/GamePlayer/ghost/GPG_Application.cpp index 580c80ee0a5..f859193ef7a 100644 --- a/source/gameengine/GamePlayer/ghost/GPG_Application.cpp +++ b/source/gameengine/GamePlayer/ghost/GPG_Application.cpp @@ -38,7 +38,6 @@ #endif #include "GL/glew.h" -#include "GPU_extensions.h" #include "GPG_Application.h" @@ -98,16 +97,16 @@ extern "C" #include "GHOST_IEventConsumer.h" #include "GHOST_IWindow.h" #include "GHOST_Rect.h" +#include "marshal.h" static void frameTimerProc(GHOST_ITimerTask* task, GHOST_TUns64 time); static GHOST_ISystem* fSystem = 0; static const int kTimerFreq = 10; -GPG_Application::GPG_Application(GHOST_ISystem* system) - : m_startSceneName(""), - m_startScene(0), - m_maggie(0), +GPG_Application::GPG_Application(GHOST_ISystem* system, struct Main* maggie, STR_String startSceneName) + : m_startSceneName(startSceneName), + m_maggie(maggie), m_exitRequested(0), m_system(system), m_mainWindow(0), @@ -128,8 +127,7 @@ GPG_Application::GPG_Application(GHOST_ISystem* system) m_blendermat(0), m_blenderglslmat(0), m_pyGlobalDictString(0), - m_pyGlobalDictString_Length(0), - m_isEmbedded(false) + m_pyGlobalDictString_Length(0) { fSystem = system; } @@ -144,16 +142,15 @@ GPG_Application::~GPG_Application(void) -bool GPG_Application::SetGameEngineData(struct Main* maggie, Scene *scene) +bool GPG_Application::SetGameEngineData(struct Main* maggie, STR_String startSceneName) { bool result = false; - if (maggie != NULL && scene != NULL) + if (maggie != NULL && startSceneName != "") { - G.scene = scene; + G.scene = (Scene*)maggie->scene.first; m_maggie = maggie; - m_startSceneName = scene->id.name+2; - m_startScene = scene; + m_startSceneName = startSceneName; result = true; } @@ -325,26 +322,6 @@ bool GPG_Application::startWindow(STR_String& title, return success; } -bool GPG_Application::startEmbeddedWindow(STR_String& title, - const GHOST_TEmbedderWindowID parentWindow, - const bool stereoVisual, - const int stereoMode) { - - m_mainWindow = fSystem->createWindow(title, 0, 0, 0, 0, GHOST_kWindowStateNormal, - GHOST_kDrawingContextTypeOpenGL, stereoVisual, parentWindow); - - if (!m_mainWindow) { - printf("error: could not create main window\n"); - exit(-1); - } - m_isEmbedded = true; - - bool success = initEngine(m_mainWindow, stereoMode); - if (success) { - success = startEngine(); - } - return success; -} bool GPG_Application::startFullScreen( @@ -503,7 +480,7 @@ bool GPG_Application::initEngine(GHOST_IWindow* window, const int stereoMode) { if (!m_engineInitialized) { - GPU_extensions_init(); + glewInit(); bgl::InitExtensions(true); // get and set the preferences @@ -522,16 +499,13 @@ bool GPG_Application::initEngine(GHOST_IWindow* window, const int stereoMode) bool fixed_framerate= (SYS_GetCommandLineInt(syshandle, "fixed_framerate", fixedFr) != 0); bool frameRate = (SYS_GetCommandLineInt(syshandle, "show_framerate", 0) != 0); - bool useLists = (SYS_GetCommandLineInt(syshandle, "displaylists", G.fileflags & G_FILE_DISPLAY_LISTS) != 0); - - if(GLEW_ARB_multitexture && GLEW_VERSION_1_1) - m_blendermat = (SYS_GetCommandLineInt(syshandle, "blender_material", 1) != 0); - - if(GPU_extensions_minimum_support()) - m_blenderglslmat = (SYS_GetCommandLineInt(syshandle, "blender_glsl_material", 1) != 0); - else if(G.fileflags & G_FILE_GAME_MAT_GLSL) - m_blendermat = false; + bool useLists = (SYS_GetCommandLineInt(syshandle, "displaylists", G.fileflags & G_FILE_DIAPLAY_LISTS) != 0); + if(GLEW_ARB_multitexture && GLEW_VERSION_1_1) { + int gameflag =(G.fileflags & G_FILE_GAME_MAT); + m_blendermat = (SYS_GetCommandLineInt(syshandle, "blender_material", gameflag) != 0); + } + // create the canvas, rasterizer and rendertools m_canvas = new GPG_Canvas(window); if (!m_canvas) @@ -654,34 +628,41 @@ bool GPG_Application::startEngine(void) { STR_String startscenename = m_startSceneName.Ptr(); m_ketsjiengine->SetSceneConverter(m_sceneconverter); - + // if (always_use_expand_framing) // sceneconverter->SetAlwaysUseExpandFraming(true); - if(m_blendermat && (G.fileflags & G_FILE_GAME_MAT)) + if(m_blendermat) m_sceneconverter->SetMaterials(true); - if(m_blenderglslmat && (G.fileflags & G_FILE_GAME_MAT_GLSL)) + if(m_blenderglslmat) m_sceneconverter->SetGLSLMaterials(true); KX_Scene* startscene = new KX_Scene(m_keyboard, m_mouse, m_networkdevice, m_audiodevice, - startscenename, - m_startScene); + startscenename); // some python things PyObject* dictionaryobject = initGamePlayerPythonScripting("Ketsji", psl_Lowest); m_ketsjiengine->SetPythonDictionary(dictionaryobject); initRasterizer(m_rasterizer, m_canvas); - PyObject *gameLogic = initGameLogic(m_ketsjiengine, startscene); + PyObject *gameLogic = initGameLogic(startscene); PyDict_SetItemString(dictionaryobject, "GameLogic", gameLogic); // Same as importing the module initGameKeys(); initPythonConstraintBinding(); initMathutils(); /* Restore the dict */ - loadGamePythonConfig(m_pyGlobalDictString, m_pyGlobalDictString_Length); + if (m_pyGlobalDictString) { + PyObject* pyGlobalDict = PyMarshal_ReadObjectFromString(m_pyGlobalDictString, m_pyGlobalDictString_Length); + if (pyGlobalDict) { + PyDict_SetItemString(PyModule_GetDict(gameLogic), "globalDict", pyGlobalDict); // Same as importing the module. + } else { + PyErr_Clear(); + printf("Error could not marshall string\n"); + } + } m_sceneconverter->ConvertScene( startscenename, @@ -719,12 +700,30 @@ bool GPG_Application::startEngine(void) void GPG_Application::stopEngine() { // get the python dict and convert to a string for future use - char *marshal_buffer; - m_pyGlobalDictString_Length = saveGamePythonConfig(&marshal_buffer); - if (m_pyGlobalDictString_Length) { - m_pyGlobalDictString = static_cast<char *> (malloc(m_pyGlobalDictString_Length)); - memcpy(m_pyGlobalDictString, marshal_buffer, m_pyGlobalDictString_Length); - } + { + SetPyGlobalDictMarshal(NULL, 0); + + PyObject* gameLogic = PyImport_ImportModule("GameLogic"); + if (gameLogic) { + PyObject* pyGlobalDict = PyDict_GetItemString(PyModule_GetDict(gameLogic), "globalDict"); // Same as importing the module + if (pyGlobalDict) { + PyObject* pyGlobalDictMarshal = PyMarshal_WriteObjectToString( pyGlobalDict, 2); // Py_MARSHAL_VERSION == 2 as of Py2.5 + if (pyGlobalDictMarshal) { + m_pyGlobalDictString_Length = PyString_Size(pyGlobalDictMarshal); + PyObject_Print(pyGlobalDictMarshal, stderr, 0); + m_pyGlobalDictString = static_cast<char *> (malloc(m_pyGlobalDictString_Length)); + memcpy(m_pyGlobalDictString, PyString_AsString(pyGlobalDictMarshal), m_pyGlobalDictString_Length); + } else { + printf("Error, GameLogic.globalDict could not be marshal'd\n"); + } + } else { + printf("Error, GameLogic.globalDict was removed\n"); + } + } else { + printf("Error, GameLogic failed to import GameLogic.globalDict will be lost\n"); + } + } + // when exiting the mainloop exitGamePythonScripting(); @@ -745,8 +744,6 @@ void GPG_Application::stopEngine() void GPG_Application::exitEngine() { - GPU_extensions_exit(); - if (m_ketsjiengine) { stopEngine(); @@ -873,7 +870,7 @@ bool GPG_Application::handleKey(GHOST_IEvent* event, bool isDown) GHOST_TEventKeyData* keyData = static_cast<GHOST_TEventKeyData*>(eventData); //no need for this test //if (fSystem->getFullScreen()) { - if (keyData->key == GHOST_kKeyEsc && !m_keyboard->m_hookesc && !m_isEmbedded) { + if (keyData->key == GHOST_kKeyEsc && !m_keyboard->m_hookesc) { m_exitRequested = KX_EXIT_REQUEST_OUTSIDE; } //} |