get rid of annoying duplicate python initialization code, added setupGamePython() which initializes modules
This commit is contained in:
@@ -391,22 +391,8 @@ extern "C" void StartKetsjiShell(struct bContext *C, struct ARegion *ar, rcti *c
|
|||||||
|
|
||||||
#ifndef DISABLE_PYTHON
|
#ifndef DISABLE_PYTHON
|
||||||
// some python things
|
// some python things
|
||||||
PyObject* dictionaryobject = initGamePythonScripting("Ketsji", psl_Lowest, blenderdata);
|
PyObject *gameLogic, *gameLogic_keys;
|
||||||
ketsjiengine->SetPyNamespace(dictionaryobject);
|
setupGamePython(ketsjiengine, startscene, blenderdata, pyGlobalDict, &gameLogic, &gameLogic_keys, 0, NULL);
|
||||||
initRasterizer(rasterizer, canvas);
|
|
||||||
PyObject *gameLogic = initGameLogic(ketsjiengine, startscene);
|
|
||||||
PyDict_SetItemString(PyModule_GetDict(gameLogic), "globalDict", pyGlobalDict); // Same as importing the module.
|
|
||||||
PyObject *gameLogic_keys = PyDict_Keys(PyModule_GetDict(gameLogic));
|
|
||||||
PyDict_SetItemString(dictionaryobject, "GameLogic", gameLogic); // Same as importing the module.
|
|
||||||
|
|
||||||
initGameKeys();
|
|
||||||
initPythonConstraintBinding();
|
|
||||||
initMathutils();
|
|
||||||
initGeometry();
|
|
||||||
initBGL();
|
|
||||||
#ifdef WITH_FFMPEG
|
|
||||||
initVideoTexture();
|
|
||||||
#endif
|
|
||||||
#endif // DISABLE_PYTHON
|
#endif // DISABLE_PYTHON
|
||||||
|
|
||||||
//initialize Dome Settings
|
//initialize Dome Settings
|
||||||
@@ -622,6 +608,7 @@ extern "C" void StartKetsjiShellSimulation(struct wmWindow *win,
|
|||||||
// Acquire Python's GIL (global interpreter lock)
|
// Acquire Python's GIL (global interpreter lock)
|
||||||
// so we can safely run Python code and API calls
|
// so we can safely run Python code and API calls
|
||||||
PyGILState_STATE gilstate = PyGILState_Ensure();
|
PyGILState_STATE gilstate = PyGILState_Ensure();
|
||||||
|
PyObject *pyGlobalDict = PyDict_New(); /* python utility storage, spans blend file loading */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bgl::InitExtensions(true);
|
bgl::InitExtensions(true);
|
||||||
@@ -722,19 +709,8 @@ extern "C" void StartKetsjiShellSimulation(struct wmWindow *win,
|
|||||||
|
|
||||||
#ifndef DISABLE_PYTHON
|
#ifndef DISABLE_PYTHON
|
||||||
// some python things
|
// some python things
|
||||||
PyObject* dictionaryobject = initGamePythonScripting("Ketsji", psl_Lowest, blenderdata);
|
PyObject *gameLogic, *gameLogic_keys;
|
||||||
ketsjiengine->SetPyNamespace(dictionaryobject);
|
setupGamePython(ketsjiengine, startscene, blenderdata, pyGlobalDict, &gameLogic, &gameLogic_keys, 0, NULL);
|
||||||
initRasterizer(rasterizer, canvas);
|
|
||||||
PyObject *gameLogic = initGameLogic(ketsjiengine, startscene);
|
|
||||||
PyDict_SetItemString(dictionaryobject, "GameLogic", gameLogic); // Same as importing the module
|
|
||||||
initGameKeys();
|
|
||||||
initPythonConstraintBinding();
|
|
||||||
initMathutils();
|
|
||||||
initGeometry();
|
|
||||||
initBGL();
|
|
||||||
#ifdef WITH_FFMPEG
|
|
||||||
initVideoTexture();
|
|
||||||
#endif
|
|
||||||
#endif // DISABLE_PYTHON
|
#endif // DISABLE_PYTHON
|
||||||
|
|
||||||
if (sceneconverter)
|
if (sceneconverter)
|
||||||
@@ -820,6 +796,8 @@ extern "C" void StartKetsjiShellSimulation(struct wmWindow *win,
|
|||||||
} while (exitrequested == KX_EXIT_REQUEST_RESTART_GAME || exitrequested == KX_EXIT_REQUEST_START_OTHER_GAME);
|
} while (exitrequested == KX_EXIT_REQUEST_RESTART_GAME || exitrequested == KX_EXIT_REQUEST_START_OTHER_GAME);
|
||||||
|
|
||||||
#ifndef DISABLE_PYTHON
|
#ifndef DISABLE_PYTHON
|
||||||
|
Py_DECREF(pyGlobalDict);
|
||||||
|
|
||||||
// Release Python's GIL
|
// Release Python's GIL
|
||||||
PyGILState_Release(gilstate);
|
PyGILState_Release(gilstate);
|
||||||
#endif
|
#endif
|
||||||
|
@@ -679,21 +679,11 @@ bool GPG_Application::startEngine(void)
|
|||||||
startscenename,
|
startscenename,
|
||||||
m_startScene);
|
m_startScene);
|
||||||
|
|
||||||
|
#ifndef DISABLE_PYTHON
|
||||||
// some python things
|
// some python things
|
||||||
PyObject* dictionaryobject = initGamePlayerPythonScripting("Ketsji", psl_Lowest, m_maggie, m_argc, m_argv);
|
PyObject *gameLogic, *gameLogic_keys;
|
||||||
m_ketsjiengine->SetPyNamespace(dictionaryobject);
|
setupGamePython(m_ketsjiengine, startscene, m_maggie, NULL, &gameLogic, &gameLogic_keys, m_argc, m_argv);
|
||||||
initRasterizer(m_rasterizer, m_canvas);
|
#endif // DISABLE_PYTHON
|
||||||
PyObject *gameLogic = initGameLogic(m_ketsjiengine, startscene);
|
|
||||||
PyDict_SetItemString(dictionaryobject, "GameLogic", gameLogic); // Same as importing the module
|
|
||||||
initGameKeys();
|
|
||||||
initPythonConstraintBinding();
|
|
||||||
initMathutils();
|
|
||||||
initGeometry();
|
|
||||||
initBGL();
|
|
||||||
#ifdef WITH_FFMPEG
|
|
||||||
initVideoTexture();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//initialize Dome Settings
|
//initialize Dome Settings
|
||||||
if(m_startScene->gm.stereoflag == STEREO_DOME)
|
if(m_startScene->gm.stereoflag == STEREO_DOME)
|
||||||
|
@@ -1926,6 +1926,38 @@ void exitGamePythonScripting()
|
|||||||
PyObjectPlus::ClearDeprecationWarning();
|
PyObjectPlus::ClearDeprecationWarning();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* similar to the above functions except it sets up the namespace
|
||||||
|
* and other more general things */
|
||||||
|
void setupGamePython(KX_KetsjiEngine* ketsjiengine, KX_Scene* startscene, Main *blenderdata, PyObject * pyGlobalDict, PyObject **gameLogic, PyObject **gameLogic_keys, int argc, char** argv)
|
||||||
|
{
|
||||||
|
PyObject* dictionaryobject;
|
||||||
|
|
||||||
|
if(argv) /* player only */
|
||||||
|
dictionaryobject= initGamePlayerPythonScripting("Ketsji", psl_Lowest, blenderdata, argc, argv);
|
||||||
|
else
|
||||||
|
dictionaryobject= initGamePythonScripting("Ketsji", psl_Lowest, blenderdata);
|
||||||
|
|
||||||
|
ketsjiengine->SetPyNamespace(dictionaryobject);
|
||||||
|
initRasterizer(ketsjiengine->GetRasterizer(), ketsjiengine->GetCanvas());
|
||||||
|
*gameLogic = initGameLogic(ketsjiengine, startscene);
|
||||||
|
|
||||||
|
/* is set in initGameLogic so only set here if we want it to persist between scenes */
|
||||||
|
if(pyGlobalDict)
|
||||||
|
PyDict_SetItemString(PyModule_GetDict(*gameLogic), "globalDict", pyGlobalDict); // Same as importing the module.
|
||||||
|
|
||||||
|
*gameLogic_keys = PyDict_Keys(PyModule_GetDict(*gameLogic));
|
||||||
|
PyDict_SetItemString(dictionaryobject, "GameLogic", *gameLogic); // Same as importing the module.
|
||||||
|
|
||||||
|
initGameKeys();
|
||||||
|
initPythonConstraintBinding();
|
||||||
|
initMathutils();
|
||||||
|
initGeometry();
|
||||||
|
initBGL();
|
||||||
|
|
||||||
|
#ifdef WITH_FFMPEG
|
||||||
|
initVideoTexture();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
static struct PyModuleDef Rasterizer_module_def = {
|
static struct PyModuleDef Rasterizer_module_def = {
|
||||||
{}, /* m_base */
|
{}, /* m_base */
|
||||||
|
@@ -52,6 +52,8 @@ void exitGamePlayerPythonScripting();
|
|||||||
PyObject* initGamePythonScripting(const STR_String& progname, TPythonSecurityLevel level, struct Main *maggie);
|
PyObject* initGamePythonScripting(const STR_String& progname, TPythonSecurityLevel level, struct Main *maggie);
|
||||||
void exitGamePythonScripting();
|
void exitGamePythonScripting();
|
||||||
|
|
||||||
|
void setupGamePython(KX_KetsjiEngine* ketsjiengine, KX_Scene* startscene, Main *blenderdata, PyObject *pyGlobalDict, PyObject **gameLogic, PyObject **gameLogic_keys, int argc, char** argv);
|
||||||
|
|
||||||
void setGamePythonPath(char *path);
|
void setGamePythonPath(char *path);
|
||||||
void resetGamePythonPath();
|
void resetGamePythonPath();
|
||||||
void pathGamePythonConfig( char *path );
|
void pathGamePythonConfig( char *path );
|
||||||
|
Reference in New Issue
Block a user