#include "Engine.hh"
#include "NetworkServer.hh"
#include "NetworkClient.hh"
#include "SinglePlayer.hh"
#include <iostream>
Engine::Engine (void) : is_running(true) {
}
void Engine::setupGraphics (void) {
// create the graphics
graphics = new Graphics(*this, game_state);
}
void Engine::setupNetworkServer (const std::string &listen_port) {
// create the server
net_server = new NetworkServer(game_state, listen_port);
}
void Engine::setupNetworkClient (const std::string &connect_host, const std::string &connect_port) {
// connect_to
CL_IPAddress connect_addr(connect_host, connect_port);
// create the client
net_client = new NetworkClient(game_state, connect_addr);
}
void Engine::setupSinglePlayer (void) {
// create player directly
LocalPlayer* lp = new SinglePlayer(game_state);
// add to gamestate
game_state.newLocalPlayer(lp);
}
void Engine::stop (void) {
is_running = false;
}
void Engine::run (void) {
while (is_running) {
// this does.... magical things
CL_System::keep_alive();
// if I can't find some better way to do this in ClanLib by next thursday, then it f*%!ing sucks
// ideally, we should be able to have a main loop that does timed waits on I/O, fufilling some set of timers
// but as far as I can tell, ClanLib doesn't have anything like that
CL_System::sleep(10);
}
}
Logger Engine::log (enum LogLevel level, const char *type) {
return Logger(level <= WARN ? std::cerr : std::cout, level, type);
}