GameEngine WIP,
authorCampbell Barton <ideasman42@gmail.com>
Sat, 13 Jun 2009 17:25:54 +0000 (17:25 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sat, 13 Jun 2009 17:25:54 +0000 (17:25 +0000)
* pressing P starts the BGE in the 3D view
* redraw window clipping isnt right
* BGE python api works in py3k (without __import__ override or Mathutils, BGL, Geometry)
* no events yet (so there is no way to exit)

source/blender/editors/space_view3d/SConscript
source/blender/editors/space_view3d/view3d_intern.h
source/blender/editors/space_view3d/view3d_ops.c
source/blender/editors/space_view3d/view3d_view.c
source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp
source/gameengine/BlenderRoutines/KX_BlenderCanvas.h
source/gameengine/BlenderRoutines/KX_BlenderGL.cpp
source/gameengine/BlenderRoutines/KX_BlenderGL.h
source/gameengine/Ketsji/KX_PythonInit.cpp

index b771095c781eef183712be58d65ac3c5d4c5f181..7d51d237ef088e4d716ef087c2e6a9fc0a204578 100644 (file)
@@ -2,10 +2,14 @@
 Import ('env')
 
 sources = env.Glob('*.c')
+defs = []
 
 incs = '../include ../../blenlib ../../blenkernel ../../makesdna ../../imbuf'
 incs += ' ../../windowmanager #/intern/guardedalloc #/extern/glew/include'
 incs += ' ../../render/extern/include #/intern/guardedalloc'
 incs += ' ../../gpu ../../makesrna ../../blenfont'
 
-env.BlenderLib ( 'bf_editors_space_view3d', sources, Split(incs), [], libtype=['core'], priority=[40] )
+if env['WITH_BF_GAMEENGINE']:
+       defs.append('GAMEBLENDER=1')
+
+env.BlenderLib ( 'bf_editors_space_view3d', sources, Split(incs), defines = defs, libtype=['core'], priority=[40] )
index ab705cb32fb7c27258a6c05c2816238889a73137..6dbd99c67be2d2b1e9d23d5f9b1644dd4e4aa125 100644 (file)
@@ -120,6 +120,8 @@ void VIEW3D_OT_select_lasso(struct wmOperatorType *ot);
 void VIEW3D_OT_smoothview(struct wmOperatorType *ot);
 void VIEW3D_OT_setcameratoview(struct wmOperatorType *ot);
 void VIEW3D_OT_localview(struct wmOperatorType *ot);
+void VIEW3D_OT_game_start(struct wmOperatorType *ot);
+
 
 int boundbox_clip(RegionView3D *rv3d, float obmat[][4], struct BoundBox *bb);
 
index 0ed43bead1778fa528d2c069748a0e4af1f322d8..6cb1051ce4afdcad58b58ce603845d20984a8937 100644 (file)
@@ -85,6 +85,7 @@ void view3d_operatortypes(void)
        WM_operatortype_append(VIEW3D_OT_drawtype);
        WM_operatortype_append(VIEW3D_OT_editmesh_face_toolbox);
        WM_operatortype_append(VIEW3D_OT_localview);
+       WM_operatortype_append(VIEW3D_OT_game_start);
        WM_operatortype_append(VIEW3D_OT_layers);
        
        WM_operatortype_append(VIEW3D_OT_properties);
@@ -173,6 +174,8 @@ void view3d_keymap(wmWindowManager *wm)
 
        WM_keymap_add_item(keymap, "VIEW3D_OT_localview", PADSLASHKEY, KM_PRESS, 0, 0);
        
+       WM_keymap_add_item(keymap, "VIEW3D_OT_game_start", PKEY, KM_PRESS, 0, 0);
+       
        /* layers, shift + alt are properties set in invoke() */
        RNA_int_set(WM_keymap_add_item(keymap, "VIEW3D_OT_layers", ONEKEY, KM_PRESS, KM_ANY, 0)->ptr, "nr", 1);
        RNA_int_set(WM_keymap_add_item(keymap, "VIEW3D_OT_layers", TWOKEY, KM_PRESS, KM_ANY, 0)->ptr, "nr", 2);
index e1a6f32aa41fd09726e8223155d5f994d2f7f82c..eaa23061322286e34fdf11468f84a484089014ac 100644 (file)
@@ -1382,6 +1382,75 @@ void VIEW3D_OT_localview(wmOperatorType *ot)
        ot->poll= ED_operator_view3d_active;
 }
 
+
+static void SaveState(void)
+{
+       glPushAttrib(GL_ALL_ATTRIB_BITS);
+
+       GPU_state_init();
+
+       if(G.f & G_TEXTUREPAINT)
+               GPU_paint_set_mipmap(1);
+
+       //XXX waitcursor(1);
+}
+
+static void RestoreState(void)
+{
+       if(G.f & G_TEXTUREPAINT)
+               GPU_paint_set_mipmap(0);
+
+       //XXX curarea->win_swap = 0;
+       //XXX curarea->head_swap=0;
+       //XXX allqueue(REDRAWVIEW3D, 1);
+       //XXX allqueue(REDRAWBUTSALL, 0);
+       //XXX reset_slowparents();
+       //XXX waitcursor(0);
+       //XXX G.qual= 0;
+       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);
+
+
+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);
+       
+#if GAMEBLENDER == 1
+       SaveState();
+       StartKetsjiShell(CTX_wm_window(C), sa, ar, startscene, CTX_data_main(C), 1);
+       RestoreState();
+       
+       //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
+       
+       return OPERATOR_FINISHED;
+}
+
+void VIEW3D_OT_game_start(wmOperatorType *ot)
+{
+       
+       /* identifiers */
+       ot->name= "Start Game Engine";
+       ot->idname= "VIEW3D_OT_game_start";
+       
+       /* api callbacks */
+       ot->exec= game_engine_exec;
+       
+       ot->poll= ED_operator_view3d_active;
+}
+
 /* ************************************** */
 
 void view3d_align_axis_to_vector(View3D *v3d, RegionView3D *rv3d, int axisidx, float vec[3])
index a1df562192209099421dc3e862dd7097e854c275..5f1437b869908481a4fbf6842accbf60d3d9c8da 100644 (file)
 extern "C" {
 #endif
 //XXX #include "BSE_headerbuttons.h"
-void update_for_newframe();
 #ifdef __cplusplus
 }
 #endif
 
+
 static BlendFileData *load_game_data(char *filename)
 {
        ReportList reports;
@@ -111,17 +111,17 @@ static BlendFileData *load_game_data(char *filename)
        return bfd;
 }
 
-extern "C" void StartKetsjiShell(struct ScrArea *area,
+extern "C" void StartKetsjiShell(struct wmWindow *win,
+                                                                struct ScrArea *area,
                                                                 struct ARegion *ar,
-                                                                char* scenename,
+                                                                Scene *scene,
                                                                 struct Main* maggie1,
                                                                 int always_use_expand_framing)
 {
        int exitrequested = KX_EXIT_REQUEST_NO_REQUEST;
-       Scene *scene= NULL; // XXX give as arg
        Main* blenderdata = maggie1;
 
-       char* startscenename = scenename;
+       char* startscenename = scene->id.name+2;
        char pathname[FILE_MAXDIR+FILE_MAXFILE], oldsce[FILE_MAXDIR+FILE_MAXFILE];
        STR_String exitstring = "";
        BlendFileData *bfd= NULL;
@@ -155,7 +155,7 @@ extern "C" void StartKetsjiShell(struct ScrArea *area,
                bool nodepwarnings = (SYS_GetCommandLineInt(syshandle, "ignore_deprecation_warnings", 0) != 0);
                bool novertexarrays = (SYS_GetCommandLineInt(syshandle, "novertexarrays", 0) != 0);
                // create the canvas, rasterizer and rendertools
-               RAS_ICanvas* canvas = new KX_BlenderCanvas(area);
+               RAS_ICanvas* canvas = new KX_BlenderCanvas(win, ar);
                canvas->SetMouseState(RAS_ICanvas::MOUSE_INVISIBLE);
                RAS_IRenderTools* rendertools = new KX_BlenderRenderTools();
                RAS_IRasterizer* rasterizer = NULL;
@@ -235,7 +235,7 @@ extern "C" void StartKetsjiShell(struct ScrArea *area,
                }
                for (i = 0; i < 16; i++)
                {
-                       float *projmat_linear;                  //XXX = (float*) area->winmat;
+                       float *projmat_linear= (float*) rv3d->winmat;
                        projmat.setElem(i, projmat_linear[i]);
                }
                
@@ -423,7 +423,7 @@ extern "C" void StartKetsjiShell(struct ScrArea *area,
                                        exitrequested = ketsjiengine->GetExitCode();
                                        
                                        // kick the engine
-                                       bool render = ketsjiengine->NextFrame();
+                                       bool render = ketsjiengine->NextFrame(); // XXX 2.5 Bug, This is never true! FIXME-  Campbell
                                        
                                        if (render)
                                        {
@@ -434,7 +434,7 @@ extern "C" void StartKetsjiShell(struct ScrArea *area,
                                        // test for the ESC key
                                        while (0) //XXX while (qtest())
                                        {
-                                               short val
+                                               short val = 0;
                                                unsigned short event = 0; //XXX extern_qread(&val);
                                                
                                                if (keyboarddevice->ConvertBlenderEvent(event,val))
@@ -444,9 +444,9 @@ extern "C" void StartKetsjiShell(struct ScrArea *area,
                                                        * should this really be?
                                                */
                                                if (event==MOUSEX) {
-                                                       val = 0;//XXX val - scrarea_get_win_x(area);
+                                                       val = val - ar->winrct.xmin;
                                                } else if (event==MOUSEY) {
-                                                       val = 0;//XXX scrarea_get_win_height(area) - (val - scrarea_get_win_y(area)) - 1;
+                                                       val = ar->winy - (val - ar->winrct.ymin) - 1;
                                                }
                                                
                                                mousedevice->ConvertBlenderEvent(event,val);
@@ -557,7 +557,8 @@ extern "C" void StartKetsjiShell(struct ScrArea *area,
        PyGILState_Release(gilstate);
 }
 
-extern "C" void StartKetsjiShellSimulation(struct ScrArea *area,
+extern "C" void StartKetsjiShellSimulation(struct wmWindow *win,
+                                                                struct ScrArea *area,
                                                                 struct ARegion *ar,
                                                                 char* scenename,
                                                                 struct Main* maggie,
@@ -595,7 +596,7 @@ extern "C" void StartKetsjiShellSimulation(struct ScrArea *area,
                bool usemat = false;
 
                // create the canvas, rasterizer and rendertools
-               RAS_ICanvas* canvas = new KX_BlenderCanvas(area);
+               RAS_ICanvas* canvas = new KX_BlenderCanvas(win, ar);
                //canvas->SetMouseState(RAS_ICanvas::MOUSE_INVISIBLE);
                RAS_IRenderTools* rendertools = new KX_BlenderRenderTools();
                RAS_IRasterizer* rasterizer = NULL;
@@ -648,7 +649,7 @@ extern "C" void StartKetsjiShellSimulation(struct ScrArea *area,
                        cframe=blscene->r.cfra;
                        startFrame = blscene->r.sfra;
                        blscene->r.cfra=startFrame;
-                       update_for_newframe();
+                       // update_for_newframe(); // XXX scene_update_for_newframe wont cut it!
                        ketsjiengine->SetGame2IpoMode(game2ipo,startFrame);
                }
 
@@ -722,7 +723,7 @@ extern "C" void StartKetsjiShellSimulation(struct ScrArea *area,
                                        // kick the engine
                                        ketsjiengine->NextFrame();
                                    blscene->r.cfra=blscene->r.cfra+1;
-                                   update_for_newframe();
+                                   // update_for_newframe(); // XXX scene_update_for_newframe wont cut it
                                        
                                }
                                exitstring = ketsjiengine->GetExitString();
index 750a1ef3f93a460c3be0097f8d57fcdcdc0f99d6..aa83d17a03a36e2d37bd4f97debef92db6fc438d 100644 (file)
  * ***** END GPL LICENSE BLOCK *****
  */
 
-//XXX #include "BIF_scrarea.h"
 #include "KX_BlenderCanvas.h"
+#include "DNA_screen_types.h"
 
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
 
-KX_BlenderCanvas::KX_BlenderCanvas(struct ScrArea *area) :
-m_area(area)
+KX_BlenderCanvas::KX_BlenderCanvas(struct wmWindow *win, ARegion *ar) :
+m_win(win),
+m_ar(ar)
 {
 }
 
@@ -50,7 +51,7 @@ void KX_BlenderCanvas::Init()
 
 void KX_BlenderCanvas::SwapBuffers()
 {
-       BL_SwapBuffers();
+       BL_SwapBuffers(m_win);
 }
 
 void KX_BlenderCanvas::BeginFrame()
@@ -93,12 +94,12 @@ void KX_BlenderCanvas::ClearBuffer(int type)
 
 int KX_BlenderCanvas::GetWidth(
 ) const {
-       return 0; //XXX scrarea_get_win_width(m_area);
+       return m_ar->winx;
 }
 
 int KX_BlenderCanvas::GetHeight(
 ) const {
-       return 0; //XXX scrarea_get_win_height(m_area);
+       return m_ar->winy;
 }
 
 RAS_Rect &
@@ -116,8 +117,8 @@ SetViewPort(
 ){
        int vp_width = (x2 - x1) + 1;
        int vp_height = (y2 - y1) + 1;
-       int minx = 0;//XXX scrarea_get_win_x(m_area);
-       int miny = 0;//XXX scrarea_get_win_y(m_area);
+       int minx = m_ar->winrct.xmin;
+       int miny = m_ar->winrct.ymin;
 
        m_area_rect.SetLeft(minx + x1);
        m_area_rect.SetBottom(miny + y1);
@@ -159,9 +160,9 @@ void KX_BlenderCanvas::SetMouseState(RAS_MouseState mousestate)
 //     (0,0) is top left, (width,height) is bottom right
 void KX_BlenderCanvas::SetMousePosition(int x,int y)
 {
-       int winX = 0;//XXX scrarea_get_win_x(m_area);
-       int winY = 0;//XXX scrarea_get_win_y(m_area);
-       int winH = 0;//XXX scrarea_get_win_height(m_area);
+       int winX = m_ar->winrct.xmin;
+       int winY = m_ar->winrct.ymin;
+       int winH = m_ar->winy;
        
        BL_warp_pointer(winX + x, winY + (winH-y-1));
 }
@@ -170,5 +171,5 @@ void KX_BlenderCanvas::SetMousePosition(int x,int y)
 
 void KX_BlenderCanvas::MakeScreenShot(const char* filename)
 {
-       BL_MakeScreenShot(m_area, filename);
+       BL_MakeScreenShot(m_ar, filename);
 }
index bc202a8558c57bd0549ea5cee249c70d334d6ea7..fd41fb90f2fc76dd81e151e200ee3df876e10e24 100644 (file)
@@ -40,7 +40,8 @@
 
 #include "KX_BlenderGL.h"
 
-struct ScrArea;
+struct ARegion;
+struct wmWindow;
 
 /**
  * 2D Blender device context abstraction. 
@@ -57,9 +58,9 @@ private:
 public:
        /* Construct a new canvas.
         * 
-        * @param area The Blender ScrArea to run the game within.
+        * @param area The Blender ARegion to run the game within.
         */
-       KX_BlenderCanvas(struct ScrArea* area);
+       KX_BlenderCanvas(struct wmWindow* win, struct ARegion* ar);
        ~KX_BlenderCanvas();
 
                void 
@@ -162,7 +163,8 @@ public:
 
 private:
        /** Blender area the game engine is running within */
-       struct ScrArea* m_area;
+       struct ARegion* m_ar;
+       struct wmWindow* m_win;
        RAS_Rect        m_area_rect;
 };
 
index de7a7f54fdeef9bc09134e37a6c1ef8acdf08bf9..5cf696fe1468af43cf12c73411234041c2f4cb05 100644 (file)
  */
 
 #include "KX_BlenderGL.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
 #include "BLF_api.h"
+#ifdef __cplusplus
+}
+#endif
 
 #ifdef HAVE_CONFIG_H
 #include <config.h>
@@ -58,6 +65,7 @@
 #include "DNA_image_types.h"
 #include "DNA_view3d_types.h"
 #include "DNA_material_types.h"
+#include "DNA_windowmanager_types.h"
 
 #include "BKE_global.h"
 #include "BKE_bmfont.h"
@@ -68,7 +76,7 @@ extern "C" {
 //XXX #include "BIF_mywindow.h"
 //XXX #include "BIF_toolbox.h"
 //XXX #include "BIF_graphics.h" /* For CURSOR_NONE CURSOR_WAIT CURSOR_STD */
-
+void wm_window_swap_buffers(wmWindow *win); // wm_window.h
 }
 
 /* end of blender block */
@@ -86,8 +94,10 @@ void BL_warp_pointer(int x,int y)
        //XXX warp_pointer(x,y);
 }
 
-void BL_SwapBuffers()
+void BL_SwapBuffers(wmWindow *win)
 {
+       //wmWindow *window= CTX_wm_window(C);
+       wm_window_swap_buffers(win);
        //XXX myswapbuffers();
 }
 
@@ -214,7 +224,7 @@ void BL_NormalMouse()
 #define MAX_FILE_LENGTH 512
 
 
-void BL_MakeScreenShot(struct ScrArea *area, const char* filename)
+void BL_MakeScreenShot(struct ARegion *ar, const char* filename)
 {
        char copyfilename[MAX_FILE_LENGTH];
        strcpy(copyfilename,filename);
index b891a7343c2f5d182398a148b946bd4059de9748..1e65f29d87c248042184ed315626c105b010149f 100644 (file)
 extern "C" {
 #endif //__cplusplus
 
-struct ScrArea;
+struct wmWindow;
+struct ARegion;
 
 // special swapbuffers, that takes care of which area (viewport) needs to be swapped
-void   BL_SwapBuffers();
+void   BL_SwapBuffers(struct wmWindow *win);
 
 void   BL_warp_pointer(int x,int y);
 
-void   BL_MakeScreenShot(struct ScrArea *area, const char* filename);
+void   BL_MakeScreenShot(struct ARegion *ar, const char* filename);
 
 void   BL_HideMouse();
 void   BL_NormalMouse();
index fc3e48f504c7a75768d6174c5de1bd99cd66cf4b..a3d464f0d5dde4bbe5c9f88c3563ebf27f9b0dcc 100644 (file)
 
 #include "PyObjectPlus.h"
 
-//XXX
-#if 0
-
 #include "KX_PythonInitTypes.h" 
 
+#if 0 //XXX25
+
 /* we only need this to get a list of libraries from the main struct */
 #include "DNA_ID.h"
 
@@ -97,7 +96,7 @@ extern "C" {
        #include "BGL.h"
 #endif
 }
-#endif
+#endif //XXX25
 
 #include "marshal.h" /* python header for loading/saving dicts */
 
@@ -1606,7 +1605,7 @@ PyObject* initGamePlayerPythonScripting(const STR_String& progname, TPythonSecur
        //importBlenderModules()
        
        setSandbox(level);
-       /* XXX 2.5 initPyTypes(); */
+       initPyTypes();
        
        /* XXX 2.5 bpy_import_main_set(maggie); */
        
@@ -1645,7 +1644,7 @@ PyObject* initGamePythonScripting(const STR_String& progname, TPythonSecurityLev
        Py_FrozenFlag=1;
 
        setSandbox(level);
-       /* XXX 2.5 initPyTypes(); */
+       initPyTypes();
        
        /* XXX 2.5 bpy_import_main_set(maggie); */