[Bf-codereview] Patch: application handler for Game Engine start/end (issue 13123044)
sjdv1982 at gmail.com
sjdv1982 at gmail.com
Tue Aug 20 16:35:44 CEST 2013
Reviewers: bf-codereview_blender.org,
Description:
This patch adds bpy.app.handlers.game_start and
bpy.app.handlers.game_end, triggered when the BGE starts and ends when
running inside Blender.
Please review this at https://codereview.appspot.com/13123044/
Affected files:
source/blender/blenlib/BLI_callbacks.h
source/blender/editors/space_view3d/view3d_view.c
source/blender/python/intern/bpy_app_handlers.c
Index: source/blender/editors/space_view3d/view3d_view.c
===================================================================
--- source/blender/editors/space_view3d/view3d_view.c (revision 58801)
+++ source/blender/editors/space_view3d/view3d_view.c (working copy)
@@ -40,6 +40,7 @@
#include "BLI_rect.h"
#include "BLI_listbase.h"
#include "BLI_utildefines.h"
+#include "BLI_callbacks.h"
#include "BKE_anim.h"
#include "BKE_action.h"
@@ -1438,6 +1439,7 @@
{
#ifdef WITH_GAMEENGINE
Scene *startscene = CTX_data_scene(C);
+ Main *bmain = CTX_data_main(C);
ScrArea /* *sa, */ /* UNUSED */ *prevsa = CTX_wm_area(C);
ARegion *ar, *prevar = CTX_wm_region(C);
wmWindow *prevwin = CTX_wm_window(C);
@@ -1454,6 +1456,8 @@
* the window manager until after this operator exits */
WM_redraw_windows(C);
+ BLI_callback_exec(bmain, &startscene->id, BLI_CB_EVT_GAME_START);
+
rv3d = CTX_wm_region_view3d(C);
/* sa = CTX_wm_area(C); */ /* UNUSED */
ar = CTX_wm_region(C);
@@ -1509,6 +1513,8 @@
BKE_scene_set_background(CTX_data_main(C), startscene);
//XXX BKE_scene_update_for_newframe(bmain, scene, scene->lay);
+ BLI_callback_exec(bmain, &startscene->id, BLI_CB_EVT_GAME_END);
+
return OPERATOR_FINISHED;
#else
(void)C; /* unused */
Index: source/blender/python/intern/bpy_app_handlers.c
===================================================================
--- source/blender/python/intern/bpy_app_handlers.c (revision 58801)
+++ source/blender/python/intern/bpy_app_handlers.c (working copy)
@@ -57,6 +57,8 @@
{(char *)"save_post", (char *)"Callback list - on saving a blend
file (after)"},
{(char *)"scene_update_pre", (char *)"Callback list - on updating the
scenes data (before)"},
{(char *)"scene_update_post", (char *)"Callback list - on updating the
scenes data (after)"},
+ {(char *)"game_start", (char *)"Callback list - on starting the
game engine"},
+ {(char *)"game_end", (char *)"Callback list - on ending the game
engine"},
/* sets the permanent tag */
# define APP_CB_OTHER_FIELDS 1
Index: source/blender/blenlib/BLI_callbacks.h
===================================================================
--- source/blender/blenlib/BLI_callbacks.h (revision 58801)
+++ source/blender/blenlib/BLI_callbacks.h (working copy)
@@ -43,6 +43,8 @@
BLI_CB_EVT_SAVE_POST,
BLI_CB_EVT_SCENE_UPDATE_PRE,
BLI_CB_EVT_SCENE_UPDATE_POST,
+ BLI_CB_EVT_GAME_START,
+ BLI_CB_EVT_GAME_END,
BLI_CB_EVT_TOT
} eCbEvent;
More information about the Bf-codereview
mailing list