author | Tero Marttila <terom@fixme.fi> |
Tue, 20 Jan 2009 23:30:18 +0200 | |
changeset 408 | e6cfc44266af |
parent 397 | 13fa0546ef87 |
child 409 | 1a03ff151abc |
permissions | -rw-r--r-- |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
1 |
|
358 | 2 |
#include "Application.hh" |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
3 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
4 |
#include <stdexcept> |
389
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
5 |
#include <cstdio> |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
6 |
#include <cassert> |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
7 |
|
389
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
8 |
enum ArgumentCodes { |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
9 |
ARG_HELP = 'h', |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
10 |
ARG_PORT = 'p', |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
11 |
ARG_SERVER = 's', |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
12 |
ARG_CLIENT = 'c', |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
13 |
ARG_GRAPHICS = 'g', |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
14 |
ARG_FULLSCREEN = 'F', |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
15 |
ARG_RESOLUTION = 'R', |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
16 |
|
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
17 |
ARG_LIST_MODES = 0xff01, |
397
13fa0546ef87
hopefully version stuff is now run properly on every make...
Tero Marttila <terom@fixme.fi>
parents:
392
diff
changeset
|
18 |
ARG_VERSION = 0xff02, |
389
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
19 |
}; |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
20 |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
21 |
|
358 | 22 |
/** |
23 |
* Set the arg_* members |
|
24 |
*/ |
|
389
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
25 |
bool Main::parse_args (int argc, char **argv) { |
358 | 26 |
// set up the options |
389
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
27 |
args.add_option(ARG_HELP, "help", "", |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
28 |
"display argument help and exit"); |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
29 |
|
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
30 |
args.add_option(ARG_PORT, "port", "PORT", |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
31 |
"set network port used"); |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
32 |
|
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
33 |
args.add_option(ARG_SERVER, "server", "", |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
34 |
"act as a network server"); |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
35 |
|
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
36 |
args.add_option(ARG_CLIENT, "client", "SERVERHOST", |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
37 |
"act as a network client"); |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
38 |
|
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
39 |
args.add_option(ARG_GRAPHICS, "graphics", "", |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
40 |
"run graphics/local input. Implied with --connect"); |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
41 |
|
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
42 |
args.add_option(ARG_FULLSCREEN, "fullscreen", "", |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
43 |
"run graphics in fullscreen mode"); |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
44 |
|
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
45 |
args.add_option(ARG_RESOLUTION, "resolution", "WIDTHxHEIGHT", |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
46 |
"set graphics resolution"); |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
47 |
|
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
48 |
args.add_option(ARG_LIST_MODES, "list-modes", "", |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
49 |
"output a list of available display modes and exit"); |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
50 |
|
397
13fa0546ef87
hopefully version stuff is now run properly on every make...
Tero Marttila <terom@fixme.fi>
parents:
392
diff
changeset
|
51 |
args.add_option(ARG_VERSION, "version", "", |
13fa0546ef87
hopefully version stuff is now run properly on every make...
Tero Marttila <terom@fixme.fi>
parents:
392
diff
changeset
|
52 |
"output application version and exit"); |
13fa0546ef87
hopefully version stuff is now run properly on every make...
Tero Marttila <terom@fixme.fi>
parents:
392
diff
changeset
|
53 |
|
358 | 54 |
// set defaults |
55 |
arg_graphics = false; |
|
56 |
arg_port = NETWORK_PORT_STR; |
|
57 |
arg_server = false; |
|
58 |
arg_connect = ""; |
|
408
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
397
diff
changeset
|
59 |
graphics.fullscreen = GRAPHICS_FULLSCREEN; |
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
397
diff
changeset
|
60 |
graphics.resolution = PixelCoordinate(GRAPHICS_RESOLUTION_WIDTH, GRAPHICS_RESOLUTION_HEIGHT); |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
61 |
|
358 | 62 |
// extra state |
392
6c4dc68360eb
remove unused graphics_default, and default to the highest resolution available in fullscreen mode
Tero Marttila <terom@fixme.fi>
parents:
389
diff
changeset
|
63 |
bool resolution_default = true; |
358 | 64 |
|
65 |
try { |
|
66 |
// parse args |
|
67 |
args.parse_args(argc, argv); |
|
267 | 68 |
|
358 | 69 |
} catch (CL_Error &e) { |
70 |
throw ArgumentError(e.message); |
|
71 |
} |
|
267 | 72 |
|
358 | 73 |
while (args.next()) { |
74 |
switch (args.get_key()) { |
|
389
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
75 |
case ARG_HELP: |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
76 |
args.print_help(); |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
77 |
return false; |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
78 |
|
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
79 |
case ARG_PORT: |
358 | 80 |
arg_port = args.get_argument(); |
81 |
break; |
|
82 |
||
389
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
83 |
case ARG_SERVER: |
358 | 84 |
arg_server = true; |
85 |
break; |
|
86 |
||
389
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
87 |
case ARG_CLIENT: |
358 | 88 |
arg_connect = args.get_argument(); |
89 |
break; |
|
90 |
||
389
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
91 |
case ARG_GRAPHICS: |
267 | 92 |
arg_graphics = true; |
358 | 93 |
break; |
94 |
||
389
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
95 |
case ARG_FULLSCREEN: |
408
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
397
diff
changeset
|
96 |
graphics.fullscreen = true; |
392
6c4dc68360eb
remove unused graphics_default, and default to the highest resolution available in fullscreen mode
Tero Marttila <terom@fixme.fi>
parents:
389
diff
changeset
|
97 |
|
6c4dc68360eb
remove unused graphics_default, and default to the highest resolution available in fullscreen mode
Tero Marttila <terom@fixme.fi>
parents:
389
diff
changeset
|
98 |
// choose best resolution unless explicitly set |
6c4dc68360eb
remove unused graphics_default, and default to the highest resolution available in fullscreen mode
Tero Marttila <terom@fixme.fi>
parents:
389
diff
changeset
|
99 |
if (resolution_default) { |
6c4dc68360eb
remove unused graphics_default, and default to the highest resolution available in fullscreen mode
Tero Marttila <terom@fixme.fi>
parents:
389
diff
changeset
|
100 |
const CL_DisplayMode best_mode = Graphics::getBestMode(); |
6c4dc68360eb
remove unused graphics_default, and default to the highest resolution available in fullscreen mode
Tero Marttila <terom@fixme.fi>
parents:
389
diff
changeset
|
101 |
const CL_Size best_resolution = best_mode.get_resolution(); |
6c4dc68360eb
remove unused graphics_default, and default to the highest resolution available in fullscreen mode
Tero Marttila <terom@fixme.fi>
parents:
389
diff
changeset
|
102 |
|
408
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
397
diff
changeset
|
103 |
graphics.resolution = PixelCoordinate(best_resolution.width, best_resolution.height); |
392
6c4dc68360eb
remove unused graphics_default, and default to the highest resolution available in fullscreen mode
Tero Marttila <terom@fixme.fi>
parents:
389
diff
changeset
|
104 |
} |
6c4dc68360eb
remove unused graphics_default, and default to the highest resolution available in fullscreen mode
Tero Marttila <terom@fixme.fi>
parents:
389
diff
changeset
|
105 |
|
389
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
106 |
break; |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
107 |
|
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
108 |
case ARG_RESOLUTION: |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
109 |
parse_arg_resolution(args.get_argument()); |
392
6c4dc68360eb
remove unused graphics_default, and default to the highest resolution available in fullscreen mode
Tero Marttila <terom@fixme.fi>
parents:
389
diff
changeset
|
110 |
resolution_default = false; |
389
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
111 |
break; |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
112 |
|
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
113 |
case ARG_LIST_MODES: |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
114 |
dump_display_modes(); |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
115 |
return false; |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
116 |
|
397
13fa0546ef87
hopefully version stuff is now run properly on every make...
Tero Marttila <terom@fixme.fi>
parents:
392
diff
changeset
|
117 |
case ARG_VERSION: |
13fa0546ef87
hopefully version stuff is now run properly on every make...
Tero Marttila <terom@fixme.fi>
parents:
392
diff
changeset
|
118 |
dump_version(); |
13fa0546ef87
hopefully version stuff is now run properly on every make...
Tero Marttila <terom@fixme.fi>
parents:
392
diff
changeset
|
119 |
return false; |
13fa0546ef87
hopefully version stuff is now run properly on every make...
Tero Marttila <terom@fixme.fi>
parents:
392
diff
changeset
|
120 |
|
358 | 121 |
case CL_CommandLine::REST_ARG: |
122 |
throw ArgumentError(args.get_argument()); |
|
123 |
||
124 |
default: |
|
125 |
throw ArgumentError(std::string(1, (char) args.get_key())); |
|
126 |
||
127 |
} |
|
128 |
} |
|
129 |
||
130 |
// check for invalid combinations of arugments |
|
131 |
if (arg_server and !arg_connect.empty()) |
|
132 |
throw ArgumentError("cannot be both server and client"); |
|
133 |
||
134 |
// enable graphics by default unless server |
|
392
6c4dc68360eb
remove unused graphics_default, and default to the highest resolution available in fullscreen mode
Tero Marttila <terom@fixme.fi>
parents:
389
diff
changeset
|
135 |
if (!arg_server) |
358 | 136 |
arg_graphics = true; |
389
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
137 |
|
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
138 |
// continue |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
139 |
return true; |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
140 |
} |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
141 |
|
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
142 |
void Main::parse_arg_resolution (const std::string &val) { |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
143 |
unsigned int w, h; |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
144 |
|
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
145 |
// sccanf as unsigned |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
146 |
if (sscanf(val.c_str(), "%ux%u", &w, &h) != 2) |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
147 |
throw ArgumentError("invalid format for --resolution"); |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
148 |
|
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
149 |
// store as PixelCoordinate |
408
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
397
diff
changeset
|
150 |
graphics.resolution = PixelCoordinate(w, h); |
389
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
151 |
} |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
152 |
|
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
153 |
void Main::dump_display_modes (void) { |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
154 |
const std::vector<CL_DisplayMode> &modes = Graphics::getDisplayModes(); |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
155 |
|
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
156 |
std::cout << "Available display modes:" << std::endl; |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
157 |
|
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
158 |
for (std::vector<CL_DisplayMode>::const_iterator it = modes.begin(); it != modes.end(); it++) |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
159 |
std::cout << "\t" << it->get_resolution().width << "x" << it->get_resolution().height << std::endl; |
358 | 160 |
} |
397
13fa0546ef87
hopefully version stuff is now run properly on every make...
Tero Marttila <terom@fixme.fi>
parents:
392
diff
changeset
|
161 |
|
13fa0546ef87
hopefully version stuff is now run properly on every make...
Tero Marttila <terom@fixme.fi>
parents:
392
diff
changeset
|
162 |
void Main::dump_version (void) { |
13fa0546ef87
hopefully version stuff is now run properly on every make...
Tero Marttila <terom@fixme.fi>
parents:
392
diff
changeset
|
163 |
std::cout << PROJECT_LONG_NAME << " version " << PROJECT_VERSION << " built " << PROJECT_BUILD_TIMESTAMP << std::endl; |
13fa0546ef87
hopefully version stuff is now run properly on every make...
Tero Marttila <terom@fixme.fi>
parents:
392
diff
changeset
|
164 |
} |
358 | 165 |
|
166 |
/** |
|
167 |
* IT BEGAN IN AFRIKA |
|
168 |
*/ |
|
169 |
int Main::main (int argc, char **argv) { |
|
170 |
// initialize the ClanLib components that we use |
|
171 |
CL_SetupCore setup_core; |
|
172 |
CL_SetupNetwork setup_network; |
|
173 |
CL_SetupDisplay setup_disp; |
|
174 |
CL_SetupGL setup_gl; |
|
175 |
||
176 |
try { |
|
389
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
177 |
// parse arugments, exit if false |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
178 |
if (parse_args(argc, argv) == false) |
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
358
diff
changeset
|
179 |
return 0; |
358 | 180 |
|
181 |
// our engine |
|
182 |
Engine engine; |
|
183 |
||
184 |
// setup graphics |
|
185 |
if (arg_graphics) |
|
408
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
397
diff
changeset
|
186 |
engine.setupGraphics(graphics); |
358 | 187 |
|
188 |
// setup either network server, client or singleplayer |
|
189 |
if (arg_server) { |
|
190 |
engine.setupNetworkServer(arg_port); |
|
191 |
||
192 |
} else if (!arg_connect.empty()) { |
|
193 |
engine.setupNetworkClient(arg_connect, arg_port); |
|
194 |
||
195 |
} else { |
|
196 |
engine.setupSinglePlayer(); |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
197 |
} |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
198 |
|
358 | 199 |
// run the main loop |
200 |
engine.run(); |
|
201 |
||
202 |
// succesful return |
|
203 |
return 0; |
|
204 |
||
205 |
} catch (ArgumentError &e) { |
|
206 |
std::cerr << e.what() << std::endl; |
|
207 |
args.print_help(); |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
208 |
|
358 | 209 |
// XXX: handle --help |
210 |
return 1; |
|
211 |
} catch (CL_Error &e) { |
|
212 |
std::cerr << "main: CL_Error:" << e.message << std::endl; |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
213 |
|
358 | 214 |
return 1; |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
215 |
|
358 | 216 |
} catch (std::exception &e) { |
217 |
std::cerr << "FATAL [uncaught_exception] " << e.what() << std::endl; |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
218 |
|
358 | 219 |
return 1; |
220 |
} |
|
221 |
} |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
222 |