--- a/src/Engine.cc Thu Jan 22 00:28:26 2009 +0200
+++ b/src/Engine.cc Thu Jan 22 01:53:05 2009 +0200
@@ -1,10 +1,23 @@
#include "Engine.hh"
#include "SinglePlayer.hh"
-#include "Network/Reactor.hh"
#include "Config.hh"
+// XXX: how does this work if we don't have NETWORK_ENABLED?
+#include "Network/Reactor.hh"
+
+// include the real component definitions
+#if NETWORK_ENABLED
+ #include "Network/Client.hh"
+ #include "Network/Server.hh"
+#endif
+
+#if GRAPHICS_ENABLED
+ #include "Graphics/Graphics.hh"
+#endif
+
#include <iostream>
+#include <cassert>
Engine::Engine (const std::string resource_xml_path) :
terrain(NULL), game_state(NULL), graphics(NULL), net_server(NULL), net_client_connect(NULL),
@@ -22,13 +35,9 @@
// create the GameState
game_state = new GameState(*terrain);
+
+ // XXX: NetworkClient + GameView?
- // put graphics into GameView mode
- // XXX: this state is a mess, this is done in three places in weird ways
- // this depends on graphics not yet being set in client mode, but not in singleplayer mode
- if (graphics)
- graphics->displayGameView(*game_state, game_state->getLocalPlayer());
-
return *game_state;
}
@@ -37,12 +46,42 @@
setupGame(new Terrain(config));
}
-void Engine::setupGraphics (const graphics::DisplayConfig &config) {
+void Engine::setupGraphics (const DisplayConfig &config) {
+
+#if GRAPHICS_ENABLED
+ assert(!graphics);
+
// create the graphics
graphics = new graphics::Graphics(*this, resources, config);
+
+#else
+ (void) config;
+
+ throw Error("No Graphics support available");
+
+#endif
+
+}
+
+void Engine::startGameView (LocalPlayer *player) {
+
+#if GRAPHICS_ENABLED
+ assert(graphics);
+
+ graphics->displayGameView(*game_state, player);
+
+#else
+ (void) player;
+
+ throw Error("No Graphics support available");
+
+#endif
+
}
void Engine::setupNetworkServer (const std::string &listen_port) {
+
+#if NETWORK_EANBLED
NetworkEndpoint listen_addr(listen_port);
assert(terrain && game_state);
@@ -52,16 +91,33 @@
// put graphics into GameView mode
if (graphics)
- graphics->displayGameView(*game_state, NULL);
-
+ startGameView(NULL);
+
+#else
+ (void) listen_port;
+
+ throw Error("No Network support available");
+
+#endif
}
void Engine::setupNetworkClient (const std::string &connect_host, const std::string &connect_port) {
+
+#if NETWORK_EANBLED
// connect_to
NetworkEndpoint connect_addr(connect_host, connect_port);
// begin connecting, the client will callback us with setupGame once it's connected
net_client_connect = new NetworkClientConnect(*this, connect_addr);
+
+#else
+ (void) connect_host;
+ (void) connect_port;
+
+ throw Error("No Network support available");
+
+#endif
+
}
void Engine::setupSinglePlayer (void) {
@@ -75,7 +131,7 @@
// put graphics into GameView mode
if (graphics)
- graphics->displayGameView(*game_state, lp);
+ startGameView(lp);
}
@@ -84,26 +140,21 @@
}
void Engine::run (void) {
- // our NetworkReactor
- NetworkReactor *reactor = NetworkReactor::current;
-
- // timeout info
- timeval timeout;
-
while (is_running) {
- // this does.... magical things
- CL_System::keep_alive();
+ /*
+ * Run internal ClanLib stuff (also includes our timers) until our timeout has elapsed
+ */
+ CL_System::keep_alive(ENGINE_TIMEOUT_MS);
- // setup our timeout to ENGINE_TIMEOUT_MS
- timeout.tv_sec = 0;
- timeout.tv_usec = ENGINE_TIMEOUT_MS * 1000;
-
+#if NETWORK_ENABLED
/*
* Thursday came and went, I re-wrote clan-event.
*
- * We use the NetworkReactor for sleeping, as it handles it effeciently even if we're not using network.
+ * (actually, we only use it for zero-timeout polling now... not sure if this is better than using the above
+ * CL_System::keep_alive)
*/
- reactor->poll(&timeout);
+ NetworkReactor::current->poll(NULL);
+#endif
}
}