src/Engine.cc
branchnew_graphics
changeset 418 194bc810a570
parent 417 c503e0c6a740
child 419 9cd4e54693b6
--- a/src/Engine.cc	Thu Jan 22 01:53:05 2009 +0200
+++ b/src/Engine.cc	Thu Jan 22 02:38:33 2009 +0200
@@ -19,11 +19,17 @@
 #include <iostream>
 #include <cassert>
 
-Engine::Engine (const std::string resource_xml_path) : 
+/*
+ * Initialize static Engine global state
+ */
+LogLevel Engine::log_level = DEBUG;
+
+Engine::Engine (const EngineConfig &config) : 
     terrain(NULL), game_state(NULL), graphics(NULL), net_server(NULL), net_client_connect(NULL),
-    is_running(true), resources(resource_xml_path)
+    is_running(true), resources(config.resource_path)
 {
-    
+    // update global log_level
+    Engine::log_level = config.log_level;
 }
 
 GameState& Engine::setupGame (Terrain *terrain) {
@@ -81,7 +87,7 @@
 
 void Engine::setupNetworkServer (const std::string &listen_port) {
 
-#if NETWORK_EANBLED    
+#if NETWORK_ENABLED    
     NetworkEndpoint listen_addr(listen_port);
     
     assert(terrain && game_state);
@@ -103,7 +109,7 @@
 
 void Engine::setupNetworkClient (const std::string &connect_host, const std::string &connect_port) {
 
-#if NETWORK_EANBLED    
+#if NETWORK_ENABLED 
     // connect_to
     NetworkEndpoint connect_addr(connect_host, connect_port);
 
@@ -140,29 +146,28 @@
 }
 
 void Engine::run (void) {
+    // timeout for NetworkReactor
+    timeval timeout;
+
     while (is_running) {
         /*
          * Run internal ClanLib stuff (also includes our timers) until our timeout has elapsed
          */
         CL_System::keep_alive(ENGINE_TIMEOUT_MS);
         
-#if NETWORK_ENABLED       
+#if NETWORK_ENABLED 
+        // setup timeout to zero
+        timeout.tv_sec = 0;
+        timeout.tv_usec = 0;
+
         /*
          * Thursday came and went, I re-wrote clan-event.
          *
          * (actually, we only use it for zero-timeout polling now... not sure if this is better than using the above
          * CL_System::keep_alive)
          */
-        NetworkReactor::current->poll(NULL);
+        NetworkReactor::current->poll(&timeout);
 #endif        
     }
 }
 
-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);
-}
-