GameEngine WIP,

* 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)
This commit is contained in:
Campbell Barton 2009-06-13 17:25:54 +00:00
parent 3a9396c47d
commit 611e2f484c
10 changed files with 136 additions and 44 deletions

@ -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] )

@ -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);

@ -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);

@ -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])

@ -88,11 +88,11 @@
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();

@ -26,15 +26,16 @@
* ***** 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);
}

@ -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;
};

@ -27,7 +27,14 @@
*/
#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);

@ -33,14 +33,15 @@
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();

@ -81,11 +81,10 @@
#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); */