src/Engine.cc
author terom
Mon, 15 Dec 2008 23:56:42 +0000
changeset 378 5589abf5e61b
parent 332 78657bf06302
child 380 d193dd1d8a7e
permissions -rw-r--r--
break the network code. Too late to set up a branch for this now

#include "Engine.hh"
#include "SinglePlayer.hh"

#include <iostream>

Engine::Engine (const std::string resource_xml_path) : 
    is_running(true), resources(resource_xml_path)
{
    
}

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
    NetworkAddress connect_addr(connect_host, connect_port);

    // create the client
    net_client = new NetworkClient(*this, game_state, connect_addr);
}

void Engine::setupSinglePlayer (void) {
    // create player directly
 	LocalPlayer* lp = new SinglePlayer(game_state);

    // add to gamestate
	game_state.setLocalPlayer(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);
    }
}

CL_ResourceManager* Engine::getResourceManager (void) {
    return &resources;
}

Logger Engine::log (enum LogLevel level, const char *type) {
    return Logger(level <= WARN ? std::cerr : std::cout, level, type);
}