build-time config option for VR mode
authorJohn Tsiombikas <nuclear@member.fsf.org>
Wed, 13 Mar 2019 20:43:58 +0000 (22:43 +0200)
committerJohn Tsiombikas <nuclear@member.fsf.org>
Wed, 13 Mar 2019 20:43:58 +0000 (22:43 +0200)
.gitignore
Makefile
src/game.c
src/gamescr.c
src/opt.c

index 5bac7c8..235d204 100644 (file)
@@ -2,6 +2,7 @@
 *.d
 *.swp
 vrtris
+gltris
 *.exe
 *.dll
 data/
index 45e4214..504c89a 100644 (file)
--- 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/')
 
index 68f6a23..eba4a23 100644 (file)
@@ -1,5 +1,7 @@
 #include <assert.h>
+#ifdef BUILD_VR
 #include <goatvr.h>
+#endif
 #include <cgmath/cgmath.h>
 #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:
index 07193fa..9d15659 100644 (file)
@@ -2,7 +2,9 @@
 #include <time.h>
 #include <assert.h>
 #include <imago2.h>
+#ifdef BUILD_VR
 #include <goatvr.h>
+#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;
 
index acce25f..fb4b341 100644 (file)
--- 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)) {