src/Engine.cc
author terom
Mon, 08 Dec 2008 22:28:51 +0000
changeset 319 9f6a838d58c4
parent 274 c35307e8645c
child 332 78657bf06302
permissions -rw-r--r--
improve input handling further, ROPE_THROW and DIG don't repeat at all 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
    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.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);
}