src/Application.cc
branchnew_graphics
changeset 418 194bc810a570
parent 417 c503e0c6a740
child 426 510c83aab425
equal deleted inserted replaced
417:c503e0c6a740 418:194bc810a570
    26 
    26 
    27     ARG_LIST_MODES      = 0xff01,
    27     ARG_LIST_MODES      = 0xff01,
    28     ARG_VERSION         = 0xff02,
    28     ARG_VERSION         = 0xff02,
    29     ARG_TERRAIN_SEED    = 0xff03,
    29     ARG_TERRAIN_SEED    = 0xff03,
    30     ARG_TERRAIN_SIZE    = 0xff04,
    30     ARG_TERRAIN_SIZE    = 0xff04,
       
    31     ARG_LOG_LEVEL       = 0xff05,
    31 
    32 
    32 };
    33 };
    33 
    34 
    34         
    35         
    35 Main::Main (void) :
    36 Main::Main (void) :
    88     args.add_option(ARG_TERRAIN_SIZE, "terrain-size", "WIDTHxHEIGHT",
    89     args.add_option(ARG_TERRAIN_SIZE, "terrain-size", "WIDTHxHEIGHT",
    89             "set terrain size for random generator");
    90             "set terrain size for random generator");
    90 
    91 
    91     
    92     
    92     args.add_group("General");
    93     args.add_group("General");
       
    94     args.add_option(ARG_LOG_LEVEL, "log-level", "LEVEL",
       
    95             "set maximum log level to one of FATAL/ERROR/WARN/INFO/DEBUG");
       
    96 
    93     args.add_option(ARG_HELP, "help", "",
    97     args.add_option(ARG_HELP, "help", "",
    94             "display argument help and exit");
    98             "display argument help and exit");
    95 
    99 
    96     args.add_option(ARG_VERSION, "version", "",
   100     args.add_option(ARG_VERSION, "version", "",
    97             "output application version plus configuration and exit");
   101             "output application version plus configuration and exit");
   113     while (args.next()) {
   117     while (args.next()) {
   114         switch (args.get_key()) {
   118         switch (args.get_key()) {
   115             case ARG_HELP:
   119             case ARG_HELP:
   116                 args.print_help();
   120                 args.print_help();
   117                 return false;
   121                 return false;
       
   122 
       
   123             case ARG_LOG_LEVEL:
       
   124                 engine.log_level = parse_arg_loglevel(args.get_argument(), "--log-level");
       
   125                 break;
   118 
   126 
   119 #if NETWORK_ENABLED                
   127 #if NETWORK_ENABLED                
   120             case ARG_PORT:
   128             case ARG_PORT:
   121                 net_port = args.get_argument();
   129                 net_port = args.get_argument();
   122                 break;
   130                 break;
   216         throw ArgumentError(std::string() + "invalid format for " + arg_name + ": " + arg_val);
   224         throw ArgumentError(std::string() + "invalid format for " + arg_name + ": " + arg_val);
   217     
   225     
   218     return PixelDimensions(w, h);
   226     return PixelDimensions(w, h);
   219 }
   227 }
   220 
   228 
       
   229 LogLevel Main::parse_arg_loglevel (const std::string &arg_val, const char *arg_name) {
       
   230     // brute-force if-elseif
       
   231     if (arg_val == "FATAL")
       
   232         return FATAL;
       
   233 
       
   234     else if (arg_val == "ERROR")
       
   235         return ERROR;
       
   236 
       
   237     else if (arg_val == "WARN")
       
   238         return WARN;
       
   239 
       
   240     else if (arg_val == "INFO")
       
   241         return INFO;
       
   242 
       
   243     else if (arg_val == "DEBUG")
       
   244         return DEBUG;
       
   245 
       
   246     else
       
   247         throw ArgumentError(std::string() + "invalid log level for " + arg_name + ": " + arg_val);
       
   248 }
       
   249 
   221 #if GRAPHICS_ENABLED
   250 #if GRAPHICS_ENABLED
   222 void Main::dump_display_modes (void) {
   251 void Main::dump_display_modes (void) {
   223     // get the list of display modes from graphics
   252     // get the list of display modes from graphics
   224     const std::vector<CL_DisplayMode> &modes = graphics::Display::getDisplayModes();
   253     const std::vector<CL_DisplayMode> &modes = graphics::Display::getDisplayModes();
   225     PixelCoordinate last_resolution;
   254     PixelCoordinate last_resolution;
   269         // parse arugments, exit if false
   298         // parse arugments, exit if false
   270         if (parse_args(argc, argv) == false)
   299         if (parse_args(argc, argv) == false)
   271             return 0;
   300             return 0;
   272 
   301 
   273         // our engine
   302         // our engine
   274         Engine engine;
   303         Engine engine(this->engine);
   275 
   304 
   276         // setup game unless client
   305         // setup game unless client
   277         if (net_connect.empty())
   306         if (net_connect.empty())
   278             engine.setupGame(terrain);
   307             engine.setupGame(terrain);
   279         
   308