reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
#ifndef ENGINE_HH
#define ENGINE_HH
// forward-declare
class Engine;
#include "GameState.hh"
#include "Graphics.hh"
#include "Network/Server.hh"
#include "Network/Client.hh"
#include "Logger.hh"
/**
* This is the core class that glues all the other components together and runs the main loop
*/
class Engine {
private:
// game state
Terrain *terrain;
GameState *game_state;
/** Set if setupGraphics has been called */
const GraphicsConfiguration *graphics_config;
// Graphics/Input
Graphics *graphics;
// network server/client
NetworkServer *net_server;
NetworkClientConnect *net_client_connect;
// XXX: currently unused: NetworkClient *net_client;
// to exit the mainloop
bool is_running;
// ClanLib resources
CL_ResourceManager resources;
public:
// default constructor
Engine (const std::string resource_xml_path = RESOURCE_XML_PATH);
/**
* Setup game world using the given terrain, returning the new GameState
*/
GameState& setupGame (Terrain *terrain);
/**
* Setup default game world using constants from Config.hh
*/
GameState& setupGame (void);
// setup graphics
void setupGraphics (const GraphicsConfiguration &config);
// set up network server/client
// setting up both of these will lead to odd behaviour :)
void setupNetworkServer (const std::string &listen_port);
void setupNetworkClient (const std::string &connect_host, const std::string &connect_port);
void setupSinglePlayer (void);
/**
* Run the game main loop. This will not return until the game aborts due to an error, or someone calls stop().
*/
void run (void);
/**
* Terminate the main loop, causing run() to return once this loop iteration is finished
*/
void stop (void);
private:
/**
* Actually start graphics, requires that game_state is now set
*/
void startGraphics (void);
public:
// get a pointer to our resource manager
CL_ResourceManager* getResourceManager (void);
// logging utility
static Logger log (enum LogLevel level, const char *type);
};
#endif /* ENGINE_HH */