vrseasons

annotate src/opt.cc @ 1:65c2e37c48b2

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