Index: code/trunk/src/orxonox/Main.cc
===================================================================
--- code/trunk/src/orxonox/Main.cc	(revision 1889)
+++ code/trunk/src/orxonox/Main.cc	(revision 1891)
@@ -39,6 +39,7 @@
 
 #include "util/OrxonoxPlatform.h"
+#include "util/Debug.h"
+#include "core/ConfigFileManager.h"
 #include "SignalHandler.h"
-#include "util/Debug.h"
 
 #include "gamestates/GSRoot.h"
@@ -90,4 +91,13 @@
     SignalHandler::getInstance()->doCatch(argv[0], "orxonox.log");
 
+    // Specifiy config file before creating the GameStates in order to have
+    // setConfigValues() in the constructor (required).
+#if ORXONOX_DEBUG_MODE == 1
+        ConfigFileManager::getInstance().setFile(CFT_Settings, "orxonox_d.ini");
+#else
+        ConfigFileManager::getInstance().setFile(CFT_Settings, "orxonox.ini");
+#endif
+
+    // create the gamestates
     GSRoot root;
     GSGraphics graphics;
@@ -99,4 +109,5 @@
     GSIOConsole ioConsole;
 
+    // make the hierarchy
     root.addChild(&graphics);
     graphics.addChild(&standalone);
@@ -104,8 +115,8 @@
     graphics.addChild(&client);
     graphics.addChild(&gui);
-
     root.addChild(&ioConsole);
     root.addChild(&dedicated);
 
+    // Here happens the game
     root.start(argc, argv);
 
Index: code/trunk/src/orxonox/gamestates/GSGraphics.cc
===================================================================
--- code/trunk/src/orxonox/gamestates/GSGraphics.cc	(revision 1889)
+++ code/trunk/src/orxonox/gamestates/GSGraphics.cc	(revision 1891)
@@ -34,4 +34,5 @@
 #include <OgreFrameListener.h>
 #include <OgreRoot.h>
+#include <OgreLogManager.h>
 #include <OgreException.h>
 #include <OgreRenderWindow.h>
@@ -61,8 +62,12 @@
     GSGraphics::GSGraphics()
         : GameState<GSRoot>("graphics")
-        , ogreRoot_(0)
+        , renderWindow_(0)
+        , viewport_(0)
         , inputManager_(0)
         , console_(0)
         , guiManager_(0)
+        , ogreRoot_(0)
+        , ogreLogger_(0)
+        , graphicsEngine_(0)
         , masterKeyBinder_(0)
         , frameCount_(0)
@@ -73,4 +78,5 @@
     {
         RegisterRootObject(GSGraphics);
+        setConfigValues();
     }
 
@@ -82,5 +88,13 @@
     {
         SetConfigValue(resourceFile_, "resources.cfg").description("Location of the resources file in the data path.");
-        SetConfigValue(statisticsRefreshCycle_, 200000).description("Sets the time in microseconds interval at which average fps, etc. get updated.");
+        SetConfigValue(ogreConfigFile_,  "ogre.cfg").description("Location of the Ogre config file");
+        SetConfigValue(ogrePluginsFile_, "plugins.cfg").description("Location of the Ogre plugins file");
+        SetConfigValue(ogreLogFile_,     "ogre.log").description("Logfile for messages from Ogre. \
+                                                                 Use \"\" to suppress log file creation.");
+        SetConfigValue(ogreLogLevelTrivial_ , 5).description("Corresponding orxonox debug level for ogre Trivial");
+        SetConfigValue(ogreLogLevelNormal_  , 4).description("Corresponding orxonox debug level for ogre Normal");
+        SetConfigValue(ogreLogLevelCritical_, 2).description("Corresponding orxonox debug level for ogre Critical");
+        SetConfigValue(statisticsRefreshCycle_, 200000).description("Sets the time in microseconds interval at \
+                                                                    which average fps, etc. get updated.");
     }
 
@@ -89,8 +103,9 @@
         Settings::_getInstance().bShowsGraphics_ = true;
 
-        setConfigValues();
-
-        this->ogreRoot_ = getParent()->getOgreRoot();
-
+        // initialise graphics engine. Doesn't load the render window yet!
+        graphicsEngine_ = new GraphicsEngine();
+
+        // Ogre setup procedure
+        setupOgre();
         this->declareResources();
         this->loadRenderer();    // creates the render window
@@ -100,8 +115,7 @@
 
         // HACK: temporary:
-        GraphicsEngine* graphicsEngine = getParent()->getGraphicsEngine();
-        graphicsEngine->renderWindow_  = this->renderWindow_;
-        graphicsEngine->root_          = this->ogreRoot_;
-        graphicsEngine->viewport_      = this->viewport_;
+        graphicsEngine_->renderWindow_  = this->renderWindow_;
+        graphicsEngine_->root_          = this->ogreRoot_;
+        graphicsEngine_->viewport_      = this->viewport_;
 
 
@@ -141,5 +155,5 @@
         using namespace Ogre;
 
-        // remove our WindowEventListener first to avoid bad calls in the procedures
+        // remove our WindowEventListener first to avoid bad calls after the window has been destroyed
         Ogre::WindowEventUtilities::removeWindowEventListener(this->renderWindow_, this);
 
@@ -156,7 +170,7 @@
         renderer->destroyRenderWindow("Orxonox");
 
+        /*** CODE SNIPPET, UNUSED ***/
         // Does the opposite of initialise()
-        ogreRoot_->shutdown();
-
+        //ogreRoot_->shutdown();
         // Remove all resources and resource groups
         //StringVector groups = ResourceGroupManager::getSingleton().getResourceGroups();
@@ -170,4 +184,15 @@
         // Shutdown the render system
         //this->ogreRoot_->setRenderSystem(0);
+
+        delete this->ogreRoot_;
+
+#if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32
+        // delete the ogre log and the logManager (since we have created it).
+        this->ogreLogger_->getDefaultLog()->removeListener(this);
+        this->ogreLogger_->destroyLog(Ogre::LogManager::getSingleton().getDefaultLog());
+        delete this->ogreLogger_;
+#endif
+
+        delete graphicsEngine_;
 
         Settings::_getInstance().bShowsGraphics_ = false;
@@ -234,4 +259,77 @@
 
         ++frameCount_;
+    }
+
+    /**
+    @brief
+        Creates the Ogre Root object and sets up the ogre log.
+    */
+    void GSGraphics::setupOgre()
+    {
+        COUT(3) << "Setting up Ogre..." << std::endl;
+
+        // TODO: LogManager doesn't work on oli platform. The why is yet unknown.
+#if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32
+        // create a new logManager
+        ogreLogger_ = new Ogre::LogManager();
+        COUT(4) << "Ogre LogManager created" << std::endl;
+
+        // create our own log that we can listen to
+        Ogre::Log *myLog;
+        if (this->ogreLogFile_ == "")
+            myLog = ogreLogger_->createLog("ogre.log", true, false, true);
+        else
+            myLog = ogreLogger_->createLog(this->ogreLogFile_, true, false, false);
+        COUT(4) << "Ogre Log created" << std::endl;
+
+        myLog->setLogDetail(Ogre::LL_BOREME);
+        myLog->addListener(this);
+#endif
+
+        // Root will detect that we've already created a Log
+        COUT(4) << "Creating Ogre Root..." << std::endl;
+
+        if (ogrePluginsFile_ == "")
+        {
+            COUT(2) << "Warning: Ogre plugins file set to \"\". Defaulting to plugins.cfg" << std::endl;
+            ModifyConfigValue(ogrePluginsFile_, tset, "plugins.cfg");
+        }
+        if (ogreConfigFile_ == "")
+        {
+            COUT(2) << "Warning: Ogre config file set to \"\". Defaulting to config.cfg" << std::endl;
+            ModifyConfigValue(ogreConfigFile_, tset, "config.cfg");
+        }
+        if (ogreLogFile_ == "")
+        {
+            COUT(2) << "Warning: Ogre log file set to \"\". Defaulting to ogre.log" << std::endl;
+            ModifyConfigValue(ogreLogFile_, tset, "ogre.log");
+        }
+
+        // check for config file existence because Ogre displays (caught) exceptions if not
+        std::ifstream probe;
+        probe.open(ogreConfigFile_.c_str());
+        if (!probe)
+        {
+            // create a zero sized file
+            std::ofstream creator;
+            creator.open(ogreConfigFile_.c_str());
+            creator.close();
+        }
+        else
+            probe.close();
+
+        ogreRoot_ = new Ogre::Root(ogrePluginsFile_, ogreConfigFile_, ogreLogFile_);
+
+#if 0 // Ogre 1.4.3 doesn't yet support setDebugOutputEnabled(.)
+#if ORXONOX_PLATFORM != ORXONOX_PLATFORM_WIN32
+        // tame the ogre ouput so we don't get all the mess in the console
+        Ogre::Log* defaultLog = Ogre::LogManager::getSingleton().getDefaultLog();
+        defaultLog->setDebugOutputEnabled(false);
+        defaultLog->setLogDetail(Ogre::LL_BOREME);
+        defaultLog->addListener(this);
+#endif
+#endif
+
+        COUT(3) << "Ogre set up done." << std::endl;
     }
 
@@ -328,4 +426,39 @@
     }
 
+    /**
+    @brief
+        Method called by the LogListener interface from Ogre.
+        We use it to capture Ogre log messages and handle it ourselves.
+    @param message
+        The message to be logged
+    @param lml
+        The message level the log is using
+    @param maskDebug
+        If we are printing to the console or not
+    @param logName
+        The name of this log (so you can have several listeners
+        for different logs, and identify them)
+    */
+    void GSGraphics::messageLogged(const std::string& message,
+        Ogre::LogMessageLevel lml, bool maskDebug, const std::string& logName)
+    {
+        int orxonoxLevel;
+        switch (lml)
+        {
+        case Ogre::LML_TRIVIAL:
+            orxonoxLevel = this->ogreLogLevelTrivial_;
+            break;
+        case Ogre::LML_NORMAL:
+            orxonoxLevel = this->ogreLogLevelNormal_;
+            break;
+        case Ogre::LML_CRITICAL:
+            orxonoxLevel = this->ogreLogLevelCritical_;
+            break;
+        default:
+            orxonoxLevel = 0;
+        }
+        OutputHandler::getOutStream().setOutputLevel(orxonoxLevel)
+            << "Ogre: " << message << std::endl;
+    }
 
     /**
Index: code/trunk/src/orxonox/gamestates/GSGraphics.h
===================================================================
--- code/trunk/src/orxonox/gamestates/GSGraphics.h	(revision 1889)
+++ code/trunk/src/orxonox/gamestates/GSGraphics.h	(revision 1891)
@@ -39,15 +39,18 @@
 namespace orxonox
 {
-    class _OrxonoxExport GSGraphics : public GameState<GSRoot>, public OrxonoxClass, public Ogre::WindowEventListener
+    class _OrxonoxExport GSGraphics : public GameState<GSRoot>, public OrxonoxClass,
+                                      public Ogre::WindowEventListener, public Ogre::LogListener
     {
         friend class ClassIdentifier<GSGraphics>;
+
     public:
         GSGraphics();
         ~GSGraphics();
 
-        Ogre::Viewport* getViewport() { return this->viewport_; }
-        GUIManager* getGUIManager() { return this->guiManager_; }
+        Ogre::Root*     getOgreRoot()   { return this->ogreRoot_  ; }
+        Ogre::Viewport* getViewport()   { return this->viewport_  ; }
+        GUIManager*     getGUIManager() { return this->guiManager_; }
 
-    private:
+    private: // functions
         void enter();
         void leave();
@@ -56,9 +59,15 @@
         void setConfigValues();
 
+        void setupOgre();
         void declareResources();
         void loadRenderer();
         void initialiseResources();
 
+        // console commands
         void printScreen();
+
+        // event from Ogre::LogListener
+        void messageLogged(const std::string& message, Ogre::LogMessageLevel lml,
+            bool maskDebug, const std::string& logName);
 
         // window events from Ogre::WindowEventListener
@@ -68,5 +77,5 @@
         void windowClosed      (Ogre::RenderWindow* rw);
 
-        Ogre::Root*           ogreRoot_;
+    private: // variables
         Ogre::RenderWindow*   renderWindow_;          //!< the current render window
         Ogre::Viewport*       viewport_;              //!< default full size viewport
@@ -76,4 +85,7 @@
         InGameConsole*        console_;
         GUIManager*           guiManager_;
+        Ogre::Root*           ogreRoot_;                  //!< Ogre's root
+        Ogre::LogManager*     ogreLogger_;
+        GraphicsEngine*       graphicsEngine_;   //!< Interface to Ogre
 
         KeyBinder*            masterKeyBinder_;
@@ -88,4 +100,10 @@
         // config values
         std::string           resourceFile_;          //!< resources file name
+        std::string           ogreConfigFile_;        //!< ogre config file name
+        std::string           ogrePluginsFile_;       //!< ogre plugins file name
+        std::string           ogreLogFile_;           //!< log file name for Ogre log messages
+        int                   ogreLogLevelTrivial_;   //!< Corresponding Orxonx debug level for LL_TRIVIAL
+        int                   ogreLogLevelNormal_;    //!< Corresponding Orxonx debug level for LL_NORMAL
+        int                   ogreLogLevelCritical_;  //!< Corresponding Orxonx debug level for LL_CRITICAL
         unsigned int          detailLevelParticle_;   //!< Detail level of particle effects (0: off, 1: low, 2: normal, 3: high)
     };
Index: code/trunk/src/orxonox/gamestates/GSRoot.cc
===================================================================
--- code/trunk/src/orxonox/gamestates/GSRoot.cc	(revision 1889)
+++ code/trunk/src/orxonox/gamestates/GSRoot.cc	(revision 1891)
@@ -30,11 +30,7 @@
 #include "GSRoot.h"
 
-#include <OgreLogManager.h>
-#include <OgreRoot.h>
-
 #include "util/Exception.h"
 #include "util/Debug.h"
 #include "core/Factory.h"
-#include "core/ConfigFileManager.h"
 #include "core/ConfigValueIncludes.h"
 #include "core/CoreIncludes.h"
@@ -71,7 +67,4 @@
         : RootGameState("root")
         , settings_(0)
-        , ogreRoot_(0)
-        , ogreLogger_(0)
-        , graphicsEngine_(0)
         , tclBind_(0)
         , tclThreadManager_(0)
@@ -79,4 +72,5 @@
     {
         RegisterRootObject(GSRoot);
+        setConfigValues();
     }
 
@@ -87,24 +81,8 @@
     void GSRoot::setConfigValues()
     {
-        SetConfigValue(ogreConfigFile_,  "ogre.cfg").description("Location of the Ogre config file");
-        SetConfigValue(ogrePluginsFile_, "plugins.cfg").description("Location of the Ogre plugins file");
-        SetConfigValue(ogreLogFile_,     "ogre.log").description("Logfile for messages from Ogre. \
-                                                                 Use \"\" to suppress log file creation.");
-        SetConfigValue(ogreLogLevelTrivial_ , 5).description("Corresponding orxonox debug level for ogre Trivial");
-        SetConfigValue(ogreLogLevelNormal_  , 4).description("Corresponding orxonox debug level for ogre Normal");
-        SetConfigValue(ogreLogLevelCritical_, 2).description("Corresponding orxonox debug level for ogre Critical");
     }
 
     void GSRoot::enter()
     {
-#if ORXONOX_DEBUG_MODE == 1
-        ConfigFileManager::getInstance().setFile(CFT_Settings, "orxonox_d.ini");
-#else
-        ConfigFileManager::getInstance().setFile(CFT_Settings, "orxonox.ini");
-#endif
-
-        // do this after the previous call..
-        setConfigValues();
-
         // creates the class hierarchy for all classes with factories
         Factory::createClassHierarchy();
@@ -130,9 +108,4 @@
         this->shell_ = new Shell();
 
-        setupOgre();
-
-        // initialise graphics engine. Doesn't load the render window yet!
-        graphicsEngine_ = new GraphicsEngine();
-
         // limit the main thread to the first core so that QueryPerformanceCounter doesn't jump
         // do this after ogre has initialised. Somehow Ogre changes the settings again (not through
@@ -157,15 +130,4 @@
     {
         // TODO: remove and destroy console commands
-
-        delete graphicsEngine_;
-
-        delete this->ogreRoot_;
-
-#if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32
-        // delete the ogre log and the logManager (since we have created it).
-        this->ogreLogger_->getDefaultLog()->removeListener(this);
-        this->ogreLogger_->destroyLog(Ogre::LogManager::getSingleton().getDefaultLog());
-        delete this->ogreLogger_;
-#endif
 
         delete this->shell_;
@@ -203,9 +165,9 @@
 	    DWORD procMask;
 	    DWORD sysMask;
-#if _MSC_VER >= 1400 && defined (_M_X64)
+#  if _MSC_VER >= 1400 && defined (_M_X64)
 	    GetProcessAffinityMask(GetCurrentProcess(), (PDWORD_PTR)&procMask, (PDWORD_PTR)&sysMask);
-#else
+#  else
 	    GetProcessAffinityMask(GetCurrentProcess(), &procMask, &sysMask);
-#endif
+#  endif
 
 	    // If procMask is 0, consider there is only one core available
@@ -227,112 +189,3 @@
 #endif
     }
-
-    /**
-    @brief
-        Creates the Ogre Root object and sets up the ogre log.
-    */
-    void GSRoot::setupOgre()
-    {
-        COUT(3) << "Setting up Ogre..." << std::endl;
-
-        // TODO: LogManager doesn't work on oli platform. The why is yet unknown.
-#if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32
-        // create a new logManager
-        ogreLogger_ = new Ogre::LogManager();
-        COUT(4) << "Ogre LogManager created" << std::endl;
-
-        // create our own log that we can listen to
-        Ogre::Log *myLog;
-        if (this->ogreLogFile_ == "")
-            myLog = ogreLogger_->createLog("ogre.log", true, false, true);
-        else
-            myLog = ogreLogger_->createLog(this->ogreLogFile_, true, false, false);
-        COUT(4) << "Ogre Log created" << std::endl;
-
-        myLog->setLogDetail(Ogre::LL_BOREME);
-        myLog->addListener(this);
-#endif
-
-        // Root will detect that we've already created a Log
-        COUT(4) << "Creating Ogre Root..." << std::endl;
-
-        if (ogrePluginsFile_ == "")
-        {
-            COUT(2) << "Warning: Ogre plugins file set to \"\". Defaulting to plugins.cfg" << std::endl;
-            ModifyConfigValue(ogrePluginsFile_, tset, "plugins.cfg");
-        }
-        if (ogreConfigFile_ == "")
-        {
-            COUT(2) << "Warning: Ogre config file set to \"\". Defaulting to config.cfg" << std::endl;
-            ModifyConfigValue(ogreConfigFile_, tset, "config.cfg");
-        }
-        if (ogreLogFile_ == "")
-        {
-            COUT(2) << "Warning: Ogre log file set to \"\". Defaulting to ogre.log" << std::endl;
-            ModifyConfigValue(ogreLogFile_, tset, "ogre.log");
-        }
-
-        // check for config file existence because Ogre displays (caught) exceptions if not
-        std::ifstream probe;
-        probe.open(ogreConfigFile_.c_str());
-        if (!probe)
-        {
-            // create a zero sized file
-            std::ofstream creator;
-            creator.open(ogreConfigFile_.c_str());
-            creator.close();
-        }
-        else
-            probe.close();
-
-        ogreRoot_ = new Ogre::Root(ogrePluginsFile_, ogreConfigFile_, ogreLogFile_);
-
-#if 0 // Ogre 1.4.3 doesn't yet support setDebugOutputEnabled(.)
-#if ORXONOX_PLATFORM != ORXONOX_PLATFORM_WIN32
-        // tame the ogre ouput so we don't get all the mess in the console
-        Ogre::Log* defaultLog = Ogre::LogManager::getSingleton().getDefaultLog();
-        defaultLog->setDebugOutputEnabled(false);
-        defaultLog->setLogDetail(Ogre::LL_BOREME);
-        defaultLog->addListener(this);
-#endif
-#endif
-
-        COUT(3) << "Ogre set up done." << std::endl;
-    }
-
-    /**
-    @brief
-        Method called by the LogListener interface from Ogre.
-        We use it to capture Ogre log messages and handle it ourselves.
-    @param message
-        The message to be logged
-    @param lml
-        The message level the log is using
-    @param maskDebug
-        If we are printing to the console or not
-    @param logName
-        The name of this log (so you can have several listeners
-        for different logs, and identify them)
-    */
-    void GSRoot::messageLogged(const std::string& message,
-        Ogre::LogMessageLevel lml, bool maskDebug, const std::string& logName)
-    {
-        int orxonoxLevel;
-        switch (lml)
-        {
-        case Ogre::LML_TRIVIAL:
-            orxonoxLevel = this->ogreLogLevelTrivial_;
-            break;
-        case Ogre::LML_NORMAL:
-            orxonoxLevel = this->ogreLogLevelNormal_;
-            break;
-        case Ogre::LML_CRITICAL:
-            orxonoxLevel = this->ogreLogLevelCritical_;
-            break;
-        default:
-            orxonoxLevel = 0;
-        }
-        OutputHandler::getOutStream().setOutputLevel(orxonoxLevel)
-            << "Ogre: " << message << std::endl;
-    }
 }
Index: code/trunk/src/orxonox/gamestates/GSRoot.h
===================================================================
--- code/trunk/src/orxonox/gamestates/GSRoot.h	(revision 1889)
+++ code/trunk/src/orxonox/gamestates/GSRoot.h	(revision 1891)
@@ -37,5 +37,5 @@
 namespace orxonox
 {
-    class _OrxonoxExport GSRoot : public RootGameState, public Ogre::LogListener, public OrxonoxClass
+    class _OrxonoxExport GSRoot : public RootGameState, public OrxonoxClass
     {
         friend class ClassIdentifier<GSRoot>;
@@ -47,7 +47,4 @@
         { requestState("root"); }
 
-        Ogre::Root* getOgreRoot() { return this->ogreRoot_; }
-        GraphicsEngine* getGraphicsEngine() { return this->graphicsEngine_; }
-
     private:
         void enter();
@@ -56,23 +53,10 @@
 
         void setConfigValues();
-        void messageLogged(const std::string& message, Ogre::LogMessageLevel lml,
-            bool maskDebug, const std::string& logName);
         void setThreadAffinity(unsigned int limitToCPU);
-        void setupOgre();
 
         Settings*             settings_;
-        Ogre::Root*           ogreRoot_;                  //!< Ogre's root
-        Ogre::LogManager*     ogreLogger_;
-        GraphicsEngine*       graphicsEngine_;   //!< Interface to Ogre
         TclBind*              tclBind_;
         TclThreadManager*     tclThreadManager_;
         Shell*                shell_;
-
-        std::string           ogreConfigFile_;        //!< ogre config file name
-        std::string           ogrePluginsFile_;       //!< ogre plugins file name
-        std::string           ogreLogFile_;           //!< log file name for Ogre log messages
-        int                   ogreLogLevelTrivial_;   //!< Corresponding Orxonx debug level for LL_TRIVIAL
-        int                   ogreLogLevelNormal_;    //!< Corresponding Orxonx debug level for LL_NORMAL
-        int                   ogreLogLevelCritical_;  //!< Corresponding Orxonx debug level for LL_CRITICAL
     };
 }
Index: code/trunk/visual_studio/vc8/orxonox.vcproj
===================================================================
--- code/trunk/visual_studio/vc8/orxonox.vcproj	(revision 1889)
+++ code/trunk/visual_studio/vc8/orxonox.vcproj	(revision 1891)
@@ -561,8 +561,4 @@
 			</File>
 			<File
-				RelativePath="..\..\src\orxonox\OrxonoxLibraryHeaders.h"
-				>
-			</File>
-			<File
 				RelativePath="..\..\src\orxonox\OrxonoxPrereqs.h"
 				>
