From 0dea748e01dab697d2f8ac245bbd5e925cd732ce Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 12 Sep 2008 02:15:16 +0000 Subject: save and load configuration actuator, (option in game actuator menu) saves a marshal'd GameLogic.globalDict to the blendfile path with the blend extension replaced with bgeconf Use this in YoFrankie to save keyboard layout and graphics quality settings. --- .../GamePlayer/ghost/GPG_Application.cpp | 47 ++++------------------ 1 file changed, 7 insertions(+), 40 deletions(-) (limited to 'source/gameengine/GamePlayer/ghost') diff --git a/source/gameengine/GamePlayer/ghost/GPG_Application.cpp b/source/gameengine/GamePlayer/ghost/GPG_Application.cpp index f35e2894f65..0287178004d 100644 --- a/source/gameengine/GamePlayer/ghost/GPG_Application.cpp +++ b/source/gameengine/GamePlayer/ghost/GPG_Application.cpp @@ -98,7 +98,6 @@ 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); @@ -685,15 +684,7 @@ bool GPG_Application::startEngine(void) initMathutils(); /* Restore the dict */ - 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"); - } - } + loadGamePythonConfig(m_pyGlobalDictString, m_pyGlobalDictString_Length); m_sceneconverter->ConvertScene( startscenename, @@ -731,36 +722,12 @@ bool GPG_Application::startEngine(void) void GPG_Application::stopEngine() { // get the python dict and convert to a string for future use - { - 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) { -#ifdef Py_MARSHAL_VERSION - PyObject* pyGlobalDictMarshal = PyMarshal_WriteObjectToString( pyGlobalDict, 2); // Py_MARSHAL_VERSION == 2 as of Py2.5 -#else - PyObject* pyGlobalDictMarshal = PyMarshal_WriteObjectToString( pyGlobalDict ); -#endif - if (pyGlobalDictMarshal) { - m_pyGlobalDictString_Length = PyString_Size(pyGlobalDictMarshal); - // for testing only - // PyObject_Print(pyGlobalDictMarshal, stderr, 0); - m_pyGlobalDictString = static_cast (malloc(m_pyGlobalDictString_Length)); - memcpy(m_pyGlobalDictString, PyString_AsString(pyGlobalDictMarshal), m_pyGlobalDictString_Length); - } else { - printf("Error, GameLogic.globalDict could not be marshal'd\n"); - } - Py_DECREF(gameLogic); - } else { - printf("Error, GameLogic.globalDict was removed\n"); - } - } else { - printf("Error, GameLogic failed to import GameLogic.globalDict will be lost\n"); - } - } - + char *marshal_buffer; + m_pyGlobalDictString_Length = saveGamePythonConfig(&marshal_buffer); + if (m_pyGlobalDictString_Length) { + m_pyGlobalDictString = static_cast (malloc(m_pyGlobalDictString_Length)); + memcpy(m_pyGlobalDictString, marshal_buffer, m_pyGlobalDictString_Length); + } // when exiting the mainloop exitGamePythonScripting(); -- cgit v1.2.3