--- a/src/Application.cc Thu Jan 22 00:28:26 2009 +0200
+++ b/src/Application.cc Thu Jan 22 01:53:05 2009 +0200
@@ -1,7 +1,15 @@
#include "Application.hh"
+#include "Config.hh"
-#include <ClanLib/gl.h>
+#if GRAPHICS_ENABLED
+ // for dump_display_modes
+ #include "Graphics/Display.hh"
+
+ // for CL_SetupGL
+ #include <ClanLib/gl.h>
+#endif
+
#include <stdexcept>
#include <sstream>
#include <cstdio>
@@ -37,42 +45,62 @@
* Set the arg_* members
*/
bool Main::parse_args (int argc, char **argv) {
- // set up the options
- args.add_option(ARG_HELP, "help", "",
- "display argument help and exit");
-
- args.add_option(ARG_PORT, "port", "PORT",
- "set network port used");
-
- args.add_option(ARG_SERVER, "server", "",
- "act as a network server");
- args.add_option(ARG_CLIENT, "client", "SERVERHOST",
- "act as a network client");
-
- args.add_option(ARG_GRAPHICS, "graphics", "",
- "run graphics/local input. Implied with --connect");
+ // set up the options
+ args.add_usage("[OPTIONS]");
+ args.set_help_indent(30);
+
+ if (NETWORK_ENABLED) {
+ args.add_group("Network");
- args.add_option(ARG_FULLSCREEN, "fullscreen", "",
- "run graphics in fullscreen mode");
+ args.add_option(ARG_PORT, "port", "PORT",
+ "set network port used");
- args.add_option(ARG_RESOLUTION, "resolution", "WIDTHxHEIGHT",
- "set graphics resolution");
-
- args.add_option(ARG_LIST_MODES, "list-modes", "",
- "output a list of available display modes and exit");
+ args.add_option(ARG_SERVER, "server", "",
+ "act as a network server");
+
+ // require graphics for network-client
+ if (GRAPHICS_ENABLED)
+ args.add_option(ARG_CLIENT, "client", "SERVERHOST",
+ "act as a network client");
+ }
+ if (GRAPHICS_ENABLED) {
+ args.add_group("Graphics");
+
+ args.add_option(ARG_GRAPHICS, "graphics", "",
+ "run graphics/local input. Implied with --client");
+
+ args.add_option(ARG_FULLSCREEN, "fullscreen", "",
+ "run graphics in fullscreen mode");
+
+ args.add_option(ARG_RESOLUTION, "resolution", "WIDTHxHEIGHT",
+ "set graphics resolution");
+
+ args.add_option(ARG_LIST_MODES, "list-modes", "",
+ "output a list of available display modes and exit");
+ }
+
+ args.add_group("Game");
args.add_option(ARG_TERRAIN_SEED, "terrain-seed", "SEED",
"set seed for terrain random generator");
args.add_option(ARG_TERRAIN_SIZE, "terrain-size", "WIDTHxHEIGHT",
"set terrain size for random generator");
+
+ args.add_group("General");
+ args.add_option(ARG_HELP, "help", "",
+ "display argument help and exit");
+
args.add_option(ARG_VERSION, "version", "",
- "output application version and exit");
+ "output application version plus configuration and exit");
+#if GRAPHICS_ENABLED
// extra state
bool resolution_default = true;
+
+#endif
try {
// parse args
@@ -88,6 +116,7 @@
args.print_help();
return false;
+#if NETWORK_ENABLED
case ARG_PORT:
net_port = args.get_argument();
break;
@@ -100,6 +129,9 @@
net_connect = args.get_argument();
break;
+#endif
+
+#if GRAPHICS_ENABLED
case ARG_GRAPHICS:
graphics_enabled = true;
break;
@@ -125,6 +157,7 @@
case ARG_LIST_MODES:
dump_display_modes();
return false;
+#endif
case ARG_VERSION:
dump_version();
@@ -147,14 +180,18 @@
}
}
+#if NETWORK_ENABLED
// check for invalid combinations of arugments
if (net_server and !net_connect.empty())
throw ArgumentError("cannot be both server and client");
+#endif
+#if GRAPHICS_ENABLED
// enable graphics by default unless server
if (!net_server)
graphics_enabled = true;
-
+#endif
+
// continue
return true;
}
@@ -180,18 +217,39 @@
return PixelDimensions(w, h);
}
-
+
+#if GRAPHICS_ENABLED
void Main::dump_display_modes (void) {
+ // get the list of display modes from graphics
const std::vector<CL_DisplayMode> &modes = graphics::Display::getDisplayModes();
+ PixelCoordinate last_resolution;
std::cout << "Available display modes:" << std::endl;
-
- for (std::vector<CL_DisplayMode>::const_iterator it = modes.begin(); it != modes.end(); it++)
- std::cout << "\t" << it->get_resolution().width << "x" << it->get_resolution().height << std::endl;
+
+ // iterate over the list of available display modes
+ for (std::vector<CL_DisplayMode>::const_iterator it = modes.begin(); it != modes.end(); it++) {
+ PixelCoordinate resolution(it->get_resolution().width, it->get_resolution().height);
+
+ // filter out those that haven't changed
+ if (resolution != last_resolution)
+ std::cout << "\t" << it->get_resolution().width << "x" << it->get_resolution().height << std::endl;
+
+ // update for next item
+ last_resolution = resolution;
+ }
}
+#endif
void Main::dump_version (void) {
- std::cout << PROJECT_LONG_NAME << " version " << PROJECT_VERSION << " built " << PROJECT_BUILD_TIMESTAMP << std::endl;
+ std::cout
+ << PROJECT_LONG_NAME << " version " << PROJECT_VERSION << " built [" << PROJECT_BUILD_TIMESTAMP << "]" << std::endl;
+
+ // then some additional stuff about what's enabled
+ std::cout
+ << std::endl
+ << "Enabled components:" << std::endl
+ << "\tGraphics:\t" << (GRAPHICS_ENABLED ? "Yes" : "No") << std::endl
+ << "\tNetwork:\t" << (NETWORK_ENABLED ? "Yes" : "No") << std::endl;
}
/**
@@ -200,8 +258,12 @@
int Main::main (int argc, char **argv) {
// initialize the ClanLib components that we use
CL_SetupCore setup_core;
+
+#if GRAPHICS_ENABLED
+ // XXX: move to Graphics/Graphics.hh?
CL_SetupDisplay setup_disp;
CL_SetupGL setup_gl;
+#endif
try {
// parse arugments, exit if false
@@ -226,8 +288,12 @@
} else if (!net_connect.empty()) {
engine.setupNetworkClient(net_connect, net_port);
+ } else if (graphics_enabled) {
+ engine.setupSinglePlayer();
+
} else {
- engine.setupSinglePlayer();
+ throw ArgumentError("Nothing to do");
+
}
// run the main loop
@@ -237,11 +303,14 @@
return 0;
} catch (ArgumentError &e) {
- std::cerr << e.what() << std::endl;
+ std::cerr
+ << "Error: " << e.what() << std::endl
+ << std::endl;
+
args.print_help();
- // XXX: handle --help
return 1;
+
} catch (CL_Error &e) {
std::cerr << "main: CL_Error:" << e.message << std::endl;