--- a/src/Engine.cc Tue Jan 20 23:24:04 2009 +0200
+++ b/src/Engine.cc Tue Jan 20 23:30:18 2009 +0200
@@ -7,37 +7,78 @@
#include <iostream>
Engine::Engine (const std::string resource_xml_path) :
+ terrain(NULL), game_state(NULL), graphics_config(NULL), graphics(NULL), net_server(NULL), net_client_connect(NULL),
is_running(true), resources(resource_xml_path)
{
}
-void Engine::setupGraphics (PixelCoordinate resolution, bool fullscreen) {
+GameState& Engine::setupGame (Terrain *terrain) {
+ // ensure this isn't called in inappropriate ways
+ assert(!net_server);
+
+ // remember the terrain
+ this->terrain = terrain;
+
+ // create the GameState
+ game_state = new GameState(*terrain);
+
+ // start graphics?
+ if (graphics_config)
+ startGraphics();
+
+ return *game_state;
+}
+
+GameState& Engine::setupGame (void) {
+ // proxy off to setupGame(Terrain *)
+ return setupGame(new Terrain(TERRAIN_WIDTH, TERRAIN_HEIGHT, TERRAIN_RANDOM_SEED));
+}
+
+void Engine::setupGraphics (const GraphicsConfiguration &config) {
+ // store config
+ graphics_config = &config;
+
+ // start already?
+ if (game_state)
+ startGraphics();
+}
+
+void Engine::startGraphics (void) {
+ // check state
+ assert(game_state && graphics_config);
+
// create the graphics
- graphics = new Graphics(*this, game_state, resolution, fullscreen);
+ graphics = new Graphics(*this, *game_state, *graphics_config);
}
void Engine::setupNetworkServer (const std::string &listen_port) {
NetworkEndpoint listen_addr(listen_port);
+
+ // setup default game
+ setupGame();
// create the server
- net_server = new NetworkServer(game_state, listen_addr);
+ net_server = new NetworkServer(*game_state, listen_addr);
}
void Engine::setupNetworkClient (const std::string &connect_host, const std::string &connect_port) {
// connect_to
NetworkEndpoint connect_addr(connect_host, connect_port);
- // create the client
- net_client = new NetworkClient(*this, game_state, connect_addr);
+ // begin connecting, the client will callback us with setupGame once it's connected
+ net_client_connect = new NetworkClientConnect(*this, connect_addr);
}
void Engine::setupSinglePlayer (void) {
+ // setup default game
+ setupGame();
+
// create player directly
- LocalPlayer* lp = new SinglePlayer(game_state);
+ LocalPlayer* lp = new SinglePlayer(*game_state);
// add to gamestate
- game_state.setLocalPlayer(lp);
+ game_state->setLocalPlayer(lp);
}
void Engine::stop (void) {