Index: code/branches/gui/src/orxonox/Orxonox.cc
===================================================================
--- code/branches/gui/src/orxonox/Orxonox.cc	(revision 1646)
+++ code/branches/gui/src/orxonox/Orxonox.cc	(revision 1653)
@@ -112,5 +112,5 @@
     , mode_(GameMode::GM_Unspecified)
     , debugRefreshTime_(0.0f)
-    , ogre_(0)
+    , graphicsEngine_(0)
     , inputManager_(0)
     , radar_(0)
@@ -157,6 +157,6 @@
       delete inputManager_;
 
-    if (this->ogre_)
-      delete ogre_;
+    if (this->graphicsEngine_)
+      delete graphicsEngine_;
 
     if (network::Client::getSingleton())
@@ -212,160 +212,169 @@
   }
 
-
-  /**
-   * Starts the whole Game.
-   * @param path path to config (in home dir or something)
-   */
-  void Orxonox::start()
-  {
-#ifdef _DEBUG
-    ConfigFileManager::getSingleton()->setFile(CFT_Settings, "orxonox_d.ini");
+    /**
+    @brief
+        Starts the whole Game.
+    @param path
+        path to config (in home dir or something)
+    */
+    void Orxonox::start()
+    {
+#if ORXONOX_DEBUG_MODE == 1
+        ConfigFileManager::getSingleton()->setFile(CFT_Settings, "orxonox_d.ini");
 #else
-    ConfigFileManager::getSingleton()->setFile(CFT_Settings, "orxonox.ini");
+        ConfigFileManager::getSingleton()->setFile(CFT_Settings, "orxonox.ini");
 #endif
-    Factory::createClassHierarchy();
-
-    setConfigValues();
-
-    const Settings::CommandLineArgument* mode = Settings::getCommandLineArgument("mode");
-    assert(mode);
-    if (!mode->bHasDefaultValue_)
+
+        // creates the class hierarchy for all classes with factories
+        Factory::createClassHierarchy();
+
+        setConfigValues();
+
+        const Settings::CommandLineArgument* mode = Settings::getCommandLineArgument("mode");
+        assert(mode);
+        if (!mode->bHasDefaultValue_)
+        {
+            Settings::setGameMode(mode->value_);
+            this->mode_ = Settings::getGameMode();
+        }
+        COUT(3) << "Orxonox: Game mode is " << mode_.name << "." << std::endl;
+
+        const Settings::CommandLineArgument* dataPath = Settings::getCommandLineArgument("dataPath");
+        assert(dataPath);
+        if (!dataPath->bHasDefaultValue_)
+        {
+            if (*dataPath->value_.getString().end() != '/' && *dataPath->value_.getString().end() != '\\')
+                Settings::tsetDataPath(dataPath->value_.getString() + "/");
+            else
+                Settings::tsetDataPath(dataPath->value_.getString());
+        }
+
+        try
+        {
+            // initialise TCL
+            TclBind::getInstance().setDataPath(Settings::getDataPath());
+
+            graphicsEngine_ = new GraphicsEngine();
+            graphicsEngine_->setup();       // creates ogre root and other essentials
+
+            if (mode_.showsGraphics)
+            {
+                graphicsEngine_->loadRenderer();    // creates the render window
+
+                // TODO: Spread this so that this call only initialises things needed for the Console and GUI
+                graphicsEngine_->initialiseResources();
+
+                // Calls the InputManager which sets up the input devices.
+                // The render window width and height are used to set up the mouse movement.
+                inputManager_ = new InputManager();
+                inputManager_->initialise(graphicsEngine_->getWindowHandle(),
+                    graphicsEngine_->getWindowWidth(), graphicsEngine_->getWindowHeight(), true, true, true);
+                KeyBinder* keyBinder = new KeyBinder();
+                keyBinder->loadBindings();
+                inputManager_->createInputState<SimpleInputState>("game", 20)->setHandler(keyBinder);
+
+                // Load the InGameConsole
+                console_ = new InGameConsole();
+                console_->initialise();
+
+                // load the CEGUI interface
+                guiManager_ = new GUIManager();
+                guiManager_->initialise();
+            }
+            else
+            {
+                // TODO: Initialise a not yet written console that operates in the shell we
+                // started the game from.
+                // We probably want to use std::cin to catch input (OIS uses DirectX or X server)
+            }
+
+            bool showGUI = true;
+            if (mode_.mode != GameMode::Unspecified)
+            {
+                showGUI = false;
+                // a game mode was specified with the command line
+                // we therefore load the game and level directly
+
+                if (!loadLevel(this->mode_))
+                {
+                    COUT(1) << "Loading with predefined mode failed. Showing main menu." << std::endl;
+                    showGUI = true;
+                    mode_ = GameMode::GM_Unspecified;
+                }
+            }
+
+            if (showGUI)
+            {
+                // show main menu
+                GUIManager::getInstance().showGUI("MainMenu", 0);
+                GraphicsEngine::getInstance().getViewport()->setCamera(GUIManager::getInstance().getCamera());
+            }
+        }
+        catch (std::exception& ex)
+        {
+            COUT(1) << ex.what() << std::endl;
+            COUT(1) << "Loading sequence aborted." << std::endl;
+            return;
+        }
+
+        modeRequest_ = mode_;
+        // here happens the game
+        startRenderLoop();
+
+        if (mode_.mode == GameMode::Client)
+            network::Client::getSingleton()->closeConnection();
+
+        if (mode_.hasServer)
+            server_g->close();
+    }
+
+    /*static*/ void Orxonox::loadGame(const std::string& name)
     {
-      Settings::setGameMode(mode->value_);
-      this->mode_ = Settings::getGameMode();
+        const GameMode& mode = Settings::getGameMode(name);
+        if (mode.mode == GameMode::None)
+            return;
+
+        getSingleton().modeRequest_ = mode;
     }
-    COUT(3) << "Orxonox: Game mode is " << mode_.name << "." << std::endl;
-
-    const Settings::CommandLineArgument* dataPath = Settings::getCommandLineArgument("dataPath");
-    assert(dataPath);
-    if (!dataPath->bHasDefaultValue_)
+
+    bool Orxonox::loadLevel(const GameMode& mode)
     {
-      if (*dataPath->value_.getString().end() != '/' && *dataPath->value_.getString().end() != '\\')
-        Settings::tsetDataPath(dataPath->value_.getString() + "/");
-      else
-        Settings::tsetDataPath(dataPath->value_.getString());
+        bool success = true;
+
+        if (mode.showsGraphics)
+        {
+            // create Ogre SceneManager for the level
+            graphicsEngine_->createNewScene();
+
+            if (!loadPlayground())
+                return false;
+        }
+
+        switch (mode.mode)
+        {
+        case GameMode::Server:
+            success &= serverLoad();
+            break;
+        case GameMode::Client:
+            success &= clientLoad();
+            break;
+        case GameMode::Dedicated:
+            success &= serverLoad();
+            break;
+        case GameMode::Standalone:
+            success &= standaloneLoad();
+            break;
+        default: // never happens
+            assert(false);
+        }
+
+        if (success)
+        {
+            InputManager::getInstance().requestEnterState("game");
+            this->mode_ = mode;
+        }
+
+        return success;
     }
-
-    try
-    {
-        // initialise TCL
-        TclBind::getInstance().setDataPath(Settings::getDataPath());
-
-        ogre_ = new GraphicsEngine();
-        ogre_->setup();       // creates ogre root and other essentials
-
-        if (mode_.showsGraphics)
-        {
-          ogre_->loadRenderer();    // creates the render window
-
-          // TODO: Spread this so that this call only initialises things needed for the Console and GUI
-          ogre_->initialiseResources();
-
-          // Calls the InputManager which sets up the input devices.
-          // The render window width and height are used to set up the mouse movement.
-          inputManager_ = new InputManager();
-          inputManager_->initialise(ogre_->getWindowHandle(),
-                ogre_->getWindowWidth(), ogre_->getWindowHeight(), true, true, true);
-          KeyBinder* keyBinder = new KeyBinder();
-          keyBinder->loadBindings();
-          inputManager_->createSimpleInputState("game", 20)->setHandler(keyBinder);
-
-          // Load the InGameConsole
-          console_ = new InGameConsole();
-          console_->initialise();
-
-          // load the CEGUI interface
-          guiManager_ = new GUIManager();
-          guiManager_->initialise();
-        }
-
-        bool showGUI = true;
-        if (mode_.mode != GameMode::Unspecified)
-        {
-          showGUI = false;
-          // a game mode was specified with the command line
-          // we therefore load the game and level directly
-
-          if (!loadLevel(this->mode_))
-          {
-            COUT(1) << "Loading with predefined mode failed. Showing main menu." << std::endl;
-            showGUI = true;
-            mode_ = GameMode::GM_Unspecified;
-          }
-        }
-        
-        if (showGUI)
-        {
-          // show main menu
-          GUIManager::getInstance().showGUI("MainMenu", 0);
-          GraphicsEngine::getSingleton().getViewport()->setCamera(GUIManager::getInstance().getCamera());
-        }
-    }
-    catch (std::exception& ex)
-    {
-      COUT(1) << ex.what() << std::endl;
-      COUT(1) << "Loading sequence aborted." << std::endl;
-      return;
-    }
-
-    modeRequest_ = mode_;
-    // here happens the game
-    startRenderLoop();
-
-    if (mode_.mode == GameMode::Client)
-      network::Client::getSingleton()->closeConnection();
-
-    if (mode_.hasServer)
-      server_g->close();
-  }
-
-  /*static*/ void Orxonox::loadGame(const std::string& name)
-  {
-      const GameMode& mode = Settings::getGameMode(name);
-      if (mode.mode == GameMode::None)
-          return;
-
-      getSingleton().modeRequest_ = mode;
-  }
-
-  bool Orxonox::loadLevel(const GameMode& mode)
-  {
-      bool success = true;
-
-      if (mode.showsGraphics)
-      {
-        // create Ogre SceneManager for the level
-        ogre_->createNewScene();
-
-        if (!loadPlayground())
-            return false;
-      }
-
-      switch (mode.mode)
-      {
-      case GameMode::Server:
-        success &= serverLoad();
-        break;
-      case GameMode::Client:
-        success &= clientLoad();
-        break;
-      case GameMode::Dedicated:
-        success &= serverLoad();
-        break;
-      case GameMode::Standalone:
-        success &= standaloneLoad();
-        break;
-      default: // never happens
-          assert(false);
-      }
-      
-      if (success)
-      {
-        InputManager::getInstance().requestEnterState("game");
-        this->mode_ = mode;
-      }
-
-      return success;
-  }
 
   /**
@@ -528,8 +537,8 @@
         if (timeAfterTick > refreshStartTime + refreshTime)
         {
-          GraphicsEngine::getSingleton().setAverageTickTime(
+          GraphicsEngine::getInstance().setAverageTickTime(
               (float)tickTime * 0.001 / (frameCount - oldFrameCount));
           float avgFPS = (float)(frameCount - oldFrameCount) / (timeAfterTick - refreshStartTime) * 1000000.0;
-          GraphicsEngine::getSingleton().setAverageFramesPerSecond(avgFPS);
+          GraphicsEngine::getInstance().setAverageFramesPerSecond(avgFPS);
 
           oldFrameCount = frameCount;
@@ -552,5 +561,5 @@
           // make sure the window stays active even when not focused
           // (probably only necessary on windows)
-          GraphicsEngine::getSingleton().setWindowActivity(true);
+          GraphicsEngine::getInstance().setWindowActivity(true);
 
           // tick CEGUI
