--- a/src/Application.cc Tue Dec 09 03:06:48 2008 +0000
+++ b/src/Application.cc Tue Dec 09 03:28:25 2008 +0000
@@ -1,140 +1,126 @@
-#include "Engine.hh"
-#include "Error.hh"
+#include "Application.hh"
#include <stdexcept>
#include <cassert>
-#include <ClanLib/core.h>
-#include <ClanLib/application.h>
-
-class ArgumentError : public Error {
- public:
- ArgumentError (const std::string &message) : Error(message) { }
-};
-
-class Main : public CL_ClanApplication {
- private:
- // arguments
- CL_CommandLine args;
-
- bool arg_graphics;
- std::string arg_port;
- bool arg_server;
- std::string arg_connect;
-
- void parse_args (int argc, char **argv) {
- // set up the options
- args.add_option('p', "port", "PORT", "set network port used", true);
- args.add_option('s', "server", "", "act as a network server", true);
- args.add_option('c', "client", "SERVERHOST", "act as a network client", true);
- args.add_option('g', "graphics", "", "run graphics/local input. Implied with --connect", true);
-
- // set defaults
- arg_graphics = false;
- arg_port = NETWORK_PORT_STR;
- arg_server = false;
- arg_connect = "";
-
- // extra state
- bool graphics_default = true;
-
- try {
- // parse args
- args.parse_args(argc, argv);
- } catch (CL_Error &e) {
- throw ArgumentError(e.message);
- }
-
- while (args.next()) {
- switch (args.get_key()) {
- case 'p':
- arg_port = args.get_argument();
- break;
-
- case 's':
- arg_server = true;
- break;
-
- case 'c':
- arg_connect = args.get_argument();
- break;
+/**
+ * Set the arg_* members
+ */
+void Main::parse_args (int argc, char **argv) {
+ // set up the options
+ args.add_option('p', "port", "PORT", "set network port used", true);
+ args.add_option('s', "server", "", "act as a network server", true);
+ args.add_option('c', "client", "SERVERHOST", "act as a network client", true);
+ args.add_option('g', "graphics", "", "run graphics/local input. Implied with --connect", true);
- case 'g':
- arg_graphics = true;
- break;
-
- case CL_CommandLine::REST_ARG:
- throw ArgumentError(args.get_argument());
-
- default:
- throw ArgumentError(std::string(1, (char) args.get_key()));
+ // set defaults
+ arg_graphics = false;
+ arg_port = NETWORK_PORT_STR;
+ arg_server = false;
+ arg_connect = "";
- }
- }
+ // extra state
+ bool graphics_default = true;
+
+ try {
+ // parse args
+ args.parse_args(argc, argv);
- // check for invalid combinations of arugments
- if (arg_server and !arg_connect.empty())
- throw ArgumentError("cannot be both server and client");
+ } catch (CL_Error &e) {
+ throw ArgumentError(e.message);
+ }
- // enable graphics by default unless server
- if (!arg_server && graphics_default)
+ while (args.next()) {
+ switch (args.get_key()) {
+ case 'p':
+ arg_port = args.get_argument();
+ break;
+
+ case 's':
+ arg_server = true;
+ break;
+
+ case 'c':
+ arg_connect = args.get_argument();
+ break;
+
+ case 'g':
arg_graphics = true;
+ break;
+
+ case CL_CommandLine::REST_ARG:
+ throw ArgumentError(args.get_argument());
+
+ default:
+ throw ArgumentError(std::string(1, (char) args.get_key()));
+
+ }
+ }
+
+ // check for invalid combinations of arugments
+ if (arg_server and !arg_connect.empty())
+ throw ArgumentError("cannot be both server and client");
+
+ // enable graphics by default unless server
+ if (!arg_server && graphics_default)
+ arg_graphics = true;
+}
+
+/**
+ * IT BEGAN IN AFRIKA
+ */
+int Main::main (int argc, char **argv) {
+ // initialize the ClanLib components that we use
+ CL_SetupCore setup_core;
+ CL_SetupNetwork setup_network;
+ CL_SetupDisplay setup_disp;
+ CL_SetupGL setup_gl;
+
+ try {
+ // parse arugments
+ parse_args(argc, argv);
+
+ // our engine
+ Engine engine;
+
+ // setup graphics
+ if (arg_graphics)
+ engine.setupGraphics();
+
+ // setup either network server, client or singleplayer
+ if (arg_server) {
+ engine.setupNetworkServer(arg_port);
+
+ } else if (!arg_connect.empty()) {
+ engine.setupNetworkClient(arg_connect, arg_port);
+
+ } else {
+ engine.setupSinglePlayer();
}
- public:
- virtual int main (int argc, char **argv) {
- // initialize the ClanLib components that we use
- CL_SetupCore setup_core;
- CL_SetupNetwork setup_network;
- CL_SetupDisplay setup_disp;
- CL_SetupGL setup_gl;
-
- try {
- // parse arugments
- parse_args(argc, argv);
-
- // our engine
- Engine engine;
-
- // setup graphics
- if (arg_graphics)
- engine.setupGraphics();
-
- // setup either network server, client or singleplayer
- if (arg_server) {
- engine.setupNetworkServer(arg_port);
+ // run the main loop
+ engine.run();
+
+ // succesful return
+ return 0;
+
+ } catch (ArgumentError &e) {
+ std::cerr << e.what() << std::endl;
+ args.print_help();
- } else if (!arg_connect.empty()) {
- engine.setupNetworkClient(arg_connect, arg_port);
-
- } else {
- engine.setupSinglePlayer();
- }
+ // XXX: handle --help
+ return 1;
+ } catch (CL_Error &e) {
+ std::cerr << "main: CL_Error:" << e.message << std::endl;
- // run the main loop
- engine.run();
-
- // succesful return
- return 0;
-
- } catch (ArgumentError &e) {
- std::cerr << e.what() << std::endl;
- args.print_help();
+ return 1;
- // XXX: handle --help
- return 1;
- } catch (CL_Error &e) {
- std::cerr << "main: CL_Error:" << e.message << std::endl;
-
- return 1;
+ } catch (std::exception &e) {
+ std::cerr << "FATAL [uncaught_exception] " << e.what() << std::endl;
- } catch (std::exception &e) {
- std::cerr << "FATAL [uncaught_exception] " << e.what() << std::endl;
+ return 1;
+ }
+}
- return 1;
- }
- }
-} app;
-