build-time config option for VR mode
[vrtris] / src / opt.c
index 91eed5d..fb4b341 100644 (file)
--- a/src/opt.c
+++ b/src/opt.c
@@ -5,22 +5,28 @@
 #include "opt.h"
 
 
-struct options def_opt = { 1024, 768, 0 };
+struct options def_opt = { 1024, 768, 0, "game" };
 
 enum {
        OPTCFG_SIZE,
+#ifdef BUILD_VR
        OPTCFG_VR,
+#endif
        OPTCFG_FULLSCREEN,
        OPTCFG_WINDOWED,
+       OPTCFG_SCREEN,
        OPTCFG_HELP
 };
 
 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"},
        {'h', "help", OPTCFG_HELP, "print usage and exit"},
        OPTCFG_OPTIONS_END
 };
@@ -36,6 +42,11 @@ int init_options(int argc, char **argv, const char *cfgfile)
 
        /* default options */
        opt = def_opt;
+       if(!(opt.start_scr = malloc(strlen(def_opt.start_scr) + 1))) {
+               perror("failed to allocate memory");
+               return -1;
+       }
+       strcpy(opt.start_scr, def_opt.start_scr);
 
        argv0 = argv[0];
 
@@ -66,17 +77,18 @@ static int is_enabled(struct optcfg *oc)
 
 static int opt_handler(struct optcfg *oc, int optid, void *cls)
 {
+       char *valstr;
+
        switch(optid) {
        case OPTCFG_SIZE:
-               {
-                       char *valstr = optcfg_next_value(oc);
-                       if(!valstr || sscanf(valstr, "%dx%d", &opt.width, &opt.height) != 2) {
-                               fprintf(stderr, "size must be in the form: WIDTHxHEIGHT\n");
-                               return -1;
-                       }
+               valstr = optcfg_next_value(oc);
+               if(!valstr || sscanf(valstr, "%dx%d", &opt.width, &opt.height) != 2) {
+                       fprintf(stderr, "size must be of the form: WIDTHxHEIGHT\n");
+                       return -1;
                }
                break;
 
+#ifdef BUILD_VR
        case OPTCFG_VR:
                if(is_enabled(oc)) {
                        opt.flags |= OPT_VR;
@@ -84,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)) {
@@ -101,6 +114,19 @@ static int opt_handler(struct optcfg *oc, int optid, void *cls)
                }
                break;
 
+       case OPTCFG_SCREEN:
+               if(!(valstr = optcfg_next_value(oc))) {
+                       fprintf(stderr, "screen name missing\n");
+                       return -1;
+               }
+               free(opt.start_scr);
+               if(!(opt.start_scr = malloc(strlen(valstr) + 1))) {
+                       perror("failed to allocate memory");
+                       return -1;
+               }
+               strcpy(opt.start_scr, valstr);
+               break;
+
        case OPTCFG_HELP:
                printf("Usage: %s [options]\nOptions:\n", argv0);
                optcfg_print_options(oc);