bloboland

view src/opt.cc @ 5:2f4406cc341e

meh
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 19 Dec 2012 02:37:20 +0200
parents cfe68befb7cc
children
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 opt.gen_num_blobs = 10;
19 }
21 bool parse_opt(int argc, char **argv)
22 {
23 default_opt();
25 for(int i=1; i<argc; i++) {
26 if(argv[i][0] == '-') {
27 if(strcmp(argv[i], "-size") == 0) {
28 if(sscanf(argv[++i], "%dx%d", &opt.xsz, &opt.ysz) != 2) {
29 fprintf(stderr, "-size must be followed by <width>x<height>\n");
30 return false;
31 }
32 } else if(strcmp(argv[i], "-world") == 0) {
33 if(sscanf(argv[++i], "%dx%dx%d", opt.world_size, opt.world_size + 1, opt.world_size + 2) != 3) {
34 fprintf(stderr, "-world must be followed by <width>x<height>x<depth>\n");
35 return false;
36 }
37 } else if(strcmp(argv[i], "-genscale") == 0) {
38 char *endp;
39 opt.gen_noise_scale = strtod(argv[++i], &endp);
40 if(endp == argv[i]) {
41 fprintf(stderr, "-genscale must be followed by a scaling factor\n");
42 return false;
43 }
44 } else if(strcmp(argv[i], "-blobs") == 0) {
45 char *endp;
46 opt.gen_num_blobs = strtol(argv[++i], &endp, 10);
47 if(endp == argv[i]) {
48 fprintf(stderr, "-blobs must be followed by the number of blobs\n");
49 return false;
50 }
51 } else if(strcmp(argv[i], "-stereo") == 0) {
52 opt.stereo = true;
53 } else {
54 fprintf(stderr, "invalid option: %s\n", argv[i]);
55 return false;
56 }
57 } else {
58 fprintf(stderr, "unexpected argument: %s\n", argv[i]);
59 return false;
60 }
61 }
62 return true;
63 }