src/Engine.cc
changeset 380 d193dd1d8a7e
parent 378 5589abf5e61b
child 381 9b35bc329d23
equal deleted inserted replaced
379:2a8e780844d2 380:d193dd1d8a7e
     1 
     1 
     2 #include "Engine.hh"
     2 #include "Engine.hh"
     3 #include "SinglePlayer.hh"
     3 #include "SinglePlayer.hh"
       
     4 #include "Network/Reactor.hh"
       
     5 #include "Config.hh"
     4 
     6 
     5 #include <iostream>
     7 #include <iostream>
     6 
     8 
     7 Engine::Engine (const std::string resource_xml_path) : 
     9 Engine::Engine (const std::string resource_xml_path) : 
     8     is_running(true), resources(resource_xml_path)
    10     is_running(true), resources(resource_xml_path)
    39 void Engine::stop (void) {
    41 void Engine::stop (void) {
    40     is_running = false;
    42     is_running = false;
    41 }
    43 }
    42 
    44 
    43 void Engine::run (void) {
    45 void Engine::run (void) {
       
    46     // our NetworkReactor
       
    47     NetworkReactor *reactor = NetworkReactor::current;
       
    48 
       
    49     // timeout info
       
    50     timeval timeout;
       
    51 
    44     while (is_running) {
    52     while (is_running) {
    45         // this does.... magical things
    53         // this does.... magical things
    46         CL_System::keep_alive();
    54         CL_System::keep_alive();
    47 
    55         
    48         // if I can't find some better way to do this in ClanLib by next thursday, then it f*%!ing sucks
    56         // setup our timeout to ENGINE_TIMEOUT_MS
    49         // ideally, we should be able to have a main loop that does timed waits on I/O, fufilling some set of timers
    57         timeout.tv_sec = 0;
    50         // but as far as I can tell, ClanLib doesn't have anything like that
    58         timeout.tv_usec = ENGINE_TIMEOUT_MS * 1000;
    51         CL_System::sleep(10);
    59        
       
    60         /*
       
    61          * Thursday came and went, I re-wrote clan-event.
       
    62          *
       
    63          * We use the NetworkReactor for sleeping, as it handles it effeciently even if we're not using network.
       
    64          */
       
    65         reactor->poll(&timeout);
    52     }
    66     }
    53 }
    67 }
    54 
    68 
    55 CL_ResourceManager* Engine::getResourceManager (void) {
    69 CL_ResourceManager* Engine::getResourceManager (void) {
    56     return &resources;
    70     return &resources;