Index: code/branches/presentation/src/orxonox/gamestates/GSRoot.cc
===================================================================
--- code/branches/presentation/src/orxonox/gamestates/GSRoot.cc	(revision 2459)
+++ code/branches/presentation/src/orxonox/gamestates/GSRoot.cc	(revision 2485)
@@ -32,4 +32,5 @@
 #include "util/Exception.h"
 #include "util/Debug.h"
+#include "core/Core.h"
 #include "core/Factory.h"
 #include "core/ConfigValueIncludes.h"
@@ -40,9 +41,10 @@
 #include "core/TclBind.h"
 #include "core/TclThreadManager.h"
+#include "core/LuaBind.h"
 #include "tools/Timer.h"
 #include "objects/Tickable.h"
 #include "Settings.h"
 
-#if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32 
+#if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32
 #  ifndef WIN32_LEAN_AND_MEAN
 #    define WIN32_LEAN_AND_MEAN
@@ -66,4 +68,7 @@
     GSRoot::GSRoot()
         : RootGameState("root")
+        , timeFactor_(1.0f)
+        , bPaused_(false)
+        , timeFactorPauseBackup_(1.0f)
         , settings_(0)
         , tclBind_(0)
@@ -73,4 +78,7 @@
         RegisterRootObject(GSRoot);
         setConfigValues();
+
+        this->ccSetTimeFactor_ = 0;
+        this->ccPause_ = 0;
     }
 
@@ -87,4 +95,10 @@
         // creates the class hierarchy for all classes with factories
         Factory::createClassHierarchy();
+
+        // reset game speed to normal
+        timeFactor_ = 1.0f;
+
+        // Create the lua interface
+        this->luaBind_ = new LuaBind();
 
         // instantiate Settings class
@@ -114,18 +128,42 @@
             setThreadAffinity((unsigned int)(limitToCPU - 1));
 
-        // add console commands
-        FunctorMember<GSRoot>* functor1 = createFunctor(&GSRoot::exitGame);
-        functor1->setObject(this);
-        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor1, "exit"));
-
-        // add console commands
-        FunctorMember01<GameStateBase, const std::string&>* functor2 = createFunctor(&GameStateBase::requestState);
-        functor2->setObject(this);
-        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor2, "selectGameState"));
+        {
+            // 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_);
+        }
+
+        {
+            // time factor console command
+            FunctorMember<GSRoot>* functor = createFunctor(&GSRoot::setTimeFactor);
+            functor->setObject(this);
+            this->ccSetTimeFactor_ = createConsoleCommand(functor, "setTimeFactor");
+            CommandExecutor::addConsoleCommandShortcut(this->ccSetTimeFactor_).accessLevel(AccessLevel::Offline).defaultValue(0, 1.0);
+        }
+
+        {
+            // time factor console command
+            FunctorMember<GSRoot>* functor = createFunctor(&GSRoot::pause);
+            functor->setObject(this);
+            this->ccPause_ = createConsoleCommand(functor, "pause");
+            CommandExecutor::addConsoleCommandShortcut(this->ccPause_).accessLevel(AccessLevel::Offline);
+        }
     }
 
     void GSRoot::leave()
     {
-        // TODO: remove and destroy console commands
+        // destroy console commands
+        delete this->ccExit_;
+        delete this->ccSelectGameState_;
 
         delete this->shell_;
@@ -133,6 +171,18 @@
         delete this->tclBind_;
 
-        delete settings_;
-
+        delete this->settings_;
+        delete this->luaBind_;
+
+        if (this->ccSetTimeFactor_)
+        {
+            delete this->ccSetTimeFactor_;
+            this->ccSetTimeFactor_ = 0;
+        }
+
+        if (this->ccPause_)
+        {
+            delete this->ccPause_;
+            this->ccPause_ = 0;
+        }
     }
 
@@ -153,5 +203,5 @@
         }
         for (ObjectList<Tickable>::iterator it = ObjectList<Tickable>::begin(); it; ++it)
-            it->tick(leveldt);
+            it->tick(leveldt * this->timeFactor_);
         /*** HACK *** HACK ***/
 
@@ -166,5 +216,5 @@
 
         Copyright (c) 2000-2008 Torus Knot Software Ltd
-        
+
         OGRE is licensed under the LGPL. For more info, see OGRE license.
     */
@@ -173,16 +223,16 @@
 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32
         // Get the current process core mask
-	    DWORD procMask;
-	    DWORD sysMask;
+        DWORD procMask;
+        DWORD sysMask;
 #  if _MSC_VER >= 1400 && defined (_M_X64)
-	    GetProcessAffinityMask(GetCurrentProcess(), (PDWORD_PTR)&procMask, (PDWORD_PTR)&sysMask);
+        GetProcessAffinityMask(GetCurrentProcess(), (PDWORD_PTR)&procMask, (PDWORD_PTR)&sysMask);
 #  else
-	    GetProcessAffinityMask(GetCurrentProcess(), &procMask, &sysMask);
+        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 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
@@ -190,12 +240,62 @@
             limitToCPU = 0;
 
-	    // Find the lowest core that this process uses and limitToCPU suggests
+        // 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);
+        while ((threadMask & procMask) == 0 || (threadMask < (1u << limitToCPU)))
+            threadMask <<= 1;
+
+        // Set affinity to the first core
+        SetThreadAffinityMask(GetCurrentThread(), threadMask);
 #endif
     }
+
+    /**
+    @brief
+        Changes the speed of Orxonox
+    */
+    void GSRoot::setTimeFactor(float factor)
+    {
+        if (Core::isMaster())
+        {
+            if (!this->bPaused_)
+            {
+                TimeFactorListener::timefactor_s = factor;
+
+                for (ObjectList<TimeFactorListener>::iterator it = ObjectList<TimeFactorListener>::begin(); it != ObjectList<TimeFactorListener>::end(); ++it)
+                    it->changedTimeFactor(factor, this->timeFactor_);
+
+                this->timeFactor_ = factor;
+            }
+            else
+                this->timeFactorPauseBackup_ = factor;
+        }
+    }
+
+    void GSRoot::pause()
+    {
+        if (Core::isMaster())
+        {
+            if (!this->bPaused_)
+            {
+                this->timeFactorPauseBackup_ = this->timeFactor_;
+                this->setTimeFactor(0.0f);
+                this->bPaused_ = true;
+            }
+            else
+            {
+                this->bPaused_ = false;
+                this->setTimeFactor(this->timeFactorPauseBackup_);
+            }
+        }
+    }
+
+    ////////////////////////
+    // TimeFactorListener //
+    ////////////////////////
+    float TimeFactorListener::timefactor_s = 1.0f;
+
+    TimeFactorListener::TimeFactorListener()
+    {
+        RegisterRootObject(TimeFactorListener);
+    }
 }
