src/proto2/Engine.cc
changeset 185 25becd2cb026
parent 184 561892e2a30e
child 186 0738f2949a2b
equal deleted inserted replaced
184:561892e2a30e 185:25becd2cb026
     1 
       
     2 #include "Engine.hh"
       
     3 #include "NetworkServer.hh"
       
     4 #include "NetworkClient.hh"
       
     5 #include "SinglePlayer.hh"
       
     6 
       
     7 #include <iostream>
       
     8 
       
     9 Engine::Engine (void) : is_running(true) {
       
    10 
       
    11 }
       
    12 
       
    13 void Engine::setupGraphics (void) {
       
    14     // create the graphics
       
    15     graphics = new Graphics(*this, game_state);
       
    16 }
       
    17 
       
    18 void Engine::setupNetworkServer (const std::string &listen_port) {
       
    19     // create the server
       
    20     net_server = new NetworkServer(game_state, listen_port);
       
    21 }
       
    22 
       
    23 void Engine::setupNetworkClient (const std::string &connect_host, const std::string &connect_port) {
       
    24     // connect_to
       
    25     CL_IPAddress connect_addr(connect_host, connect_port);
       
    26 
       
    27     // create the client
       
    28     net_client = new NetworkClient(game_state, connect_addr);
       
    29 }
       
    30 
       
    31 void Engine::setupSinglePlayer (void) {
       
    32     // create player directly
       
    33  	LocalPlayer* lp = new SinglePlayer(game_state);
       
    34 
       
    35     // add to gamestate
       
    36 	game_state.newLocalPlayer(lp);
       
    37 }
       
    38 
       
    39 void Engine::stop (void) {
       
    40     is_running = false;
       
    41 }
       
    42 
       
    43 void Engine::run (void) {
       
    44     while (is_running) {
       
    45         // this does.... magical things
       
    46         CL_System::keep_alive();
       
    47 
       
    48         // if I can't find some better way to do this in ClanLib by next thursday, then it f*%!ing sucks
       
    49         // ideally, we should be able to have a main loop that does timed waits on I/O, fufilling some set of timers
       
    50         // but as far as I can tell, ClanLib doesn't have anything like that
       
    51         CL_System::sleep(10);
       
    52     }
       
    53 }
       
    54 
       
    55 Logger Engine::log (enum LogLevel level, const char *type) {
       
    56     return Logger(level <= WARN ? std::cerr : std::cout, level, type);
       
    57 }
       
    58