Index: code/branches/gui/src/core/Clock.h
===================================================================
--- code/branches/gui/src/core/Clock.h	(revision 2801)
+++ code/branches/gui/src/core/Clock.h	(revision 2805)
@@ -45,9 +45,9 @@
     class _CoreExport Clock
     {
-        friend class RootGameState;
-
     public:
         Clock();
         ~Clock();
+
+        void capture();
 
         unsigned long long getMicroseconds()   const { return tickTime_; }
@@ -63,5 +63,4 @@
     private:
         Clock(const Clock& instance);
-        void capture();
 
         Ogre::Timer*       timer_;
Index: code/branches/gui/src/core/GameState.h
===================================================================
--- code/branches/gui/src/core/GameState.h	(revision 2801)
+++ code/branches/gui/src/core/GameState.h	(revision 2805)
@@ -65,4 +65,6 @@
         template <class ParentType>
         friend class GameState;
+        // Hack
+        friend class Game;
 
     public:
Index: code/branches/gui/src/core/RootGameState.cc
===================================================================
--- code/branches/gui/src/core/RootGameState.cc	(revision 2801)
+++ code/branches/gui/src/core/RootGameState.cc	(revision 2805)
@@ -32,10 +32,7 @@
 #include "util/Exception.h"
 #include "Clock.h"
-#include "CommandLine.h"
 
 namespace orxonox
 {
-    SetCommandLineArgument(state, "gui").shortcut("s");
-
     RootGameState::RootGameState(const std::string& name)
         : GameState<GameStateBase>(name)
@@ -119,60 +116,3 @@
         this->stateRequest_ = name;
     }
-
-    /**
-    @brief
-        Main loop of the orxonox game.
-        Starts the game. The little 'while' denotes the main loop.
-        Whenever the root state is selected, the game ends.
-    @param name
-        State to start with (usually main menu or specified by command line)
-    @note
-        We use the Ogre::Timer to measure time since it uses the most precise
-        method an a platform (however the windows timer lacks time when under
-        heavy kernel load!).
-    */
-    void RootGameState::start()
-    {
-        // Don't catch errors when having a debugger in msvc
-#if !defined(ORXONOX_COMPILER_MSVC) || defined(NDEBUG)
-        try
-        {
-#endif
-            // start global orxonox time
-            Clock clock;
-
-            this->activate();
-
-            // get initial state from command line
-            gotoState(CommandLine::getValue("state"));
-
-            while (this->activeChild_)
-            {
-                clock.capture();
-
-                this->tick(clock);
-
-                if (this->stateRequest_ != "")
-                    gotoState(stateRequest_);
-            }
-
-            this->deactivate();
-#if !defined(ORXONOX_COMPILER_MSVC) || defined(NDEBUG)
-        }
-        // Note: These are all unhandled exceptions that should not have made its way here!
-        // almost complete game catch block to display the messages appropriately.
-        catch (std::exception& ex)
-        {
-            COUT(0) << ex.what() << std::endl;
-            COUT(0) << "Program aborted." << std::endl;
-            abort();
-        }
-        // anything that doesn't inherit from std::exception
-        catch (...)
-        {
-            COUT(0) << "An unidentifiable exception has occured. Program aborted." << std::endl;
-            abort();
-        }
-#endif
-    }
 }
Index: code/branches/gui/src/core/RootGameState.h
===================================================================
--- code/branches/gui/src/core/RootGameState.h	(revision 2801)
+++ code/branches/gui/src/core/RootGameState.h	(revision 2805)
@@ -37,4 +37,7 @@
     class _CoreExport RootGameState : public GameState<GameStateBase>
     {
+        // Hack!
+        friend class Game;
+
     public:
         RootGameState(const std::string& name);
@@ -42,5 +45,4 @@
 
         void requestState(const std::string& name);
-        void start();
 
     private:
Index: code/branches/gui/src/orxonox/CMakeLists.txt
===================================================================
--- code/branches/gui/src/orxonox/CMakeLists.txt	(revision 2801)
+++ code/branches/gui/src/orxonox/CMakeLists.txt	(revision 2805)
@@ -20,7 +20,7 @@
 SET_SOURCE_FILES(ORXONOX_SRC_FILES
   CameraManager.cc
+  Game.cc
   GraphicsManager.cc
   LevelManager.cc
-  Main.cc
   PawnManager.cc
   PlayerManager.cc
Index: code/branches/gui/src/orxonox/Game.cc
===================================================================
--- code/branches/gui/src/orxonox/Game.cc	(revision 2805)
+++ code/branches/gui/src/orxonox/Game.cc	(revision 2805)
@@ -0,0 +1,171 @@
+/*
+ *   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:
+ *      ...
+ *
+ */
+
+/**
+@file
+@brief
+    Implementation of the Game class.
+*/
+
+#include "OrxonoxStableHeaders.h"
+#include "Game.h"
+
+#include <exception>
+#include <cassert>
+
+#include "util/Debug.h"
+#include "util/Exception.h"
+#include "core/CommandLine.h"
+#include "core/ConsoleCommand.h"
+#include "core/Core.h"
+#include "core/Identifier.h"
+
+#include "gamestates/GSRoot.h"
+#include "gamestates/GSGraphics.h"
+#include "gamestates/GSStandalone.h"
+#include "gamestates/GSServer.h"
+#include "gamestates/GSClient.h"
+#include "gamestates/GSDedicated.h"
+#include "gamestates/GSGUI.h"
+#include "gamestates/GSIOConsole.h"
+
+/*
+@brief
+    Main method. Game starts here (except for static initialisations).
+*/
+int main(int argc, char** argv)
+{
+    orxonox::Game orxonox(argc, argv);
+    orxonox.run();
+    return 0;
+}
+
+namespace orxonox
+{
+    void stop_game()
+    {
+        Game::getInstance().stop();
+    }
+
+    SetCommandLineArgument(state, "gui").shortcut("s");
+    SetConsoleCommandShortcutExternAlias(stop_game, "exit");
+
+    Game* Game::singletonRef_s = 0;
+
+    /**
+    @brief
+        Non-initialising constructor.
+    */
+    Game::Game(int argc, char** argv)
+    {
+        assert(singletonRef_s == 0);
+        singletonRef_s = this;
+
+        this->abort_ = false;
+
+        this->core_ = new orxonox::Core(argc, argv);
+        if (!this->core_->isLoaded())
+        {
+            COUT(0) << "Core was not fully loaded, probably an exception occurred during consruction. Aborting" << std::endl;
+            abort();
+        }
+    }
+
+    /**
+    @brief
+    */
+    Game::~Game()
+    {
+        // Destroy pretty much everyhting left
+        delete this->core_;
+
+        // Clean up class hierarchy stuff (identifiers, xmlport, configvalue, consolecommand)
+        // Needs to be done after 'delete core' because of ~OrxonoxClass
+        orxonox::Identifier::destroyAllIdentifiers();
+
+        assert(singletonRef_s);
+        singletonRef_s = 0;
+    }
+
+    /**
+    @brief
+        Main loop of the orxonox game.
+    @note
+        We use the Ogre::Timer to measure time since it uses the most precise
+        method an any platform (however the windows timer lacks time when under
+        heavy kernel load!).
+    */
+    void Game::run()
+    {
+        // create the gamestates
+        GSRoot root;
+        GSGraphics graphics;
+        GSStandalone standalone;
+        GSServer server;
+        GSClient client;
+        GSDedicated dedicated;
+        GSGUI gui;
+        GSIOConsole ioConsole;
+
+        // make the hierarchy
+        root.addChild(&graphics);
+        graphics.addChild(&standalone);
+        graphics.addChild(&server);
+        graphics.addChild(&client);
+        graphics.addChild(&gui);
+        root.addChild(&ioConsole);
+        root.addChild(&dedicated);
+
+
+        // start global orxonox time
+        Clock clock;
+
+        root.activate();
+
+        // get initial state from command line
+        root.gotoState(CommandLine::getValue("state"));
+
+        while (!this->abort_)
+        {
+            clock.capture();
+
+            root.tick(clock);
+
+            if (root.stateRequest_ != "")
+                root.gotoState(root.stateRequest_);
+        }
+
+        root.gotoState("root");
+        root.deactivate();
+    }
+
+    void Game::stop()
+    {
+        this->abort_ = true;
+    }
+}
Index: code/branches/gui/src/orxonox/Game.h
===================================================================
--- code/branches/gui/src/orxonox/Game.h	(revision 2805)
+++ code/branches/gui/src/orxonox/Game.h	(revision 2805)
@@ -0,0 +1,70 @@
+/*
+ *   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:
+ *      ...
+ *
+ */
+
+/**
+@file
+@brief
+    Declaration of Game Singleton.
+ */
+
+#ifndef _Game_H__
+#define _Game_H__
+
+#include "OrxonoxPrereqs.h"
+#include <cassert>
+#include "core/CorePrereqs.h"
+
+namespace orxonox
+{
+    /**
+    @brief
+        Main class responsible for running the game.
+    */
+    class _OrxonoxExport Game
+    {
+    public:
+        Game(int argc, char** argv);
+        ~Game();
+
+        void run();
+        void stop();
+
+        static Game& getInstance() { assert(singletonRef_s); return *singletonRef_s; }
+
+    private:
+        Game(Game&); // don't mess with singletons
+
+        Core* core_;
+
+        bool abort_;
+
+        static Game* singletonRef_s;        //!< Pointer to the Singleton
+    };
+}
+
+#endif /* _Game_H__ */
Index: code/branches/gui/src/orxonox/GraphicsManager.h
===================================================================
--- code/branches/gui/src/orxonox/GraphicsManager.h	(revision 2801)
+++ code/branches/gui/src/orxonox/GraphicsManager.h	(revision 2805)
@@ -34,6 +34,6 @@
  */
 
-#ifndef _GraphicsEngine_H__
-#define _GraphicsEngine_H__
+#ifndef _GraphicsManager_H__
+#define _GraphicsManager_H__
 
 #include "OrxonoxPrereqs.h"
@@ -131,3 +131,3 @@
 }
 
-#endif /* _GraphicsEngine_H__ */
+#endif /* _GraphicsManager_H__ */
Index: code/branches/gui/src/orxonox/Main.cc
===================================================================
--- code/branches/gui/src/orxonox/Main.cc	(revision 2801)
+++ 	(revision )
@@ -1,126 +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:
- *      Benjamin Knecht <beni_at_orxonox.net>, (C) 2007
- *      Reto Grieder
- *   Co-authors:
- *      ...
- *
- */
-
- /**
- @file
- @brief Entry point of the program.
-  */
-
-#include "OrxonoxStableHeaders.h"
-#include "OrxonoxConfig.h"
-
-#include <exception>
-#include <cassert>
-
-#include "util/Debug.h"
-#include "core/Core.h"
-#include "core/Identifier.h"
-
-#include "gamestates/GSRoot.h"
-#include "gamestates/GSGraphics.h"
-#include "gamestates/GSStandalone.h"
-#include "gamestates/GSServer.h"
-#include "gamestates/GSClient.h"
-#include "gamestates/GSDedicated.h"
-#include "gamestates/GSGUI.h"
-#include "gamestates/GSIOConsole.h"
-
-#ifdef ORXONOX_PLATFORM_APPLE
-#include <CoreFoundation/CoreFoundation.h>
-
-// This function will locate the path to our application on OS X,
-// unlike windows you can not rely on the curent working directory
-// for locating your configuration files and resources.
-             std::string macBundlePath()
-{
-    char path[1024];
-    CFBundleRef mainBundle = CFBundleGetMainBundle();
-    assert(mainBundle);
-
-    CFURLRef mainBundleURL = CFBundleCopyBundleURL(mainBundle);
-    assert(mainBundleURL);
-
-    CFStringRef cfStringRef = CFURLCopyFileSystemPath( mainBundleURL, kCFURLPOSIXPathStyle);
-    assert(cfStringRef);
-
-    CFStringGetCString(cfStringRef, path, 1024, kCFStringEncodingASCII);
-
-    CFRelease(mainBundleURL);
-    CFRelease(cfStringRef);
-
-    return std::string(path);
-}
-#endif
-
-
-
-int main(int argc, char** argv)
-{
-    orxonox::Core* core = new orxonox::Core(argc, argv);
-    if (!core->isLoaded())
-    {
-        COUT(0) << "Core was not fully loaded, probably an exception occurred during consruction. Aborting" << std::endl;
-        abort();
-    }
-
-    // put GameStates in its own scope so we can destroy the identifiers at the end of main().
-    {
-        using namespace orxonox;
-        // create the gamestates
-        GSRoot root;
-        GSGraphics graphics;
-        GSStandalone standalone;
-        GSServer server;
-        GSClient client;
-        GSDedicated dedicated;
-        GSGUI gui;
-        GSIOConsole ioConsole;
-
-        // make the hierarchy
-        root.addChild(&graphics);
-        graphics.addChild(&standalone);
-        graphics.addChild(&server);
-        graphics.addChild(&client);
-        graphics.addChild(&gui);
-        root.addChild(&ioConsole);
-        root.addChild(&dedicated);
-
-        // Here happens the game
-        root.start();
-    }
-
-    // Destroy pretty much everyhting left
-    delete core;
-
-    // Clean up class hierarchy stuff (identifiers, xmlport, configvalue, consolecommand)
-    // Needs to be done after 'delete core' because of ~OrxonoxClass
-    orxonox::Identifier::destroyAllIdentifiers();
-
-    return 0;
-}
Index: code/branches/gui/src/orxonox/gamestates/GSGraphics.cc
===================================================================
--- code/branches/gui/src/orxonox/gamestates/GSGraphics.cc	(revision 2801)
+++ code/branches/gui/src/orxonox/gamestates/GSGraphics.cc	(revision 2805)
@@ -75,5 +75,5 @@
         Core::setShowsGraphics(true);
 
-        // initialise graphics engine. Doesn't load the render window yet!
+        // initialise graphics manager. Doesn't load the render window yet!
         this->graphicsManager_ = new GraphicsManager();
         this->graphicsManager_->initialise();
Index: code/branches/gui/src/orxonox/gamestates/GSRoot.cc
===================================================================
--- code/branches/gui/src/orxonox/gamestates/GSRoot.cc	(revision 2801)
+++ code/branches/gui/src/orxonox/gamestates/GSRoot.cc	(revision 2805)
@@ -80,12 +80,4 @@
         {
             // 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);
@@ -114,5 +106,4 @@
     {
         // destroy console commands
-        delete this->ccExit_;
         delete this->ccSelectGameState_;
 
Index: code/branches/gui/src/orxonox/gamestates/GSRoot.h
===================================================================
--- code/branches/gui/src/orxonox/gamestates/GSRoot.h	(revision 2801)
+++ code/branches/gui/src/orxonox/gamestates/GSRoot.h	(revision 2805)
@@ -53,7 +53,4 @@
         ~GSRoot();
 
-        void exitGame()
-        { requestState("root"); }
-
         // this has to be public because proteced triggers a bug in msvc
         // when taking the function address.
@@ -93,5 +90,4 @@
 
         // console commands
-        ConsoleCommand*       ccExit_;
         ConsoleCommand*       ccSelectGameState_;
         ConsoleCommand*       ccSetTimeFactor_;
