vrseasons

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