vrseasons

annotate src/opt.cc @ 0:393ef1143c9c

VR seasons
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 07 Apr 2015 11:16:56 +0300
parents
children 65c2e37c48b2
rev   line source
nuclear@0 1 #include <stdio.h>
nuclear@0 2 #include "opt.h"
nuclear@0 3
nuclear@0 4 enum {
nuclear@0 5 OPT_SIZE,
nuclear@0 6 OPT_FULLSCREEN,
nuclear@0 7 OPT_WINDOWED,
nuclear@0 8 OPT_VR,
nuclear@0 9 OPT_HELP,
nuclear@0 10
nuclear@0 11 NUM_OPTS
nuclear@0 12 };
nuclear@0 13 static const char *optname[] = {
nuclear@0 14 "size", "fullscreen", "windowed", "vr", "help", 0
nuclear@0 15 };
nuclear@0 16
nuclear@0 17 static int get_option(const char *str);
nuclear@0 18
nuclear@0 19 void default_opt(Options *opt)
nuclear@0 20 {
nuclear@0 21 opt->xres = 1280;
nuclear@0 22 opt->yres = 800;
nuclear@0 23 opt->fov = 50.0;
nuclear@0 24 opt->fullscreen = false;
nuclear@0 25 opt->use_vr = false;
nuclear@0 26 }
nuclear@0 27
nuclear@0 28 bool parse_args(Options *opt, int argc, char **argv)
nuclear@0 29 {
nuclear@0 30 for(int i=1; i<argc; i++) {
nuclear@0 31 if(argv[i][0] == '-') {
nuclear@0 32 int o = get_option(argv[i] + 1);
nuclear@0 33 switch(o) {
nuclear@0 34 case OPT_SIZE:
nuclear@0 35 if(sscanf(argv[++i], "%dx%d", &opt->xres, &opt->yres) != 2) {
nuclear@0 36 fprintf(stderr, "invalid argument to option: %s\n", argv[i - 1]);
nuclear@0 37 return false;
nuclear@0 38 }
nuclear@0 39 break;
nuclear@0 40
nuclear@0 41 case OPT_FULLSCREEN:
nuclear@0 42 opt->fullscreen = true;
nuclear@0 43 break;
nuclear@0 44 case OPT_WINDOWED:
nuclear@0 45 opt->fullscreen = false;
nuclear@0 46 break;
nuclear@0 47
nuclear@0 48 case OPT_VR:
nuclear@0 49 opt->use_vr = true;
nuclear@0 50 break;
nuclear@0 51
nuclear@0 52 case OPT_HELP:
nuclear@0 53 printf("options:\n");
nuclear@0 54 for(int j=0; optname[j]; j++) {
nuclear@0 55 printf(" -%s\n", optname[j]);
nuclear@0 56 }
nuclear@0 57 break;
nuclear@0 58 }
nuclear@0 59 }
nuclear@0 60 }
nuclear@0 61 }
nuclear@0 62
nuclear@0 63 static int get_option(const char *str)
nuclear@0 64 {
nuclear@0 65 for(int i=0; optname[i], i++) {
nuclear@0 66 if(strcmp(str, optname[i]) == 0) {
nuclear@0 67 return i;
nuclear@0 68 }
nuclear@0 69 }
nuclear@0 70 return -1;
nuclear@0 71 }