bloboland

view src/opt.cc @ 1:cfe68befb7cc

some progress
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 15 Dec 2012 23:43:03 +0200
parents e4818a3300b9
children 9021a906c5d3
line source
1 #include <stdio.h>
2 #include <string.h>
3 #include <stdlib.h>
4 #include "opt.h"
6 Options opt;
8 static void default_opt()
9 {
10 opt.xsz = 800;
11 opt.ysz = 450;
12 opt.stereo = false;
14 opt.world_size[0] = opt.world_size[1] = 128;
15 opt.world_size[2] = 64;
17 opt.gen_noise_scale = 1.0f;
18 }
20 bool parse_opt(int argc, char **argv)
21 {
22 default_opt();
24 for(int i=1; i<argc; i++) {
25 if(argv[i][0] == '-') {
26 if(strcmp(argv[i], "-size") == 0) {
27 if(sscanf(argv[++i], "%dx%d", &opt.xsz, &opt.ysz) != 2) {
28 fprintf(stderr, "-size must be followed by <width>x<height>\n");
29 return false;
30 }
31 } else if(strcmp(argv[i], "-world") == 0) {
32 if(sscanf(argv[++i], "%dx%dx%d", opt.world_size, opt.world_size + 1, opt.world_size + 2) != 3) {
33 fprintf(stderr, "-world must be followed by <width>x<height>x<depth>\n");
34 return false;
35 }
36 } else if(strcmp(argv[i], "-genscale") == 0) {
37 char *endp;
38 opt.gen_noise_scale = strtod(argv[++i], &endp);
39 if(endp == argv[i]) {
40 fprintf(stderr, "-genscale must be followed by a scaling factor\n");
41 return false;
42 }
43 } else if(strcmp(argv[i], "-stereo") == 0) {
44 opt.stereo = true;
45 } else {
46 fprintf(stderr, "invalid option: %s\n", argv[i]);
47 return false;
48 }
49 } else {
50 fprintf(stderr, "unexpected argument: %s\n", argv[i]);
51 return false;
52 }
53 }
54 return true;
55 }