Index: code/branches/network/src/orxonox/Orxonox.cc
===================================================================
--- code/branches/network/src/orxonox/Orxonox.cc	(revision 928)
+++ code/branches/network/src/orxonox/Orxonox.cc	(revision 929)
@@ -37,5 +37,4 @@
 //#include <OgreException.h>
 #include <OgreFrameListener.h>
-#include <OgreRoot.h>
 #include <OgreOverlay.h>
 #include <OgreOverlayManager.h>
@@ -86,5 +85,5 @@
     this->auMan_ = 0;
     this->inputHandler_ = 0;
-    this->root_ = 0;
+    //this->root_ = 0;
     // turn on frame smoothing by setting a value different from 0
     this->frameSmoothingTime_ = 0.0f;
@@ -97,6 +96,49 @@
   Orxonox::~Orxonox()
   {
-    // nothing to delete as for now
-    inputHandler_->destroy();
+    // keep in mind: the order of deletion is very important!
+
+    if (this->bulletMgr_)
+      delete this->bulletMgr_;
+    if (this->orxonoxHUD_)
+      delete this->orxonoxHUD_;
+    Loader::close();
+    this->inputHandler_->destroy();
+    if (this->auMan_)
+      delete this->auMan_;
+    if (this->timer_)
+      delete this->timer_;
+    if (this->ogre_)
+      delete this->ogre_;
+
+    if (client_g)
+      delete client_g;
+    if (server_g)
+      delete server_g;
+  }
+
+  /**
+   * error kills orxonox
+   */
+  void Orxonox::abortImmediate(/* some error code */)
+  {
+    //TODO: destroy and destruct everything and print nice error msg
+    delete this;
+  }
+
+  /**
+    Asks the mainloop nicely to abort.
+  */
+  void Orxonox::abortRequest()
+  {
+    bAbort_ = true;
+  }
+
+  /**
+   * @return singleton object
+   */
+  Orxonox* Orxonox::getSingleton()
+  {
+    static Orxonox theOnlyInstance;
+    return &theOnlyInstance;
   }
 
@@ -118,5 +160,5 @@
     ar.checkArgument("data", this->dataPath_, false);
     ar.checkArgument("ip", serverIp_, false);
-    if(ar.errorHandling()) die();
+    if(ar.errorHandling()) abortImmediate();
     if(mode == std::string("client"))
     {
@@ -134,4 +176,38 @@
   }
 
+  void Orxonox::serverInit(std::string path)
+  {
+    COUT(2) << "initialising server" << std::endl;
+    
+    ogre_->setConfigPath(path);
+    ogre_->setup();
+    //root_ = ogre_->getRoot();
+    if(!ogre_->load(this->dataPath_)) abortImmediate(/* unable to load */);
+    
+    server_g = new network::Server();
+  }
+
+  void Orxonox::clientInit(std::string path)
+  {
+    COUT(2) << "initialising client" << std::endl;\
+    
+    ogre_->setConfigPath(path);
+    ogre_->setup();
+    if(serverIp_.compare("")==0)
+      client_g = new network::Client();
+    else
+      client_g = new network::Client(serverIp_, NETWORK_PORT);
+    if(!ogre_->load(this->dataPath_)) abortImmediate(/* unable to load */);
+  }
+  
+  void Orxonox::standaloneInit(std::string path)
+  {
+    COUT(2) << "initialising standalone mode" << std::endl;
+    
+    ogre_->setConfigPath(path);
+    ogre_->setup();
+    //root_ = ogre_->getRoot();
+    if(!ogre_->load(this->dataPath_)) abortImmediate(/* unable to load */);
+  }
   
   /**
@@ -153,5 +229,5 @@
   
   void Orxonox::clientStart(){
-    ogre_->startRender();
+    ogre_->initialise();
     Factory::createClassHierarchy();
     
@@ -179,5 +255,5 @@
   void Orxonox::serverStart(){
     //TODO: start modules
-    ogre_->startRender();
+    ogre_->initialise();
     //TODO: run engine
     Factory::createClassHierarchy();
@@ -192,5 +268,5 @@
   void Orxonox::standaloneStart(){
     //TODO: start modules
-    ogre_->startRender();
+    ogre_->initialise();
     //TODO: run engine
     Factory::createClassHierarchy();
@@ -199,66 +275,4 @@
     
     startRenderLoop();
-  }
-
-  /**
-   * @return singleton object
-   */
-  Orxonox* Orxonox::getSingleton()
-  {
-    static Orxonox theOnlyInstance;
-    return &theOnlyInstance;
-  }
-
-  /**
-   * error kills orxonox
-   */
-  void Orxonox::die(/* some error code */)
-  {
-    //TODO: destroy and destruct everything and print nice error msg
-    delete this;
-  }
-
-  /**
-    Asks the mainloop nicely to abort.
-  */
-  void Orxonox::abortRequest()
-  {
-    bAbort_ = true;
-  }
-
-
-  void Orxonox::serverInit(std::string path)
-  {
-    COUT(2) << "initialising server" << std::endl;
-    
-    ogre_->setConfigPath(path);
-    ogre_->setup();
-    root_ = ogre_->getRoot();
-    if(!ogre_->load(this->dataPath_)) die(/* unable to load */);
-    
-    server_g = new network::Server();
-  }
-
-  void Orxonox::clientInit(std::string path)
-  {
-    COUT(2) << "initialising client" << std::endl;\
-    
-    ogre_->setConfigPath(path);
-    ogre_->setup();
-    if(serverIp_.compare("")==0)
-      client_g = new network::Client();
-    else
-      client_g = new network::Client(serverIp_, NETWORK_PORT);
-    if(!ogre_->load(this->dataPath_)) die(/* unable to load */);
-  }
-  
-  void Orxonox::standaloneInit(std::string path)
-  {
-    COUT(2) << "initialising standalone mode" << std::endl;
-    
-    ogre_->setConfigPath(path);
-    ogre_->setup();
-    root_ = ogre_->getRoot();
-    if(!ogre_->load(this->dataPath_)) die(/* unable to load */);
   }
 
@@ -285,5 +299,6 @@
     auMan_->ambientAdd("a3");
     //auMan->ambientAdd("ambient1");
-    auMan_->ambientStart();*/
+    auMan_->ambientStart();
+  */
   }
 
@@ -316,6 +331,7 @@
   {
     // use the ogre timer class to measure time.
-    Ogre::Timer *timer = new Ogre::Timer();
-    timer->reset();
+    if (!timer_)
+      timer_ = new Ogre::Timer();
+    timer_->reset();
 
     // Contains the times of recently fired events
@@ -331,5 +347,5 @@
 
       // get current time
-      unsigned long now = timer->getMilliseconds();
+      unsigned long now = timer_->getMilliseconds();
 
       // create an event to pass to the frameStarted method in ogre
@@ -341,21 +357,17 @@
       orxonoxHUD_->setTime((int)now, 0);
 
-      // don't forget to call _fireFrameStarted in ogre to make sure
-      // everything goes smoothly
-      if (!ogre_->getRoot()->_fireFrameStarted(evt))
-        break;
-
       // Iterate through all Tickables and call their tick(dt) function
       for (Iterator<Tickable> it = ObjectList<Tickable>::start(); it; )
         (it++)->tick((float)evt.timeSinceLastFrame);
 
+      // don't forget to call _fireFrameStarted in ogre to make sure
+      // everything goes smoothly
+      ogre_->frameStarted(evt);
+
       if (mode_ != SERVER)
-      {
-        // only render in non-server mode
-        ogre_->getRoot()->_updateAllRenderTargets();
-      }
+        ogre_->renderOneFrame(); // only render in non-server mode
 
       // get current time
-      now = timer->getMilliseconds();
+      now = timer_->getMilliseconds();
 
       // create an event to pass to the frameEnded method in ogre
@@ -364,6 +376,5 @@
 
       // again, just to be sure ogre works fine
-      if (!ogre_->getRoot()->_fireFrameEnded(evt))
-        break;
+      ogre_->frameEnded(evt);
 	  }
   }
@@ -406,4 +417,8 @@
   }
 
+  /**
+    @brief Test method for the InputHandler.
+    But: Is actually responsible for catching an exit event..
+  */
   void Orxonox::eventOccured(InputEvent &evt)
   {
