]> git.tdb.fi Git - r2c2.git/blob - source/engineer/options.cpp
bdac3619356bbc6b3a1c9558a4bce74b66f6cf65
[r2c2.git] / source / engineer / options.cpp
1 #include <msp/core/getopt.h>
2 #include <msp/fs/utils.h>
3 #include <msp/strings/lexicalcast.h>
4 #include <msp/strings/regex.h>
5 #include "options.h"
6
7 using namespace std;
8 using namespace Msp;
9
10 Options::Options(int argc, char **argv):
11         screen_w(1280),
12         screen_h(960),
13         fullscreen(false),
14         debug(false),
15         network(false),
16         simulate(false),
17         sim_speed(1.0f)
18 {
19         string res;
20
21         GetOpt getopt;
22         getopt.add_option('r', "resolution",  res,         GetOpt::REQUIRED_ARG);
23         getopt.add_option('f', "fullscreen",  fullscreen,  GetOpt::NO_ARG);
24         getopt.add_option('g', "debug",       debug,       GetOpt::NO_ARG);
25         getopt.add_option('d', "driver",      driver,      GetOpt::REQUIRED_ARG);
26         getopt.add_option('s', "simulate",    simulate,    GetOpt::NO_ARG);
27         getopt.add_option(     "sim-speed",   sim_speed,   GetOpt::REQUIRED_ARG);
28         getopt.add_option('n', "network",     network,     GetOpt::NO_ARG);
29         getopt.add_option(     "state",       state_fn,    GetOpt::REQUIRED_ARG);
30         getopt(argc, argv);
31
32         if(!res.empty())
33         {
34                 if(RegMatch m=Regex("([1-9][0-9]*)x([1-9][0-9]*)").match(res))
35                 {
36                         screen_w = lexical_cast<unsigned>(m[1].str);
37                         screen_h = lexical_cast<unsigned>(m[2].str);
38                 }
39                 else
40                         throw usage_error("Invalid resolution");
41         }
42
43         const vector<string> &args = getopt.get_args();
44         if(args.empty())
45                 throw usage_error("No layout given");
46
47         layout_fn = args[0];
48
49         if(state_fn.empty())
50                 state_fn = FS::basepart(layout_fn)+".state";
51 }