BGE events, not sure every event works as it should but keyboard looking and mouse...
authorCampbell Barton <ideasman42@gmail.com>
Sat, 13 Jun 2009 20:58:43 +0000 (20:58 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sat, 13 Jun 2009 20:58:43 +0000 (20:58 +0000)
Tested some basic logic brick blend files that use key input which run properly.

source/blender/editors/space_view3d/view3d_view.c
source/blender/windowmanager/intern/wm_event_system.c
source/blender/windowmanager/intern/wm_window.c
source/blender/windowmanager/wm_event_system.h
source/blender/windowmanager/wm_window.h
source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp

index eaa2306..2db5f2c 100644 (file)
@@ -1382,21 +1382,29 @@ void VIEW3D_OT_localview(wmOperatorType *ot)
        ot->poll= ED_operator_view3d_active;
 }
 
-
-static void SaveState(void)
+static ListBase queue_back;
+static void SaveState(bContext *C)
 {
+       wmWindow *win= CTX_wm_window(C);
+       
        glPushAttrib(GL_ALL_ATTRIB_BITS);
 
        GPU_state_init();
 
        if(G.f & G_TEXTUREPAINT)
                GPU_paint_set_mipmap(1);
-
+       
+       queue_back= win->queue;
+       
+       win->queue.first= win->queue.last= NULL;
+       
        //XXX waitcursor(1);
 }
 
-static void RestoreState(void)
+static void RestoreState(bContext *C)
 {
+       wmWindow *win= CTX_wm_window(C);
+       
        if(G.f & G_TEXTUREPAINT)
                GPU_paint_set_mipmap(0);
 
@@ -1407,34 +1415,33 @@ static void RestoreState(void)
        //XXX reset_slowparents();
        //XXX waitcursor(0);
        //XXX G.qual= 0;
+       
+       win->queue= queue_back;
+       
        glPopAttrib();
 }
 
 /* maybe we need this defined somewhere else */
-extern void StartKetsjiShell(wmWindow *win, ScrArea *area, struct ARegion *ar, struct Scene *scene, struct Main* maggie,int always_use_expand_framing);
+extern void StartKetsjiShell(struct bContext *C,int always_use_expand_framing);
 
 
 static int game_engine_exec(bContext *C, wmOperator *unused)
 {
-       View3D *v3d= CTX_wm_view3d(C);
-       ScrArea *sa= CTX_wm_area(C); // curarea
-       ARegion *ar= CTX_wm_region(C);
-       Scene *sc, *startscene = CTX_data_scene(C);
+       Scene *startscene = CTX_data_scene(C);
        
 #if GAMEBLENDER == 1
-       SaveState();
-       StartKetsjiShell(CTX_wm_window(C), sa, ar, startscene, CTX_data_main(C), 1);
-       RestoreState();
+       SaveState(C);
+       StartKetsjiShell(C, 1);
+       RestoreState(C);
        
        //XXX restore_all_scene_cfra(scene_cfra_store);
        set_scene_bg(startscene);
        //XXX scene_update_for_newframe(G.scene, G.scene->lay);
        
-       ED_area_tag_redraw(CTX_wm_area(C));
 #else
        printf("GameEngine Disabled\n");
 #endif
-       
+       ED_area_tag_redraw(CTX_wm_area(C));
        return OPERATOR_FINISHED;
 }
 
index f5c8e53..ea6a658 100644 (file)
@@ -76,7 +76,7 @@ void wm_event_add(wmWindow *win, wmEvent *event_to_add)
        BLI_addtail(&win->queue, event);
 }
 
-static void wm_event_free(wmEvent *event)
+void wm_event_free(wmEvent *event)
 {
        if(event->customdata && event->customdatafree)
                MEM_freeN(event->customdata);
index cb6bcb4..2d32045 100644 (file)
@@ -595,6 +595,12 @@ void wm_window_process_events(const bContext *C)
                PIL_sleep_ms(5);
 }
 
+void wm_window_process_events_nosleep(const bContext *C) 
+{
+       if(GHOST_ProcessEvents(g_system, 0))
+               GHOST_DispatchEvents(g_system);
+}
+
 /* exported as handle callback to bke blender.c */
 void wm_window_testbreak(void)
 {
index 99853c7..9a3bba9 100644 (file)
@@ -82,6 +82,8 @@ enum {
 /* wm_event_system.c */
 void           wm_event_add                    (wmWindow *win, wmEvent *event_to_add);
 void           wm_event_free_all               (wmWindow *win);
+void           wm_event_free                   (wmEvent *event);
+
 
                        /* goes over entire hierarchy:  events -> window -> screen -> area -> region */
 void           wm_event_do_handlers    (bContext *C);
index 7bf0861..45fa9bf 100644 (file)
@@ -40,6 +40,7 @@ void          wm_window_free                  (bContext *C, wmWindow *win);
 void           wm_window_title                         (wmWindowManager *wm, wmWindow *win);
 void           wm_window_add_ghostwindows      (wmWindowManager *wm);
 void           wm_window_process_events        (const bContext *C);
+void           wm_window_process_events_nosleep(const bContext *C);
 
 void           wm_window_make_drawable(bContext *C, wmWindow *win);
 
index 5f1437b..44678cb 100644 (file)
 #include "SYS_System.h"
 
        /***/
-
 #include "DNA_view3d_types.h"
 #include "DNA_screen_types.h"
+#include "DNA_windowmanager_types.h"
 #include "BKE_global.h"
 #include "BKE_report.h"
+
 #include "BKE_utildefines.h"
 //XXX #include "BIF_screen.h"
 //XXX #include "BIF_scrarea.h"
 
-#include "BKE_main.h"  
+#include "BKE_main.h"
+//#include "BKE_context.h"
 #include "BLI_blenlib.h"
 #include "BLO_readfile.h"
 #include "DNA_scene_types.h"
 #include "GPU_extensions.h"
 #include "Value.h"
 
+
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 //XXX #include "BSE_headerbuttons.h"
+#include "../../blender/windowmanager/WM_types.h"
+#include "../../blender/windowmanager/wm_window.h"
+#include "../../blender/windowmanager/wm_event_system.h"
 #ifdef __cplusplus
 }
 #endif
@@ -111,13 +118,24 @@ static BlendFileData *load_game_data(char *filename)
        return bfd;
 }
 
-extern "C" void StartKetsjiShell(struct wmWindow *win,
-                                                                struct ScrArea *area,
-                                                                struct ARegion *ar,
-                                                                Scene *scene,
-                                                                struct Main* maggie1,
-                                                                int always_use_expand_framing)
+
+/* screw it, BKE_context.h is complaining! */
+extern "C" struct wmWindow *CTX_wm_window(const bContext *C);
+extern "C" struct ScrArea *CTX_wm_area(const bContext *C);
+extern "C" struct ARegion *CTX_wm_region(const bContext *C);
+extern "C" struct Scene *CTX_data_scene(const bContext *C);
+extern "C" struct Main *CTX_data_main(const bContext *C);
+
+extern "C" void StartKetsjiShell(struct bContext *C, int always_use_expand_framing)
 {
+       /* context values */
+       struct wmWindow *win= CTX_wm_window(C);
+       struct ScrArea *area= CTX_wm_area(C); // curarea
+       struct ARegion *ar= CTX_wm_region(C);
+       struct Scene *scene= CTX_data_scene(C);
+       struct Main* maggie1= CTX_data_main(C);
+       
+       
        int exitrequested = KX_EXIT_REQUEST_NO_REQUEST;
        Main* blenderdata = maggie1;
 
@@ -431,26 +449,37 @@ extern "C" void StartKetsjiShell(struct wmWindow *win,
                                                ketsjiengine->Render();
                                        }
                                        
+                                       wm_window_process_events_nosleep(C);
+                                       
                                        // test for the ESC key
-                                       while (0) //XXX while (qtest())
+                                       //XXX while (qtest())
+                                       while(wmEvent *event= (wmEvent *)win->queue.first)
                                        {
                                                short val = 0;
-                                               unsigned short event = 0; //XXX extern_qread(&val);
+                                               //unsigned short event = 0; //XXX extern_qread(&val);
                                                
-                                               if (keyboarddevice->ConvertBlenderEvent(event,val))
+                                               if (keyboarddevice->ConvertBlenderEvent(event->type,event->val))
                                                        exitrequested = KX_EXIT_REQUEST_BLENDER_ESC;
                                                
                                                        /* Coordinate conversion... where
                                                        * should this really be?
                                                */
-                                               if (event==MOUSEX) {
-                                                       val = val - ar->winrct.xmin;
-                                               } else if (event==MOUSEY) {
-                                                       val = ar->winy - (val - ar->winrct.ymin) - 1;
+                                               if (event->type==MOUSEMOVE) {
+                                                       /* Note nice! XXX 2.5 event hack */
+                                                       val = event->x - ar->winrct.xmin;
+                                                       mousedevice->ConvertBlenderEvent(MOUSEX, val);
+                                                       
+                                                       val = ar->winy - (event->y - ar->winrct.ymin) - 1;
+                                                       mousedevice->ConvertBlenderEvent(MOUSEY, val);
+                                               }
+                                               else {
+                                                       mousedevice->ConvertBlenderEvent(event->type,event->val);
                                                }
                                                
-                                               mousedevice->ConvertBlenderEvent(event,val);
+                                               BLI_remlink(&win->queue, event);
+                                               wm_event_free(event);
                                        }
+                                       
                                }
                                printf("\nBlender Game Engine Finished\n\n");
                                exitstring = ketsjiengine->GetExitString();