35 |
43 |
36 /** |
44 /** |
37 * Set the arg_* members |
45 * Set the arg_* members |
38 */ |
46 */ |
39 bool Main::parse_args (int argc, char **argv) { |
47 bool Main::parse_args (int argc, char **argv) { |
|
48 |
40 // set up the options |
49 // set up the options |
|
50 args.add_usage("[OPTIONS]"); |
|
51 args.set_help_indent(30); |
|
52 |
|
53 if (NETWORK_ENABLED) { |
|
54 args.add_group("Network"); |
|
55 |
|
56 args.add_option(ARG_PORT, "port", "PORT", |
|
57 "set network port used"); |
|
58 |
|
59 args.add_option(ARG_SERVER, "server", "", |
|
60 "act as a network server"); |
|
61 |
|
62 // require graphics for network-client |
|
63 if (GRAPHICS_ENABLED) |
|
64 args.add_option(ARG_CLIENT, "client", "SERVERHOST", |
|
65 "act as a network client"); |
|
66 } |
|
67 |
|
68 if (GRAPHICS_ENABLED) { |
|
69 args.add_group("Graphics"); |
|
70 |
|
71 args.add_option(ARG_GRAPHICS, "graphics", "", |
|
72 "run graphics/local input. Implied with --client"); |
|
73 |
|
74 args.add_option(ARG_FULLSCREEN, "fullscreen", "", |
|
75 "run graphics in fullscreen mode"); |
|
76 |
|
77 args.add_option(ARG_RESOLUTION, "resolution", "WIDTHxHEIGHT", |
|
78 "set graphics resolution"); |
|
79 |
|
80 args.add_option(ARG_LIST_MODES, "list-modes", "", |
|
81 "output a list of available display modes and exit"); |
|
82 } |
|
83 |
|
84 args.add_group("Game"); |
|
85 args.add_option(ARG_TERRAIN_SEED, "terrain-seed", "SEED", |
|
86 "set seed for terrain random generator"); |
|
87 |
|
88 args.add_option(ARG_TERRAIN_SIZE, "terrain-size", "WIDTHxHEIGHT", |
|
89 "set terrain size for random generator"); |
|
90 |
|
91 |
|
92 args.add_group("General"); |
41 args.add_option(ARG_HELP, "help", "", |
93 args.add_option(ARG_HELP, "help", "", |
42 "display argument help and exit"); |
94 "display argument help and exit"); |
43 |
95 |
44 args.add_option(ARG_PORT, "port", "PORT", |
|
45 "set network port used"); |
|
46 |
|
47 args.add_option(ARG_SERVER, "server", "", |
|
48 "act as a network server"); |
|
49 |
|
50 args.add_option(ARG_CLIENT, "client", "SERVERHOST", |
|
51 "act as a network client"); |
|
52 |
|
53 args.add_option(ARG_GRAPHICS, "graphics", "", |
|
54 "run graphics/local input. Implied with --connect"); |
|
55 |
|
56 args.add_option(ARG_FULLSCREEN, "fullscreen", "", |
|
57 "run graphics in fullscreen mode"); |
|
58 |
|
59 args.add_option(ARG_RESOLUTION, "resolution", "WIDTHxHEIGHT", |
|
60 "set graphics resolution"); |
|
61 |
|
62 args.add_option(ARG_LIST_MODES, "list-modes", "", |
|
63 "output a list of available display modes and exit"); |
|
64 |
|
65 args.add_option(ARG_TERRAIN_SEED, "terrain-seed", "SEED", |
|
66 "set seed for terrain random generator"); |
|
67 |
|
68 args.add_option(ARG_TERRAIN_SIZE, "terrain-size", "WIDTHxHEIGHT", |
|
69 "set terrain size for random generator"); |
|
70 |
|
71 args.add_option(ARG_VERSION, "version", "", |
96 args.add_option(ARG_VERSION, "version", "", |
72 "output application version and exit"); |
97 "output application version plus configuration and exit"); |
73 |
98 |
|
99 #if GRAPHICS_ENABLED |
74 // extra state |
100 // extra state |
75 bool resolution_default = true; |
101 bool resolution_default = true; |
|
102 |
|
103 #endif |
76 |
104 |
77 try { |
105 try { |
78 // parse args |
106 // parse args |
79 args.parse_args(argc, argv); |
107 args.parse_args(argc, argv); |
80 |
108 |
178 if (sscanf(arg_val.c_str(), "%ux%u", &w, &h) != 2) |
215 if (sscanf(arg_val.c_str(), "%ux%u", &w, &h) != 2) |
179 throw ArgumentError(std::string() + "invalid format for " + arg_name + ": " + arg_val); |
216 throw ArgumentError(std::string() + "invalid format for " + arg_name + ": " + arg_val); |
180 |
217 |
181 return PixelDimensions(w, h); |
218 return PixelDimensions(w, h); |
182 } |
219 } |
183 |
220 |
|
221 #if GRAPHICS_ENABLED |
184 void Main::dump_display_modes (void) { |
222 void Main::dump_display_modes (void) { |
|
223 // get the list of display modes from graphics |
185 const std::vector<CL_DisplayMode> &modes = graphics::Display::getDisplayModes(); |
224 const std::vector<CL_DisplayMode> &modes = graphics::Display::getDisplayModes(); |
|
225 PixelCoordinate last_resolution; |
186 |
226 |
187 std::cout << "Available display modes:" << std::endl; |
227 std::cout << "Available display modes:" << std::endl; |
188 |
228 |
189 for (std::vector<CL_DisplayMode>::const_iterator it = modes.begin(); it != modes.end(); it++) |
229 // iterate over the list of available display modes |
190 std::cout << "\t" << it->get_resolution().width << "x" << it->get_resolution().height << std::endl; |
230 for (std::vector<CL_DisplayMode>::const_iterator it = modes.begin(); it != modes.end(); it++) { |
191 } |
231 PixelCoordinate resolution(it->get_resolution().width, it->get_resolution().height); |
|
232 |
|
233 // filter out those that haven't changed |
|
234 if (resolution != last_resolution) |
|
235 std::cout << "\t" << it->get_resolution().width << "x" << it->get_resolution().height << std::endl; |
|
236 |
|
237 // update for next item |
|
238 last_resolution = resolution; |
|
239 } |
|
240 } |
|
241 #endif |
192 |
242 |
193 void Main::dump_version (void) { |
243 void Main::dump_version (void) { |
194 std::cout << PROJECT_LONG_NAME << " version " << PROJECT_VERSION << " built " << PROJECT_BUILD_TIMESTAMP << std::endl; |
244 std::cout |
|
245 << PROJECT_LONG_NAME << " version " << PROJECT_VERSION << " built [" << PROJECT_BUILD_TIMESTAMP << "]" << std::endl; |
|
246 |
|
247 // then some additional stuff about what's enabled |
|
248 std::cout |
|
249 << std::endl |
|
250 << "Enabled components:" << std::endl |
|
251 << "\tGraphics:\t" << (GRAPHICS_ENABLED ? "Yes" : "No") << std::endl |
|
252 << "\tNetwork:\t" << (NETWORK_ENABLED ? "Yes" : "No") << std::endl; |
195 } |
253 } |
196 |
254 |
197 /** |
255 /** |
198 * IT BEGAN IN AFRIKA |
256 * IT BEGAN IN AFRIKA |
199 */ |
257 */ |
200 int Main::main (int argc, char **argv) { |
258 int Main::main (int argc, char **argv) { |
201 // initialize the ClanLib components that we use |
259 // initialize the ClanLib components that we use |
202 CL_SetupCore setup_core; |
260 CL_SetupCore setup_core; |
|
261 |
|
262 #if GRAPHICS_ENABLED |
|
263 // XXX: move to Graphics/Graphics.hh? |
203 CL_SetupDisplay setup_disp; |
264 CL_SetupDisplay setup_disp; |
204 CL_SetupGL setup_gl; |
265 CL_SetupGL setup_gl; |
|
266 #endif |
205 |
267 |
206 try { |
268 try { |
207 // parse arugments, exit if false |
269 // parse arugments, exit if false |
208 if (parse_args(argc, argv) == false) |
270 if (parse_args(argc, argv) == false) |
209 return 0; |
271 return 0; |
224 engine.setupNetworkServer(net_port); |
286 engine.setupNetworkServer(net_port); |
225 |
287 |
226 } else if (!net_connect.empty()) { |
288 } else if (!net_connect.empty()) { |
227 engine.setupNetworkClient(net_connect, net_port); |
289 engine.setupNetworkClient(net_connect, net_port); |
228 |
290 |
|
291 } else if (graphics_enabled) { |
|
292 engine.setupSinglePlayer(); |
|
293 |
229 } else { |
294 } else { |
230 engine.setupSinglePlayer(); |
295 throw ArgumentError("Nothing to do"); |
|
296 |
231 } |
297 } |
232 |
298 |
233 // run the main loop |
299 // run the main loop |
234 engine.run(); |
300 engine.run(); |
235 |
301 |
236 // succesful return |
302 // succesful return |
237 return 0; |
303 return 0; |
238 |
304 |
239 } catch (ArgumentError &e) { |
305 } catch (ArgumentError &e) { |
240 std::cerr << e.what() << std::endl; |
306 std::cerr |
|
307 << "Error: " << e.what() << std::endl |
|
308 << std::endl; |
|
309 |
241 args.print_help(); |
310 args.print_help(); |
242 |
311 |
243 // XXX: handle --help |
|
244 return 1; |
312 return 1; |
|
313 |
245 } catch (CL_Error &e) { |
314 } catch (CL_Error &e) { |
246 std::cerr << "main: CL_Error:" << e.message << std::endl; |
315 std::cerr << "main: CL_Error:" << e.message << std::endl; |
247 |
316 |
248 return 1; |
317 return 1; |
249 |
318 |