diff options
author | Campbell Barton <ideasman42@gmail.com> | 2008-09-12 06:15:16 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2008-09-12 06:15:16 +0400 |
commit | 0dea748e01dab697d2f8ac245bbd5e925cd732ce (patch) | |
tree | 4699d5a262f3ff2a78643fd35243f0225b9397b3 /source/gameengine/GamePlayer | |
parent | 75841bc97f82836e7af5524b79220b984da3b4f8 (diff) |
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.
Diffstat (limited to 'source/gameengine/GamePlayer')
-rw-r--r-- | source/gameengine/GamePlayer/ghost/GPG_Application.cpp | 47 |
1 files changed, 7 insertions, 40 deletions
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<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"); - } - 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<char *> (malloc(m_pyGlobalDictString_Length)); + memcpy(m_pyGlobalDictString, marshal_buffer, m_pyGlobalDictString_Length); + } // when exiting the mainloop exitGamePythonScripting(); |