bloboland

annotate 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
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@1 18 }
nuclear@1 19
nuclear@0 20 bool parse_opt(int argc, char **argv)
nuclear@0 21 {
nuclear@1 22 default_opt();
nuclear@1 23
nuclear@1 24 for(int i=1; i<argc; i++) {
nuclear@1 25 if(argv[i][0] == '-') {
nuclear@1 26 if(strcmp(argv[i], "-size") == 0) {
nuclear@1 27 if(sscanf(argv[++i], "%dx%d", &opt.xsz, &opt.ysz) != 2) {
nuclear@1 28 fprintf(stderr, "-size must be followed by <width>x<height>\n");
nuclear@1 29 return false;
nuclear@1 30 }
nuclear@1 31 } else if(strcmp(argv[i], "-world") == 0) {
nuclear@1 32 if(sscanf(argv[++i], "%dx%dx%d", opt.world_size, opt.world_size + 1, opt.world_size + 2) != 3) {
nuclear@1 33 fprintf(stderr, "-world must be followed by <width>x<height>x<depth>\n");
nuclear@1 34 return false;
nuclear@1 35 }
nuclear@1 36 } else if(strcmp(argv[i], "-genscale") == 0) {
nuclear@1 37 char *endp;
nuclear@1 38 opt.gen_noise_scale = strtod(argv[++i], &endp);
nuclear@1 39 if(endp == argv[i]) {
nuclear@1 40 fprintf(stderr, "-genscale must be followed by a scaling factor\n");
nuclear@1 41 return false;
nuclear@1 42 }
nuclear@1 43 } else if(strcmp(argv[i], "-stereo") == 0) {
nuclear@1 44 opt.stereo = true;
nuclear@1 45 } else {
nuclear@1 46 fprintf(stderr, "invalid option: %s\n", argv[i]);
nuclear@1 47 return false;
nuclear@1 48 }
nuclear@1 49 } else {
nuclear@1 50 fprintf(stderr, "unexpected argument: %s\n", argv[i]);
nuclear@1 51 return false;
nuclear@1 52 }
nuclear@1 53 }
nuclear@0 54 return true;
nuclear@0 55 }