rev |
line source |
nuclear@1
|
1 #include <stdio.h>
|
nuclear@1
|
2 #include <string.h>
|
nuclear@1
|
3 #include <stdlib.h>
|
nuclear@0
|
4 #include "opt.h"
|
nuclear@0
|
5
|
nuclear@1
|
6 Options opt;
|
nuclear@1
|
7
|
nuclear@1
|
8 static void default_opt()
|
nuclear@1
|
9 {
|
nuclear@1
|
10 opt.xsz = 800;
|
nuclear@1
|
11 opt.ysz = 450;
|
nuclear@1
|
12 opt.stereo = false;
|
nuclear@1
|
13
|
nuclear@1
|
14 opt.world_size[0] = opt.world_size[1] = 128;
|
nuclear@1
|
15 opt.world_size[2] = 64;
|
nuclear@1
|
16
|
nuclear@1
|
17 opt.gen_noise_scale = 1.0f;
|
nuclear@4
|
18 opt.gen_num_blobs = 10;
|
nuclear@1
|
19 }
|
nuclear@1
|
20
|
nuclear@0
|
21 bool parse_opt(int argc, char **argv)
|
nuclear@0
|
22 {
|
nuclear@1
|
23 default_opt();
|
nuclear@1
|
24
|
nuclear@1
|
25 for(int i=1; i<argc; i++) {
|
nuclear@1
|
26 if(argv[i][0] == '-') {
|
nuclear@1
|
27 if(strcmp(argv[i], "-size") == 0) {
|
nuclear@1
|
28 if(sscanf(argv[++i], "%dx%d", &opt.xsz, &opt.ysz) != 2) {
|
nuclear@1
|
29 fprintf(stderr, "-size must be followed by <width>x<height>\n");
|
nuclear@1
|
30 return false;
|
nuclear@1
|
31 }
|
nuclear@1
|
32 } else if(strcmp(argv[i], "-world") == 0) {
|
nuclear@1
|
33 if(sscanf(argv[++i], "%dx%dx%d", opt.world_size, opt.world_size + 1, opt.world_size + 2) != 3) {
|
nuclear@1
|
34 fprintf(stderr, "-world must be followed by <width>x<height>x<depth>\n");
|
nuclear@1
|
35 return false;
|
nuclear@1
|
36 }
|
nuclear@1
|
37 } else if(strcmp(argv[i], "-genscale") == 0) {
|
nuclear@1
|
38 char *endp;
|
nuclear@1
|
39 opt.gen_noise_scale = strtod(argv[++i], &endp);
|
nuclear@1
|
40 if(endp == argv[i]) {
|
nuclear@1
|
41 fprintf(stderr, "-genscale must be followed by a scaling factor\n");
|
nuclear@1
|
42 return false;
|
nuclear@1
|
43 }
|
nuclear@4
|
44 } else if(strcmp(argv[i], "-blobs") == 0) {
|
nuclear@4
|
45 char *endp;
|
nuclear@4
|
46 opt.gen_num_blobs = strtol(argv[++i], &endp, 10);
|
nuclear@4
|
47 if(endp == argv[i]) {
|
nuclear@4
|
48 fprintf(stderr, "-blobs must be followed by the number of blobs\n");
|
nuclear@4
|
49 return false;
|
nuclear@4
|
50 }
|
nuclear@1
|
51 } else if(strcmp(argv[i], "-stereo") == 0) {
|
nuclear@1
|
52 opt.stereo = true;
|
nuclear@1
|
53 } else {
|
nuclear@1
|
54 fprintf(stderr, "invalid option: %s\n", argv[i]);
|
nuclear@1
|
55 return false;
|
nuclear@1
|
56 }
|
nuclear@1
|
57 } else {
|
nuclear@1
|
58 fprintf(stderr, "unexpected argument: %s\n", argv[i]);
|
nuclear@1
|
59 return false;
|
nuclear@1
|
60 }
|
nuclear@1
|
61 }
|
nuclear@0
|
62 return true;
|
nuclear@0
|
63 }
|