Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenoit Bolsee <benoit.bolsee@online.be>2012-09-02 01:23:05 +0400
committerBenoit Bolsee <benoit.bolsee@online.be>2012-09-02 01:23:05 +0400
commit53f343edd785f346dccdf39dedfe7626260b63a5 (patch)
treea9c3ac907eae3dd1247168e4cd9dff2760669b27 /source/gameengine/GamePlayer/ghost/GPG_ghost.cpp
parent779ecb06dd3f3b5c47391675622fb96d041b23ae (diff)
..\commmit_hive.txt
Diffstat (limited to 'source/gameengine/GamePlayer/ghost/GPG_ghost.cpp')
-rw-r--r--source/gameengine/GamePlayer/ghost/GPG_ghost.cpp76
1 files changed, 67 insertions, 9 deletions
diff --git a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp
index 41f641b4368..f4d4f774db2 100644
--- a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp
+++ b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp
@@ -47,6 +47,7 @@
#endif // __APPLE__
#include "KX_KetsjiEngine.h"
#include "KX_PythonInit.h"
+#include "KX_PythonMain.h"
/**********************************
* Begin Blender include block
@@ -332,6 +333,40 @@ static BlendFileData *load_game_data(const char *progname, char *filename = NULL
return bfd;
}
+bool GPG_NextFrame(GHOST_ISystem* system, GPG_Application *app, int &exitcode, STR_String &exitstring, GlobalSettings *gs)
+{
+ bool run = true;
+ system->processEvents(false);
+ system->dispatchEvents();
+ if ((exitcode = app->getExitRequested()))
+ {
+ run = false;
+ exitstring = app->getExitString();
+ *gs = *app->getGlobalSettings();
+ }
+ return run;
+}
+
+struct GPG_NextFrameState {
+ GHOST_ISystem* system;
+ GPG_Application *app;
+ GlobalSettings *gs;
+} gpg_nextframestate;
+
+int GPG_PyNextFrame(void *state0)
+{
+ GPG_NextFrameState *state = (GPG_NextFrameState *) state0;
+ int exitcode;
+ STR_String exitstring;
+ bool run = GPG_NextFrame(state->system, state->app, exitcode, exitstring, state->gs);
+ if (run) return 0;
+ else {
+ if (exitcode)
+ fprintf(stderr, "Exit code %d: %s\n", exitcode, exitstring.ReadPtr());
+ return 1;
+ }
+}
+
int main(int argc, char** argv)
{
int i;
@@ -966,17 +1001,39 @@ int main(int argc, char** argv)
// Enter main loop
bool run = true;
- while (run)
+ char *python_main = NULL;
+ pynextframestate.state = NULL;
+ pynextframestate.func = NULL;
+#ifdef WITH_PYTHON
+ python_main = KX_GetPythonMain(scene);
+#endif // WITH_PYTHON
+ if (python_main)
{
- system->processEvents(false);
- system->dispatchEvents();
- app.EngineNextFrame();
-
- if ((exitcode = app.getExitRequested()))
+ char *python_code = KX_GetPythonCode(maggie, python_main);
+ if (python_code)
+ {
+#ifdef WITH_PYTHON
+ gpg_nextframestate.system = system;
+ gpg_nextframestate.app = &app;
+ gpg_nextframestate.gs = &gs;
+ pynextframestate.state = &gpg_nextframestate;
+ pynextframestate.func = &GPG_PyNextFrame;
+
+ printf("Yielding control to Python script '%s'...\n", python_main);
+ PyRun_SimpleString(python_code);
+ printf("Exit Python script '%s'\n", python_main);
+#endif // WITH_PYTHON
+ MEM_freeN(python_code);
+ }
+ else {
+ fprintf(stderr, "ERROR: cannot yield control to Python: no Python text data block named '%s'\n", python_main);
+ }
+ }
+ else
+ {
+ while (run)
{
- run = false;
- exitstring = app.getExitString();
- gs = *app.getGlobalSettings();
+ run = GPG_NextFrame(system, &app, exitcode, exitstring, &gs);
}
}
app.StopGameEngine();
@@ -986,6 +1043,7 @@ int main(int argc, char** argv)
system->removeEventConsumer(&app);
BLO_blendfiledata_free(bfd);
+ if (python_main) MEM_freeN(python_main);
}
} while (exitcode == KX_EXIT_REQUEST_RESTART_GAME || exitcode == KX_EXIT_REQUEST_START_OTHER_GAME);
}