-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
73 lines (63 loc) · 1.72 KB
/
main.cpp
File metadata and controls
73 lines (63 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <memory>
#include <string>
#include <vector>
#include "SDL2/SDL.h"
#include "application.h"
#if defined(DEBUG)
bool debugMode = true;
#else
bool debugMode = false;
#endif
int main (int argc, char **argv)
{
SDL_Init(SDL_INIT_EVERYTHING);
std::vector<std::string> args(argv + 1, argv + argc);
std::string startMap;
bool help = false;
auto arg = args.begin ();
while (arg != args.end ()) {
if (arg->empty ()) { // helps debugging
++arg;
continue;
}
if (*arg == "-m" || *arg == "--map") {
if (++arg != args.end () && !arg->empty()) {
startMap = *arg;
}
} else if (*arg == "-d" || *arg == "--debug") {
debugMode = true;
} else if (*arg == "-t" || *arg == "--test") {
testMode = true;
} else if (*arg == "-h" || *arg == "--help") {
help = true;
break;
} else {
help = true;
printf ("Unknown command line option '%s'\n", arg->c_str ());
break;
}
if (arg == args.end()) {
help = true;
printf ("Bad command line options\n");
break;
}
++arg;
}
if (debugMode || help) {
printf ("%s%s\n", APP_NAME " by PJT v", Application::VersionStr());
}
if (help) {
printf ("Usage: " APP_NAME " [optons]\n"\
" -m|--map <map path>\n"\
" -d|--debug\n"\
" -h|--help\n");
return 0;
}
Application app;
if (!app.Init ()) {
return 1;
}
bool ok = app.Run (startMap.c_str());
app.Destroy();
return ok ? 0 : 1;
}