Index: code/branches/questsystem5/src/orxonox/gamestates/CMakeLists.txt
===================================================================
--- code/branches/questsystem5/src/orxonox/gamestates/CMakeLists.txt	(revision 2788)
+++ code/branches/questsystem5/src/orxonox/gamestates/CMakeLists.txt	(revision 2907)
@@ -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/branches/questsystem5/src/orxonox/gamestates/GSClient.cc
===================================================================
--- code/branches/questsystem5/src/orxonox/gamestates/GSClient.cc	(revision 2788)
+++ code/branches/questsystem5/src/orxonox/gamestates/GSClient.cc	(revision 2907)
@@ -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/branches/questsystem5/src/orxonox/gamestates/GSClient.h
===================================================================
--- code/branches/questsystem5/src/orxonox/gamestates/GSClient.h	(revision 2788)
+++ code/branches/questsystem5/src/orxonox/gamestates/GSClient.h	(revision 2907)
@@ -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/branches/questsystem5/src/orxonox/gamestates/GSDedicated.cc
===================================================================
--- code/branches/questsystem5/src/orxonox/gamestates/GSDedicated.cc	(revision 2788)
+++ code/branches/questsystem5/src/orxonox/gamestates/GSDedicated.cc	(revision 2907)
@@ -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/branches/questsystem5/src/orxonox/gamestates/GSDedicated.h
===================================================================
--- code/branches/questsystem5/src/orxonox/gamestates/GSDedicated.h	(revision 2788)
+++ code/branches/questsystem5/src/orxonox/gamestates/GSDedicated.h	(revision 2907)
@@ -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/branches/questsystem5/src/orxonox/gamestates/GSGUI.cc
===================================================================
--- code/branches/questsystem5/src/orxonox/gamestates/GSGUI.cc	(revision 2788)
+++ 	(revision )
@@ -1,69 +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_->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/branches/questsystem5/src/orxonox/gamestates/GSGUI.h
===================================================================
--- code/branches/questsystem5/src/orxonox/gamestates/GSGUI.h	(revision 2788)
+++ 	(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/branches/questsystem5/src/orxonox/gamestates/GSGraphics.cc
===================================================================
--- code/branches/questsystem5/src/orxonox/gamestates/GSGraphics.cc	(revision 2788)
+++ code/branches/questsystem5/src/orxonox/gamestates/GSGraphics.cc	(revision 2907)
@@ -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/branches/questsystem5/src/orxonox/gamestates/GSGraphics.h
===================================================================
--- code/branches/questsystem5/src/orxonox/gamestates/GSGraphics.h	(revision 2788)
+++ code/branches/questsystem5/src/orxonox/gamestates/GSGraphics.h	(revision 2907)
@@ -23,7 +23,12 @@
  *      Reto Grieder
  *   Co-authors:
- *      ...
+ *      Benjamin Knecht (documentation)
  *
  */
+
+ /**
+    @file
+    @brief Declaration of the Graphics GameState class.
+  */
 
 #ifndef _GSGraphics_H__
@@ -31,82 +36,44 @@
 
 #include "OrxonoxPrereqs.h"
-#include <OgrePrerequisites.h>
-#define NOMINMAX // required to stop windows.h screwing up std::min definition
-#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/branches/questsystem5/src/orxonox/gamestates/GSIOConsole.cc
===================================================================
--- code/branches/questsystem5/src/orxonox/gamestates/GSIOConsole.cc	(revision 2788)
+++ code/branches/questsystem5/src/orxonox/gamestates/GSIOConsole.cc	(revision 2907)
@@ -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/branches/questsystem5/src/orxonox/gamestates/GSIOConsole.h
===================================================================
--- code/branches/questsystem5/src/orxonox/gamestates/GSIOConsole.h	(revision 2788)
+++ code/branches/questsystem5/src/orxonox/gamestates/GSIOConsole.h	(revision 2907)
@@ -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/branches/questsystem5/src/orxonox/gamestates/GSLevel.cc
===================================================================
--- code/branches/questsystem5/src/orxonox/gamestates/GSLevel.cc	(revision 2788)
+++ code/branches/questsystem5/src/orxonox/gamestates/GSLevel.cc	(revision 2907)
@@ -24,4 +24,5 @@
  *   Co-authors:
  *      Fabian 'x3n' Landau
+ *      Benjamin Knecht
  *
  */
@@ -39,22 +40,31 @@
 #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 "objects/quest/QuestManager.h"
-#include "overlays/notifications/NotificationManager.h"
+#include "orxonox/objects/quest/QuestManager.h"
+#include "orxonox/overlays/notifications/NotificationManager.h"
+#include "gui/GUIManager.h"
 
 namespace orxonox
 {
-    SetCommandLineArgument(level, "presentation.oxw").shortcut("l");
-
-    GSLevel::GSLevel()
-//        : GameState<GSGraphics>(name)
-        : keyBinder_(0)
-        , inputState_(0)
+    AddGameState(GSLevel, "level");
+
+    SetCommandLineArgument(level, "presentation_dm.oxw").shortcut("l");
+    SetConsoleCommand(GSLevel, showIngameGUI, true);
+
+    GSLevel::GSLevel(const std::string& name)
+        : GameState(name)
+        , keyBinder_(0)
+        , gameInputState_(0)
+        , guiMouseOnlyInputState_(0)
+        , guiKeysOnlyInputState_(0)
         , radar_(0)
         , startFile_(0)
@@ -66,29 +76,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
@@ -102,5 +117,5 @@
         this->notificationManager_ = new NotificationManager();
 
-        if (Core::isMaster())
+        if (GameMode::isMaster())
         {
             // create the global LevelManager
@@ -110,9 +125,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);
@@ -132,5 +144,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
@@ -145,4 +173,5 @@
             this->ccTkeybind_ = 0;
         }
+
 
         // this call will delete every BaseObject!
@@ -152,8 +181,8 @@
         //Loader::close();
 
-        if (Core::showsGraphics())
+        if (GameMode::showsGraphics())
             InputManager::getInstance().requestLeaveState("game");
 
-        if (Core::isMaster())
+        if (GameMode::isMaster())
             this->unloadLevel();
 
@@ -194,7 +223,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_)
@@ -206,7 +237,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)
@@ -251,9 +282,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/branches/questsystem5/src/orxonox/gamestates/GSLevel.h
===================================================================
--- code/branches/questsystem5/src/orxonox/gamestates/GSLevel.h	(revision 2788)
+++ code/branches/questsystem5/src/orxonox/gamestates/GSLevel.h	(revision 2907)
@@ -23,5 +23,5 @@
  *      Reto Grieder
  *   Co-authors:
- *      ...
+ *      Benjamin Knecht
  *
  */
@@ -31,21 +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();
+        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();
@@ -56,13 +58,15 @@
         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_;
-        QuestManager*          questManager_;
-        NotificationManager*  notificationManager_;
+        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
+        QuestManager*         questManager_;            //!< quest manager for this level
+        NotificationManager*  notificationManager_;     //!< notification manager for this level
 
         //##### ConfigValues #####
@@ -72,8 +76,4 @@
         ConsoleCommand*       ccKeybind_;
         ConsoleCommand*       ccTkeybind_;
-
-    private:
-        void setConfigValues();
-
     };
 }
Index: code/branches/questsystem5/src/orxonox/gamestates/GSMainMenu.cc
===================================================================
--- code/branches/questsystem5/src/orxonox/gamestates/GSMainMenu.cc	(revision 2907)
+++ code/branches/questsystem5/src/orxonox/gamestates/GSMainMenu.cc	(revision 2907)
@@ -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/branches/questsystem5/src/orxonox/gamestates/GSMainMenu.h
===================================================================
--- code/branches/questsystem5/src/orxonox/gamestates/GSMainMenu.h	(revision 2907)
+++ code/branches/questsystem5/src/orxonox/gamestates/GSMainMenu.h	(revision 2907)
@@ -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/branches/questsystem5/src/orxonox/gamestates/GSRoot.cc
===================================================================
--- code/branches/questsystem5/src/orxonox/gamestates/GSRoot.cc	(revision 2788)
+++ code/branches/questsystem5/src/orxonox/gamestates/GSRoot.cc	(revision 2907)
@@ -32,41 +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
-#  define NOMINMAX // required to stop windows.h screwing up std::min definition
-#  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;
@@ -77,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;
 
         {
@@ -148,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_)
         {
@@ -175,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)
@@ -198,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);
     }
 
@@ -281,5 +170,5 @@
     void GSRoot::setTimeFactor(float factor)
     {
-        if (Core::isMaster())
+        if (GameMode::isMaster())
         {
             if (!this->bPaused_)
@@ -299,5 +188,5 @@
     void GSRoot::pause()
     {
-        if (Core::isMaster())
+        if (GameMode::isMaster())
         {
             if (!this->bPaused_)
@@ -314,13 +203,3 @@
         }
     }
-
-    ////////////////////////
-    // TimeFactorListener //
-    ////////////////////////
-    float TimeFactorListener::timefactor_s = 1.0f;
-
-    TimeFactorListener::TimeFactorListener()
-    {
-        RegisterRootObject(TimeFactorListener);
-    }
 }
Index: code/branches/questsystem5/src/orxonox/gamestates/GSRoot.h
===================================================================
--- code/branches/questsystem5/src/orxonox/gamestates/GSRoot.h	(revision 2788)
+++ code/branches/questsystem5/src/orxonox/gamestates/GSRoot.h	(revision 2907)
@@ -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/branches/questsystem5/src/orxonox/gamestates/GSServer.cc
===================================================================
--- code/branches/questsystem5/src/orxonox/gamestates/GSServer.cc	(revision 2788)
+++ code/branches/questsystem5/src/orxonox/gamestates/GSServer.cc	(revision 2907)
@@ -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/branches/questsystem5/src/orxonox/gamestates/GSServer.h
===================================================================
--- code/branches/questsystem5/src/orxonox/gamestates/GSServer.h	(revision 2788)
+++ code/branches/questsystem5/src/orxonox/gamestates/GSServer.h	(revision 2907)
@@ -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/branches/questsystem5/src/orxonox/gamestates/GSStandalone.cc
===================================================================
--- code/branches/questsystem5/src/orxonox/gamestates/GSStandalone.cc	(revision 2788)
+++ code/branches/questsystem5/src/orxonox/gamestates/GSStandalone.cc	(revision 2907)
@@ -30,10 +30,18 @@
 #include "GSStandalone.h"
 
-#include "core/Core.h"
+#include <OgreViewport.h>
+#include <OgreCamera.h>
+#include "core/Game.h"
+#include "core/GameMode.h"
+#include "core/ConsoleCommand.h"
+#include "gui/GUIManager.h"
+#include "GraphicsManager.h"
 
 namespace orxonox
 {
-    GSStandalone::GSStandalone()
-        : GameState<GSGraphics>("standalone")
+    AddGameState(GSStandalone, "standalone");
+
+    GSStandalone::GSStandalone(const std::string& name)
+        : GameState(name)
     {
     }
@@ -43,22 +51,17 @@
     }
 
-    void GSStandalone::enter()
+
+    void GSStandalone::activate()
     {
-        Core::setIsStandalone(true);
-
-        GSLevel::enter(this->getParent()->getViewport());
+        GameMode::setIsStandalone(true);
     }
 
-    void GSStandalone::leave()
+    void GSStandalone::deactivate()
     {
-        GSLevel::leave();
-
-        Core::setIsStandalone(false);
+        GameMode::setIsStandalone(false);
     }
 
-    void GSStandalone::ticked(const Clock& time)
+    void GSStandalone::update(const Clock& time)
     {
-        GSLevel::ticked(time);
-        this->tickChild(time);
     }
 }
Index: code/branches/questsystem5/src/orxonox/gamestates/GSStandalone.h
===================================================================
--- code/branches/questsystem5/src/orxonox/gamestates/GSStandalone.h	(revision 2788)
+++ code/branches/questsystem5/src/orxonox/gamestates/GSStandalone.h	(revision 2907)
@@ -31,19 +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();
 
+        void activate();
+        void deactivate();
+        void update(const Clock& time);
+
     private:
-        void enter();
-        void leave();
-        void ticked(const Clock& time);
     };
 }
