Index: code/branches/gui/src/core/GameState.cc
===================================================================
--- code/branches/gui/src/core/GameState.cc	(revision 1660)
+++ code/branches/gui/src/core/GameState.cc	(revision 1661)
@@ -56,4 +56,19 @@
     /**
     @brief
+        Destructor only checks that we don't delete an active state.
+    */
+    GameState::~GameState()
+    {
+        if (this->bActive_)
+        {
+            if (this->parent_)
+                this->requestState(this->parent_->getName());
+            else
+                this->requestState("");
+        }
+    }
+
+    /**
+    @brief
         Adds a child to the current tree. The Child can contain children of its own.
         But you cannot a state tree that already has an active state.
@@ -104,4 +119,64 @@
         // mark us as parent
         state->parent_ = this;
+    }
+
+    /**
+    @brief
+        Removes a child by instance. This splits the tree in two parts,
+        each of them functional on its own.
+    @param state
+        GameState by instance pointer
+    */
+    void GameState::removeChild(GameState* state)
+    {
+        std::map<GameState*, GameState*>::iterator it = this->grandchildrenToChildren_.find(state);
+        if (it != this->grandchildrenToChildren_.end())
+        {
+            if (state->isActive())
+            {
+                ThrowException(GameState, "Cannot remove active game state child '"
+                    + state->getName() + "' from '" + name_ + "'.");
+                //COUT(2) << "Warning: Cannot remove active game state child '" << state->getName()
+                //    << "' from '" << name_ << "'." << std::endl;
+            }
+            else
+            {
+                for (std::map<GameState*, GameState*>::const_iterator it = state->grandchildrenToChildren_.begin();
+                    it != state->grandchildrenToChildren_.end(); ++it)
+                {
+                    this->grandchildRemoved(it->first);
+                }
+                this->grandchildRemoved(state);
+            }
+        }
+        else
+        {
+            ThrowException(GameState, "Game state '" + name_ + "' doesn't have a child named '"
+                + state->getName() + "'. Removal skipped.");
+            //COUT(2) << "Warning: Game state '" << name_ << "' doesn't have a child named '"
+            //    << state->getName() << "'. Removal skipped." << std::endl;
+        }
+    }
+
+    /**
+    @brief
+        Removes a child by name. This splits the tree in two parts,
+        each of them functional on its own.
+    @param state
+        GameState by name
+    */
+
+    void GameState::removeChild(const std::string& name)
+    {
+        GameState* state = checkState(name);
+        if (state)
+        {
+            removeChild(state);
+        }
+        else
+        {
+            ThrowException(GameState, "GameState '" + name + "' doesn't exist.");
+            //COUT(2) << "Warning: GameState '" << name << "' doesn't exist." << std::endl;
+        }
     }
 
@@ -126,4 +201,22 @@
     /**
     @brief
+        Tells a state that one of its children has removed a child. This is necessary
+        to fill the internal maps correctly.
+    @param child
+        The child who notices this state.
+    @param grandchild
+        The child that has been removed.
+    */
+    void GameState::grandchildRemoved(GameState* grandchild)
+    {
+        // adjust the two maps correctly.
+        this->allChildren_.erase(grandchild->getName());
+        this->grandchildrenToChildren_.erase(grandchild);
+        if (this->parent_)
+            this->parent_->grandchildRemoved(grandchild);
+    }
+
+    /**
+    @brief
         Checks whether a specific game states exists in the hierarchy.
     @remarks
@@ -191,24 +284,40 @@
     void GameState::requestState(const std::string& name)
     {
-        GameState* request = checkState(name);
-        GameState* current = getCurrentState();
-        if (request)
-        {
+        if (name == "")
+        {
+            // user would like to leave every state.
+            GameState* current = getCurrentState();
             if (current)
             {
-                // There is already an active state
-                current->makeTransition(request);
-            }
-            else
-            {
-                // no active state --> we have to activate the root node first.
+                // Deactivate all states but root
                 GameState* root = getRootNode();
-                root->activate();
-                root->makeTransition(request);
-            }
-        }
-        else
-        {
-            COUT(2) << "Warning: GameState '" << name << "' doesn't exist." << std::endl;
+                current->makeTransition(root);
+                // Kick root too
+                root->deactivate();
+            }
+        }
+        else
+        {
+            GameState* request = checkState(name);
+            GameState* current = getCurrentState();
+            if (request)
+            {
+                if (current)
+                {
+                    // There is already an active state
+                    current->makeTransition(request);
+                }
+                else
+                {
+                    // no active state --> we have to activate the root node first.
+                    GameState* root = getRootNode();
+                    root->activate();
+                    root->makeTransition(request);
+                }
+            }
+            else
+            {
+                COUT(2) << "Warning: GameState '" << name << "' doesn't exist." << std::endl;
+            }
         }
     }
Index: code/branches/gui/src/core/GameState.h
===================================================================
--- code/branches/gui/src/core/GameState.h	(revision 1660)
+++ code/branches/gui/src/core/GameState.h	(revision 1661)
@@ -62,9 +62,11 @@
     public:
         GameState(const std::string& name);
-        virtual ~GameState() { }
+        virtual ~GameState();
 
         const std::string& getName() const { return name_; }
 
         void addChild(GameState* state);
+        void removeChild(GameState* state);
+        void removeChild(const std::string& name);
         void requestState(const std::string& name);
 
@@ -76,8 +78,14 @@
         bool isCurrentState() { return this->bActive_ && !this->activeChild_; }
 
+        virtual bool tick(float dt) { return true; }
+
     protected:
+        //virtual void enter() = 0;
+        //virtual void leave() = 0;
+        //virtual void tick(float dt) = 0;
         virtual void enter() { }
         virtual void leave() { }
-        virtual void tick(float dt) { }
+
+        GameState* getActiveChild() { return this->activeChild_; }
 
     private:
@@ -86,4 +94,5 @@
         GameState* getRootNode();
         void grandchildAdded(GameState* child, GameState* grandchild);
+        void grandchildRemoved(GameState* grandchild);
         void makeTransition(GameState* state);
         void activate();
Index: code/branches/gui/src/orxonox/Main.cc
===================================================================
--- code/branches/gui/src/orxonox/Main.cc	(revision 1660)
+++ code/branches/gui/src/orxonox/Main.cc	(revision 1661)
@@ -45,4 +45,9 @@
 #include "Settings.h"
 #include "Orxonox.h"
+
+#include "gamestates/GSRoot.h"
+#include "gamestates/GSGraphics.h"
+#include "gamestates/GSLevel.h"
+#include "gamestates/GSGUI.h"
 
 using namespace orxonox;
@@ -140,6 +145,7 @@
     state2->addChild(state3);
     state2->addChild(state5);
-    state3->addChild(state1);
     state6->addChild(state2);
+
+    state6->removeChild("state2");
 
     state5->requestState("state3");
@@ -160,4 +166,17 @@
     COUT(2) << std::endl;*/
 
+
+    GSRoot root;
+    GSGraphics graphics;
+    GSLevel level;
+    GSGUI gui;
+
+    root.addChild(&graphics);
+    graphics.addChild(&level);
+    graphics.addChild(&gui);
+
+    root.requestState("gui");
+    root.tick(0.0f);
+    root.requestState("");
 
 
@@ -169,5 +188,5 @@
         orxonoxInstance.start(macBundlePath());
 #else
-        orxonoxInstance.start();
+        //orxonoxInstance.start();
 #endif
     }
Index: code/branches/gui/src/orxonox/Orxonox.cc
===================================================================
--- code/branches/gui/src/orxonox/Orxonox.cc	(revision 1660)
+++ code/branches/gui/src/orxonox/Orxonox.cc	(revision 1661)
@@ -43,6 +43,4 @@
 //****** OGRE ******
 #include <OgreFrameListener.h>
-#include <OgreOverlay.h>
-#include <OgreOverlayManager.h>
 #include <OgreRoot.h>
 #include <OgreTimer.h>
Index: code/branches/gui/src/orxonox/gamestates/GSGUI.cc
===================================================================
--- code/branches/gui/src/orxonox/gamestates/GSGUI.cc	(revision 1661)
+++ code/branches/gui/src/orxonox/gamestates/GSGUI.cc	(revision 1661)
@@ -0,0 +1,69 @@
+/*
+ *   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 "GraphicsEngine.h"
+#include "core/input/InputManager.h"
+#include "core/input/SimpleInputState.h"
+#include "core/input/KeyBinder.h"
+#include "overlays/console/InGameConsole.h"
+#include "gui/GUIManager.h"
+
+namespace orxonox
+{
+    GSGUI::GSGUI()
+        : GameState("gui")
+    {
+    }
+
+    GSGUI::~GSGUI()
+    {
+    }
+
+    void GSGUI::enter()
+    {
+        // show main menu
+        GUIManager::getInstance().showGUI("MainMenu", 0);
+        GraphicsEngine::getInstance().getViewport()->setCamera(GUIManager::getInstance().getCamera());
+    }
+
+    void GSGUI::leave()
+    {
+        GUIManager::getInstance().hideGUI();
+    }
+
+    bool GSGUI::tick(float dt)
+    {
+        // tick CEGUI
+        GUIManager::getInstance().tick(dt);
+
+        return true;
+    }
+}
Index: code/branches/gui/src/orxonox/gamestates/GSGUI.h
===================================================================
--- code/branches/gui/src/orxonox/gamestates/GSGUI.h	(revision 1661)
+++ code/branches/gui/src/orxonox/gamestates/GSGUI.h	(revision 1661)
@@ -0,0 +1,51 @@
+/*
+ *   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"
+
+namespace orxonox
+{
+    class _OrxonoxExport GSGUI : public GameState
+    {
+    public:
+        GSGUI();
+        ~GSGUI();
+
+    private:
+        void enter();
+        void leave();
+        bool tick(float dt);
+
+    };
+}
+
+#endif /* _GSGUI_H__ */
Index: code/branches/gui/src/orxonox/gamestates/GSGraphics.cc
===================================================================
--- code/branches/gui/src/orxonox/gamestates/GSGraphics.cc	(revision 1661)
+++ code/branches/gui/src/orxonox/gamestates/GSGraphics.cc	(revision 1661)
@@ -0,0 +1,194 @@
+/*
+ *   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 "GSGraphics.h"
+
+#include <OgreFrameListener.h>
+#include <OgreRoot.h>
+#include <OgreTimer.h>
+#include <OgreWindowEventUtilities.h>
+
+#include "core/input/InputManager.h"
+#include "core/input/SimpleInputState.h"
+#include "core/input/KeyBinder.h"
+#include "core/Core.h"
+
+#include "GraphicsEngine.h"
+#include "overlays/console/InGameConsole.h"
+#include "gui/GUIManager.h"
+
+namespace orxonox
+{
+    GSGraphics::GSGraphics()
+        : GameState("graphics")
+        , timer_(0)
+        , bAbort_(false)
+        , debugRefreshTime_(0.0f)
+        , inputManager_(0)
+        , console_(0)
+        , guiManager_(0)
+    {
+    }
+
+    GSGraphics::~GSGraphics()
+    {
+    }
+
+    void GSGraphics::setConfigValues()
+    {
+        SetConfigValue(debugRefreshTime_, 0.2).description("Sets the time interval at which average fps, etc. get updated.");
+    }
+
+    void GSGraphics::enter()
+    {
+        this->graphicsEngine_ = GraphicsEngine::getInstancePtr();
+
+        graphicsEngine_->loadRenderer();    // creates the render window
+
+        // TODO: Spread this so that this call only initialises things needed for the Console and GUI
+        graphicsEngine_->initialiseResources();
+
+        // Calls the InputManager which sets up the input devices.
+        // The render window width and height are used to set up the mouse movement.
+        inputManager_ = new InputManager();
+        inputManager_->initialise(graphicsEngine_->getWindowHandle(),
+            graphicsEngine_->getWindowWidth(), graphicsEngine_->getWindowHeight(), true);
+
+        // Load the InGameConsole
+        console_ = new InGameConsole();
+        console_->initialise();
+
+        // load the CEGUI interface
+        guiManager_ = new GUIManager();
+        guiManager_->initialise();
+    }
+
+    void GSGraphics::leave()
+    {
+        if (this->guiManager_)
+          delete guiManager_;
+
+        if (this->console_)
+          delete this->console_;
+
+        if (inputManager_)
+          delete inputManager_;
+
+        // TODO: deintialise graphics
+    }
+
+    bool GSGraphics::tick(float dt)
+    {
+        Ogre::Root& ogreRoot = Ogre::Root::getSingleton();
+
+        // use the ogre timer class to measure time.
+        if (!timer_)
+            timer_ = new Ogre::Timer();
+
+        unsigned long frameCount = 0;
+
+        const unsigned long refreshTime = (unsigned long)(debugRefreshTime_ * 1000000.0f);
+        unsigned long refreshStartTime = 0;
+        unsigned long tickTime = 0;
+        unsigned long oldFrameCount = 0;
+
+        unsigned long timeBeforeTick = 0;
+        unsigned long timeBeforeTickOld = 0;
+        unsigned long timeAfterTick = 0;
+
+        // TODO: Update time in seconds every 7 seconds to avoid any overflow (7 secs is very tight)
+
+        COUT(3) << "Orxonox: Starting the main loop." << std::endl;
+
+        try
+        {
+            timer_->reset();
+            while (!bAbort_)
+            {
+                // get current time
+                timeBeforeTickOld = timeBeforeTick;
+                timeBeforeTick    = timer_->getMicroseconds();
+                float dt = (timeBeforeTick - timeBeforeTickOld) / 1000000.0;
+
+
+                // tick the core (needs real time for input and tcl thread management)
+                // TODO: ticks of InputManager and tcl thread manager have to be separated.
+                Core::tick(dt);
+
+                // tick child state
+                if (this->getActiveChild())
+                    this->getActiveChild()->tick(dt);
+
+                // get current time once again
+                timeAfterTick = timer_->getMicroseconds();
+
+                tickTime += timeAfterTick - timeBeforeTick;
+                if (timeAfterTick > refreshStartTime + refreshTime)
+                {
+                    GraphicsEngine::getInstance().setAverageTickTime(
+                        (float)tickTime * 0.001 / (frameCount - oldFrameCount));
+                    float avgFPS = (float)(frameCount - oldFrameCount) / (timeAfterTick - refreshStartTime) * 1000000.0;
+                    GraphicsEngine::getInstance().setAverageFramesPerSecond(avgFPS);
+
+                    oldFrameCount = frameCount;
+                    tickTime = 0;
+                    refreshStartTime = timeAfterTick;
+                }
+
+                // 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)
+                GraphicsEngine::getInstance().setWindowActivity(true);
+
+                // render
+                ogreRoot._updateAllRenderTargets();
+
+                // again, just to be sure ogre works fine
+                ogreRoot._fireFrameEnded(evt); // note: uses the same time as _fireFrameStarted
+
+                ++frameCount;
+            }
+        }
+        catch (std::exception& ex)
+        {
+            // something went wrong.
+            COUT(1) << ex.what() << std::endl;
+            COUT(1) << "Main loop was stopped by an unhandled exception. Shutting down." << std::endl;
+        }        return true;
+    }
+}
Index: code/branches/gui/src/orxonox/gamestates/GSGraphics.h
===================================================================
--- code/branches/gui/src/orxonox/gamestates/GSGraphics.h	(revision 1661)
+++ code/branches/gui/src/orxonox/gamestates/GSGraphics.h	(revision 1661)
@@ -0,0 +1,63 @@
+/*
+ *   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 _GSGraphics_H__
+#define _GSGraphics_H__
+
+#include "OrxonoxPrereqs.h"
+#include "core/GameState.h"
+
+namespace orxonox
+{
+    class _OrxonoxExport GSGraphics : public GameState, public OrxonoxClass
+    {
+    public:
+        GSGraphics();
+        ~GSGraphics();
+
+        bool tick(float dt);
+        void setConfigValues();
+
+    private:
+        void enter();
+        void leave();
+
+        Ogre::Timer*          timer_;            //!< Main loop timer
+        bool                  bAbort_;           //!< aborts the render loop if true
+
+        // config values
+        float                 debugRefreshTime_;
+
+        GraphicsEngine*       graphicsEngine_;   //!< our dearest graphics engine <3
+        InputManager*         inputManager_;
+        InGameConsole*        console_;
+        GUIManager*           guiManager_;
+    };
+}
+
+#endif /* _GSGraphics_H__ */
Index: code/branches/gui/src/orxonox/gamestates/GSLevel.cc
===================================================================
--- code/branches/gui/src/orxonox/gamestates/GSLevel.cc	(revision 1661)
+++ code/branches/gui/src/orxonox/gamestates/GSLevel.cc	(revision 1661)
@@ -0,0 +1,99 @@
+/*
+ *   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 "GSLevel.h"
+
+#include "GraphicsEngine.h"
+#include "core/ConsoleCommand.h"
+#include "core/input/InputManager.h"
+#include "core/input/SimpleInputState.h"
+#include "core/input/KeyBinder.h"
+#include "overlays/console/InGameConsole.h"
+#include "gui/GUIManager.h"
+
+namespace orxonox
+{
+    GSLevel::GSLevel()
+        : GameState("level")
+        , timefactor_(1.0f)
+    {
+    }
+
+    GSLevel::~GSLevel()
+    {
+    }
+
+    void GSLevel::enter()
+    {
+        KeyBinder* keyBinder = new KeyBinder();
+        keyBinder->loadBindings();
+        InputManager::getInstance().createInputState<SimpleInputState>("game", 20)->setHandler(keyBinder);
+
+        // add console commands
+        //ConsoleCommand* command = createConsoleCommand(createFunctor(&classname::function), )
+        //CommandExecutor::addConsoleCommandShortcut(command);
+    }
+
+    void GSLevel::leave()
+    {
+    }
+
+    bool GSLevel::tick(float dt)
+    {
+        // Call those objects that need the real time
+        for (Iterator<TickableReal> it = ObjectList<TickableReal>::start(); it; ++it)
+            it->tick(dt);
+        // Call the scene objects
+        for (Iterator<Tickable> it = ObjectList<Tickable>::start(); it; ++it)
+            it->tick(dt * this->timefactor_);
+
+        // call server/client with normal dt
+        //if (client_g)
+        //    client_g->tick(dt * this->timefactor_);
+        //if (server_g)
+        //    server_g->tick(dt * this->timefactor_);
+
+        return true;
+    }
+
+    /**
+    @brief
+        Changes the speed of Orxonox
+    */
+    //void GSLevel::setTimeFactor(float factor)
+    //{
+    //    float change = factor / Orxonox::getInstance().getTimeFactor();
+    //    Orxonox::getInstance().timefactor_ = factor;
+    //    for (Iterator<ParticleInterface> it = ObjectList<ParticleInterface>::begin(); it; ++it)
+    //        it->setSpeedFactor(it->getSpeedFactor() * change);
+
+    //    for (Iterator<Backlight> it = ObjectList<Backlight>::begin(); it; ++it)
+    //        it->setTimeFactor(Orxonox::getInstance().getTimeFactor());
+    //}
+}
Index: code/branches/gui/src/orxonox/gamestates/GSLevel.h
===================================================================
--- code/branches/gui/src/orxonox/gamestates/GSLevel.h	(revision 1661)
+++ code/branches/gui/src/orxonox/gamestates/GSLevel.h	(revision 1661)
@@ -0,0 +1,55 @@
+/*
+ *   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 _GSLevel_H__
+#define _GSLevel_H__
+
+#include "OrxonoxPrereqs.h"
+#include "core/GameState.h"
+
+namespace orxonox
+{
+    class _OrxonoxExport GSLevel : public GameState
+    {
+    public:
+        GSLevel();
+        ~GSLevel();
+
+        bool tick(float dt);
+
+    private:
+        void enter();
+        void leave();
+
+        void setTimeFactor(float factor);
+
+        float                 timefactor_;       //!< A factor to change the gamespeed
+    };
+}
+
+#endif /* _GSLevel_H__ */
Index: code/branches/gui/src/orxonox/gamestates/GSRoot.cc
===================================================================
--- code/branches/gui/src/orxonox/gamestates/GSRoot.cc	(revision 1661)
+++ code/branches/gui/src/orxonox/gamestates/GSRoot.cc	(revision 1661)
@@ -0,0 +1,100 @@
+/*
+ *   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 "GSRoot.h"
+
+#include <cassert>
+#include "core/Factory.h"
+#include "core/ConfigFileManager.h"
+#include "core/ConfigValueIncludes.h"
+#include "core/ConsoleCommand.h"
+#include "core/Debug.h"
+//#include "core/Exception.h"
+#include "core/TclBind.h"
+#include "core/Core.h"
+#include "GraphicsEngine.h"
+#include "Settings.h"
+
+namespace orxonox
+{
+    GSRoot::GSRoot()
+        : GameState("root")
+        , graphicsEngine_(0)
+    {
+    }
+
+    GSRoot::~GSRoot()
+    {
+    }
+
+    void GSRoot::enter()
+    {
+#if ORXONOX_DEBUG_MODE == 1
+        ConfigFileManager::getSingleton()->setFile(CFT_Settings, "orxonox_d.ini");
+#else
+        ConfigFileManager::getSingleton()->setFile(CFT_Settings, "orxonox.ini");
+#endif
+
+        // creates the class hierarchy for all classes with factories
+        Factory::createClassHierarchy();
+
+        // TODO: config values
+        //setConfigValues();
+
+        const Settings::CommandLineArgument* dataPath = Settings::getCommandLineArgument("dataPath");
+        assert(dataPath);
+        if (!dataPath->bHasDefaultValue_)
+        {
+            if (*dataPath->value_.getString().end() != '/' && *dataPath->value_.getString().end() != '\\')
+                Settings::tsetDataPath(dataPath->value_.getString() + "/");
+            else
+                Settings::tsetDataPath(dataPath->value_.getString());
+        }
+
+        // initialise TCL
+        TclBind::getInstance().setDataPath(Settings::getDataPath());
+
+        graphicsEngine_ = new GraphicsEngine();
+        graphicsEngine_->setup();       // creates ogre root and other essentials
+
+    }
+
+    void GSRoot::leave()
+    {
+        if (this->graphicsEngine_)
+            delete graphicsEngine_;
+    }
+
+    bool GSRoot::tick(float dt)
+    {
+        if (this->getActiveChild())
+            this->getActiveChild()->tick(dt);
+        return true;
+    }
+}
Index: code/branches/gui/src/orxonox/gamestates/GSRoot.h
===================================================================
--- code/branches/gui/src/orxonox/gamestates/GSRoot.h	(revision 1661)
+++ code/branches/gui/src/orxonox/gamestates/GSRoot.h	(revision 1661)
@@ -0,0 +1,53 @@
+/*
+ *   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 _GSRoot_H__
+#define _GSRoot_H__
+
+#include "OrxonoxPrereqs.h"
+#include "core/GameState.h"
+
+namespace orxonox
+{
+    class _OrxonoxExport GSRoot : public GameState
+    {
+    public:
+        GSRoot();
+        ~GSRoot();
+
+        bool tick(float dt);
+
+    private:
+        void enter();
+        void leave();
+
+        GraphicsEngine*       graphicsEngine_;   //!< our dearest graphics engine <3
+    };
+}
+
+#endif /* _GSGraphics_H__ */
Index: code/branches/gui/src/orxonox/gui/GUIManager.cc
===================================================================
--- code/branches/gui/src/orxonox/gui/GUIManager.cc	(revision 1660)
+++ code/branches/gui/src/orxonox/gui/GUIManager.cc	(revision 1661)
@@ -84,5 +84,11 @@
 
         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().destroyState("gui");
@@ -218,5 +224,5 @@
         {
             if (state_ == OnDisplay)
-                _hideGUI();
+                hideGUI();
 
             COUT(3) << "Loading GUI " << name << std::endl;
@@ -264,5 +270,5 @@
     }
 
-    void GUIManager::_hideGUI()
+    void GUIManager::hideGUI()
     {
         if (this->state_ != OnDisplay)
Index: code/branches/gui/src/orxonox/gui/GUIManager.h
===================================================================
--- code/branches/gui/src/orxonox/gui/GUIManager.h	(revision 1660)
+++ code/branches/gui/src/orxonox/gui/GUIManager.h	(revision 1661)
@@ -71,5 +71,5 @@
         }
         void showGUI(const std::string& name, Ogre::SceneManager* sceneManager);// bool showBackground); // tolua_export
-        void _hideGUI(); // tolua_export
+        void hideGUI(); // tolua_export
 
         Ogre::Camera* getCamera() { return this->backgroundCamera_; }
Index: code/branches/gui/visual_studio/vc8/orxonox.vcproj
===================================================================
--- code/branches/gui/visual_studio/vc8/orxonox.vcproj	(revision 1660)
+++ code/branches/gui/visual_studio/vc8/orxonox.vcproj	(revision 1661)
@@ -492,4 +492,24 @@
 				</File>
 			</Filter>
+			<Filter
+				Name="gamestates"
+				>
+				<File
+					RelativePath="..\..\src\orxonox\gamestates\GSGraphics.cc"
+					>
+				</File>
+				<File
+					RelativePath="..\..\src\orxonox\gamestates\GSGUI.cc"
+					>
+				</File>
+				<File
+					RelativePath="..\..\src\orxonox\gamestates\GSLevel.cc"
+					>
+				</File>
+				<File
+					RelativePath="..\..\src\orxonox\gamestates\GSRoot.cc"
+					>
+				</File>
+			</Filter>
 		</Filter>
 		<Filter
@@ -711,4 +731,24 @@
 				<File
 					RelativePath="..\..\src\orxonox\gui\OgreCEGUITexture.h"
+					>
+				</File>
+			</Filter>
+			<Filter
+				Name="gamestates"
+				>
+				<File
+					RelativePath="..\..\src\orxonox\gamestates\GSGraphics.h"
+					>
+				</File>
+				<File
+					RelativePath="..\..\src\orxonox\gamestates\GSGUI.h"
+					>
+				</File>
+				<File
+					RelativePath="..\..\src\orxonox\gamestates\GSLevel.h"
+					>
+				</File>
+				<File
+					RelativePath="..\..\src\orxonox\gamestates\GSRoot.h"
 					>
 				</File>
