dungeon_crawler

view prototype/src/cfg.cc @ 29:2fc004802739

lalala
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 26 Aug 2012 03:39:32 +0300
parents 5c41e6fcb300
children 6d71dd4760f9
line source
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include "cfg.h"
6 Config cfg;
8 Config::Config()
9 {
10 width = 800;
11 height = 600;
12 stereo = false;
13 level_file = "0.level";
14 tileset_file = "default.tileset";
15 }
17 bool Config::parse_args(int argc, char **argv)
18 {
19 for(int i=1; i<argc; i++) {
20 if(argv[i][0] == '-') {
21 if(strcmp(argv[i], "-s") == 0) {
22 if(sscanf(argv[++i], "%dx%d", &width, &height) != 2) {
23 fprintf(stderr, "-s must be followed by <width>x<height>\n");
24 return false;
25 }
26 } else if(strcmp(argv[i], "-stereo") == 0) {
27 stereo = true;
28 } else if(strcmp(argv[i], "-level") == 0) {
29 level_file = argv[++i];
30 } else if(strcmp(argv[i], "-tileset") == 0) {
31 tileset_file = argv[++i];
32 } else if(strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "-help") == 0) {
33 printf("Usage: %s [options]\n", argv[0]);
34 printf(" -s WxH window size (resolution)\n");
35 printf(" -level <filename> specify which level file to load\n");
36 printf(" -tileset <filename> specify which tileset to use\n");
37 printf(" -stereo enable stereoscopic rendering\n");
38 printf(" -h/-help print usage information and exit\n");
39 exit(0);
41 } else {
42 fprintf(stderr, "unrecognized option: %s\n", argv[i]);
43 return false;
44 }
45 } else {
46 level_file = argv[i];
47 }
48 }
49 return true;
50 }