From 96757b3e8d4c7ad71ebcae67c40c5fed14c471ce Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Wed, 13 Mar 2019 22:43:58 +0200 Subject: [PATCH] build-time config option for VR mode --- .gitignore | 1 + Makefile | 16 +++++++++++++--- src/game.c | 19 +++++++++++++++++-- src/gamescr.c | 4 ++++ src/opt.c | 6 ++++++ 5 files changed, 41 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 5bac7c8..235d204 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ *.d *.swp vrtris +gltris *.exe *.dll data/ diff --git a/Makefile b/Makefile index 45e4214..504c89a 100644 --- a/Makefile +++ b/Makefile @@ -1,16 +1,26 @@ +# options ------------------------------------------------- +vrbuild = true +# --------------------------------------------------------- + src = $(wildcard src/*.c) obj = $(src:.c=.o) dep = $(obj:.o=.d) -bin = vrtris +ifeq ($(vrbuild), true) + bin = vrtris + vr_ldflags = -lgoatvr + vr_cflags = -DBUILD_VR +else + bin = gltris +endif warn = -pedantic -Wall -Wno-pointer-to-int-cast -Wno-int-to-pointer-cast dbg = -g opt = -O0 -CFLAGS = $(warn) $(dbg) $(opt) `pkg-config --cflags sdl2 freetype2` +CFLAGS = $(warn) $(dbg) $(opt) `pkg-config --cflags sdl2 freetype2` $(vr_cflags) LDFLAGS = $(libsys) -ldrawtext $(libgl) `pkg-config --libs sdl2 freetype2` \ - -lgoatvr -limago -lpng -lz -ljpeg -lpthread -lm + $(vr_ldflags) -limago -lpng -lz -ljpeg -lpthread -lm sys ?= $(shell uname -s | sed 's/MINGW.*/mingw/') diff --git a/src/game.c b/src/game.c index 68f6a23..eba4a23 100644 --- a/src/game.c +++ b/src/game.c @@ -1,5 +1,7 @@ #include +#ifdef BUILD_VR #include +#endif #include #include "opengl.h" #include "game.h" @@ -12,7 +14,9 @@ static void calc_framerate(void); static void print_framerate(void); +#ifdef BUILD_VR static int should_swap; +#endif static unsigned long framerate; @@ -30,6 +34,7 @@ int game_init(int argc, char **argv) return -1; } +#ifdef BUILD_VR if(opt.flags & OPT_VR) { if(goatvr_init() == -1) { return -1; @@ -40,6 +45,7 @@ int game_init(int argc, char **argv) goatvr_startvr(); should_swap = goatvr_should_swap(); } +#endif /* BUILD_VR */ glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); @@ -51,9 +57,11 @@ int game_init(int argc, char **argv) void game_cleanup() { +#ifdef BUILD_VR if(opt.flags & OPT_VR) { goatvr_shutdown(); } +#endif cleanup_screens(); } @@ -65,13 +73,14 @@ static void update(float dt) void game_display(void) { static long prev_msec; - int i; float dt = (float)(time_msec - prev_msec) / 1000.0f; prev_msec = time_msec; update(dt); +#ifdef BUILD_VR if(opt.flags & OPT_VR) { + int i; goatvr_draw_start(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -98,7 +107,9 @@ void game_display(void) game_swap_buffers(); } - } else { + } else +#endif /* BUILD_VR */ + { /* non-VR mode */ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -125,7 +136,9 @@ void game_display(void) void game_reshape(int x, int y) { glViewport(0, 0, x, y); +#ifdef BUILD_VR goatvr_set_fb_size(x, y, 1.0f); +#endif reshape_screens(x, y); } @@ -149,9 +162,11 @@ void game_keyboard(int key, int pressed) break; case KEY_HOME: +#ifdef BUILD_VR if(opt.flags & OPT_VR) { goatvr_recenter(); } +#endif break; default: diff --git a/src/gamescr.c b/src/gamescr.c index 07193fa..9d15659 100644 --- a/src/gamescr.c +++ b/src/gamescr.c @@ -2,7 +2,9 @@ #include #include #include +#ifdef BUILD_VR #include +#endif #include "opengl.h" #include "game.h" #include "screen.h" @@ -164,6 +166,7 @@ static void stop(void) static void update_input(float dtsec) { +#ifdef BUILD_VR int num_vr_sticks; if((num_vr_sticks = goatvr_num_sticks()) > 0) { @@ -178,6 +181,7 @@ static void update_input(float dtsec) joy_axis[GPAD_LSTICK_Y] = p[1]; } } +#endif /* BUILD_VR */ ginp_bnstate = 0; diff --git a/src/opt.c b/src/opt.c index acce25f..fb4b341 100644 --- a/src/opt.c +++ b/src/opt.c @@ -9,7 +9,9 @@ struct options def_opt = { 1024, 768, 0, "game" }; enum { OPTCFG_SIZE, +#ifdef BUILD_VR OPTCFG_VR, +#endif OPTCFG_FULLSCREEN, OPTCFG_WINDOWED, OPTCFG_SCREEN, @@ -19,7 +21,9 @@ enum { static struct optcfg_option options[] = { // short, long, id, desc {'s', "size", OPTCFG_SIZE, "window size (WxH)"}, +#ifdef BUILD_VR {0, "vr", OPTCFG_VR, "enable VR mode"}, +#endif {'f', "fullscreen", OPTCFG_FULLSCREEN, "run in fullscreen mode"}, {'w', "windowed", OPTCFG_WINDOWED, "run in windowed mode"}, {0, "screen", OPTCFG_SCREEN, "select starting screen"}, @@ -84,6 +88,7 @@ static int opt_handler(struct optcfg *oc, int optid, void *cls) } break; +#ifdef BUILD_VR case OPTCFG_VR: if(is_enabled(oc)) { opt.flags |= OPT_VR; @@ -91,6 +96,7 @@ static int opt_handler(struct optcfg *oc, int optid, void *cls) opt.flags &= ~OPT_VR; } break; +#endif case OPTCFG_FULLSCREEN: if(is_enabled(oc)) { -- 1.7.10.4