Index: code/trunk/src/orxonox/CMakeLists.txt
===================================================================
--- code/trunk/src/orxonox/CMakeLists.txt	(revision 2894)
+++ code/trunk/src/orxonox/CMakeLists.txt	(revision 2896)
@@ -20,5 +20,5 @@
 SET_SOURCE_FILES(ORXONOX_SRC_FILES
   CameraManager.cc
-  GraphicsEngine.cc
+  GraphicsManager.cc
   LevelManager.cc
   Main.cc
Index: code/trunk/src/orxonox/CameraManager.cc
===================================================================
--- code/trunk/src/orxonox/CameraManager.cc	(revision 2894)
+++ code/trunk/src/orxonox/CameraManager.cc	(revision 2896)
@@ -35,5 +35,5 @@
 #include <OgreResource.h>
 
-#include "core/Core.h"
+#include "core/GameMode.h"
 #include "core/Iterator.h"
 #include "objects/worldentities/Camera.h"
@@ -41,4 +41,5 @@
 #include "tools/Shader.h"
 #include "util/String.h"
+#include "gui/GUIManager.h"
 
 namespace orxonox
@@ -74,5 +75,5 @@
     void CameraManager::requestFocus(Camera* camera)
     {
-        if (!Core::showsGraphics())
+        if (!GameMode::showsGraphics())
             return;
 
@@ -99,5 +100,5 @@
     void CameraManager::releaseFocus(Camera* camera)
     {
-        if (!Core::showsGraphics())
+        if (!GameMode::showsGraphics())
             return;
 
@@ -141,4 +142,5 @@
 
         this->viewport_->setCamera(camera);
+        GUIManager::getInstance().setCamera(camera);
 
         // reactivate all visible compositors
Index: code/trunk/src/orxonox/GraphicsEngine.cc
===================================================================
--- code/trunk/src/orxonox/GraphicsEngine.cc	(revision 2894)
+++ 	(revision )
@@ -1,106 +1,0 @@
-/*
- *   ORXONOX - the hottest 3D action shooter ever to exist
- *                    > www.orxonox.net <
- *
- *
- *   License notice:
- *
- *   This program is free software; you can redistribute it and/or
- *   modify it under the terms of the GNU General Public License
- *   as published by the Free Software Foundation; either version 2
- *   of the License, or (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program; if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- *
- *   Author:
- *      Reto Grieder
- *      Benjamin Knecht <beni_at_orxonox.net>, (C) 2007
- *   Co-authors:
- *      Felix Schulthess
- *
- */
-
-/**
-@file
-@brief
-    Implementation of an partial interface to Ogre.
-*/
-
-#include "OrxonoxStableHeaders.h"
-#include "GraphicsEngine.h"
-
-#include <OgreRenderWindow.h>
-
-#include "core/CoreIncludes.h"
-#include "core/ConfigValueIncludes.h"
-#include "util/Debug.h"
-
-#include "tools/ParticleInterface.h"
-
-namespace orxonox
-{
-    //SetConsoleCommand(GraphicsEngine, printScreen, true).setKeybindMode(KeybindMode::OnPress);
-
-    GraphicsEngine* GraphicsEngine::singletonRef_s = 0;
-
-    /**
-    @brief
-        Returns the singleton instance.
-    @return
-        The only instance of GraphicsEngine.
-    */
-    /*static*/ GraphicsEngine& GraphicsEngine::getInstance()
-    {
-        assert(singletonRef_s);
-        return *singletonRef_s;
-    }
-
-    /**
-    @brief
-        Non-initialising constructor.
-    */
-    GraphicsEngine::GraphicsEngine()
-//        : root_(0)
-//        , renderWindow_(0)
-//        , viewport_(0)
-    {
-        RegisterObject(GraphicsEngine);
-
-        assert(singletonRef_s == 0);
-        singletonRef_s = this;
-
-        this->viewport_ = 0;
-
-        this->detailLevelParticle_ = 0;
-
-        this->setConfigValues();
-        CCOUT(4) << "Constructed" << std::endl;
-    }
-
-    void GraphicsEngine::setConfigValues()
-    {
-        SetConfigValue(detailLevelParticle_, 2).description("O: off, 1: low, 2: normal, 3: high").callback(this, &GraphicsEngine::detailLevelParticleChanged);
-    }
-
-    void GraphicsEngine::detailLevelParticleChanged()
-    {
-        for (ObjectList<ParticleInterface>::iterator it = ObjectList<ParticleInterface>::begin(); it; ++it)
-            it->detailLevelChanged(this->detailLevelParticle_);
-    }
-
-    /**
-    @brief
-        Destroys all the Ogre related objects
-    */
-    GraphicsEngine::~GraphicsEngine()
-    {
-        singletonRef_s = 0;
-    }
-}
Index: code/trunk/src/orxonox/GraphicsEngine.h
===================================================================
--- code/trunk/src/orxonox/GraphicsEngine.h	(revision 2894)
+++ 	(revision )
@@ -1,96 +1,0 @@
-/*
- *   ORXONOX - the hottest 3D action shooter ever to exist
- *                    > www.orxonox.net <
- *
- *
- *   License notice:
- *
- *   This program is free software; you can redistribute it and/or
- *   modify it under the terms of the GNU General Public License
- *   as published by the Free Software Foundation; either version 2
- *   of the License, or (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program; if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- *
- *   Author:
- *      Reto Grieder
- *      Benjamin Knecht <beni_at_orxonox.net>, (C) 2007
- *   Co-authors:
- *      Felix Schulthess
- *
- */
-
-/**
-  @file
-  @brief Declaration of GraphicsEngine Singleton.
-  @author Benjamin Knecht <beni_at_orxonox.net>
- */
-
-#ifndef _GraphicsEngine_H__
-#define _GraphicsEngine_H__
-
-#include "OrxonoxPrereqs.h"
-
-#include <string>
-
-#include <OgrePrerequisites.h>
-#include "core/OrxonoxClass.h"
-
-namespace orxonox
-{
-    /**
-    @brief Graphics engine manager class
-    */
-    class _OrxonoxExport GraphicsEngine : public OrxonoxClass
-    {
-        // HACK: temporary means
-        friend class GSGraphics;
-
-    public:
-        GraphicsEngine();
-        ~GraphicsEngine();
-
-        void setConfigValues();
-        void detailLevelParticleChanged();
-
-        float getAverageFramesPerSecond() const   { return this->avgFramesPerSecond_; }
-        float getAverageTickTime() const          { return this->avgTickTime_; }
-        void setAverageTickTime(float tickTime)   { this->avgTickTime_ = tickTime; }
-        void setAverageFramesPerSecond(float fps) { this->avgFramesPerSecond_ = fps; }
-
-        inline unsigned int getDetailLevelParticle() const
-        { return this->detailLevelParticle_; }
-
-        static GraphicsEngine& getInstance();
-        static GraphicsEngine* getInstancePtr() { return singletonRef_s; }
-
-        inline void setViewport(Ogre::Viewport* viewport)
-            { this->viewport_ = viewport; }
-        inline Ogre::Viewport* getViewport() const
-            { return this->viewport_; }
-
-    private:
-        // don't mess with singletons
-        GraphicsEngine(GraphicsEngine&);
-
-        Ogre::Viewport*     viewport_;              //!< default full size viewport
-
-        // stats
-        float               avgTickTime_;           //!< time in ms to tick() one frame
-        float               avgFramesPerSecond_;    //!< number of frames processed in one second
-
-        // config values
-        unsigned int        detailLevelParticle_;   //!< Detail level of particle effects (0: off, 1: low, 2: normal, 3: high)
-
-        static GraphicsEngine* singletonRef_s;      //!< Pointer to the Singleton
-    };
-}
-
-#endif /* _GraphicsEngine_H__ */
Index: code/trunk/src/orxonox/GraphicsManager.cc
===================================================================
--- code/trunk/src/orxonox/GraphicsManager.cc	(revision 2896)
+++ code/trunk/src/orxonox/GraphicsManager.cc	(revision 2896)
@@ -0,0 +1,444 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Reto Grieder
+ *      Benjamin Knecht <beni_at_orxonox.net>, (C) 2007
+ *   Co-authors:
+ *      Felix Schulthess
+ *
+ */
+
+/**
+@file
+@brief
+    Implementation of an partial interface to Ogre.
+*/
+
+#include "OrxonoxStableHeaders.h"
+#include "GraphicsManager.h"
+
+#include <fstream>
+#include <boost/filesystem.hpp>
+
+#include <OgreCompositorManager.h>
+#include <OgreConfigFile.h>
+#include <OgreFrameListener.h>
+#include <OgreRoot.h>
+#include <OgreLogManager.h>
+#include <OgreException.h>
+#include <OgreRenderWindow.h>
+#include <OgreRenderSystem.h>
+#include <OgreTextureManager.h>
+#include <OgreViewport.h>
+#include <OgreWindowEventUtilities.h>
+
+#include "SpecialConfig.h"
+#include "util/Debug.h"
+#include "util/Exception.h"
+#include "util/String.h"
+#include "util/SubString.h"
+#include "core/Clock.h"
+#include "core/ConsoleCommand.h"
+#include "core/ConfigValueIncludes.h"
+#include "core/CoreIncludes.h"
+#include "core/Core.h"
+#include "core/GameMode.h"
+#include "tools/WindowEventListener.h"
+#include "tools/ParticleInterface.h"
+
+namespace orxonox
+{
+    class _OrxonoxExport OgreWindowEventListener : public Ogre::WindowEventListener
+    {
+        void windowResized     (Ogre::RenderWindow* rw);
+        void windowFocusChange (Ogre::RenderWindow* rw);
+        void windowClosed      (Ogre::RenderWindow* rw);
+        //void windowMoved       (Ogre::RenderWindow* rw);
+    };
+
+    GraphicsManager* GraphicsManager::singletonRef_s = 0;
+
+    /**
+    @brief
+        Non-initialising constructor.
+    */
+    GraphicsManager::GraphicsManager()
+        : ogreRoot_(0)
+        , ogreLogger_(0)
+        , renderWindow_(0)
+        , viewport_(0)
+        , ogreWindowEventListener_(0)
+        , avgTickTime_(0.0f)
+        , avgFramesPerSecond_(0.0f)
+    {
+        RegisterObject(GraphicsManager);
+
+        assert(singletonRef_s == 0);
+        singletonRef_s = this;
+
+        this->loaded_ = false;
+
+        this->setConfigValues();
+    }
+
+    void GraphicsManager::initialise()
+    {
+        // Ogre setup procedure
+        setupOgre();
+        // load all the required plugins for Ogre
+        loadOgrePlugins();
+        // read resource declaration file
+        this->declareResources();
+        // Reads ogre config and creates the render window
+        this->loadRenderer();
+
+        // TODO: Spread this
+        this->initialiseResources();
+
+        // add console commands
+        FunctorMember<GraphicsManager>* functor1 = createFunctor(&GraphicsManager::printScreen);
+        functor1->setObject(this);
+        ccPrintScreen_ = createConsoleCommand(functor1, "printScreen");
+        CommandExecutor::addConsoleCommandShortcut(ccPrintScreen_);
+
+        this->loaded_ = true;
+    }
+
+    /**
+    @brief
+        Destroys all the Ogre related objects
+    */
+    GraphicsManager::~GraphicsManager()
+    {
+        if (this->loaded_)
+        {
+            delete this->ccPrintScreen_;
+
+            if (this->ogreWindowEventListener_)
+            {
+                // remove our WindowEventListener first to avoid bad calls after the window has been destroyed
+                Ogre::WindowEventUtilities::removeWindowEventListener(this->renderWindow_, this->ogreWindowEventListener_);
+                delete this->ogreWindowEventListener_;
+            }
+
+            // unload all compositors
+            Ogre::CompositorManager::getSingleton().removeAll();
+
+            // destroy render window
+            Ogre::RenderSystem* renderer = this->ogreRoot_->getRenderSystem();
+            renderer->destroyRenderWindow("Orxonox");
+
+            // Delete OGRE main control organ
+            delete this->ogreRoot_;
+
+            // delete the ogre log and the logManager (since we have created it in the first place).
+            this->ogreLogger_->getDefaultLog()->removeListener(this);
+            this->ogreLogger_->destroyLog(Ogre::LogManager::getSingleton().getDefaultLog());
+            delete this->ogreLogger_;
+        }
+
+        assert(singletonRef_s);
+        singletonRef_s = 0;
+    }
+
+    void GraphicsManager::setConfigValues()
+    {
+        SetConfigValue(resourceFile_,    "resources.cfg")
+            .description("Location of the resources file in the data path.");
+        SetConfigValue(ogreConfigFile_,  "ogre.cfg")
+            .description("Location of the Ogre config file");
+        SetConfigValue(ogrePluginsFolder_, ORXONOX_OGRE_PLUGINS_FOLDER)
+            .description("Folder where the Ogre plugins are located.");
+        SetConfigValue(ogrePlugins_, ORXONOX_OGRE_PLUGINS)
+            .description("Comma separated list of all plugins to load.");
+        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(detailLevelParticle_, 2)
+            .description("O: off, 1: low, 2: normal, 3: high").callback(this, &GraphicsManager::detailLevelParticleChanged);
+    }
+
+    void GraphicsManager::detailLevelParticleChanged()
+    {
+        for (ObjectList<ParticleInterface>::iterator it = ObjectList<ParticleInterface>::begin(); it; ++it)
+            it->detailLevelChanged(this->detailLevelParticle_);
+    }
+
+    void GraphicsManager::update(const Clock& time)
+    {
+        if (this->loaded_)
+        {
+            Ogre::FrameEvent evt;
+            evt.timeSinceLastFrame = time.getDeltaTime();
+            evt.timeSinceLastEvent = time.getDeltaTime(); // note: same time, but shouldn't matter anyway
+
+            // don't forget to call _fireFrameStarted to OGRE to make sure
+            // everything goes smoothly
+            ogreRoot_->_fireFrameStarted(evt);
+
+            // Pump messages in all registered RenderWindows
+            // This calls the WindowEventListener objects.
+            Ogre::WindowEventUtilities::messagePump();
+            // make sure the window stays active even when not focused
+            // (probably only necessary on windows)
+            this->renderWindow_->setActive(true);
+
+            // render
+            ogreRoot_->_updateAllRenderTargets();
+
+            // again, just to be sure OGRE works fine
+            ogreRoot_->_fireFrameEnded(evt); // note: uses the same time as _fireFrameStarted
+        }
+    }
+
+    void GraphicsManager::setCamera(Ogre::Camera* camera)
+    {
+        this->viewport_->setCamera(camera);
+    }
+
+    /**
+    @brief
+        Creates the Ogre Root object and sets up the ogre log.
+    */
+    void GraphicsManager::setupOgre()
+    {
+        COUT(3) << "Setting up Ogre..." << std::endl;
+
+        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");
+        }
+
+        boost::filesystem::path ogreConfigFilepath(Core::getConfigPath() / this->ogreConfigFile_);
+        boost::filesystem::path ogreLogFilepath(Core::getLogPath() / this->ogreLogFile_);
+
+        // create a new logManager
+        // Ogre::Root will detect that we've already created a Log
+        ogreLogger_ = new Ogre::LogManager();
+        COUT(4) << "Ogre LogManager created" << std::endl;
+
+        // create our own log that we can listen to
+        Ogre::Log *myLog;
+        myLog = ogreLogger_->createLog(ogreLogFilepath.string(), true, false, false);
+        COUT(4) << "Ogre Log created" << std::endl;
+
+        myLog->setLogDetail(Ogre::LL_BOREME);
+        myLog->addListener(this);
+
+        COUT(4) << "Creating Ogre Root..." << std::endl;
+
+        // check for config file existence because Ogre displays (caught) exceptions if not
+        if (!boost::filesystem::exists(ogreConfigFilepath))
+        {
+            // create a zero sized file
+            std::ofstream creator;
+            creator.open(ogreConfigFilepath.string().c_str());
+            creator.close();
+        }
+
+        // Leave plugins file empty. We're going to do that part manually later
+        ogreRoot_ = new Ogre::Root("", ogreConfigFilepath.string(), ogreLogFilepath.string());
+
+        COUT(3) << "Ogre set up done." << std::endl;
+    }
+
+    void GraphicsManager::loadOgrePlugins()
+    {
+        // just to make sure the next statement doesn't segfault
+        if (ogrePluginsFolder_ == "")
+            ogrePluginsFolder_ = ".";
+
+        boost::filesystem::path folder(ogrePluginsFolder_);
+        // Do some SubString magic to get the comma separated list of plugins
+        SubString plugins(ogrePlugins_, ",", " ", false, 92, false, 34, false, 40, 41, false, '\0');
+        // Use backslash paths on Windows! file_string() already does that though.
+        for (unsigned int i = 0; i < plugins.size(); ++i)
+            ogreRoot_->loadPlugin((folder / plugins[i]).file_string());
+    }
+
+    void GraphicsManager::declareResources()
+    {
+        CCOUT(4) << "Declaring Resources" << std::endl;
+        //TODO: Specify layout of data file and maybe use xml-loader
+        //TODO: Work with ressource groups (should be generated by a special loader)
+
+        if (resourceFile_ == "")
+        {
+            COUT(2) << "Warning: Ogre resource file set to \"\". Defaulting to resources.cfg" << std::endl;
+            ModifyConfigValue(resourceFile_, tset, "resources.cfg");
+        }
+
+        // Load resource paths from data file using configfile ressource type
+        Ogre::ConfigFile cf;
+        try
+        {
+            cf.load((Core::getMediaPath() / resourceFile_).string());
+        }
+        catch (...)
+        {
+            //COUT(1) << ex.getFullDescription() << std::endl;
+            COUT(0) << "Have you forgotten to set the data path in orxnox.ini?" << std::endl;
+            throw;
+        }
+
+        // Go through all sections & settings in the file
+        Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();
+
+        std::string secName, typeName, archName;
+        while (seci.hasMoreElements())
+        {
+            try
+            {
+                secName = seci.peekNextKey();
+                Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
+                Ogre::ConfigFile::SettingsMultiMap::iterator i;
+                for (i = settings->begin(); i != settings->end(); ++i)
+                {
+                    typeName = i->first; // for instance "FileSystem" or "Zip"
+                    archName = i->second; // name (and location) of archive
+
+                    Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
+                        (Core::getMediaPath() / archName).string(), typeName, secName);
+                }
+            }
+            catch (Ogre::Exception& ex)
+            {
+                COUT(1) << ex.getFullDescription() << std::endl;
+            }
+        }
+    }
+
+    void GraphicsManager::loadRenderer()
+    {
+        CCOUT(4) << "Configuring Renderer" << std::endl;
+
+        if (!ogreRoot_->restoreConfig())
+            if (!ogreRoot_->showConfigDialog())
+                ThrowException(InitialisationFailed, "Could not show Ogre configuration dialogue.");
+
+        CCOUT(4) << "Creating render window" << std::endl;
+
+        this->renderWindow_ = ogreRoot_->initialise(true, "Orxonox");
+
+        this->ogreWindowEventListener_ = new OgreWindowEventListener();
+        Ogre::WindowEventUtilities::addWindowEventListener(this->renderWindow_, ogreWindowEventListener_);
+
+        Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(0);
+
+        // create a full screen default viewport
+        this->viewport_ = this->renderWindow_->addViewport(0, 0);
+    }
+
+    void GraphicsManager::initialiseResources()
+    {
+        CCOUT(4) << "Initialising resources" << std::endl;
+        //TODO: Do NOT load all the groups, why are we doing that? And do we really do that? initialise != load...
+        //try
+        //{
+            Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
+            /*Ogre::StringVector str = Ogre::ResourceGroupManager::getSingleton().getResourceGroups();
+            for (unsigned int i = 0; i < str.size(); i++)
+            {
+            Ogre::ResourceGroupManager::getSingleton().loadResourceGroup(str[i]);
+            }*/
+        //}
+        //catch (...)
+        //{
+        //    CCOUT(2) << "Error: There was a serious error when initialising the resources." << std::endl;
+        //    throw;
+        //}
+    }
+
+    /**
+    @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 GraphicsManager::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;
+    }
+
+    void GraphicsManager::printScreen()
+    {
+        assert(this->renderWindow_);
+       
+        this->renderWindow_->writeContentsToTimestampedFile(Core::getLogPathString() + "screenShot_", ".jpg");
+    }
+
+
+    /****** OgreWindowEventListener ******/
+
+    void OgreWindowEventListener::windowResized(Ogre::RenderWindow* rw)
+    {
+        for (ObjectList<orxonox::WindowEventListener>::iterator it
+            = ObjectList<orxonox::WindowEventListener>::begin(); it; ++it)
+            it->windowResized(rw->getWidth(), rw->getHeight());
+    }
+    void OgreWindowEventListener::windowFocusChange(Ogre::RenderWindow* rw)
+    {
+        for (ObjectList<orxonox::WindowEventListener>::iterator it
+            = ObjectList<orxonox::WindowEventListener>::begin(); it; ++it)
+            it->windowFocusChanged();
+    }
+    void OgreWindowEventListener::windowClosed(Ogre::RenderWindow* rw)
+    {
+        // TODO: Notify the right class to shut down the Game
+    }
+}
Index: code/trunk/src/orxonox/GraphicsManager.h
===================================================================
--- code/trunk/src/orxonox/GraphicsManager.h	(revision 2896)
+++ code/trunk/src/orxonox/GraphicsManager.h	(revision 2896)
@@ -0,0 +1,125 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Reto Grieder
+ *      Benjamin Knecht <beni_at_orxonox.net>, (C) 2007
+ *   Co-authors:
+ *      Felix Schulthess
+ *
+ */
+
+/**
+@file
+@brief
+    Declaration of GraphicsManager Singleton.
+ */
+
+#ifndef _GraphicsManager_H__
+#define _GraphicsManager_H__
+
+#include "OrxonoxPrereqs.h"
+
+#include <string>
+#include <cassert>
+#include <OgreLog.h>
+
+#include "core/OrxonoxClass.h"
+
+namespace orxonox
+{
+    /**
+    @brief
+        Graphics engine manager class
+    */
+    class _OrxonoxExport GraphicsManager : public OrxonoxClass, public Ogre::LogListener
+    {
+    public:
+        GraphicsManager();
+        ~GraphicsManager();
+
+        void setConfigValues();
+        void initialise();
+
+        void update(const Clock& time);
+
+        void detailLevelParticleChanged();
+        inline unsigned int getDetailLevelParticle() const
+            { return this->detailLevelParticle_; }
+
+        inline Ogre::Viewport* getViewport() const
+            { return this->viewport_; }
+        inline Ogre::RenderWindow* getRenderWindow()
+            { return this->renderWindow_; }
+
+        void setCamera(Ogre::Camera* camera);
+
+        static GraphicsManager& getInstance() { assert(singletonRef_s); return *singletonRef_s; }
+
+    private:
+        GraphicsManager(GraphicsManager&); // don't mess with singletons
+
+        // OGRE initialisation
+        void setupOgre();
+        void loadOgrePlugins();
+        void declareResources();
+        void loadRenderer();
+        void initialiseResources();
+
+        // event from Ogre::LogListener
+        void messageLogged(const std::string& message, Ogre::LogMessageLevel lml,
+            bool maskDebug, const std::string& logName);
+
+        // console commands
+        void printScreen();
+
+    private:
+        bool                loaded_;
+
+        Ogre::Root*         ogreRoot_;                 //!< Ogre's root
+        Ogre::LogManager*   ogreLogger_;
+        Ogre::RenderWindow* renderWindow_;             //!< the one and only render window
+        Ogre::Viewport*     viewport_;                 //!< default full size viewport
+        OgreWindowEventListener* ogreWindowEventListener_;
+
+        // stats (Hack)
+        float               avgTickTime_;              //!< time in ms to tick() one frame
+        float               avgFramesPerSecond_;       //!< number of frames processed in one second
+
+        // config values
+        unsigned int        detailLevelParticle_;      //!< Detail level of particle effects (0: off, 1: low, 2: normal, 3: high)
+        std::string         resourceFile_;             //!< resources file name
+        std::string         ogreConfigFile_;           //!< ogre config file name
+        std::string         ogrePluginsFolder_;        //!< Folder where the Ogre plugins are located
+        std::string         ogrePlugins_;              //!< Comma separated list of all plugins to load
+        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
+
+        // console commands
+        ConsoleCommand*     ccPrintScreen_;
+
+        static GraphicsManager* singletonRef_s;        //!< Pointer to the Singleton
+    };
+}
+
+#endif /* _GraphicsManager_H__ */
Index: code/trunk/src/orxonox/Main.cc
===================================================================
--- code/trunk/src/orxonox/Main.cc	(revision 2894)
+++ code/trunk/src/orxonox/Main.cc	(revision 2896)
@@ -38,124 +38,40 @@
 
 #include "OrxonoxStableHeaders.h"
+#include "OrxonoxConfig.h"
 
-#include <exception>
-#include <cassert>
+#include "util/Debug.h"
+#include "core/Identifier.h"
+#include "core/Game.h"
 
-#include "OrxonoxConfig.h"
-#include "util/Debug.h"
-#include "util/SignalHandler.h"
-#include "core/ConfigFileManager.h"
-#include "core/CommandLine.h"
-#include "core/CommandExecutor.h"
-#include "core/Identifier.h"
-#include "core/Core.h"
-#include "core/Language.h"
-
-#include "gamestates/GSRoot.h"
-#include "gamestates/GSGraphics.h"
-#include "gamestates/GSStandalone.h"
-#include "gamestates/GSServer.h"
-#include "gamestates/GSClient.h"
-#include "gamestates/GSDedicated.h"
-#include "gamestates/GSGUI.h"
-#include "gamestates/GSIOConsole.h"
-
-#ifdef ORXONOX_PLATFORM_APPLE
-#include <CoreFoundation/CoreFoundation.h>
-
-// This function will locate the path to our application on OS X,
-// unlike windows you can not rely on the curent working directory
-// for locating your configuration files and resources.
-             std::string macBundlePath()
-{
-    char path[1024];
-    CFBundleRef mainBundle = CFBundleGetMainBundle();
-    assert(mainBundle);
-
-    CFURLRef mainBundleURL = CFBundleCopyBundleURL(mainBundle);
-    assert(mainBundleURL);
-
-    CFStringRef cfStringRef = CFURLCopyFileSystemPath( mainBundleURL, kCFURLPOSIXPathStyle);
-    assert(cfStringRef);
-
-    CFStringGetCString(cfStringRef, path, 1024, kCFStringEncodingASCII);
-
-    CFRelease(mainBundleURL);
-    CFRelease(cfStringRef);
-
-    return std::string(path);
-}
-#endif
-
-
-SetCommandLineArgument(settingsFile, "orxonox.ini");
-SetCommandLineArgument(configFileDirectory, "");
-
+/*
+@brief
+    Main method. Game starts here (except for static initialisations).
+*/
 int main(int argc, char** argv)
 {
-    using namespace orxonox;
+    {
+        orxonox::Game orxonox(argc, argv);
 
-    // Parse command line arguments
-    try
-    {
-        CommandLine::parseAll(argc, argv);
-    }
-    catch (ArgumentException& ex)
-    {
-        COUT(1) << ex.what() << std::endl;
-        COUT(0) << "Usage:" << std::endl << "orxonox " << CommandLine::getUsageInformation() << std::endl;
-    }
+        orxonox.setStateHierarchy(
+        "root"
+        " graphics"
+        "  mainMenu"
+        "  standalone"
+        "   level"
+        "  server"
+        "   level"
+        "  client"
+        "   level"
+        " dedicated"
+        "  level"
+        " ioConsole"
+        );
 
-    // Do this after parsing the command line to allow customisation
-    Core::postMainInitialisation();
-
-    // create a signal handler (only active for linux)
-    SignalHandler signalHandler;
-    signalHandler.doCatch(argv[0], Core::getLogPathString() + "orxonox_crash.log");
-
-    // Create the ConfigFileManager before creating the GameStates in order to have
-    // setConfigValues() in the constructor (required).
-    ConfigFileManager* configFileManager = new ConfigFileManager();
-    configFileManager->setFilename(ConfigFileType::Settings, CommandLine::getValue("settingsFile").getString());
-    // create the Core settings to configure the output level
-    Language* language = new Language();
-    Core*     core     = new Core();
-
-    // put GameStates in its own scope so we can destroy the identifiers at the end of main().
-    {
-        // create the gamestates
-        GSRoot root;
-        GSGraphics graphics;
-        GSStandalone standalone;
-        GSServer server;
-        GSClient client;
-        GSDedicated dedicated;
-        GSGUI gui;
-        GSIOConsole ioConsole;
-
-        // make the hierarchy
-        root.addChild(&graphics);
-        graphics.addChild(&standalone);
-        graphics.addChild(&server);
-        graphics.addChild(&client);
-        graphics.addChild(&gui);
-        root.addChild(&ioConsole);
-        root.addChild(&dedicated);
-
-        // Here happens the game
-        root.start();
-    }
-
-    // destroy singletons
-    delete core;
-    delete language;
-    delete configFileManager;
+        orxonox.run();
+    } // orxonox gets destroyed right here!
 
     // Clean up class hierarchy stuff (identifiers, xmlport, configvalue, consolecommand)
-    Identifier::destroyAllIdentifiers();
-    // destroy command line arguments
-    CommandLine::destroyAllArguments();
-    // Also delete external console command that don't belong to an Identifier
-    CommandExecutor::destroyExternalCommands();
+    // Needs to be done after Game destructor because of ~OrxonoxClass
+    orxonox::Identifier::destroyAllIdentifiers();
 
     return 0;
Index: code/trunk/src/orxonox/OrxonoxPrereqs.h
===================================================================
--- code/trunk/src/orxonox/OrxonoxPrereqs.h	(revision 2894)
+++ code/trunk/src/orxonox/OrxonoxPrereqs.h	(revision 2896)
@@ -77,7 +77,4 @@
     namespace MunitionType
     {
-
-
-
         enum Enum
         { laserGunMunition };
@@ -97,5 +94,6 @@
 
 
-    class GraphicsEngine;
+    class GraphicsManager;
+    class OgreWindowEventListener;
     class Settings;
 
@@ -250,15 +248,4 @@
     //gui
     class GUIManager;
-
-    // game states
-    class GSRoot;
-    class GSGraphics;
-    class GSIO;
-    class GSIOConsole;
-    class GSLevel;
-    class GSStandalone;
-    class GSServer;
-    class GSClient;
-    class GSGUI;
 }
 
Index: code/trunk/src/orxonox/PlayerManager.cc
===================================================================
--- code/trunk/src/orxonox/PlayerManager.cc	(revision 2894)
+++ code/trunk/src/orxonox/PlayerManager.cc	(revision 2896)
@@ -31,5 +31,5 @@
 
 #include "LevelManager.h"
-#include "core/Core.h"
+#include "core/GameMode.h"
 #include "core/CoreIncludes.h"
 #include "objects/Level.h"
@@ -58,5 +58,5 @@
     void PlayerManager::clientConnected(unsigned int clientID)
     {
-        if (Core::isMaster())
+        if (GameMode::isMaster())
         {
             COUT(3) << "client connected" << std::endl;
@@ -77,5 +77,5 @@
     void PlayerManager::clientDisconnected(unsigned int clientID)
     {
-        if (Core::isMaster())
+        if (GameMode::isMaster())
         {
             COUT(3) << "client disconnected" << std::endl;
@@ -97,5 +97,5 @@
     PlayerInfo* PlayerManager::getClient(unsigned int clientID) const
     {
-        if (Core::isMaster())
+        if (GameMode::isMaster())
         {
             std::map<unsigned int, PlayerInfo*>::const_iterator it = this->clients_.find(clientID);
Index: code/trunk/src/orxonox/gamestates/CMakeLists.txt
===================================================================
--- code/trunk/src/orxonox/gamestates/CMakeLists.txt	(revision 2894)
+++ code/trunk/src/orxonox/gamestates/CMakeLists.txt	(revision 2896)
@@ -1,9 +1,9 @@
 ADD_SOURCE_FILES(ORXONOX_SRC_FILES
+  GSClient.cc
   GSDedicated.cc
-  GSClient.cc
   GSGraphics.cc
-  GSGUI.cc
   GSIOConsole.cc
   GSLevel.cc
+  GSMainMenu.cc
   GSRoot.cc
   GSServer.cc
Index: code/trunk/src/orxonox/gamestates/GSClient.cc
===================================================================
--- code/trunk/src/orxonox/gamestates/GSClient.cc	(revision 2894)
+++ code/trunk/src/orxonox/gamestates/GSClient.cc	(revision 2896)
@@ -31,14 +31,18 @@
 
 #include "core/input/InputManager.h"
+#include "core/Clock.h"
 #include "core/CommandLine.h"
-#include "core/Core.h"
+#include "core/Game.h"
+#include "core/GameMode.h"
 #include "network/Client.h"
 
 namespace orxonox
 {
+    AddGameState(GSClient, "client");
+
     SetCommandLineArgument(ip, "127.0.0.1").information("#.#.#.#");
 
-    GSClient::GSClient()
-        : GameState<GSGraphics>("client")
+    GSClient::GSClient(const std::string& name)
+        : GameState(name)
         , client_(0)
     {
@@ -49,7 +53,7 @@
     }
 
-    void GSClient::enter()
+    void GSClient::activate()
     {
-        Core::setIsClient(true);
+        GameMode::setIsClient(true);
 
         this->client_ = new Client(CommandLine::getValue("ip").getString(), CommandLine::getValue("port"));
@@ -58,13 +62,9 @@
             ThrowException(InitialisationFailed, "Could not establish connection with server.");
 
-        GSLevel::enter(this->getParent()->getViewport());
-
-        client_->tick(0);
+        client_->update(Game::getInstance().getGameClock());
     }
 
-    void GSClient::leave()
+    void GSClient::deactivate()
     {
-        GSLevel::leave();
-
         client_->closeConnection();
 
@@ -72,13 +72,10 @@
         delete this->client_;
 
-        Core::setIsClient(false);
+        GameMode::setIsClient(false);
     }
 
-    void GSClient::ticked(const Clock& time)
+    void GSClient::update(const Clock& time)
     {
-        GSLevel::ticked(time);
-        client_->tick(time.getDeltaTime());
-
-        this->tickChild(time);
+        client_->update(time);
     }
 }
Index: code/trunk/src/orxonox/gamestates/GSClient.h
===================================================================
--- code/trunk/src/orxonox/gamestates/GSClient.h	(revision 2894)
+++ code/trunk/src/orxonox/gamestates/GSClient.h	(revision 2896)
@@ -31,22 +31,20 @@
 
 #include "OrxonoxPrereqs.h"
+#include "core/GameState.h"
 #include "network/NetworkPrereqs.h"
-#include "GSLevel.h"
-#include "GSGraphics.h"
 
 namespace orxonox
 {
-    class _OrxonoxExport GSClient : public GameState<GSGraphics>, public GSLevel
+    class _OrxonoxExport GSClient : public GameState
     {
     public:
-        GSClient();
+        GSClient(const std::string& name);
         ~GSClient();
 
+        void activate();
+        void deactivate();
+        void update(const Clock& time);
 
     private:
-        void enter();
-        void leave();
-        void ticked(const Clock& time);
-
         Client* client_;
     };
Index: code/trunk/src/orxonox/gamestates/GSDedicated.cc
===================================================================
--- code/trunk/src/orxonox/gamestates/GSDedicated.cc	(revision 2894)
+++ code/trunk/src/orxonox/gamestates/GSDedicated.cc	(revision 2896)
@@ -30,6 +30,8 @@
 #include "GSDedicated.h"
 
+#include "core/Clock.h"
 #include "core/CommandLine.h"
-#include "core/Core.h"
+#include "core/Game.h"
+#include "core/GameMode.h"
 #include "core/Iterator.h"
 #include "network/Server.h"
@@ -39,6 +41,8 @@
 namespace orxonox
 {
-    GSDedicated::GSDedicated()
-        : GameState<GSRoot>("dedicated")
+    AddGameState(GSDedicated, "dedicated");
+
+    GSDedicated::GSDedicated(const std::string& name)
+        : GameState(name)
         , server_(0)
         , timeSinceLastUpdate_(0)
@@ -50,27 +54,23 @@
     }
 
-    void GSDedicated::enter()
+    void GSDedicated::activate()
     {
-        Core::setHasServer(true);
+        GameMode::setHasServer(true);
 
         this->server_ = new Server(CommandLine::getValue("port"));
         COUT(0) << "Loading scene in server mode" << std::endl;
 
-        GSLevel::enter(0);
-
         server_->open();
     }
 
-    void GSDedicated::leave()
+    void GSDedicated::deactivate()
     {
-        GSLevel::leave();
-
         this->server_->close();
         delete this->server_;
 
-        Core::setHasServer(false);
+        GameMode::setHasServer(false);
     }
 
-    void GSDedicated::ticked(const Clock& time)
+    void GSDedicated::update(const Clock& time)
     {
 //        static float startTime = time.getSecondsPrecise();
@@ -82,7 +82,5 @@
 //            COUT(0) << "estimated ticks/sec: " << nrOfTicks/(time.getSecondsPrecise()-startTime) << endl;
             timeSinceLastUpdate_ -= static_cast<unsigned int>(timeSinceLastUpdate_ / NETWORK_PERIOD) * NETWORK_PERIOD;
-            GSLevel::ticked(time);
-            server_->tick(time.getDeltaTime());
-            this->tickChild(time);
+            server_->update(time);
         }
         else
Index: code/trunk/src/orxonox/gamestates/GSDedicated.h
===================================================================
--- code/trunk/src/orxonox/gamestates/GSDedicated.h	(revision 2894)
+++ code/trunk/src/orxonox/gamestates/GSDedicated.h	(revision 2896)
@@ -31,23 +31,22 @@
 
 #include "OrxonoxPrereqs.h"
+#include "core/GameState.h"
 #include "network/NetworkPrereqs.h"
-#include "GSLevel.h"
-#include "GSRoot.h"
 
 namespace orxonox
 {
-    class _OrxonoxExport GSDedicated : public GameState<GSRoot>, public GSLevel
+    class _OrxonoxExport GSDedicated : public GameState
     {
     public:
-        GSDedicated();
+        GSDedicated(const std::string& name);
         ~GSDedicated();
 
+        void activate();
+        void deactivate();
+        void update(const Clock& time);
+
     private:
-        void enter();
-        void leave();
-        void ticked(const Clock& time);
-
-        Server*      server_;
-        float        timeSinceLastUpdate_;
+        Server* server_;
+        float   timeSinceLastUpdate_;
     };
 }
Index: code/trunk/src/orxonox/gamestates/GSGUI.cc
===================================================================
--- code/trunk/src/orxonox/gamestates/GSGUI.cc	(revision 2894)
+++ 	(revision )
@@ -1,70 +1,0 @@
-/*
- *   ORXONOX - the hottest 3D action shooter ever to exist
- *                    > www.orxonox.net <
- *
- *
- *   License notice:
- *
- *   This program is free software; you can redistribute it and/or
- *   modify it under the terms of the GNU General Public License
- *   as published by the Free Software Foundation; either version 2
- *   of the License, or (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program; if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- *
- *   Author:
- *      Reto Grieder
- *   Co-authors:
- *      ...
- *
- */
-
-#include "OrxonoxStableHeaders.h"
-#include "GSGUI.h"
-
-#include <OgreViewport.h>
-#include "core/input/InputManager.h"
-#include "core/input/SimpleInputState.h"
-#include "gui/GUIManager.h"
-
-namespace orxonox
-{
-    GSGUI::GSGUI()
-        : GameState<GSGraphics>("gui")
-    {
-    }
-
-    GSGUI::~GSGUI()
-    {
-    }
-
-    void GSGUI::enter()
-    {
-        guiManager_ = getParent()->getGUIManager();
-
-        // show main menu
-        guiManager_->loadScene("MainMenu");
-        guiManager_->showGUI("MainMenu", 0);
-        getParent()->getViewport()->setCamera(guiManager_->getCamera());
-    }
-
-    void GSGUI::leave()
-    {
-        guiManager_->hideGUI();
-    }
-
-    void GSGUI::ticked(const Clock& time)
-    {
-        // tick CEGUI
-        guiManager_->tick(time.getDeltaTime());
-
-        this->tickChild(time);
-    }
-}
Index: code/trunk/src/orxonox/gamestates/GSGUI.h
===================================================================
--- code/trunk/src/orxonox/gamestates/GSGUI.h	(revision 2894)
+++ 	(revision )
@@ -1,53 +1,0 @@
-/*
- *   ORXONOX - the hottest 3D action shooter ever to exist
- *                    > www.orxonox.net <
- *
- *
- *   License notice:
- *
- *   This program is free software; you can redistribute it and/or
- *   modify it under the terms of the GNU General Public License
- *   as published by the Free Software Foundation; either version 2
- *   of the License, or (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program; if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- *
- *   Author:
- *      Reto Grieder
- *   Co-authors:
- *      ...
- *
- */
-
-#ifndef _GSGUI_H__
-#define _GSGUI_H__
-
-#include "OrxonoxPrereqs.h"
-#include "core/GameState.h"
-#include "GSGraphics.h"
-
-namespace orxonox
-{
-    class _OrxonoxExport GSGUI : public GameState<GSGraphics>
-    {
-    public:
-        GSGUI();
-        ~GSGUI();
-
-    private:
-        void enter();
-        void leave();
-        void ticked(const Clock& time);
-
-        GUIManager* guiManager_;
-    };
-}
-
-#endif /* _GSGUI_H__ */
Index: code/trunk/src/orxonox/gamestates/GSGraphics.cc
===================================================================
--- code/trunk/src/orxonox/gamestates/GSGraphics.cc	(revision 2894)
+++ code/trunk/src/orxonox/gamestates/GSGraphics.cc	(revision 2896)
@@ -23,6 +23,11 @@
  *      Reto Grieder
  *   Co-authors:
- *      ...
- *
+ *      Benjamin Knecht
+ *
+ */
+
+/**
+    @file
+    @brief Implementation of Graphics GameState class.
  */
 
@@ -30,107 +35,78 @@
 #include "GSGraphics.h"
 
-#include <fstream>
 #include <boost/filesystem.hpp>
-
-#include <OgreCompositorManager.h>
-#include <OgreConfigFile.h>
-#include <OgreFrameListener.h>
-#include <OgreRoot.h>
-#include <OgreLogManager.h>
-#include <OgreException.h>
 #include <OgreRenderWindow.h>
-#include <OgreRenderSystem.h>
-#include <OgreTextureManager.h>
-#include <OgreViewport.h>
-#include <OgreWindowEventUtilities.h>
-
-#include "SpecialConfig.h"
+
 #include "util/Debug.h"
-#include "util/Exception.h"
-#include "util/String.h"
-#include "util/SubString.h"
+#include "core/ConfigValueIncludes.h"
+#include "core/Clock.h"
 #include "core/ConsoleCommand.h"
-#include "core/ConfigValueIncludes.h"
+#include "core/Core.h"
 #include "core/CoreIncludes.h"
-#include "core/Core.h"
+#include "core/Game.h"
+#include "core/GameMode.h"
 #include "core/input/InputManager.h"
 #include "core/input/KeyBinder.h"
-#include "core/input/ExtendedInputState.h"
+#include "core/input/SimpleInputState.h"
 #include "core/Loader.h"
 #include "core/XMLFile.h"
 #include "overlays/console/InGameConsole.h"
 #include "gui/GUIManager.h"
-#include "tools/WindowEventListener.h"
-
-// for compatibility
-#include "GraphicsEngine.h"
+#include "GraphicsManager.h"
 
 namespace orxonox
 {
-    GSGraphics::GSGraphics()
-        : GameState<GSRoot>("graphics")
-        , renderWindow_(0)
-        , viewport_(0)
-        , bWindowEventListenerUpdateRequired_(false)
+    AddGameState(GSGraphics, "graphics");
+
+    GSGraphics::GSGraphics(const std::string& name)
+        : GameState(name)
         , inputManager_(0)
         , console_(0)
         , guiManager_(0)
-        , ogreRoot_(0)
-        , ogreLogger_(0)
-        , graphicsEngine_(0)
+        , graphicsManager_(0)
         , masterKeyBinder_(0)
+        , masterInputState_(0)
         , debugOverlay_(0)
     {
         RegisterRootObject(GSGraphics);
+    }
+
+    GSGraphics::~GSGraphics()
+    {
+    }
+
+    /**
+    @brief
+        this function does nothing
+
+        Indeed. Here goes nothing.
+    */
+    void GSGraphics::setConfigValues()
+    {
+    }
+
+    /**
+    @brief
+        This function is called when we enter this game state.
+
+        Since graphics is very important for our game this function does quite a lot:
+        \li starts graphics manager
+        \li loads debug overlay
+        \li manages render window
+        \li creates input manager
+        \li loads master key bindings
+        \li loads ingame console
+        \li loads GUI interface (GUIManager)
+        \li creates console command to toggle GUI
+    */
+    void GSGraphics::activate()
+    {
+        GameMode::setShowsGraphics(true);
+
         setConfigValues();
-    }
-
-    GSGraphics::~GSGraphics()
-    {
-    }
-
-    void GSGraphics::setConfigValues()
-    {
-        SetConfigValue(resourceFile_,    "resources.cfg")
-            .description("Location of the resources file in the data path.");
-        SetConfigValue(ogreConfigFile_,  "ogre.cfg")
-            .description("Location of the Ogre config file");
-        SetConfigValue(ogrePluginsFolder_, ORXONOX_OGRE_PLUGINS_FOLDER)
-            .description("Folder where the Ogre plugins are located.");
-        SetConfigValue(ogrePlugins_, ORXONOX_OGRE_PLUGINS)
-            .description("Comma separated list of all plugins to load.");
-        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 GSGraphics::enter()
-    {
-        Core::setShowsGraphics(true);
-
-        // initialise graphics engine. Doesn't load the render window yet!
-        graphicsEngine_ = new GraphicsEngine();
-
-        // Ogre setup procedure
-        setupOgre();
-        // load all the required plugins for Ogre
-        loadOgrePlugins();
-        // read resource declaration file
-        this->declareResources();
-        // Reads ogre config and creates the render window
-        this->loadRenderer();
-
-        // TODO: Spread this so that this call only initialises things needed for the Console and GUI
-        this->initialiseResources();
-
-        // We want to get informed whenever an object of type WindowEventListener is created
-        // in order to later update the window size.
-        bWindowEventListenerUpdateRequired_ = false;
-        RegisterConstructionCallback(GSGraphics, orxonox::WindowEventListener, requestWindowEventListenerUpdate);
+
+        // initialise graphics manager. Doesn't load the render window yet!
+        this->graphicsManager_ = new GraphicsManager();
+        this->graphicsManager_->initialise();
 
         // load debug overlay
@@ -139,82 +115,80 @@
         Loader::open(debugOverlay_);
 
+        // The render window width and height are used to set up the mouse movement.
+        size_t windowHnd = 0;
+        Ogre::RenderWindow* renderWindow = GraphicsManager::getInstance().getRenderWindow();
+        renderWindow->getCustomAttribute("WINDOW", &windowHnd);
+
         // 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();
-        size_t windowHnd = 0;
-        this->renderWindow_->getCustomAttribute("WINDOW", &windowHnd);
-        inputManager_->initialise(windowHnd, renderWindow_->getWidth(), renderWindow_->getHeight(), true);
-        // Configure master input state with a KeyBinder
+        inputManager_->initialise(windowHnd, renderWindow->getWidth(), renderWindow->getHeight(), true);
+
+        // load master key bindings
+        masterInputState_ = InputManager::getInstance().createInputState<SimpleInputState>("master", true);
         masterKeyBinder_ = new KeyBinder();
         masterKeyBinder_->loadBindings("masterKeybindings.ini");
-        inputManager_->getMasterInputState()->addKeyHandler(masterKeyBinder_);
+        masterInputState_->setKeyHandler(masterKeyBinder_);
 
         // Load the InGameConsole
         console_ = new InGameConsole();
-        console_->initialise(this->renderWindow_->getWidth(), this->renderWindow_->getHeight());
+        console_->initialise(renderWindow->getWidth(), renderWindow->getHeight());
 
         // load the CEGUI interface
         guiManager_ = new GUIManager();
-        guiManager_->initialise(this->renderWindow_);
-
-        // add console commands
-        FunctorMember<GSGraphics>* functor1 = createFunctor(&GSGraphics::printScreen);
-        functor1->setObject(this);
-        ccPrintScreen_ = createConsoleCommand(functor1, "printScreen");
-        CommandExecutor::addConsoleCommandShortcut(ccPrintScreen_);
-    }
-
-    void GSGraphics::leave()
-    {
-        using namespace Ogre;
-
-        delete this->ccPrintScreen_;
-
-        // remove our WindowEventListener first to avoid bad calls after the window has been destroyed
-        Ogre::WindowEventUtilities::removeWindowEventListener(this->renderWindow_, this);
+        guiManager_->initialise(renderWindow);
+
+        // add console command to toggle GUI
+        FunctorMember<GSGraphics>* functor = createFunctor(&GSGraphics::toggleGUI);
+        functor->setObject(this);
+        this->ccToggleGUI_ = createConsoleCommand(functor, "toggleGUI");
+        CommandExecutor::addConsoleCommandShortcut(this->ccToggleGUI_);
+
+        // enable master input
+        InputManager::getInstance().requestEnterState("master");
+    }
+
+    /**
+    @brief
+        This function is called when the game state is left
+
+        Created references, input states and console commands are deleted.
+    */
+    void GSGraphics::deactivate()
+    {
+
+        if (this->ccToggleGUI_)
+        {
+            delete this->ccToggleGUI_;
+            this->ccToggleGUI_ = 0;
+        }
+
+        masterInputState_->setHandler(0);
+        InputManager::getInstance().requestDestroyState("master");
+        delete this->masterKeyBinder_;
 
         delete this->guiManager_;
-
         delete this->console_;
-
-        //inputManager_->getMasterInputState()->removeKeyHandler(this->masterKeyBinder_);
-        delete this->masterKeyBinder_;
-        delete this->inputManager_;
 
         Loader::unload(this->debugOverlay_);
         delete this->debugOverlay_;
 
-        // unload all compositors
-        Ogre::CompositorManager::getSingleton().removeAll();
-
-        // destroy render window
-        RenderSystem* renderer = this->ogreRoot_->getRenderSystem();
-        renderer->destroyRenderWindow("Orxonox");
-
-        /*** CODE SNIPPET, UNUSED ***/
-        // Does the opposite of initialise()
-        //ogreRoot_->shutdown();
-        // Remove all resources and resource groups
-        //StringVector groups = ResourceGroupManager::getSingleton().getResourceGroups();
-        //for (StringVector::iterator it = groups.begin(); it != groups.end(); ++it)
-        //{
-        //    ResourceGroupManager::getSingleton().destroyResourceGroup(*it);
-        //}
-
-        //ParticleSystemManager::getSingleton().removeAllTemplates();
-
-        // Shutdown the render system
-        //this->ogreRoot_->setRenderSystem(0);
-
-        delete this->ogreRoot_;
-
-        // 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_;
-
-        delete graphicsEngine_;
-
-        Core::setShowsGraphics(false);
+        delete this->inputManager_;
+        this->inputManager_ = 0;
+
+        delete graphicsManager_;
+
+        GameMode::setShowsGraphics(false);
+    }
+
+    /**
+    @brief
+        Toggles the visibility of the current GUI
+
+        This function just executes a Lua function in the main script of the GUI by accessing the GUIManager.
+        For more details on this function check out the Lua code.
+    */
+    void GSGraphics::toggleGUI()
+    {
+            GUIManager::getInstance().executeCode("toggleGUI()");
     }
 
@@ -227,259 +201,26 @@
         need the time. So we shouldn't run into problems.
     */
-    void GSGraphics::ticked(const Clock& time)
-    {
+    void GSGraphics::update(const Clock& time)
+    {
+        if (this->getActivity().topState)
+        {
+            // This state can not 'survive' on its own.
+            // Load a user interface therefore
+            Game::getInstance().requestState("mainMenu");
+        }
+
         uint64_t timeBeforeTick = time.getRealMicroseconds();
 
-        float dt = time.getDeltaTime();
-
-        this->inputManager_->tick(dt);
-        // tick console
-        this->console_->tick(dt);
-        this->tickChild(time);
-
-        if (this->bWindowEventListenerUpdateRequired_)
-        {
-            // Update all WindowEventListeners for the case a new one was created.
-            this->windowResized(this->renderWindow_);
-            this->bWindowEventListenerUpdateRequired_ = false;
-        }
+        this->inputManager_->update(time);        // tick console
+        this->console_->update(time);
+        this->guiManager_->update(time);
 
         uint64_t timeAfterTick = time.getRealMicroseconds();
 
-        // Also add our tick time to the list in GSRoot
-        this->getParent()->addTickTime(timeAfterTick - timeBeforeTick);
-
-        // Update statistics overlay. Note that the values only change periodically in GSRoot.
-        GraphicsEngine::getInstance().setAverageFramesPerSecond(this->getParent()->getAvgFPS());
-        GraphicsEngine::getInstance().setAverageTickTime(this->getParent()->getAvgTickTime());
-
-        // don't forget to call _fireFrameStarted in ogre to make sure
-        // everything goes smoothly
-        Ogre::FrameEvent evt;
-        evt.timeSinceLastFrame = dt;
-        evt.timeSinceLastEvent = dt; // note: same time, but shouldn't matter anyway
-        ogreRoot_->_fireFrameStarted(evt);
-
-        // Pump messages in all registered RenderWindows
-        // This calls the WindowEventListener objects.
-        Ogre::WindowEventUtilities::messagePump();
-        // make sure the window stays active even when not focused
-        // (probably only necessary on windows)
-        this->renderWindow_->setActive(true);
-
-        // render
-        ogreRoot_->_updateAllRenderTargets();
-
-        // again, just to be sure ogre works fine
-        ogreRoot_->_fireFrameEnded(evt); // note: uses the same time as _fireFrameStarted
-    }
-
-    /**
-    @brief
-        Creates the Ogre Root object and sets up the ogre log.
-    */
-    void GSGraphics::setupOgre()
-    {
-        COUT(3) << "Setting up Ogre..." << std::endl;
-
-        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");
-        }
-
-        boost::filesystem::path ogreConfigFilepath(Core::getConfigPath() / this->ogreConfigFile_);
-        boost::filesystem::path ogreLogFilepath(Core::getLogPath() / this->ogreLogFile_);
-
-        // create a new logManager
-        // Ogre::Root will detect that we've already created a Log
-        ogreLogger_ = new Ogre::LogManager();
-        COUT(4) << "Ogre LogManager created" << std::endl;
-
-        // create our own log that we can listen to
-        Ogre::Log *myLog;
-        myLog = ogreLogger_->createLog(ogreLogFilepath.string(), true, false, false);
-        COUT(4) << "Ogre Log created" << std::endl;
-
-        myLog->setLogDetail(Ogre::LL_BOREME);
-        myLog->addListener(this);
-
-        COUT(4) << "Creating Ogre Root..." << std::endl;
-
-        // check for config file existence because Ogre displays (caught) exceptions if not
-        if (!boost::filesystem::exists(ogreConfigFilepath))
-        {
-            // create a zero sized file
-            std::ofstream creator;
-            creator.open(ogreConfigFilepath.string().c_str());
-            creator.close();
-        }
-
-        // Leave plugins file empty. We're going to do that part manually later
-        ogreRoot_ = new Ogre::Root("", ogreConfigFilepath.string(), ogreLogFilepath.string());
-
-        COUT(3) << "Ogre set up done." << std::endl;
-    }
-
-    void GSGraphics::loadOgrePlugins()
-    {
-        // just to make sure the next statement doesn't segfault
-        if (ogrePluginsFolder_ == "")
-            ogrePluginsFolder_ = ".";
-
-        boost::filesystem::path folder(ogrePluginsFolder_);
-        // Do some SubString magic to get the comma separated list of plugins
-        SubString plugins(ogrePlugins_, ",", " ", false, 92, false, 34, false, 40, 41, false, '\0');
-        // Use backslash paths on Windows! file_string() already does that though.
-        for (unsigned int i = 0; i < plugins.size(); ++i)
-            ogreRoot_->loadPlugin((folder / plugins[i]).file_string());
-    }
-
-    void GSGraphics::declareResources()
-    {
-        CCOUT(4) << "Declaring Resources" << std::endl;
-        //TODO: Specify layout of data file and maybe use xml-loader
-        //TODO: Work with ressource groups (should be generated by a special loader)
-
-        if (resourceFile_ == "")
-        {
-            COUT(2) << "Warning: Ogre resource file set to \"\". Defaulting to resources.cfg" << std::endl;
-            ModifyConfigValue(resourceFile_, tset, "resources.cfg");
-        }
-
-        // Load resource paths from data file using configfile ressource type
-        Ogre::ConfigFile cf;
-        try
-        {
-            cf.load((Core::getMediaPath() / resourceFile_).string());
-        }
-        catch (...)
-        {
-            //COUT(1) << ex.getFullDescription() << std::endl;
-            COUT(0) << "Have you forgotten to set the data path in orxnox.ini?" << std::endl;
-            throw;
-        }
-
-        // Go through all sections & settings in the file
-        Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();
-
-        std::string secName, typeName, archName;
-        while (seci.hasMoreElements())
-        {
-            try
-            {
-                secName = seci.peekNextKey();
-                Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
-                Ogre::ConfigFile::SettingsMultiMap::iterator i;
-                for (i = settings->begin(); i != settings->end(); ++i)
-                {
-                    typeName = i->first; // for instance "FileSystem" or "Zip"
-                    archName = i->second; // name (and location) of archive
-
-                    Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
-                        (Core::getMediaPath() / archName).string(), typeName, secName);
-                }
-            }
-            catch (Ogre::Exception& ex)
-            {
-                COUT(1) << ex.getFullDescription() << std::endl;
-            }
-        }
-    }
-
-    void GSGraphics::loadRenderer()
-    {
-        CCOUT(4) << "Configuring Renderer" << std::endl;
-
-        if (!ogreRoot_->restoreConfig())
-            if (!ogreRoot_->showConfigDialog())
-                ThrowException(InitialisationFailed, "Could not show Ogre configuration dialogue.");
-
-        CCOUT(4) << "Creating render window" << std::endl;
-
-        this->renderWindow_ = ogreRoot_->initialise(true, "Orxonox");
-
-        Ogre::WindowEventUtilities::addWindowEventListener(this->renderWindow_, this);
-
-        Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(0);
-
-        // create a full screen default viewport
-        this->viewport_ = this->renderWindow_->addViewport(0, 0);
-
-        if (this->graphicsEngine_)
-            this->graphicsEngine_->setViewport(this->viewport_);
-    }
-
-    void GSGraphics::initialiseResources()
-    {
-        CCOUT(4) << "Initialising resources" << std::endl;
-        //TODO: Do NOT load all the groups, why are we doing that? And do we really do that? initialise != load...
-        //try
-        //{
-            Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
-            /*Ogre::StringVector str = Ogre::ResourceGroupManager::getSingleton().getResourceGroups();
-            for (unsigned int i = 0; i < str.size(); i++)
-            {
-            Ogre::ResourceGroupManager::getSingleton().loadResourceGroup(str[i]);
-            }*/
-        //}
-        //catch (...)
-        //{
-        //    CCOUT(2) << "Error: There was a serious error when initialising the resources." << std::endl;
-        //    throw;
-        //}
-    }
-
-    /**
-    @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;
-    }
-
-    /**
-    @brief
-        Window has moved.
-    @param rw
-        The render window it occured in
-    */
-    void GSGraphics::windowMoved(Ogre::RenderWindow *rw)
-    {
-        for (ObjectList<orxonox::WindowEventListener>::iterator it = ObjectList<orxonox::WindowEventListener>::begin(); it; ++it)
-            it->windowMoved();
+        // Also add our tick time
+        Game::getInstance().addTickTime(timeAfterTick - timeBeforeTick);
+
+        // Render
+        this->graphicsManager_->update(time);
     }
 
@@ -490,15 +231,12 @@
         The render window it occured in
     @note
-        GraphicsEngine has a render window stored itself. This is the same
+        GraphicsManager has a render window stored itself. This is the same
         as rw. But we have to be careful when using multiple render windows!
     */
-    void GSGraphics::windowResized(Ogre::RenderWindow *rw)
-    {
-        for (ObjectList<orxonox::WindowEventListener>::iterator it = ObjectList<orxonox::WindowEventListener>::begin(); it; ++it)
-            it->windowResized(this->renderWindow_->getWidth(), this->renderWindow_->getHeight());
-
+    void GSGraphics::windowResized(unsigned int newWidth, unsigned int newHeight)
+    {
         // OIS needs this under linux even if we only use relative input measurement.
         if (this->inputManager_)
-            this->inputManager_->setWindowExtents(renderWindow_->getWidth(), renderWindow_->getHeight());
+            this->inputManager_->setWindowExtents(newWidth, newHeight);
     }
 
@@ -509,9 +247,6 @@
         The render window it occured in
     */
-    void GSGraphics::windowFocusChange(Ogre::RenderWindow *rw)
-    {
-        for (ObjectList<orxonox::WindowEventListener>::iterator it = ObjectList<orxonox::WindowEventListener>::begin(); it; ++it)
-            it->windowFocusChanged();
-
+    void GSGraphics::windowFocusChanged()
+    {
         // instruct InputManager to clear the buffers (core library so we cannot use the interface)
         if (this->inputManager_)
@@ -519,21 +254,3 @@
     }
 
-    /**
-    @brief
-        Window was closed.
-    @param rw
-        The render window it occured in
-    */
-    void GSGraphics::windowClosed(Ogre::RenderWindow *rw)
-    {
-        this->requestState("root");
-    }
-
-    void GSGraphics::printScreen()
-    {
-        if (this->renderWindow_)
-        {
-            this->renderWindow_->writeContentsToTimestampedFile("shot_", ".jpg");
-        }
-    }
 }
Index: code/trunk/src/orxonox/gamestates/GSGraphics.h
===================================================================
--- code/trunk/src/orxonox/gamestates/GSGraphics.h	(revision 2894)
+++ code/trunk/src/orxonox/gamestates/GSGraphics.h	(revision 2896)
@@ -23,7 +23,12 @@
  *      Reto Grieder
  *   Co-authors:
- *      ...
+ *      Benjamin Knecht (documentation)
  *
  */
+
+ /**
+    @file
+    @brief Declaration of the Graphics GameState class.
+  */
 
 #ifndef _GSGraphics_H__
@@ -31,84 +36,44 @@
 
 #include "OrxonoxPrereqs.h"
-#include <OgrePrerequisites.h>
-#ifndef NOMINMAX
-#  define NOMINMAX // required to stop windows.h screwing up std::min definition
-#endif
-#include <OgreWindowEventUtilities.h>
 #include "core/GameState.h"
-#include "core/OrxonoxClass.h"
-#include "GSRoot.h"
+#include "tools/WindowEventListener.h"
 
 namespace orxonox
 {
-    class _OrxonoxExport GSGraphics : public GameState<GSRoot>, public OrxonoxClass,
-                                      public Ogre::WindowEventListener, public Ogre::LogListener
+    /**
+    @class GSGraphics
+    @brief
+        Game state used when displaying graphics of any kind
+
+        This game state is only left out if we start a dedicated server where no graphics are present.
+    */
+    class _OrxonoxExport GSGraphics : public GameState, public WindowEventListener
     {
-        friend class ClassIdentifier<GSGraphics>;
-
     public:
-        GSGraphics();
+        GSGraphics(const std::string& name);
         ~GSGraphics();
-
-        Ogre::Root*     getOgreRoot()   { return this->ogreRoot_  ; }
-        Ogre::Viewport* getViewport()   { return this->viewport_  ; }
-        GUIManager*     getGUIManager() { return this->guiManager_; }
-
-    private: // functions
-        void enter();
-        void leave();
-        void ticked(const Clock& time);
-
         void setConfigValues();
 
-        void setupOgre();
-        void loadOgrePlugins();
-        void declareResources();
-        void loadRenderer();
-        void initialiseResources();
+        void activate();
+        void deactivate();
+        void update(const Clock& time);
 
-        // console commands
-        void printScreen();
+        void toggleGUI();
 
-        // event from Ogre::LogListener
-        void messageLogged(const std::string& message, Ogre::LogMessageLevel lml,
-            bool maskDebug, const std::string& logName);
-
-        // window events from Ogre::WindowEventListener
-        void windowMoved       (Ogre::RenderWindow* rw);
-        void windowResized     (Ogre::RenderWindow* rw);
-        void windowFocusChange (Ogre::RenderWindow* rw);
-        void windowClosed      (Ogre::RenderWindow* rw);
-
-        void requestWindowEventListenerUpdate() { this->bWindowEventListenerUpdateRequired_ = true; }
-
-    private: // variables
-        Ogre::RenderWindow*   renderWindow_;          //!< the current render window
-        Ogre::Viewport*       viewport_;              //!< default full size viewport
-        bool bWindowEventListenerUpdateRequired_;     //!< True if a new WindowEventListener was created but not yet updated.
+    private:
+        // Window events from WindowEventListener
+        void windowResized(unsigned int newWidth, unsigned int newHeight);
+        void windowFocusChanged();
 
         // managed singletons
-        InputManager*         inputManager_;
+        InputManager*         inputManager_;        //!< Reference to input management
         InGameConsole*        console_;
-        GUIManager*           guiManager_;
-        Ogre::Root*           ogreRoot_;                  //!< Ogre's root
-        Ogre::LogManager*     ogreLogger_;
-        GraphicsEngine*       graphicsEngine_;   //!< Interface to Ogre
+        GUIManager*           guiManager_;          //!< Interface to GUI
+        GraphicsManager*      graphicsManager_;     //!< Interface to Ogre
 
-        KeyBinder*            masterKeyBinder_;
+        KeyBinder*            masterKeyBinder_;     //!< Key binder for master key bindings
+        SimpleInputState*     masterInputState_;    //!< Special input state for master input
         XMLFile*              debugOverlay_;
-
-        // config values
-        std::string           resourceFile_;             //!< resources file name
-        std::string           ogreConfigFile_;           //!< ogre config file name
-        std::string           ogrePluginsFolder_;        //!< Folder where the Ogre plugins are located
-        std::string           ogrePlugins_;              //!< Comma separated list of all plugins to load
-        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
-
-        // console commands
-        ConsoleCommand*       ccPrintScreen_;
+        ConsoleCommand*       ccToggleGUI_;         //!< Console command to toggle GUI
     };
 }
Index: code/trunk/src/orxonox/gamestates/GSIOConsole.cc
===================================================================
--- code/trunk/src/orxonox/gamestates/GSIOConsole.cc	(revision 2894)
+++ code/trunk/src/orxonox/gamestates/GSIOConsole.cc	(revision 2896)
@@ -36,9 +36,12 @@
 
 #include "core/ConsoleCommand.h"
+#include "core/Game.h"
 
 namespace orxonox
 {
-    GSIOConsole::GSIOConsole()
-        : GameState<GSRoot>("ioConsole")
+    AddGameState(GSIOConsole, "ioConsole");
+
+    GSIOConsole::GSIOConsole(const std::string& name)
+        : GameState(name)
     {
     }
@@ -48,19 +51,35 @@
     }
 
-    void GSIOConsole::enter()
+    void GSIOConsole::activate()
     {
+        {
+            FunctorMember<GSIOConsole>* functor = createFunctor(&GSIOConsole::loadMenu);
+            functor->setObject(this);
+            this->ccLoadMenu_ = createConsoleCommand(functor, "loadMenu");
+            CommandExecutor::addConsoleCommandShortcut(this->ccLoadMenu_);
+        }
     }
 
-    void GSIOConsole::leave()
+    void GSIOConsole::deactivate()
     {
+        if (this->ccLoadMenu_)
+        {
+            delete this->ccLoadMenu_;
+            this->ccLoadMenu_ = 0;
+        }
     }
 
-    void GSIOConsole::ticked(const Clock& time)
+    void GSIOConsole::update(const Clock& time)
     {
+        std::cout << ">";
         std::string command;
         std::getline(std::cin, command);
         CommandExecutor::execute(command, true);
-        
-        tickChild(time);
+    }
+
+    void GSIOConsole::loadMenu()
+    {
+        Game::getInstance().popState();
+        Game::getInstance().requestStates("graphics, mainMenu");
     }
 }
Index: code/trunk/src/orxonox/gamestates/GSIOConsole.h
===================================================================
--- code/trunk/src/orxonox/gamestates/GSIOConsole.h	(revision 2894)
+++ code/trunk/src/orxonox/gamestates/GSIOConsole.h	(revision 2896)
@@ -31,20 +31,23 @@
 
 #include "OrxonoxPrereqs.h"
-#include <OgrePrerequisites.h>
 #include "core/GameState.h"
-#include "GSRoot.h"
 
 namespace orxonox
 {
-    class _OrxonoxExport GSIOConsole : public GameState<GSRoot>
+    class _OrxonoxExport GSIOConsole : public GameState
     {
     public:
-        GSIOConsole();
+        GSIOConsole(const std::string& name);
         ~GSIOConsole();
 
+        void activate();
+        void deactivate();
+        void update(const Clock& time);
+
     private:
-        void enter();
-        void leave();
-        void ticked(const Clock& time);
+        void loadMenu();
+
+        // console commands
+        ConsoleCommand* ccLoadMenu_;
     };
 }
Index: code/trunk/src/orxonox/gamestates/GSLevel.cc
===================================================================
--- code/trunk/src/orxonox/gamestates/GSLevel.cc	(revision 2894)
+++ code/trunk/src/orxonox/gamestates/GSLevel.cc	(revision 2896)
@@ -24,4 +24,5 @@
  *   Co-authors:
  *      Fabian 'x3n' Landau
+ *      Benjamin Knecht
  *
  */
@@ -39,20 +40,29 @@
 #include "core/CommandLine.h"
 #include "core/ConfigValueIncludes.h"
+#include "core/Core.h"
 #include "core/CoreIncludes.h"
-#include "core/Core.h"
+#include "core/Game.h"
+#include "core/GameMode.h"
 #include "objects/Tickable.h"
 #include "objects/Radar.h"
 #include "CameraManager.h"
+#include "GraphicsManager.h"
 #include "LevelManager.h"
 #include "PlayerManager.h"
+#include "gui/GUIManager.h"
 
 namespace orxonox
 {
+    AddGameState(GSLevel, "level");
+
     SetCommandLineArgument(level, "presentation_dm.oxw").shortcut("l");
-
-    GSLevel::GSLevel()
-//        : GameState<GSGraphics>(name)
-        : keyBinder_(0)
-        , inputState_(0)
+    SetConsoleCommand(GSLevel, showIngameGUI, true);
+
+    GSLevel::GSLevel(const std::string& name)
+        : GameState(name)
+        , keyBinder_(0)
+        , gameInputState_(0)
+        , guiMouseOnlyInputState_(0)
+        , guiKeysOnlyInputState_(0)
         , radar_(0)
         , startFile_(0)
@@ -64,29 +74,34 @@
         this->ccKeybind_ = 0;
         this->ccTkeybind_ = 0;
-
+    }
+
+    GSLevel::~GSLevel()
+    {
+    }
+
+    void GSLevel::setConfigValues()
+    {
+        SetConfigValue(keyDetectorCallbackCode_, "KeybindBindingStringKeyName=");
+    }
+
+    void GSLevel::activate()
+    {
         setConfigValues();
-    }
-
-    GSLevel::~GSLevel()
-    {
-    }
-
-    void GSLevel::setConfigValues()
-    {
-        SetConfigValue(keyDetectorCallbackCode_, "KeybindBindingStringKeyName=");
-    }
-
-    void GSLevel::enter(Ogre::Viewport* viewport)
-    {
-        if (Core::showsGraphics())
-        {
-            inputState_ = InputManager::getInstance().createInputState<SimpleInputState>("game", 20);
+
+        if (GameMode::showsGraphics())
+        {
+            gameInputState_ = InputManager::getInstance().createInputState<SimpleInputState>("game");
             keyBinder_ = new KeyBinder();
             keyBinder_->loadBindings("keybindings.ini");
-            inputState_->setHandler(keyBinder_);
+            gameInputState_->setHandler(keyBinder_);
+
+            guiMouseOnlyInputState_ = InputManager::getInstance().createInputState<SimpleInputState>("guiMouseOnly");
+            guiMouseOnlyInputState_->setMouseHandler(GUIManager::getInstancePtr());
+
+            guiKeysOnlyInputState_ = InputManager::getInstance().createInputState<SimpleInputState>("guiKeysOnly");
+            guiKeysOnlyInputState_->setKeyHandler(GUIManager::getInstancePtr());
 
             // create the global CameraManager
-            assert(viewport);
-            this->cameraManager_ = new CameraManager(viewport);
+            this->cameraManager_ = new CameraManager(GraphicsManager::getInstance().getViewport());
 
             // Start the Radar
@@ -96,5 +111,5 @@
         this->playerManager_ = new PlayerManager();
 
-        if (Core::isMaster())
+        if (GameMode::isMaster())
         {
             // create the global LevelManager
@@ -104,9 +119,6 @@
         }
 
-        if (Core::showsGraphics())
-        {
-            // TODO: insert slomo console command with
-            // .accessLevel(AccessLevel::Offline).defaultValue(0, 1.0).axisParamIndex(0).isAxisRelative(false);
-
+        if (GameMode::showsGraphics())
+        {
             // keybind console command
             FunctorMember<GSLevel>* functor1 = createFunctor(&GSLevel::keybind);
@@ -126,5 +138,21 @@
     }
 
-    void GSLevel::leave()
+    void GSLevel::showIngameGUI(bool show)
+    {
+        if (show)
+        {
+            GUIManager::getInstancePtr()->showGUI("inGameTest");
+            GUIManager::getInstancePtr()->executeCode("showCursor()");
+            InputManager::getInstance().requestEnterState("guiMouseOnly");
+        }
+        else
+        {
+            GUIManager::getInstancePtr()->executeCode("hideGUI(\"inGameTest\")");
+            GUIManager::getInstancePtr()->executeCode("hideCursor()");
+            InputManager::getInstance().requestLeaveState("guiMouseOnly");
+        }
+    }
+
+    void GSLevel::deactivate()
     {
         // destroy console commands
@@ -139,4 +167,5 @@
             this->ccTkeybind_ = 0;
         }
+
 
         // this call will delete every BaseObject!
@@ -146,8 +175,8 @@
         //Loader::close();
 
-        if (Core::showsGraphics())
+        if (GameMode::showsGraphics())
             InputManager::getInstance().requestLeaveState("game");
 
-        if (Core::isMaster())
+        if (GameMode::isMaster())
             this->unloadLevel();
 
@@ -176,7 +205,9 @@
         }
 
-        if (Core::showsGraphics())
-        {
-            inputState_->setHandler(0);
+        if (GameMode::showsGraphics())
+        {
+            gameInputState_->setHandler(0);
+            guiMouseOnlyInputState_->setHandler(0);
+            guiKeysOnlyInputState_->setHandler(0);
             InputManager::getInstance().requestDestroyState("game");
             if (this->keyBinder_)
@@ -188,7 +219,7 @@
     }
 
-    void GSLevel::ticked(const Clock& time)
-    {
-        // Commented by 1337: Temporarily moved to GSGraphics.
+    void GSLevel::update(const Clock& time)
+    {
+        // Note: Temporarily moved to GSGraphics.
         //// Call the scene objects
         //for (ObjectList<Tickable>::iterator it = ObjectList<Tickable>::begin(); it; ++it)
@@ -233,9 +264,9 @@
         Command string that can be executed by the CommandExecutor
         OR: Internal string "KeybindBindingStringKeyName=" used for the second call to identify
-        the key/button/axis that has been activated. This is configured above in enter().
+        the key/button/axis that has been activated. This is configured above in activate().
     */
     void GSLevel::keybindInternal(const std::string& command, bool bTemporary)
     {
-        if (Core::showsGraphics())
+        if (GameMode::showsGraphics())
         {
             static std::string bindingString = "";
Index: code/trunk/src/orxonox/gamestates/GSLevel.h
===================================================================
--- code/trunk/src/orxonox/gamestates/GSLevel.h	(revision 2894)
+++ code/trunk/src/orxonox/gamestates/GSLevel.h	(revision 2896)
@@ -23,5 +23,5 @@
  *      Reto Grieder
  *   Co-authors:
- *      ...
+ *      Benjamin Knecht
  *
  */
@@ -31,24 +31,23 @@
 
 #include "OrxonoxPrereqs.h"
-#include <OgrePrerequisites.h>
 #include "core/OrxonoxClass.h"
+#include "core/GameState.h"
 
 namespace orxonox
 {
-    class _OrxonoxExport GSLevel : public OrxonoxClass
+    class _OrxonoxExport GSLevel : public GameState, public OrxonoxClass
     {
-        friend class ClassIdentifier<GSLevel>;
     public:
-        GSLevel();
+        GSLevel(const std::string& name);
         ~GSLevel();
-
-        // was private before (is public now because of console command in GSStandalone)
         void setConfigValues();
 
+        void activate();
+        void deactivate();
+        void update(const Clock& time);
+
+        static void showIngameGUI(bool show);
+
     protected:
-        void enter(Ogre::Viewport* viewport);
-        void leave();
-        void ticked(const Clock& time);
-
         void loadLevel();
         void unloadLevel();
@@ -59,11 +58,13 @@
         void keybindInternal(const std::string& command, bool bTemporary);
 
-        KeyBinder*            keyBinder_;        //!< tool that loads and manages the input bindings
-        SimpleInputState*     inputState_;
-        Radar*                radar_;            //!< represents the Radar (not the HUD part)
-        XMLFile*              startFile_;        //!< current hard coded default level
-        CameraManager*        cameraManager_;
-        LevelManager*         levelManager_;
-        PlayerManager*        playerManager_;
+        KeyBinder*            keyBinder_;               //!< tool that loads and manages the input bindings
+        SimpleInputState*     gameInputState_;          //!< input state for normal ingame playing
+        SimpleInputState*     guiMouseOnlyInputState_;  //!< input state if we only need the mouse to use the GUI
+        SimpleInputState*     guiKeysOnlyInputState_;   //!< input state if we only need the keys to use the GUI
+        Radar*                radar_;                   //!< represents the Radar (not the HUD part)
+        XMLFile*              startFile_;               //!< current hard coded default level
+        CameraManager*        cameraManager_;           //!< camera manager for this level
+        LevelManager*         levelManager_;            //!< global level manager
+        PlayerManager*        playerManager_;           //!< player manager for this level
 
         //##### ConfigValues #####
@@ -73,5 +74,4 @@
         ConsoleCommand*       ccKeybind_;
         ConsoleCommand*       ccTkeybind_;
-
     };
 }
Index: code/trunk/src/orxonox/gamestates/GSMainMenu.cc
===================================================================
--- code/trunk/src/orxonox/gamestates/GSMainMenu.cc	(revision 2896)
+++ code/trunk/src/orxonox/gamestates/GSMainMenu.cc	(revision 2896)
@@ -0,0 +1,107 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Reto Grieder
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "OrxonoxStableHeaders.h"
+#include "GSMainMenu.h"
+
+//#include <OgreViewport.h>
+#include <OgreSceneManager.h>
+#include "core/Clock.h"
+#include "core/ConsoleCommand.h"
+#include "core/Game.h"
+#include "core/input/InputManager.h"
+#include "core/input/SimpleInputState.h"
+#include "gui/GUIManager.h"
+#include "objects/Scene.h"
+#include "GraphicsManager.h"
+
+namespace orxonox
+{
+    AddGameState(GSMainMenu, "mainMenu");
+
+    GSMainMenu::GSMainMenu(const std::string& name)
+        : GameState(name)
+        , inputState_(0)
+    {
+    }
+
+    GSMainMenu::~GSMainMenu()
+    {
+    }
+
+    void GSMainMenu::activate()
+    {
+        inputState_ = InputManager::getInstance().createInputState<SimpleInputState>("mainMenu");
+        inputState_->setHandler(GUIManager::getInstancePtr());
+        inputState_->setJoyStickHandler(&InputManager::EMPTY_HANDLER);
+
+        // create an empty Scene
+        this->scene_ = new Scene(0);
+        // and a Camera
+        this->camera_ = this->scene_->getSceneManager()->createCamera("mainMenu/Camera");
+
+        // show main menu
+        GUIManager::getInstance().showGUI("mainmenu");
+        GUIManager::getInstance().setCamera(this->camera_);
+        GraphicsManager::getInstance().setCamera(this->camera_);
+
+        {
+            FunctorMember<GSMainMenu>* functor = createFunctor(&GSMainMenu::startGame);
+            functor->setObject(this);
+            this->ccStartGame_ = createConsoleCommand(functor, "startGame");
+            CommandExecutor::addConsoleCommandShortcut(this->ccStartGame_);
+        }
+
+        InputManager::getInstance().requestEnterState("mainMenu");
+    }
+
+    void GSMainMenu::deactivate()
+    {
+        InputManager::getInstance().requestLeaveState("mainMenu");
+        InputManager::getInstance().requestDestroyState("mainMenu");
+
+/*
+        if (this->ccStartGame_)
+        {
+            delete this->ccStartGame_;
+            this->ccStartGame_ = 0;
+        }
+*/
+    }
+
+    void GSMainMenu::update(const Clock& time)
+    {
+    }
+
+    void GSMainMenu::startGame()
+    {
+        // HACK - HACK
+        Game::getInstance().popState();
+        Game::getInstance().requestStates("standalone, level");
+    }
+}
Index: code/trunk/src/orxonox/gamestates/GSMainMenu.h
===================================================================
--- code/trunk/src/orxonox/gamestates/GSMainMenu.h	(revision 2896)
+++ code/trunk/src/orxonox/gamestates/GSMainMenu.h	(revision 2896)
@@ -0,0 +1,60 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Reto Grieder
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _GSMainMenu_H__
+#define _GSMainMenu_H__
+
+#include "OrxonoxPrereqs.h"
+#include <OgrePrerequisites.h>
+#include "core/GameState.h"
+
+namespace orxonox
+{
+    class _OrxonoxExport GSMainMenu : public GameState
+    {
+    public:
+        GSMainMenu(const std::string& name);
+        ~GSMainMenu();
+
+        void activate();
+        void deactivate();
+        void update(const Clock& time);
+
+        void startGame();
+
+    private:
+        SimpleInputState* inputState_;
+        Scene*            scene_;
+        Ogre::Camera*     camera_;
+
+        // console commands
+        ConsoleCommand* ccStartGame_;
+    };
+}
+
+#endif /* _GSMainMenu_H__ */
Index: code/trunk/src/orxonox/gamestates/GSRoot.cc
===================================================================
--- code/trunk/src/orxonox/gamestates/GSRoot.cc	(revision 2894)
+++ code/trunk/src/orxonox/gamestates/GSRoot.cc	(revision 2896)
@@ -32,43 +32,29 @@
 #include "util/Exception.h"
 #include "util/Debug.h"
-#include "core/Core.h"
-#include "core/Factory.h"
-#include "core/ConfigValueIncludes.h"
-#include "core/CoreIncludes.h"
+#include "core/Clock.h"
+#include "core/Game.h"
+#include "core/GameMode.h"
+#include "core/CommandLine.h"
 #include "core/ConsoleCommand.h"
-#include "core/CommandLine.h"
-#include "core/Shell.h"
-#include "core/TclBind.h"
-#include "core/TclThreadManager.h"
-#include "core/LuaBind.h"
+#include "tools/TimeFactorListener.h"
 #include "tools/Timer.h"
 #include "objects/Tickable.h"
 
-#ifdef ORXONOX_PLATFORM_WINDOWS
-#  ifndef WIN32_LEAN_AND_MEAN
-#    define WIN32_LEAN_AND_MEAN
-#  endif
-#  ifndef NOMINMAX
-#    define NOMINMAX // required to stop windows.h screwing up std::min definition
-#  endif
-#  include "windows.h"
-#endif
-
 namespace orxonox
 {
-    SetCommandLineArgument(limitToCPU, 1).information("0: off | #cpu");
-
-    GSRoot::GSRoot()
-        : RootGameState("root")
+    AddGameState(GSRoot, "root");
+    SetCommandLineSwitch(console);
+    // Shortcuts for easy direct loading
+    SetCommandLineSwitch(server);
+    SetCommandLineSwitch(client);
+    SetCommandLineSwitch(dedicated);
+    SetCommandLineSwitch(standalone);
+
+    GSRoot::GSRoot(const std::string& name)
+        : GameState(name)
         , timeFactor_(1.0f)
         , bPaused_(false)
         , timeFactorPauseBackup_(1.0f)
-        , tclBind_(0)
-        , tclThreadManager_(0)
-        , shell_(0)
-    {
-        RegisterRootObject(GSRoot);
-        setConfigValues();
-
+    {
         this->ccSetTimeFactor_ = 0;
         this->ccPause_ = 0;
@@ -79,59 +65,8 @@
     }
 
-    void GSRoot::setConfigValues()
-    {
-        SetConfigValue(statisticsRefreshCycle_, 250000)
-            .description("Sets the time in microseconds interval at which average fps, etc. get updated.");
-        SetConfigValue(statisticsAvgLength_, 1000000)
-            .description("Sets the time in microseconds interval at which average fps, etc. gets calculated.");
-    }
-
-    void GSRoot::enter()
-    {
-        // creates the class hierarchy for all classes with factories
-        Factory::createClassHierarchy();
-
+    void GSRoot::activate()
+    {
         // reset game speed to normal
-        timeFactor_ = 1.0f;
-
-        // reset frame counter
-        this->statisticsStartTime_ = 0;
-        this->statisticsTickTimes_.clear();
-        this->periodTickTime_ = 0;
-        this->avgFPS_ = 0.0f;
-        this->avgTickTime_ = 0.0f;
-
-        // Create the lua interface
-        this->luaBind_ = new LuaBind();
-
-        // initialise TCL
-        this->tclBind_ = new TclBind(Core::getMediaPathString());
-        this->tclThreadManager_ = new TclThreadManager(tclBind_->getTclInterpreter());
-
-        // create a shell
-        this->shell_ = new Shell();
-
-        // 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
-        // the timer though).
-        int limitToCPU = CommandLine::getValue("limitToCPU");
-        if (limitToCPU > 0)
-            setThreadAffinity((unsigned int)(limitToCPU - 1));
-
-        {
-            // add console commands
-            FunctorMember<GSRoot>* functor = createFunctor(&GSRoot::exitGame);
-            functor->setObject(this);
-            this->ccExit_ = createConsoleCommand(functor, "exit");
-            CommandExecutor::addConsoleCommandShortcut(this->ccExit_);
-        }
-
-        {
-            // add console commands
-            FunctorMember01<GameStateBase, const std::string&>* functor = createFunctor(&GameStateBase::requestState);
-            functor->setObject(this);
-            this->ccSelectGameState_ = createConsoleCommand(functor, "selectGameState");
-            CommandExecutor::addConsoleCommandShortcut(this->ccSelectGameState_);
-        }
+        this->timeFactor_ = 1.0f;
 
         {
@@ -150,18 +85,38 @@
             CommandExecutor::addConsoleCommandShortcut(this->ccPause_).accessLevel(AccessLevel::Offline);
         }
-    }
-
-    void GSRoot::leave()
-    {
-        // destroy console commands
-        delete this->ccExit_;
-        delete this->ccSelectGameState_;
-
-        delete this->shell_;
-        delete this->tclThreadManager_;
-        delete this->tclBind_;
-
-        delete this->luaBind_;
-
+
+        // Load level directly?
+        bool loadLevel = false;
+        if (CommandLine::getValue("standalone").getBool())
+        {
+            Game::getInstance().requestStates("graphics, standalone, level");
+            loadLevel = true;
+        }
+        if (CommandLine::getValue("server").getBool())
+        {
+            Game::getInstance().requestStates("graphics, server, level");
+            loadLevel = true;
+        }
+        if (CommandLine::getValue("client").getBool())
+        {
+            Game::getInstance().requestStates("graphics, client, level");
+            loadLevel = true;
+        }
+        if (CommandLine::getValue("dedicated").getBool())
+        {
+            Game::getInstance().requestStates("dedicated, level");
+            loadLevel = true;
+        }
+        
+        // Determine where to start otherwise
+        if (!loadLevel && !CommandLine::getValue("console").getBool())
+        {
+            // Also load graphics
+            Game::getInstance().requestState("graphics");
+        }
+    }
+
+    void GSRoot::deactivate()
+    {
         if (this->ccSetTimeFactor_)
         {
@@ -177,9 +132,14 @@
     }
 
-    void GSRoot::ticked(const Clock& time)
-    {
+    void GSRoot::update(const Clock& time)
+    {
+        if (this->getActivity().topState)
+        {
+            // This state can not 'survive' on its own.
+            // Load a user interface therefore
+            Game::getInstance().requestState("ioConsole");
+        }
+
         uint64_t timeBeforeTick = time.getRealMicroseconds();
-
-        TclThreadManager::getInstance().tick(time.getDeltaTime());
 
         for (ObjectList<TimerBase>::iterator it = ObjectList<TimerBase>::begin(); it; ++it)
@@ -200,79 +160,6 @@
         uint64_t timeAfterTick = time.getRealMicroseconds();
 
-        // STATISTICS
-        assert(timeAfterTick - timeBeforeTick >= 0 );
-        statisticsTickInfo tickInfo = {timeAfterTick, timeAfterTick - timeBeforeTick};
-        statisticsTickTimes_.push_back(tickInfo);
-        assert(statisticsTickTimes_.back().tickLength==tickInfo.tickLength);
-        this->periodTickTime_ += tickInfo.tickLength;
-
-        // Ticks GSGraphics or GSDedicated
-        this->tickChild(time);
-
-        if (timeAfterTick > statisticsStartTime_ + statisticsRefreshCycle_)
-        {
-            std::list<statisticsTickInfo>::iterator it = this->statisticsTickTimes_.begin();
-            assert(it != this->statisticsTickTimes_.end());
-            int64_t lastTime = timeAfterTick - statisticsAvgLength_;
-            if ((int64_t)it->tickTime < lastTime)
-            {
-                do
-                {
-                    assert(this->periodTickTime_ > it->tickLength);
-                    this->periodTickTime_ -= it->tickLength;
-                    ++it;
-                    assert(it != this->statisticsTickTimes_.end());
-                } while ((int64_t)it->tickTime < lastTime);
-                this->statisticsTickTimes_.erase(this->statisticsTickTimes_.begin(), it);
-            }
-
-            uint32_t framesPerPeriod = this->statisticsTickTimes_.size();
-            this->avgFPS_ = (float)framesPerPeriod / (timeAfterTick - this->statisticsTickTimes_.front().tickTime) * 1000000.0;
-            this->avgTickTime_ = (float)this->periodTickTime_ / framesPerPeriod / 1000.0;
-
-            statisticsStartTime_ = timeAfterTick;
-        }
-
-    }
-
-    /**
-    @note
-        The code of this function has been copied and adjusted from OGRE, an open source graphics engine.
-            (Object-oriented Graphics Rendering Engine)
-        For the latest info, see http://www.ogre3d.org/
-
-        Copyright (c) 2000-2008 Torus Knot Software Ltd
-
-        OGRE is licensed under the LGPL. For more info, see OGRE license.
-    */
-    void GSRoot::setThreadAffinity(unsigned int limitToCPU)
-    {
-#ifdef ORXONOX_PLATFORM_WINDOWS
-        // Get the current process core mask
-        DWORD procMask;
-        DWORD sysMask;
-#  if _MSC_VER >= 1400 && defined (_M_X64)
-        GetProcessAffinityMask(GetCurrentProcess(), (PDWORD_PTR)&procMask, (PDWORD_PTR)&sysMask);
-#  else
-        GetProcessAffinityMask(GetCurrentProcess(), &procMask, &sysMask);
-#  endif
-
-        // If procMask is 0, consider there is only one core available
-        // (using 0 as procMask will cause an infinite loop below)
-        if (procMask == 0)
-            procMask = 1;
-
-        // if the core specified with limitToCPU is not available, take the lowest one
-        if (!(procMask & (1 << limitToCPU)))
-            limitToCPU = 0;
-
-        // Find the lowest core that this process uses and limitToCPU suggests
-        DWORD threadMask = 1;
-        while ((threadMask & procMask) == 0 || (threadMask < (1u << limitToCPU)))
-            threadMask <<= 1;
-
-        // Set affinity to the first core
-        SetThreadAffinityMask(GetCurrentThread(), threadMask);
-#endif
+        // Also add our tick time
+        Game::getInstance().addTickTime(timeAfterTick - timeBeforeTick);
     }
 
@@ -283,5 +170,5 @@
     void GSRoot::setTimeFactor(float factor)
     {
-        if (Core::isMaster())
+        if (GameMode::isMaster())
         {
             if (!this->bPaused_)
@@ -301,5 +188,5 @@
     void GSRoot::pause()
     {
-        if (Core::isMaster())
+        if (GameMode::isMaster())
         {
             if (!this->bPaused_)
@@ -316,13 +203,3 @@
         }
     }
-
-    ////////////////////////
-    // TimeFactorListener //
-    ////////////////////////
-    float TimeFactorListener::timefactor_s = 1.0f;
-
-    TimeFactorListener::TimeFactorListener()
-    {
-        RegisterRootObject(TimeFactorListener);
-    }
 }
Index: code/trunk/src/orxonox/gamestates/GSRoot.h
===================================================================
--- code/trunk/src/orxonox/gamestates/GSRoot.h	(revision 2894)
+++ code/trunk/src/orxonox/gamestates/GSRoot.h	(revision 2896)
@@ -31,29 +31,18 @@
 
 #include "OrxonoxPrereqs.h"
-
-#include <list>
-#include <OgreLog.h>
-#include "core/RootGameState.h"
+#include "core/GameState.h"
 #include "core/OrxonoxClass.h"
 
 namespace orxonox
 {
-    class _OrxonoxExport GSRoot : public RootGameState, public OrxonoxClass
+    class _OrxonoxExport GSRoot : public GameState
     {
-        friend class ClassIdentifier<GSRoot>;
-
     public:
-        struct statisticsTickInfo
-        {
-            uint64_t    tickTime;
-            uint32_t    tickLength;
-        };
-    
-    public:
-        GSRoot();
+        GSRoot(const std::string& name);
         ~GSRoot();
 
-        void exitGame()
-        { requestState("root"); }
+        void activate();
+        void deactivate();
+        void update(const Clock& time);
 
         // this has to be public because proteced triggers a bug in msvc
@@ -63,61 +52,12 @@
         float getTimeFactor() { return this->timeFactor_; }
 
-        float getAvgTickTime() { return this->avgTickTime_; }
-        float getAvgFPS()      { return this->avgFPS_; }
-
-        inline void addTickTime(uint32_t length)
-            { assert(!this->statisticsTickTimes_.empty()); this->statisticsTickTimes_.back().tickLength += length;
-              this->periodTickTime_+=length; }
-
     private:
-        void enter();
-        void leave();
-        void ticked(const Clock& time);
-
-        void setConfigValues();
-        void setThreadAffinity(unsigned int limitToCPU);
-
         float                 timeFactor_;       //!< A factor that sets the gamespeed. 1 is normal.
         bool                  bPaused_;
         float                 timeFactorPauseBackup_;
-        TclBind*              tclBind_;
-        TclThreadManager*     tclThreadManager_;
-        Shell*                shell_;
-        LuaBind*              luaBind_;
-
-        // variables for time statistics
-        uint64_t              statisticsStartTime_;
-        std::list<statisticsTickInfo>
-                              statisticsTickTimes_;
-        uint32_t              periodTickTime_;
-        float                 avgFPS_;
-        float                 avgTickTime_;
-
-        // config values
-        unsigned int          statisticsRefreshCycle_;
-        unsigned int          statisticsAvgLength_;
 
         // console commands
-        ConsoleCommand*       ccExit_;
-        ConsoleCommand*       ccSelectGameState_;
         ConsoleCommand*       ccSetTimeFactor_;
         ConsoleCommand*       ccPause_;
-    };
-
-    class _OrxonoxExport TimeFactorListener : virtual public OrxonoxClass
-    {
-        friend class GSRoot;
-
-        public:
-            TimeFactorListener();
-            virtual ~TimeFactorListener() {}
-
-        protected:
-            virtual void changedTimeFactor(float factor_new, float factor_old) {}
-            inline float getTimeFactor() const
-                { return TimeFactorListener::timefactor_s; }
-
-        private:
-            static float timefactor_s;
     };
 }
Index: code/trunk/src/orxonox/gamestates/GSServer.cc
===================================================================
--- code/trunk/src/orxonox/gamestates/GSServer.cc	(revision 2894)
+++ code/trunk/src/orxonox/gamestates/GSServer.cc	(revision 2896)
@@ -31,13 +31,16 @@
 
 #include "core/CommandLine.h"
-#include "core/Core.h"
+#include "core/Game.h"
+#include "core/GameMode.h"
 #include "network/Server.h"
 
 namespace orxonox
 {
+    AddGameState(GSServer, "server");
+
     SetCommandLineArgument(port, 55556).shortcut("p").information("0-65535");
 
-    GSServer::GSServer()
-        : GameState<GSGraphics>("server")
+    GSServer::GSServer(const std::string& name)
+        : GameState(name)
         , server_(0)
     {
@@ -48,31 +51,25 @@
     }
 
-    void GSServer::enter()
+    void GSServer::activate()
     {
-        Core::setHasServer(true);
+        GameMode::setHasServer(true);
 
         this->server_ = new Server(CommandLine::getValue("port"));
         COUT(0) << "Loading scene in server mode" << std::endl;
 
-        GSLevel::enter(this->getParent()->getViewport());
-
         server_->open();
     }
 
-    void GSServer::leave()
+    void GSServer::deactivate()
     {
-        GSLevel::leave();
-
         this->server_->close();
         delete this->server_;
 
-        Core::setHasServer(false);
+        GameMode::setHasServer(false);
     }
 
-    void GSServer::ticked(const Clock& time)
+    void GSServer::update(const Clock& time)
     {
-        GSLevel::ticked(time);
-        server_->tick(time.getDeltaTime());
-        this->tickChild(time);
+        server_->update(time);
     }
 }
Index: code/trunk/src/orxonox/gamestates/GSServer.h
===================================================================
--- code/trunk/src/orxonox/gamestates/GSServer.h	(revision 2894)
+++ code/trunk/src/orxonox/gamestates/GSServer.h	(revision 2896)
@@ -31,22 +31,21 @@
 
 #include "OrxonoxPrereqs.h"
+#include "core/GameState.h"
 #include "network/NetworkPrereqs.h"
-#include "GSLevel.h"
-#include "GSGraphics.h"
 
 namespace orxonox
 {
-    class _OrxonoxExport GSServer : public GameState<GSGraphics>, public GSLevel
+    class _OrxonoxExport GSServer : public GameState
     {
     public:
-        GSServer();
+        GSServer(const std::string& name);
         ~GSServer();
 
+        void activate();
+        void deactivate();
+        void update(const Clock& time);
+
     private:
-        void enter();
-        void leave();
-        void ticked(const Clock& time);
-
-        Server*      server_;
+        Server* server_;
     };
 }
Index: code/trunk/src/orxonox/gamestates/GSStandalone.cc
===================================================================
--- code/trunk/src/orxonox/gamestates/GSStandalone.cc	(revision 2894)
+++ code/trunk/src/orxonox/gamestates/GSStandalone.cc	(revision 2896)
@@ -32,16 +32,16 @@
 #include <OgreViewport.h>
 #include <OgreCamera.h>
-#include "core/Core.h"
+#include "core/Game.h"
+#include "core/GameMode.h"
 #include "core/ConsoleCommand.h"
 #include "gui/GUIManager.h"
+#include "GraphicsManager.h"
 
 namespace orxonox
 {
-    SetConsoleCommand(GSStandalone, showGUI, true).setAsInputCommand();
+    AddGameState(GSStandalone, "standalone");
 
-    bool GSStandalone::guiShowing_s = false;
-
-    GSStandalone::GSStandalone()
-        : GameState<GSGraphics>("standalone")
+    GSStandalone::GSStandalone(const std::string& name)
+        : GameState(name)
     {
     }
@@ -51,43 +51,17 @@
     }
 
-    void GSStandalone::showGUI()
+
+    void GSStandalone::activate()
     {
-        GSStandalone::guiShowing_s = true;
+        GameMode::setIsStandalone(true);
     }
 
-    void GSStandalone::enter()
+    void GSStandalone::deactivate()
     {
-        Core::setIsStandalone(true);
-
-        GSLevel::enter(this->getParent()->getViewport());
-
-        guiManager_ = getParent()->getGUIManager();
-        // not sure if necessary
-        // guiManager_->loadScene("IngameMenu");
+        GameMode::setIsStandalone(false);
     }
 
-    void GSStandalone::leave()
+    void GSStandalone::update(const Clock& time)
     {
-        GSLevel::leave();
-
-        Core::setIsStandalone(false);
-    }
-
-    void GSStandalone::ticked(const Clock& time)
-    {
-        if (guiShowing_s)
-        {
-            guiManager_->showGUI("IngameMenu", this->getParent()->getViewport()->getCamera()->getSceneManager());
-        }
-        else
-        {
-            if (guiManager_)
-                guiManager_->hideGUI();
-        }
-        // tick CEGUI
-        guiManager_->tick(time.getDeltaTime());
-
-        GSLevel::ticked(time);
-        this->tickChild(time);
     }
 }
Index: code/trunk/src/orxonox/gamestates/GSStandalone.h
===================================================================
--- code/trunk/src/orxonox/gamestates/GSStandalone.h	(revision 2894)
+++ code/trunk/src/orxonox/gamestates/GSStandalone.h	(revision 2896)
@@ -31,23 +31,19 @@
 
 #include "OrxonoxPrereqs.h"
-#include "GSLevel.h"
-#include "GSGraphics.h"
+#include "core/GameState.h"
 
 namespace orxonox
 {
-    class _OrxonoxExport GSStandalone : public GameState<GSGraphics>, public GSLevel
+    class _OrxonoxExport GSStandalone : public GameState
     {
     public:
-        GSStandalone();
+        GSStandalone(const std::string& name);
         ~GSStandalone();
-        static void showGUI();
+
+        void activate();
+        void deactivate();
+        void update(const Clock& time);
 
     private:
-        void enter();
-        void leave();
-        void ticked(const Clock& time);
-
-        GUIManager*     guiManager_;
-        static bool     guiShowing_s;
     };
 }
Index: code/trunk/src/orxonox/gui/GUIManager.cc
===================================================================
--- code/trunk/src/orxonox/gui/GUIManager.cc	(revision 2894)
+++ code/trunk/src/orxonox/gui/GUIManager.cc	(revision 2896)
@@ -22,6 +22,7 @@
  *   Author:
  *      Reto Grieder
+ *      Benjamin Knecht
  *   Co-authors:
- *      ...
+ *
  *
  */
@@ -36,7 +37,6 @@
 #include "GUIManager.h"
 
-#include <boost/filesystem.hpp>
+#include <boost/filesystem/path.hpp>
 #include <OgreRenderWindow.h>
-#include <OgreRoot.h>
 #include <CEGUI.h>
 #include <CEGUIDefaultLogger.h>
@@ -50,8 +50,7 @@
 
 #include "util/Exception.h"
-#include "core/input/InputManager.h"
-#include "core/input/SimpleInputState.h"
 #include "core/ConsoleCommand.h"
 #include "core/Core.h"
+#include "core/Clock.h"
 #include "ToluaBindCore.h"
 #include "ToluaBindOrxonox.h"
@@ -63,15 +62,8 @@
 namespace orxonox
 {
-    SetConsoleCommandShortcut(GUIManager, showGUI_s).keybindMode(KeybindMode::OnPress);
-
     GUIManager* GUIManager::singletonRef_s = 0;
 
     GUIManager::GUIManager()
-        //: emptySceneManager_(0)
-        : backgroundSceneManager_(0)
-        //, emptyCamera_(0)
-        , backgroundCamera_(0)
-        //, viewport_(0)
-        , renderWindow_(0)
+        : renderWindow_(0)
         , guiRenderer_(0)
         , resourceProvider_(0)
@@ -84,20 +76,12 @@
     }
 
+    /**
+    @brief
+        Deconstructor of the GUIManager
+
+        Basically shuts down CEGUI and destroys the Lua engine and afterwards the interface to the Ogre engine.
+    */
     GUIManager::~GUIManager()
     {
-        if (backgroundCamera_)
-            backgroundSceneManager_->destroyCamera(backgroundCamera_);
-
-        if (backgroundSceneManager_)
-        {
-            // We have to make sure the SceneManager is not anymore referenced.
-            // For the case that the target SceneManager was yet another one, it
-            // wouldn't matter anyway since this is the destructor.
-            guiRenderer_->setTargetSceneManager(0);
-            Ogre::Root::getSingleton().destroySceneManager(backgroundSceneManager_);
-        }
-
-        InputManager::getInstance().requestDestroyState("gui");
-
         if (guiSystem_)
             delete guiSystem_;
@@ -110,8 +94,4 @@
 	        lua_pushnil(luaState_);
 	        lua_setglobal(luaState_, "Core");
-            // TODO: deleting the script module fails an assertion.
-            // However there is not much we can do about it since it occurs too when
-            // we don't open Core or Orxonox. Might be a CEGUI issue.
-            // The memory leak is not a problem anyway..
             delete scriptModule_;
         }
@@ -123,4 +103,18 @@
     }
 
+    /**
+    @brief
+        Initialises the GUIManager by starting up CEGUI
+    @param renderWindow
+        Ogre's render window. Without this, the GUI cannot be displayed.
+    @return true if success, otherwise false
+
+        Before this call the GUIManager won't do anything, but can be accessed.
+
+        Creates the interface to Ogre, sets up the CEGUI renderer and the Lua script module together with the Lua engine.
+        The log is set up and connected to the CEGUILogger.
+        After Lua setup tolua++-elements are linked to Lua-state to give Lua access to C++-code.
+        Finally initial Lua code is executed (maybe we can do this with the CEGUI startup script automatically).
+    */
     bool GUIManager::initialise(Ogre::RenderWindow* renderWindow)
     {
@@ -135,13 +129,6 @@
                 renderWindow_ = renderWindow;
 
-                // Full screen viewport with Z order = 0 (top most). Don't yet feed a camera (so nothing gets rendered)
-                //this->viewport_ = renderWindow_->addViewport(0, 3);
-                //this->viewport_->setOverlaysEnabled(false);
-                //this->viewport_->setShadowsEnabled(false);
-                //this->viewport_->setSkiesEnabled(false);
-                //this->viewport_->setClearEveryFrame(false);
-
                 // Note: No SceneManager specified yet
-                this->guiRenderer_ = new OgreCEGUIRenderer(renderWindow_, Ogre::RENDER_QUEUE_MAIN, true, 3000);
+                this->guiRenderer_ = new OgreCEGUIRenderer(renderWindow_, Ogre::RENDER_QUEUE_OVERLAY, true, 3000);
                 this->resourceProvider_ = guiRenderer_->createResourceProvider();
                 this->resourceProvider_->setDefaultResourceGroup("GUI");
@@ -166,13 +153,6 @@
                 tolua_Orxonox_open(this->scriptModule_->getLuaState());
 
-                // register us as input handler
-                SimpleInputState* state = InputManager::getInstance().createInputState<SimpleInputState>("gui", 30);
-                state->setHandler(this);
-                state->setJoyStickHandler(&InputManager::EMPTY_HANDLER);
-
-                // load the background scene
-                //loadScenes();
-                //CEGUI::KeyEventArgs e;
-                //e.codepoint
+                // initialise the basic lua code
+                loadLuaCode();
             }
             catch (CEGUI::Exception& ex)
@@ -192,61 +172,24 @@
     }
 
-    void GUIManager::loadScene(const std::string& name)
-    {
-        if (name.compare("IngameMenu") == 0)
-        {
-            try
-            {
-                /*this->scriptModule_ = new LuaScriptModule();
-                this->luaState_ = this->scriptModule_->getLuaState();
-                this->guiSystem_ = new System(this->guiRenderer_, this->resourceProvider_, 0, this->scriptModule_);
-                tolua_Core_open(this->scriptModule_->getLuaState());
-                tolua_Orxonox_open(this->scriptModule_->getLuaState());
-                */
-                this->scriptModule_->executeScriptFile("ingameGUI.lua", "GUI");
-            }
-            catch (CEGUI::Exception& ex)
-            {
-#if CEGUI_VERSION_MINOR < 6
-                throw GeneralException(ex.getMessage().c_str());
-#else
-                throw GeneralException(ex.getMessage().c_str(), ex.getLine(),
-                                       ex.getFileName().c_str(), ex.getName().c_str());
-#endif
-            }
-        }
-        else
-        {
-            loadScenes();
-        }
-    }
-
-    void GUIManager::loadScenes()
-    {
-        // first of all, we need to have our own SceneManager for the GUI. The reason
-        // is that we might have multiple viewports when in play mode (e.g. the view of
-        // a camera fixed at the back of the ship). That forces us to create our own
-        // full screen viewport that is on top of all the others, but doesn't clear the
-        // port before rendering, so everything from the GUI gets on top eventually.
-        // But in order to realise that, we also need a SceneManager with an empty scene,
-        // because the SceneManager is responsible for the render queue.
-        //this->emptySceneManager_ = Ogre::Root::getSingleton()
-        //    .createSceneManager(Ogre::ST_GENERIC, "GUI/EmptySceneManager");
-
-        // we also need a camera or we won't see anything at all.
-        // The camera settings don't matter at all for an empty scene since the GUI
-        // gets rendered on top of the screen rather than into the scene.
-        //this->emptyCamera_ = this->emptySceneManager_->createCamera("GUI/EmptyCamera");
-
-        // Create another SceneManager that enables to display some 3D
-        // scene in the background of the main menu.
-        this->backgroundSceneManager_ = Ogre::Root::getSingleton()
-            .createSceneManager(Ogre::ST_GENERIC, "GUI/BackgroundSceneManager");
-        this->backgroundCamera_ = backgroundSceneManager_->createCamera("GUI/BackgroundCamera");
-
-        // TODO: create something 3D
+    /**
+    @brief
+        Calls main Lua script
+    @todo
+        Replace loadGUI.lua with loadGUI_2.lua after merging this back to trunk.
+        However CEGUI is able to execute a startup script. We could maybe put this call in this startup code.
+
+        This function calls the main Lua script for our GUI.
+
+        Additionally we set the datapath variable in Lua. This is needed so Lua can access the data used for the GUI.
+    */
+    void GUIManager::loadLuaCode()
+    {
         try
         {
-            this->scriptModule_->executeScriptFile("loadGUI.lua", "GUI");
+            // call main Lua script
+            this->scriptModule_->executeScriptFile("loadGUI_2.lua", "GUI");
+            // set datapath for GUI data
+            lua_pushfstring(this->scriptModule_->getLuaState(), Core::getMediaPathString().c_str());
+            lua_setglobal(this->scriptModule_->getLuaState(), "datapath");
         }
         catch (CEGUI::Exception& ex)
@@ -261,40 +204,72 @@
     }
 
-    void GUIManager::showGUI(const std::string& name, Ogre::SceneManager* sceneManager)// bool showBackground)
+    /**
+    @brief
+        used to tick the GUI
+    @param time
+        clock which provides time value for the GUI System
+
+        Ticking the GUI means updating it with a certain regularity.
+        The elapsed time since the last call is given in the time value provided by the clock.
+        This time value is then used to provide a fluent animation of the GUI.
+    */
+    void GUIManager::update(const Clock& time)
+    {
+        assert(guiSystem_);
+        guiSystem_->injectTimePulse(time.getDeltaTime());
+    }
+
+    /**
+    @brief
+        Executes Lua code
+    @param str
+        reference to string object holding the Lua code which is to be executed
+
+        This function gives total access to the GUI. You can execute ANY Lua code here.
+    */
+    void GUIManager::executeCode(const std::string& str)
+    {
+        try
+        {
+            this->scriptModule_->executeString(str);
+        }
+        catch (CEGUI::Exception& ex)
+        {
+            COUT(2) << "CEGUI Error: \"" << ex.getMessage() << "\" while executing code \"" << str << "\"" << std::endl;
+        }
+    }
+
+    /**
+    @brief
+        Tells the GUIManager which SceneManager to use
+    @param camera
+        The current camera on which the GUI should be displayed on.
+
+        In fact the GUIManager needs the SceneManager and not the Camera to display the GUI.
+        This means the GUI is not bound to a camera but rather to the SceneManager.
+        Hidding the GUI when needed can therefore not be solved by just NOT setting the current camera.
+    */
+    void GUIManager::setCamera(Ogre::Camera* camera)
+    {
+        this->guiRenderer_->setTargetSceneManager(camera->getSceneManager());
+    }
+
+    /**
+    @brief
+        Displays specified GUI on screen
+    @param name
+        The name of the GUI
+
+        The function executes the Lua function with the same name in case the GUIManager is ready.
+        For more details check out loadGUI_2.lua where the function presides.
+    */
+    void GUIManager::showGUI(const std::string& name)
     {
         if (state_ != Uninitialised)
         {
-            if (state_ == OnDisplay)
-                hideGUI();
-
-            COUT(3) << "Loading GUI " << name << std::endl;
+            //COUT(3) << "Loading GUI " << name << std::endl;
             try
             {
-                COUT (0) << "************* sceneManager: " << sceneManager << std::endl;
-                if (!sceneManager)
-                {
-                    // currently, only an image is loaded. We could do 3D, see loadBackground.
-                    //this->viewport_->setClearEveryFrame(true);
-                    this->guiRenderer_->setTargetSceneManager(this->backgroundSceneManager_);
-                    //this->viewport_->setCamera(this->backgroundCamera_);
-
-                    lua_pushboolean(this->scriptModule_->getLuaState(), true);
-                    lua_setglobal(this->scriptModule_->getLuaState(), "showBackground");
-                }
-                else
-                {
-                    //this->viewport_->setClearEveryFrame(false);
-                    this->guiRenderer_->setTargetSceneManager(sceneManager);
-                    //this->viewport_->setCamera(this->emptyCamera_);
-
-                    lua_pushboolean(this->scriptModule_->getLuaState(), false);
-                    lua_setglobal(this->scriptModule_->getLuaState(), "showBackground");
-                }
-
-                this->scriptModule_->executeScriptGlobal("showMainMenu");
-
-                InputManager::getInstance().requestEnterState("gui");
-
-                this->state_ = OnDisplay;
+                this->scriptModule_->executeString(std::string("showGUI(\"") + name + "\")");
             }
             catch (CEGUI::Exception& ex)
@@ -313,15 +288,13 @@
     }
 
-    void GUIManager::hideGUI()
-    {
-        if (this->state_ != OnDisplay)
-            return;
-        //this->viewport_->setCamera(0);
-        // has no effect since you cannot assign 0 as SceneManager
-        //this->guiRenderer_->setTargetSceneManager(0);
-        this->state_ = Ready;
-        InputManager::getInstance().requestLeaveState("gui");
-    }
-
+    /**
+    @brief
+        Function receiving a mouse button pressed event.
+    @param id
+        ID of the mouse button which got pressed
+
+        This function is inherited by MouseHandler and injects the event into CEGUI.
+        It is for CEGUI to process the event.
+    */
     void GUIManager::mouseButtonPressed(MouseButtonCode::ByEnum id)
     {
@@ -337,4 +310,13 @@
     }
 
+    /**
+    @brief
+        Function receiving a mouse button released event.
+    @param id
+        ID of the mouse button which got released
+
+        This function is inherited by MouseHandler and injects the event into CEGUI.
+        It is for CEGUI to process the event.
+    */
     void GUIManager::mouseButtonReleased(MouseButtonCode::ByEnum id)
     {
@@ -350,5 +332,14 @@
     }
 
-
+    /**
+    @brief
+        converts mouse event code to CEGUI event code
+    @param button
+        code of the mouse button as we use it in Orxonox
+    @return
+        code of the mouse button as it is used by CEGUI
+
+        Simple convertion from mouse event code in Orxonox to the one used in CEGUI.
+     */
     inline CEGUI::MouseButton GUIManager::convertButton(MouseButtonCode::ByEnum button)
     {
Index: code/trunk/src/orxonox/gui/GUIManager.h
===================================================================
--- code/trunk/src/orxonox/gui/GUIManager.h	(revision 2894)
+++ code/trunk/src/orxonox/gui/GUIManager.h	(revision 2896)
@@ -23,5 +23,5 @@
  *      Reto Grieder
  *   Co-authors:
- *      ...
+ *      Benjamin Knecht
  *
  */
@@ -49,6 +49,13 @@
 {
     /**
+    @class GUIManager
     @brief
-        Provides a simple interface to CEGUI with tolua methods and console commands
+        Provides a simple interface to CEGUI with tolua methods and console commands. It also acts as a key and mouse handler.
+
+        The GUIManager is a singleton and can be called anywhere when access on the GUI is needed.
+        Creation of the GUIManager is therefore not possible and the cunstructor is private.
+
+        Since the GUI needs user input, the GUIManager implements the functions needed to act as a key and/or mouse handler.
+        Those input events are then injected into CEGUI in Lua.
     */
     class _OrxonoxExport GUIManager
@@ -59,9 +66,13 @@
 // tolua_end
     public:
+        /**
+        @enum State
+            The current state of the GUIManager. There should maybe be more (or we can omit this totally).
+        */
         enum State
         {
-            Uninitialised,
-            Ready,
-            OnDisplay
+            Uninitialised,  //!< Initial state of the GUIManager
+            Ready,          //!< State after initialisation if ready
+            OnDisplay       //!< State if GUI is displayed
         };
 
@@ -70,19 +81,11 @@
 
         bool initialise(Ogre::RenderWindow* renderWindow);
-        void loadScene(const std::string& name);
-        void tick(float dt)
-        {
-            assert(guiSystem_);
-            guiSystem_->injectTimePulse(dt);
-        }
-        void showGUI(const std::string& name, Ogre::SceneManager* sceneManager);// bool showBackground); // tolua_export
-        void hideGUI(); // tolua_export
 
-        Ogre::Camera* getCamera() { return this->backgroundCamera_; }
+        void update(const Clock& time);
 
-        static void showGUI_s(const std::string& name, Ogre::SceneManager* sceneManager)//bool showBackground)
-        {
-            getInstance().showGUI(name, sceneManager);
-        }
+        void showGUI(const std::string& name);
+        void executeCode(const std::string& str);
+
+        void setCamera(Ogre::Camera* camera);
 
         static GUIManager& getInstance()    { assert(singletonRef_s); return *singletonRef_s; } // tolua_export
@@ -90,47 +93,41 @@
 
     private:
-        GUIManager(const GUIManager& instance);
+        GUIManager(const GUIManager& instance);                 //!< private constructor (this is a singleton class)
 
+        void loadLuaCode();
+
+        // keyHandler functions
         void keyPressed (const KeyEvent& evt)
-        { guiSystem_->injectKeyDown(evt.key); guiSystem_->injectChar(evt.text); }
+            { guiSystem_->injectKeyDown(evt.key); guiSystem_->injectChar(evt.text); }
         void keyReleased(const KeyEvent& evt)
-        { guiSystem_->injectKeyUp(evt.key); }
-        void keyHeld    (const KeyEvent& evt)
-        { }
+            { guiSystem_->injectKeyUp(evt.key); }
+        void keyHeld    (const KeyEvent& evt) { }
 
+        // mouseHandler functions
         void mouseButtonPressed (MouseButtonCode::ByEnum id);
         void mouseButtonReleased(MouseButtonCode::ByEnum id);
-        void mouseButtonHeld    (MouseButtonCode::ByEnum id)
-        { }
+        void mouseButtonHeld    (MouseButtonCode::ByEnum id) { }
         void mouseMoved         (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize)
-        { guiSystem_->injectMouseMove(rel.x, rel.y); }
+            { guiSystem_->injectMouseMove(rel.x, rel.y); }
         void mouseScrolled      (int abs, int rel)
-        { guiSystem_->injectMouseWheelChange(rel);}
+            { guiSystem_->injectMouseWheelChange(rel);}
 
-        void tickInput(float dt) { }
-        void tickKey(float dt) { }
-        void tickMouse(float dt) { }
-
-        void loadScenes();
-
-        //Ogre::SceneManager*       emptySceneManager_;
-        Ogre::SceneManager*       backgroundSceneManager_;
-        //Ogre::Camera*             emptyCamera_;
-        Ogre::Camera*             backgroundCamera_;
-        //Ogre::Viewport*           viewport_;
-        Ogre::RenderWindow*       renderWindow_;
-        CEGUI::OgreCEGUIRenderer* guiRenderer_;
-        CEGUI::ResourceProvider*  resourceProvider_;
-        CEGUI::LuaScriptModule*   scriptModule_;
-        CEGUI::DefaultLogger*     ceguiLogger_;
-        CEGUI::System*            guiSystem_;
-        CEGUI::Imageset*          backgroundImage_;
-        lua_State*                luaState_;
-
-        State state_;
+        void updateInput(float dt)  { }
+        void updateKey  (float dt)  { }
+        void updateMouse(float dt)  { }
 
         static CEGUI::MouseButton convertButton(MouseButtonCode::ByEnum button);
 
-        static GUIManager*        singletonRef_s;
+        Ogre::RenderWindow*         renderWindow_;      //!< Ogre's render window to give CEGUI access to it
+        CEGUI::OgreCEGUIRenderer*   guiRenderer_;       //!< CEGUI's interface to the Ogre Engine
+        CEGUI::ResourceProvider*    resourceProvider_;  //!< CEGUI's resource provider
+        CEGUI::LuaScriptModule*     scriptModule_;      //!< CEGUI's script module to use Lua
+        CEGUI::DefaultLogger*       ceguiLogger_;       //!< CEGUI's logger to be able to log CEGUI errors in our log
+        CEGUI::System*              guiSystem_;         //!< CEGUI's main system
+        lua_State*                  luaState_;          //!< Lua state, access point to the Lua engine
+
+        State                       state_;             //!< reflects state of the GUIManager
+
+        static GUIManager*          singletonRef_s;     //!< Singleton reference to GUIManager
     }; // tolua_export
 } // tolua_export
Index: code/trunk/src/orxonox/objects/EventTarget.cc
===================================================================
--- code/trunk/src/orxonox/objects/EventTarget.cc	(revision 2894)
+++ code/trunk/src/orxonox/objects/EventTarget.cc	(revision 2896)
@@ -66,5 +66,5 @@
     void EventTarget::addAsEvent(BaseObject* object)
     {
-        if (object != (BaseObject*)this)
+        if (object != static_cast<BaseObject*>(this))
             object->addEvent(this, "");
     }
Index: code/trunk/src/orxonox/objects/Radar.cc
===================================================================
--- code/trunk/src/orxonox/objects/Radar.cc	(revision 2894)
+++ code/trunk/src/orxonox/objects/Radar.cc	(revision 2896)
@@ -144,5 +144,5 @@
             for (ObjectList<RadarViewable>::iterator it = ObjectList<RadarViewable>::begin(); it; ++it)
             {
-                if (*it == (RadarViewable*)this->owner_)
+                if (*it == static_cast<RadarViewable*>(this)->owner_)
                     continue;
 
Index: code/trunk/src/orxonox/objects/Scene.cc
===================================================================
--- code/trunk/src/orxonox/objects/Scene.cc	(revision 2894)
+++ code/trunk/src/orxonox/objects/Scene.cc	(revision 2896)
@@ -41,5 +41,5 @@
 
 #include "core/CoreIncludes.h"
-#include "core/Core.h"
+#include "core/GameMode.h"
 #include "core/XMLPort.h"
 #include "tools/BulletConversions.h"
@@ -57,5 +57,5 @@
         this->bShadows_ = true;
 
-        if (Core::showsGraphics())
+        if (GameMode::showsGraphics())
         {
             if (Ogre::Root::getSingletonPtr())
@@ -99,5 +99,5 @@
                 Ogre::Root::getSingleton().destroySceneManager(this->sceneManager_);
             }
-            else if (!Core::showsGraphics())
+            else if (!GameMode::showsGraphics())
             {
                 delete this->sceneManager_;
@@ -227,5 +227,5 @@
     void Scene::tick(float dt)
     {
-        if (!Core::showsGraphics())
+        if (!GameMode::showsGraphics())
         {
             // We need to update the scene nodes if we don't render
@@ -256,5 +256,5 @@
     void Scene::setSkybox(const std::string& skybox)
     {
-        if (Core::showsGraphics() && this->sceneManager_)
+        if (GameMode::showsGraphics() && this->sceneManager_)
             this->sceneManager_->setSkyBox(true, skybox);
 
@@ -264,5 +264,5 @@
     void Scene::setAmbientLight(const ColourValue& colour)
     {
-        if (Core::showsGraphics() && this->sceneManager_)
+        if (GameMode::showsGraphics() && this->sceneManager_)
             this->sceneManager_->setAmbientLight(colour);
 
@@ -272,5 +272,5 @@
     void Scene::setShadow(bool bShadow)
     {
-        if (Core::showsGraphics() && this->sceneManager_)
+        if (GameMode::showsGraphics() && this->sceneManager_)
         {
             if (bShadow)
Index: code/trunk/src/orxonox/objects/controllers/AIController.cc
===================================================================
--- code/trunk/src/orxonox/objects/controllers/AIController.cc	(revision 2894)
+++ code/trunk/src/orxonox/objects/controllers/AIController.cc	(revision 2896)
@@ -30,5 +30,5 @@
 #include "AIController.h"
 
-#include "core/Core.h"
+#include "core/GameMode.h"
 #include "core/CoreIncludes.h"
 #include "core/Executor.h"
@@ -45,5 +45,5 @@
         RegisterObject(AIController);
 
-        if (Core::isMaster())
+        if (GameMode::isMaster())
             this->actionTimer_.setTimer(ACTION_INTERVAL, true, this, createExecutor(createFunctor(&AIController::action)));
     }
Index: code/trunk/src/orxonox/objects/gametypes/Gametype.cc
===================================================================
--- code/trunk/src/orxonox/objects/gametypes/Gametype.cc	(revision 2894)
+++ code/trunk/src/orxonox/objects/gametypes/Gametype.cc	(revision 2896)
@@ -36,5 +36,5 @@
 #include "core/ConfigValueIncludes.h"
 #include "core/Template.h"
-#include "core/Core.h"
+#include "core/GameMode.h"
 #include "overlays/OverlayGroup.h"
 #include "objects/infos/PlayerInfo.h"
@@ -65,5 +65,5 @@
 
         // load the corresponding score board
-        if (Core::showsGraphics() && this->scoreboardTemplate_ != "")
+        if (GameMode::showsGraphics() && this->scoreboardTemplate_ != "")
         {
             this->scoreboard_ = new OverlayGroup(this);
Index: code/trunk/src/orxonox/objects/infos/Bot.cc
===================================================================
--- code/trunk/src/orxonox/objects/infos/Bot.cc	(revision 2894)
+++ code/trunk/src/orxonox/objects/infos/Bot.cc	(revision 2896)
@@ -30,5 +30,5 @@
 #include "Bot.h"
 
-#include "core/Core.h"
+#include "core/GameMode.h"
 #include "core/CoreIncludes.h"
 #include "core/ConfigValueIncludes.h"
@@ -46,5 +46,5 @@
 
         this->bHumanPlayer_ = false;
-        this->bLocalPlayer_ = Core::isMaster();
+        this->bLocalPlayer_ = GameMode::isMaster();
         this->bSetUnreadyAfterSpawn_ = false;
         this->setReadyToSpawn(true);
Index: code/trunk/src/orxonox/objects/infos/HumanPlayer.cc
===================================================================
--- code/trunk/src/orxonox/objects/infos/HumanPlayer.cc	(revision 2894)
+++ code/trunk/src/orxonox/objects/infos/HumanPlayer.cc	(revision 2896)
@@ -30,5 +30,5 @@
 #include "HumanPlayer.h"
 
-#include "core/Core.h"
+#include "core/GameMode.h"
 #include "core/CoreIncludes.h"
 #include "core/ConfigValueIncludes.h"
@@ -47,5 +47,5 @@
         RegisterObject(HumanPlayer);
 
-        this->server_initialized_ = Core::isMaster();
+        this->server_initialized_ = GameMode::isMaster();
         this->client_initialized_ = false;
 
@@ -93,5 +93,5 @@
             this->synchronize_nick_ = this->nick_;
 
-            if (Core::isMaster())
+            if (GameMode::isMaster())
                 this->setName(this->nick_);
         }
@@ -116,5 +116,5 @@
             this->client_initialized_ = true;
 
-            if (!Core::isMaster())
+            if (!GameMode::isMaster())
                 this->setObjectMode(objectDirection::bidirectional);
             else
Index: code/trunk/src/orxonox/objects/items/MultiStateEngine.cc
===================================================================
--- code/trunk/src/orxonox/objects/items/MultiStateEngine.cc	(revision 2894)
+++ code/trunk/src/orxonox/objects/items/MultiStateEngine.cc	(revision 2896)
@@ -30,5 +30,5 @@
 #include "MultiStateEngine.h"
 
-#include "core/Core.h"
+#include "core/GameMode.h"
 #include "core/CoreIncludes.h"
 #include "core/XMLPort.h"
@@ -123,5 +123,5 @@
             }
 
-            if (Core::isMaster())
+            if (GameMode::isMaster())
             {
                 for (std::list<WorldEntity*>::const_iterator it = this->activeEffects_.begin(); it != this->activeEffects_.end(); ++it)
Index: code/trunk/src/orxonox/objects/pickup/PickupSpawner.cc
===================================================================
--- code/trunk/src/orxonox/objects/pickup/PickupSpawner.cc	(revision 2894)
+++ code/trunk/src/orxonox/objects/pickup/PickupSpawner.cc	(revision 2896)
@@ -89,5 +89,5 @@
 		ExecutorMember<BaseObject>* executor = createExecutor(createFunctor(&BaseObject::setActive));
 		executor->setDefaultValues(true);
-		RespawnTimer_.setTimer(this->respawntimer_, false, (BaseObject*)this, executor);
+		RespawnTimer_.setTimer(this->respawntimer_, false, this, executor);
 		COUT(0) << "TIMER SET" << std::endl;
 	}
Index: code/trunk/src/orxonox/objects/weaponSystem/projectiles/BillboardProjectile.cc
===================================================================
--- code/trunk/src/orxonox/objects/weaponSystem/projectiles/BillboardProjectile.cc	(revision 2894)
+++ code/trunk/src/orxonox/objects/weaponSystem/projectiles/BillboardProjectile.cc	(revision 2896)
@@ -32,5 +32,5 @@
 #include <OgreBillboardSet.h>
 
-#include "core/Core.h"
+#include "core/GameMode.h"
 #include "core/CoreIncludes.h"
 #include "objects/Scene.h"
@@ -44,5 +44,5 @@
         RegisterObject(BillboardProjectile);
 
-        if (Core::showsGraphics())
+        if (GameMode::showsGraphics())
         {
             assert(this->getScene()->getSceneManager()); // getScene() was already checked by WorldEntity
@@ -56,5 +56,5 @@
     BillboardProjectile::~BillboardProjectile()
     {
-        if (this->isInitialized() && Core::showsGraphics() && this->billboard_.getBillboardSet())
+        if (this->isInitialized() && GameMode::showsGraphics() && this->billboard_.getBillboardSet())
             this->detachOgreObject(this->billboard_.getBillboardSet());
     }
Index: code/trunk/src/orxonox/objects/weaponSystem/projectiles/ParticleProjectile.cc
===================================================================
--- code/trunk/src/orxonox/objects/weaponSystem/projectiles/ParticleProjectile.cc	(revision 2894)
+++ code/trunk/src/orxonox/objects/weaponSystem/projectiles/ParticleProjectile.cc	(revision 2896)
@@ -33,5 +33,5 @@
 #include <OgreParticleEmitter.h>
 
-#include "core/Core.h"
+#include "core/GameMode.h"
 #include "core/CoreIncludes.h"
 #include "core/ConfigValueIncludes.h"
@@ -46,5 +46,5 @@
         RegisterObject(ParticleProjectile);
 
-        if (Core::showsGraphics())
+        if (GameMode::showsGraphics())
         {
             this->particles_ = new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/shot3_small", LODParticle::normal);
Index: code/trunk/src/orxonox/objects/weaponSystem/projectiles/Projectile.cc
===================================================================
--- code/trunk/src/orxonox/objects/weaponSystem/projectiles/Projectile.cc	(revision 2894)
+++ code/trunk/src/orxonox/objects/weaponSystem/projectiles/Projectile.cc	(revision 2896)
@@ -41,5 +41,5 @@
 #include "objects/worldentities/ParticleSpawner.h"
 #include "objects/collisionshapes/SphereCollisionShape.h"
-#include "core/Core.h"
+#include "core/GameMode.h"
 
 namespace orxonox
@@ -55,5 +55,5 @@
         // Get notification about collisions
 
-        if (Core::isMaster())
+        if (GameMode::isMaster())
         {
             this->enableCollisionCallback();
@@ -93,5 +93,5 @@
     void Projectile::destroyObject()
     {
-        if (Core::isMaster())
+        if (GameMode::isMaster())
             delete this;
     }
@@ -99,5 +99,5 @@
     bool Projectile::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint)
     {
-        if (!this->bDestroy_ && Core::isMaster())
+        if (!this->bDestroy_ && GameMode::isMaster())
         {
             this->bDestroy_ = true;
Index: code/trunk/src/orxonox/objects/worldentities/Backlight.cc
===================================================================
--- code/trunk/src/orxonox/objects/worldentities/Backlight.cc	(revision 2894)
+++ code/trunk/src/orxonox/objects/worldentities/Backlight.cc	(revision 2896)
@@ -33,5 +33,5 @@
 #include <OgreSceneManager.h>
 
-#include "core/Core.h"
+#include "core/GameMode.h"
 #include "core/CoreIncludes.h"
 #include "core/Executor.h"
@@ -58,5 +58,5 @@
         this->tickcount_ = 0;
 
-        if (Core::showsGraphics())
+        if (GameMode::showsGraphics())
         {
             if (!this->getScene())
Index: code/trunk/src/orxonox/objects/worldentities/Backlight.h
===================================================================
--- code/trunk/src/orxonox/objects/worldentities/Backlight.h	(revision 2894)
+++ code/trunk/src/orxonox/objects/worldentities/Backlight.h	(revision 2896)
@@ -32,5 +32,5 @@
 #include "OrxonoxPrereqs.h"
 #include "FadingBillboard.h"
-#include "gamestates/GSRoot.h"
+#include "tools/TimeFactorListener.h"
 
 namespace orxonox
Index: code/trunk/src/orxonox/objects/worldentities/Billboard.cc
===================================================================
--- code/trunk/src/orxonox/objects/worldentities/Billboard.cc	(revision 2894)
+++ code/trunk/src/orxonox/objects/worldentities/Billboard.cc	(revision 2896)
@@ -34,5 +34,5 @@
 #include "core/CoreIncludes.h"
 #include "core/XMLPort.h"
-#include "core/Core.h"
+#include "core/GameMode.h"
 #include "objects/Scene.h"
 
@@ -81,5 +81,5 @@
         if (!this->billboard_.getBillboardSet())
         {
-            if (this->getScene() && Core::showsGraphics())
+            if (this->getScene() && GameMode::showsGraphics())
             {
                 this->billboard_.setBillboardSet(this->getScene()->getSceneManager(), this->material_, this->colour_, 1);
@@ -98,5 +98,5 @@
         {
 /*
-            if (this->getScene() && Core::showsGraphics() && (this->material_ != ""))
+            if (this->getScene() && GameMode::showsGraphics() && (this->material_ != ""))
             {
                 this->billboard_.setBillboardSet(this->getScene()->getSceneManager(), this->material_, this->colour_, 1);
Index: code/trunk/src/orxonox/objects/worldentities/BlinkingBillboard.cc
===================================================================
--- code/trunk/src/orxonox/objects/worldentities/BlinkingBillboard.cc	(revision 2894)
+++ code/trunk/src/orxonox/objects/worldentities/BlinkingBillboard.cc	(revision 2896)
@@ -30,5 +30,5 @@
 #include "BlinkingBillboard.h"
 
-#include "core/Core.h"
+#include "core/GameMode.h"
 #include "core/CoreIncludes.h"
 #include "core/XMLPort.h"
@@ -77,5 +77,5 @@
         SUPER(BlinkingBillboard, tick, dt);
 
-        if (Core::isMaster() && this->isActive())
+        if (GameMode::isMaster() && this->isActive())
         {
             this->time_ += dt;
Index: code/trunk/src/orxonox/objects/worldentities/ControllableEntity.cc
===================================================================
--- code/trunk/src/orxonox/objects/worldentities/ControllableEntity.cc	(revision 2894)
+++ code/trunk/src/orxonox/objects/worldentities/ControllableEntity.cc	(revision 2896)
@@ -34,5 +34,5 @@
 #include "core/CoreIncludes.h"
 #include "core/ConfigValueIncludes.h"
-#include "core/Core.h"
+#include "core/GameMode.h"
 #include "core/XMLPort.h"
 #include "core/Template.h"
@@ -245,5 +245,5 @@
             this->startLocalHumanControl();
 
-            if (!Core::isMaster())
+            if (!GameMode::isMaster())
             {
                 this->client_overwrite_ = this->server_overwrite_;
@@ -357,5 +357,5 @@
             if (!this->isDynamic())
             {
-                if (Core::isMaster())
+                if (GameMode::isMaster())
                 {
                     this->server_position_ = this->getPosition();
@@ -472,5 +472,5 @@
     void ControllableEntity::setPosition(const Vector3& position)
     {
-        if (Core::isMaster())
+        if (GameMode::isMaster())
         {
             MobileEntity::setPosition(position);
@@ -487,5 +487,5 @@
     void ControllableEntity::setOrientation(const Quaternion& orientation)
     {
-        if (Core::isMaster())
+        if (GameMode::isMaster())
         {
             MobileEntity::setOrientation(orientation);
@@ -502,5 +502,5 @@
     void ControllableEntity::setVelocity(const Vector3& velocity)
     {
-        if (Core::isMaster())
+        if (GameMode::isMaster())
         {
             MobileEntity::setVelocity(velocity);
@@ -517,5 +517,5 @@
     void ControllableEntity::setAngularVelocity(const Vector3& velocity)
     {
-        if (Core::isMaster())
+        if (GameMode::isMaster())
         {
             MobileEntity::setAngularVelocity(velocity);
@@ -533,5 +533,5 @@
     {
         MobileEntity::setWorldTransform(worldTrans);
-        if (Core::isMaster())
+        if (GameMode::isMaster())
         {
             this->server_position_ = this->getPosition();
Index: code/trunk/src/orxonox/objects/worldentities/ExplosionChunk.cc
===================================================================
--- code/trunk/src/orxonox/objects/worldentities/ExplosionChunk.cc	(revision 2894)
+++ code/trunk/src/orxonox/objects/worldentities/ExplosionChunk.cc	(revision 2896)
@@ -32,5 +32,5 @@
 #include <OgreParticleSystem.h>
 
-#include "core/Core.h"
+#include "core/GameMode.h"
 #include "core/CoreIncludes.h"
 #include "core/Executor.h"
@@ -47,5 +47,5 @@
         RegisterObject(ExplosionChunk);
 
-        if ( Core::showsGraphics() && ( !this->getScene() || !this->getScene()->getSceneManager() ) )
+        if ( GameMode::showsGraphics() && ( !this->getScene() || !this->getScene()->getSceneManager() ) )
             ThrowException(AbortLoading, "Can't create ExplosionChunk, no scene or no scene manager given.");
 
@@ -53,5 +53,5 @@
         this->LOD_ = LODParticle::normal;
 
-        if ( Core::showsGraphics() )
+        if ( GameMode::showsGraphics() )
         {
             try
@@ -75,5 +75,5 @@
         }
 
-        if (Core::isMaster())
+        if (GameMode::isMaster())
         {
             Vector3 velocity(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1));
@@ -132,5 +132,5 @@
             this->smoke_->setEnabled(false);
 
-        if (Core::isMaster())
+        if (GameMode::isMaster())
         {
             this->bStop_ = true;
@@ -148,5 +148,5 @@
         static const unsigned int CHANGES_PER_SECOND = 5;
 
-        if (Core::isMaster() && rnd() < dt*CHANGES_PER_SECOND)
+        if (GameMode::isMaster() && rnd() < dt*CHANGES_PER_SECOND)
         {
             float length = this->getVelocity().length();
Index: code/trunk/src/orxonox/objects/worldentities/Light.cc
===================================================================
--- code/trunk/src/orxonox/objects/worldentities/Light.cc	(revision 2894)
+++ code/trunk/src/orxonox/objects/worldentities/Light.cc	(revision 2896)
@@ -37,5 +37,5 @@
 #include "util/String.h"
 #include "util/Exception.h"
-#include "core/Core.h"
+#include "core/GameMode.h"
 #include "core/CoreIncludes.h"
 #include "core/XMLPort.h"
@@ -57,5 +57,5 @@
         this->spotlightRange_ = Vector3(40.0f, 30.0f, 1.0f);
 
-        if (Core::showsGraphics())
+        if (GameMode::showsGraphics())
         {
             if (!this->getScene())
Index: code/trunk/src/orxonox/objects/worldentities/Model.cc
===================================================================
--- code/trunk/src/orxonox/objects/worldentities/Model.cc	(revision 2894)
+++ code/trunk/src/orxonox/objects/worldentities/Model.cc	(revision 2896)
@@ -31,4 +31,5 @@
 #include <OgreEntity.h>
 #include "Model.h"
+#include "core/GameMode.h"
 #include "core/CoreIncludes.h"
 #include "core/XMLPort.h"
@@ -70,5 +71,5 @@
     void Model::changedMesh()
     {
-        if (Core::showsGraphics())
+        if (GameMode::showsGraphics())
         {
             if (this->mesh_.getEntity())
Index: code/trunk/src/orxonox/objects/worldentities/MovableEntity.cc
===================================================================
--- code/trunk/src/orxonox/objects/worldentities/MovableEntity.cc	(revision 2894)
+++ code/trunk/src/orxonox/objects/worldentities/MovableEntity.cc	(revision 2896)
@@ -34,5 +34,5 @@
 #include "core/XMLPort.h"
 #include "core/Executor.h"
-#include "core/Core.h"
+#include "core/GameMode.h"
 
 namespace orxonox
@@ -89,5 +89,5 @@
     void MovableEntity::resynchronize()
     {
-        if (Core::isMaster() && !this->continuousResynchroTimer_)
+        if (GameMode::isMaster() && !this->continuousResynchroTimer_)
         {
             // Resynchronise every few seconds because we only work with velocities (no positions)
Index: code/trunk/src/orxonox/objects/worldentities/ParticleEmitter.cc
===================================================================
--- code/trunk/src/orxonox/objects/worldentities/ParticleEmitter.cc	(revision 2894)
+++ code/trunk/src/orxonox/objects/worldentities/ParticleEmitter.cc	(revision 2896)
@@ -39,4 +39,5 @@
 #include "tools/ParticleInterface.h"
 #include "util/Exception.h"
+#include "core/GameMode.h"
 #include "core/CoreIncludes.h"
 #include "core/XMLPort.h"
@@ -51,5 +52,5 @@
         RegisterObject(ParticleEmitter);
 
-        if (Core::showsGraphics() && (!this->getScene() || !this->getScene()->getSceneManager()))
+        if (GameMode::showsGraphics() && (!this->getScene() || !this->getScene()->getSceneManager()))
             ThrowException(AbortLoading, "Can't create ParticleEmitter, no scene or no scene manager given.");
 
@@ -107,5 +108,5 @@
         }
 
-        if (Core::showsGraphics() && this->getScene() && this->getScene()->getSceneManager())
+        if (GameMode::showsGraphics() && this->getScene() && this->getScene()->getSceneManager())
         {
             try
Index: code/trunk/src/orxonox/objects/worldentities/Planet.cc
===================================================================
--- code/trunk/src/orxonox/objects/worldentities/Planet.cc	(revision 2894)
+++ code/trunk/src/orxonox/objects/worldentities/Planet.cc	(revision 2896)
@@ -42,5 +42,5 @@
 #include "CameraManager.h"
 #include "Camera.h"
-#include "GraphicsEngine.h"
+#include "GraphicsManager.h"
 
 namespace orxonox
Index: code/trunk/src/orxonox/objects/worldentities/PongBall.cc
===================================================================
--- code/trunk/src/orxonox/objects/worldentities/PongBall.cc	(revision 2894)
+++ code/trunk/src/orxonox/objects/worldentities/PongBall.cc	(revision 2896)
@@ -31,4 +31,5 @@
 
 #include "core/CoreIncludes.h"
+#include "core/GameMode.h"
 #include "objects/worldentities/PongBat.h"
 #include "objects/gametypes/Gametype.h"
@@ -53,5 +54,5 @@
         SUPER(PongBall, tick, dt);
 
-        if (Core::isMaster())
+        if (GameMode::isMaster())
         {
             Vector3 position = this->getPosition();
Index: code/trunk/src/orxonox/objects/worldentities/pawns/Pawn.cc
===================================================================
--- code/trunk/src/orxonox/objects/worldentities/pawns/Pawn.cc	(revision 2894)
+++ code/trunk/src/orxonox/objects/worldentities/pawns/Pawn.cc	(revision 2896)
@@ -30,5 +30,5 @@
 #include "Pawn.h"
 
-#include "core/Core.h"
+#include "core/GameMode.h"
 #include "core/CoreIncludes.h"
 #include "core/XMLPort.h"
@@ -63,5 +63,5 @@
         this->getPickUp().setPlayer(this);
 
-        if (Core::isMaster())
+        if (GameMode::isMaster())
         {
             this->weaponSystem_ = new WeaponSystem(this);
@@ -211,5 +211,5 @@
                 this->getPlayer()->stopControl(this);
 
-            if (Core::isMaster())
+            if (GameMode::isMaster())
                 this->deatheffect();
         }
@@ -260,5 +260,5 @@
     {
         this->setHealth(this->initialHealth_);
-        if (Core::isMaster())
+        if (GameMode::isMaster())
             this->spawneffect();
     }
Index: code/trunk/src/orxonox/objects/worldentities/pawns/Spectator.cc
===================================================================
--- code/trunk/src/orxonox/objects/worldentities/pawns/Spectator.cc	(revision 2894)
+++ code/trunk/src/orxonox/objects/worldentities/pawns/Spectator.cc	(revision 2896)
@@ -34,5 +34,5 @@
 #include "core/CoreIncludes.h"
 #include "core/ConfigValueIncludes.h"
-#include "core/Core.h"
+#include "core/GameMode.h"
 #include "objects/worldentities/Model.h"
 #include "objects/Scene.h"
@@ -63,5 +63,5 @@
         this->setDestroyWhenPlayerLeft(true);
 
-        if (Core::showsGraphics())
+        if (GameMode::showsGraphics())
         {
             this->greetingFlare_ = new BillboardSet();
@@ -206,5 +206,5 @@
         this->bGreeting_ = !this->bGreeting_;
 
-        if (Core::isMaster())
+        if (GameMode::isMaster())
         {
             this->bGreetingFlareVisible_ = this->bGreeting_;
Index: code/trunk/src/orxonox/objects/worldentities/triggers/Trigger.cc
===================================================================
--- code/trunk/src/orxonox/objects/worldentities/triggers/Trigger.cc	(revision 2894)
+++ code/trunk/src/orxonox/objects/worldentities/triggers/Trigger.cc	(revision 2896)
@@ -36,5 +36,5 @@
 #include "core/ConsoleCommand.h"
 #include "core/XMLPort.h"
-#include "core/Core.h"
+#include "core/GameMode.h"
 #include "objects/Scene.h"
 
@@ -67,5 +67,5 @@
 //    this->bUpdating_ = false;
 
-    if (this->getScene() && Core::showsGraphics())
+    if (this->getScene() && GameMode::showsGraphics())
     {
       this->debugBillboard_.setBillboardSet(this->getScene()->getSceneManager(), "Examples/Flare", ColourValue(1.0, 0.0, 0.0), 1);
Index: code/trunk/src/orxonox/overlays/OrxonoxOverlay.cc
===================================================================
--- code/trunk/src/orxonox/overlays/OrxonoxOverlay.cc	(revision 2894)
+++ code/trunk/src/orxonox/overlays/OrxonoxOverlay.cc	(revision 2896)
@@ -39,11 +39,14 @@
 #include <OgreOverlayManager.h>
 #include <OgrePanelOverlayElement.h>
+#include <OgreRenderWindow.h>
+
 #include "util/Convert.h"
 #include "util/Exception.h"
 #include "util/String.h"
-#include "core/Core.h"
+#include "core/GameMode.h"
 #include "core/CoreIncludes.h"
 #include "core/XMLPort.h"
 #include "core/ConsoleCommand.h"
+#include "GraphicsManager.h"
 
 namespace orxonox
@@ -64,5 +67,5 @@
         this->group_ = 0;
 
-        if (!Core::showsGraphics())
+        if (!GameMode::showsGraphics())
             ThrowException(NoGraphics, "Can't create OrxonoxOverlay, graphics engine not initialized");
 
@@ -77,7 +80,7 @@
         this->overlay_->add2D(this->background_);
 
-        // We'll have to set the aspect ratio to a default value first.
-        // GSGraphics gets informed about our construction here and can update us in the next tick.
-        this->windowAspectRatio_ = 1.0;
+        // Get aspect ratio from the render window. Later on, we get informed automatically
+        Ogre::RenderWindow* defaultWindow = GraphicsManager::getInstance().getRenderWindow();
+        this->windowAspectRatio_ = (float)defaultWindow->getWidth() / defaultWindow->getHeight();
         this->sizeCorrectionChanged();
 
@@ -175,8 +178,8 @@
     /**
     @brief
-        Called by the GraphicsEngine whenever the window size changes.
+        Called by the GraphicsManager whenever the window size changes.
         Calculates the aspect ratio only.
     */
-    void OrxonoxOverlay::windowResized(int newWidth, int newHeight)
+    void OrxonoxOverlay::windowResized(unsigned int newWidth, unsigned int newHeight)
     {
         this->windowAspectRatio_ = newWidth/(float)newHeight;
Index: code/trunk/src/orxonox/overlays/OrxonoxOverlay.h
===================================================================
--- code/trunk/src/orxonox/overlays/OrxonoxOverlay.h	(revision 2894)
+++ code/trunk/src/orxonox/overlays/OrxonoxOverlay.h	(revision 2896)
@@ -200,5 +200,5 @@
 
     private:
-        void windowResized(int newWidth, int newHeight);
+        void windowResized(unsigned int newWidth, unsigned int newHeight);
 
         static unsigned int hudOverlayCounter_s;   //!< Static counter for hud elements
Index: code/trunk/src/orxonox/overlays/console/InGameConsole.cc
===================================================================
--- code/trunk/src/orxonox/overlays/console/InGameConsole.cc	(revision 2894)
+++ code/trunk/src/orxonox/overlays/console/InGameConsole.cc	(revision 2896)
@@ -42,4 +42,5 @@
 #include "util/Convert.h"
 #include "util/Debug.h"
+#include "core/Clock.h"
 #include "core/CoreIncludes.h"
 #include "core/ConfigValueIncludes.h"
@@ -172,5 +173,5 @@
     {
         // create the corresponding input state
-        inputState_ = InputManager::getInstance().createInputState<SimpleInputState>("console", 40);
+        inputState_ = InputManager::getInstance().createInputState<SimpleInputState>("console", false, false, InputStatePriority::Console);
         inputState_->setKeyHandler(Shell::getInstance().getInputBuffer());
         bHidesAllInputChanged();
@@ -347,5 +348,5 @@
         @brief Used to control the actual scrolling and the cursor.
     */
-    void InGameConsole::tick(float dt)
+    void InGameConsole::update(const Clock& time)
     {
         if (this->scroll_ != 0)
@@ -358,5 +359,5 @@
                 // enlarge oldTop a little bit so that this exponential function
                 // reaches 0 before infinite time has passed...
-                float deltaScroll = (oldTop - 0.01) * dt * this->scrollSpeed_;
+                float deltaScroll = (oldTop - 0.01) * time.getDeltaTime() * this->scrollSpeed_;
                 if (oldTop - deltaScroll >= 0)
                 {
@@ -373,5 +374,5 @@
                 // scrolling up
                 // note: +0.01 for the same reason as when scrolling down
-                float deltaScroll = (1.2 * this->relativeHeight + 0.01 + oldTop) * dt * this->scrollSpeed_;
+                float deltaScroll = (1.2 * this->relativeHeight + 0.01 + oldTop) * time.getDeltaTime() * this->scrollSpeed_;
                 if (oldTop - deltaScroll <= -1.2 * this->relativeHeight)
                 {
@@ -388,5 +389,5 @@
         if (this->bActive_)
         {
-            this->cursor_ += dt;
+            this->cursor_ += time.getDeltaTime();
             if (this->cursor_ >= this->blinkTime)
             {
@@ -409,5 +410,5 @@
         @brief Resizes the console elements. Call if window size changes.
     */
-    void InGameConsole::windowResized(int newWidth, int newHeight)
+    void InGameConsole::windowResized(unsigned int newWidth, unsigned int newHeight)
     {
         this->windowW_ = newWidth;
Index: code/trunk/src/orxonox/overlays/console/InGameConsole.h
===================================================================
--- code/trunk/src/orxonox/overlays/console/InGameConsole.h	(revision 2894)
+++ code/trunk/src/orxonox/overlays/console/InGameConsole.h	(revision 2896)
@@ -53,5 +53,5 @@
         void setConfigValues();
 
-        virtual void tick(float dt);
+        void update(const Clock& time);
 
         static InGameConsole& getInstance() { assert(singletonRef_s); return *singletonRef_s; }
@@ -81,5 +81,5 @@
         void print(const std::string& text, int index, bool alwaysShift = false);
 
-        void windowResized(int newWidth, int newHeight);
+        void windowResized(unsigned int newWidth, unsigned int newHeight);
 
         // config value related
Index: code/trunk/src/orxonox/overlays/debug/DebugFPSText.cc
===================================================================
--- code/trunk/src/orxonox/overlays/debug/DebugFPSText.cc	(revision 2894)
+++ code/trunk/src/orxonox/overlays/debug/DebugFPSText.cc	(revision 2896)
@@ -30,7 +30,7 @@
 #include "DebugFPSText.h"
 #include <OgreTextAreaOverlayElement.h>
+#include "util/Convert.h"
 #include "core/CoreIncludes.h"
-#include "GraphicsEngine.h"
-#include "util/Convert.h"
+#include "core/Game.h"
 
 namespace orxonox
@@ -51,5 +51,5 @@
         SUPER(DebugFPSText, tick, dt);
 
-        float fps = GraphicsEngine::getInstance().getAverageFramesPerSecond();
+        float fps = Game::getInstance().getAvgFPS();
         this->setCaption(convertToString(fps));
     }
Index: code/trunk/src/orxonox/overlays/debug/DebugRTRText.cc
===================================================================
--- code/trunk/src/orxonox/overlays/debug/DebugRTRText.cc	(revision 2894)
+++ code/trunk/src/orxonox/overlays/debug/DebugRTRText.cc	(revision 2896)
@@ -32,5 +32,5 @@
 #include "core/CoreIncludes.h"
 #include "util/Convert.h"
-#include "GraphicsEngine.h"
+#include "core/Game.h"
 
 namespace orxonox
@@ -51,5 +51,5 @@
         SUPER(DebugRTRText, tick, dt);
 
-        float rtr = GraphicsEngine::getInstance().getAverageTickTime();
+        float rtr = Game::getInstance().getAvgTickTime();
         this->setCaption(convertToString(rtr));
     }
Index: code/trunk/src/orxonox/overlays/hud/HUDRadar.cc
===================================================================
--- code/trunk/src/orxonox/overlays/hud/HUDRadar.cc	(revision 2894)
+++ code/trunk/src/orxonox/overlays/hud/HUDRadar.cc	(revision 2896)
@@ -94,5 +94,5 @@
     void HUDRadar::displayObject(RadarViewable* object, bool bIsMarked)
     {
-        if (object == (RadarViewable*)this->owner_)
+        if (object == static_cast<RadarViewable*>(this->owner_))
             return;
 
Index: code/trunk/src/orxonox/tools/BillboardSet.cc
===================================================================
--- code/trunk/src/orxonox/tools/BillboardSet.cc	(revision 2894)
+++ code/trunk/src/orxonox/tools/BillboardSet.cc	(revision 2896)
@@ -37,5 +37,5 @@
 #include <OgreBillboard.h>
 
-#include "core/Core.h"
+#include "core/GameMode.h"
 #include "util/Convert.h"
 #include "util/String.h"
@@ -72,5 +72,5 @@
         try
         {
-            if (Core::showsGraphics())
+            if (GameMode::showsGraphics())
             {
                 this->billboardSet_ = scenemanager->createBillboardSet("Billboard" + convertToString(BillboardSet::billboardSetCounter_s++), count);
@@ -95,5 +95,5 @@
         try
         {
-            if (Core::showsGraphics())
+            if (GameMode::showsGraphics())
             {
                 this->billboardSet_ = scenemanager->createBillboardSet("Billboard" + convertToString(BillboardSet::billboardSetCounter_s++), count);
Index: code/trunk/src/orxonox/tools/CMakeLists.txt
===================================================================
--- code/trunk/src/orxonox/tools/CMakeLists.txt	(revision 2894)
+++ code/trunk/src/orxonox/tools/CMakeLists.txt	(revision 2896)
@@ -5,4 +5,5 @@
   Shader.cc
   TextureGenerator.cc
+  TimeFactorListener.cc
   Timer.cc
   WindowEventListener.cc
Index: code/trunk/src/orxonox/tools/Mesh.cc
===================================================================
--- code/trunk/src/orxonox/tools/Mesh.cc	(revision 2894)
+++ code/trunk/src/orxonox/tools/Mesh.cc	(revision 2896)
@@ -35,5 +35,5 @@
 #include <cassert>
 
-#include "core/Core.h"
+#include "core/GameMode.h"
 #include "util/Convert.h"
 #include "util/String.h"
@@ -64,5 +64,5 @@
             this->scenemanager_->destroyEntity(this->entity_);
 
-        if (Core::showsGraphics())
+        if (GameMode::showsGraphics())
         {
             try
Index: code/trunk/src/orxonox/tools/ParticleInterface.cc
===================================================================
--- code/trunk/src/orxonox/tools/ParticleInterface.cc	(revision 2894)
+++ code/trunk/src/orxonox/tools/ParticleInterface.cc	(revision 2896)
@@ -40,6 +40,6 @@
 #include <cassert>
 
-#include "GraphicsEngine.h"
-#include "core/Core.h"
+#include "GraphicsManager.h"
+#include "core/GameMode.h"
 #include "core/CoreIncludes.h"
 #include "util/Convert.h"
@@ -64,5 +64,5 @@
         this->speedFactor_ = 1.0f;
 
-        if (Core::showsGraphics())
+        if (GameMode::showsGraphics())
         {
             try
@@ -178,6 +178,6 @@
     {
         this->detaillevel_ = level;
-        if (GraphicsEngine::getInstancePtr())
-            this->detailLevelChanged(GraphicsEngine::getInstance().getDetailLevelParticle());
+        if (GameMode::showsGraphics())
+            this->detailLevelChanged(GraphicsManager::getInstance().getDetailLevelParticle());
     }
 
Index: code/trunk/src/orxonox/tools/ParticleInterface.h
===================================================================
--- code/trunk/src/orxonox/tools/ParticleInterface.h	(revision 2894)
+++ code/trunk/src/orxonox/tools/ParticleInterface.h	(revision 2896)
@@ -37,5 +37,5 @@
 #include "core/OrxonoxClass.h"
 #include "util/Math.h"
-#include "gamestates/GSRoot.h"
+#include "tools/TimeFactorListener.h"
 
 #define getAllEmitters() \
Index: code/trunk/src/orxonox/tools/Shader.cc
===================================================================
--- code/trunk/src/orxonox/tools/Shader.cc	(revision 2894)
+++ code/trunk/src/orxonox/tools/Shader.cc	(revision 2896)
@@ -36,8 +36,8 @@
 #include <OgrePlugin.h>
 
-#include "core/Core.h"
+#include "core/GameMode.h"
 #include "core/CoreIncludes.h"
 #include "core/Executor.h"
-#include "GraphicsEngine.h"
+#include "GraphicsManager.h"
 #include "util/Exception.h"
 
@@ -59,5 +59,5 @@
         this->compositorInstance_ = 0;
         this->bVisible_ = true;
-        this->bLoadCompositor_ = Core::showsGraphics() && GraphicsEngine::getInstancePtr();
+        this->bLoadCompositor_ = GameMode::showsGraphics();
         this->bViewportInitialized_ = false;
         this->compositor_ = "";
@@ -86,5 +86,5 @@
         if (this->bLoadCompositor_ && this->compositorInstance_)
         {
-            Ogre::Viewport* viewport = GraphicsEngine::getInstance().getViewport();
+            Ogre::Viewport* viewport = GraphicsManager::getInstance().getViewport();
             assert(viewport);
             Ogre::CompositorManager::getSingleton().removeCompositor(viewport, this->compositor_);
@@ -114,5 +114,5 @@
         if (this->bLoadCompositor_)
         {
-            Ogre::Viewport* viewport = GraphicsEngine::getInstance().getViewport();
+            Ogre::Viewport* viewport = GraphicsManager::getInstance().getViewport();
             assert(viewport);
             if (this->oldcompositor_ != "")
@@ -246,5 +246,5 @@
     Shader::ParameterPointer* Shader::getParameterPointer(const std::string& material, size_t technique, size_t pass, const std::string& parameter)
     {
-        if (!Core::showsGraphics() || !Shader::bLoadedCgPlugin_s)
+        if (!GameMode::showsGraphics() || !Shader::bLoadedCgPlugin_s)
             return 0;
 
Index: code/trunk/src/orxonox/tools/TimeFactorListener.cc
===================================================================
--- code/trunk/src/orxonox/tools/TimeFactorListener.cc	(revision 2896)
+++ code/trunk/src/orxonox/tools/TimeFactorListener.cc	(revision 2896)
@@ -0,0 +1,41 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Reto Grieder
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "OrxonoxStableHeaders.h"
+#include "TimeFactorListener.h"
+#include "core/CoreIncludes.h"
+
+namespace orxonox
+{
+    float TimeFactorListener::timefactor_s = 1.0f;
+
+    TimeFactorListener::TimeFactorListener()
+    {
+        RegisterRootObject(TimeFactorListener);
+    }
+}
Index: code/trunk/src/orxonox/tools/TimeFactorListener.h
===================================================================
--- code/trunk/src/orxonox/tools/TimeFactorListener.h	(revision 2896)
+++ code/trunk/src/orxonox/tools/TimeFactorListener.h	(revision 2896)
@@ -0,0 +1,56 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Reto Grieder
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _TimeFactorListener_H__
+#define _TimeFactorListener_H__
+
+#include "OrxonoxPrereqs.h"
+#include "core/OrxonoxClass.h"
+
+
+namespace orxonox
+{
+    class _OrxonoxExport TimeFactorListener : virtual public OrxonoxClass
+    {
+        friend class GSRoot;
+
+        public:
+            TimeFactorListener();
+            virtual ~TimeFactorListener() {}
+
+        protected:
+            virtual void changedTimeFactor(float factor_new, float factor_old) {}
+            inline float getTimeFactor() const
+                { return TimeFactorListener::timefactor_s; }
+
+        private:
+            static float timefactor_s;
+    };
+}
+
+#endif /* _TimeFactorListener_H__ */
Index: code/trunk/src/orxonox/tools/Timer.h
===================================================================
--- code/trunk/src/orxonox/tools/Timer.h	(revision 2894)
+++ code/trunk/src/orxonox/tools/Timer.h	(revision 2896)
@@ -64,5 +64,5 @@
 #include "core/Executor.h"
 #include "core/OrxonoxClass.h"
-#include "gamestates/GSRoot.h"
+#include "tools/TimeFactorListener.h"
 
 namespace orxonox
Index: code/trunk/src/orxonox/tools/WindowEventListener.h
===================================================================
--- code/trunk/src/orxonox/tools/WindowEventListener.h	(revision 2894)
+++ code/trunk/src/orxonox/tools/WindowEventListener.h	(revision 2896)
@@ -49,5 +49,5 @@
 
             /** Window has resized */
-            virtual void windowResized(int newWidth, int newHeight) { }
+            virtual void windowResized(unsigned int newWidth, unsigned int newHeight) { }
 
             /** Window has lost/gained focus */
