dungeon_crawler

annotate prototype/src/cfg.cc @ 63:7f52d6310317

fixed design issue with datafile_path
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 02 Oct 2012 04:52:59 +0300
parents d52711f2b9a1
children
rev   line source
nuclear@18 1 #include <stdio.h>
nuclear@18 2 #include <stdlib.h>
nuclear@18 3 #include <string.h>
nuclear@18 4 #include "cfg.h"
nuclear@18 5
nuclear@18 6 Config cfg;
nuclear@18 7
nuclear@18 8 Config::Config()
nuclear@18 9 {
nuclear@60 10 width = 1280;
nuclear@60 11 height = 800;
nuclear@18 12 stereo = false;
nuclear@47 13 sound = true;
nuclear@18 14 level_file = "0.level";
nuclear@18 15 tileset_file = "default.tileset";
nuclear@60 16
nuclear@60 17 rend = Renderer::any;
nuclear@18 18 }
nuclear@18 19
nuclear@18 20 bool Config::parse_args(int argc, char **argv)
nuclear@18 21 {
nuclear@18 22 for(int i=1; i<argc; i++) {
nuclear@25 23 if(argv[i][0] == '-') {
nuclear@25 24 if(strcmp(argv[i], "-s") == 0) {
nuclear@25 25 if(sscanf(argv[++i], "%dx%d", &width, &height) != 2) {
nuclear@25 26 fprintf(stderr, "-s must be followed by <width>x<height>\n");
nuclear@25 27 return false;
nuclear@25 28 }
nuclear@25 29 } else if(strcmp(argv[i], "-stereo") == 0) {
nuclear@25 30 stereo = true;
nuclear@47 31 } else if(strcmp(argv[i], "-nosound") == 0) {
nuclear@47 32 sound = false;
nuclear@25 33 } else if(strcmp(argv[i], "-level") == 0) {
nuclear@25 34 level_file = argv[++i];
nuclear@25 35 } else if(strcmp(argv[i], "-tileset") == 0) {
nuclear@25 36 tileset_file = argv[++i];
nuclear@60 37 } else if(strcmp(argv[i], "-renderer") == 0) {
nuclear@60 38 if(strcmp(argv[++i], "mrt") == 0) {
nuclear@60 39 rend = Renderer::mrt;
nuclear@60 40 } else if(strcmp(argv[i], "mp") == 0) {
nuclear@60 41 rend = Renderer::multipass;
nuclear@60 42 } else if(strcmp(argv[i], "fwd") == 0) {
nuclear@60 43 rend = Renderer::fwd;
nuclear@60 44 } else {
nuclear@60 45 fprintf(stderr, "invalid renderer specified: %s\n", argv[i]);
nuclear@60 46 return false;
nuclear@60 47 }
nuclear@25 48 } else if(strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "-help") == 0) {
nuclear@25 49 printf("Usage: %s [options]\n", argv[0]);
nuclear@60 50 printf(" -s WxH window size (resolution)\n");
nuclear@60 51 printf(" -level <file> specify which level file to load\n");
nuclear@60 52 printf(" -tileset <file> specify which tileset to use\n");
nuclear@60 53 printf(" -renderer <rend> specify which renderer to use\n");
nuclear@60 54 printf(" -stereo enable stereoscopic rendering\n");
nuclear@60 55 printf(" -nosound disable sound output\n");
nuclear@60 56 printf(" -h/-help print usage information and exit\n");
nuclear@60 57 printf("\n");
nuclear@60 58 printf("Renderers:\n");
nuclear@60 59 printf(" mrt - deferred renderer using multiple draw buffers\n");
nuclear@60 60 printf(" mp - multipass deferred renderer for each g-buffer\n");
nuclear@60 61 printf(" fwd - fallback forward renderer with simplistic lighting\n");
nuclear@25 62 exit(0);
nuclear@25 63
nuclear@25 64 } else {
nuclear@25 65 fprintf(stderr, "unrecognized option: %s\n", argv[i]);
nuclear@18 66 return false;
nuclear@18 67 }
nuclear@18 68 } else {
nuclear@25 69 level_file = argv[i];
nuclear@18 70 }
nuclear@18 71 }
nuclear@18 72 return true;
nuclear@18 73 }