bloboland

diff 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 diff
     1.1 --- a/src/opt.cc	Sat Dec 15 07:52:13 2012 +0200
     1.2 +++ b/src/opt.cc	Sat Dec 15 23:43:03 2012 +0200
     1.3 @@ -1,6 +1,55 @@
     1.4 +#include <stdio.h>
     1.5 +#include <string.h>
     1.6 +#include <stdlib.h>
     1.7  #include "opt.h"
     1.8  
     1.9 +Options opt;
    1.10 +
    1.11 +static void default_opt()
    1.12 +{
    1.13 +	opt.xsz = 800;
    1.14 +	opt.ysz = 450;
    1.15 +	opt.stereo = false;
    1.16 +
    1.17 +	opt.world_size[0] = opt.world_size[1] = 128;
    1.18 +	opt.world_size[2] = 64;
    1.19 +
    1.20 +	opt.gen_noise_scale = 1.0f;
    1.21 +}
    1.22 +
    1.23  bool parse_opt(int argc, char **argv)
    1.24  {
    1.25 +	default_opt();
    1.26 +
    1.27 +	for(int i=1; i<argc; i++) {
    1.28 +		if(argv[i][0] == '-') {
    1.29 +			if(strcmp(argv[i], "-size") == 0) {
    1.30 +				if(sscanf(argv[++i], "%dx%d", &opt.xsz, &opt.ysz) != 2) {
    1.31 +					fprintf(stderr, "-size must be followed by <width>x<height>\n");
    1.32 +					return false;
    1.33 +				}
    1.34 +			} else if(strcmp(argv[i], "-world") == 0) {
    1.35 +				if(sscanf(argv[++i], "%dx%dx%d", opt.world_size, opt.world_size + 1, opt.world_size + 2) != 3) {
    1.36 +					fprintf(stderr, "-world must be followed by <width>x<height>x<depth>\n");
    1.37 +					return false;
    1.38 +				}
    1.39 +			} else if(strcmp(argv[i], "-genscale") == 0) {
    1.40 +				char *endp;
    1.41 +				opt.gen_noise_scale = strtod(argv[++i], &endp);
    1.42 +				if(endp == argv[i]) {
    1.43 +					fprintf(stderr, "-genscale must be followed by a scaling factor\n");
    1.44 +					return false;
    1.45 +				}
    1.46 +			} else if(strcmp(argv[i], "-stereo") == 0) {
    1.47 +				opt.stereo = true;
    1.48 +			} else {
    1.49 +				fprintf(stderr, "invalid option: %s\n", argv[i]);
    1.50 +				return false;
    1.51 +			}
    1.52 +		} else {
    1.53 +			fprintf(stderr, "unexpected argument: %s\n", argv[i]);
    1.54 +			return false;
    1.55 +		}
    1.56 +	}
    1.57  	return true;
    1.58  }