[Orxonox-commit 3334] r8022 - in code/branches/usability: data/gui/scripts src/libraries/tools

landauf at orxonox.net landauf at orxonox.net
Sat Mar 5 20:39:21 CET 2011


Author: landauf
Date: 2011-03-05 20:39:21 +0100 (Sat, 05 Mar 2011)
New Revision: 8022

Modified:
   code/branches/usability/data/gui/scripts/GraphicsMenu.lua
   code/branches/usability/src/libraries/tools/Timer.cc
   code/branches/usability/src/libraries/tools/Timer.h
   code/branches/usability/src/libraries/tools/ToolsPrereqs.h
Log:
added RealTimer, a subclass of Timer which is not affected by the game's time factor
added "delayreal" command which works like "delay" but uses RealTimer instead of Timer

in the graphics menu, the resolution confirmation popup now also closes itself after 10 seconds if it is used ingame while the game is paused

Modified: code/branches/usability/data/gui/scripts/GraphicsMenu.lua
===================================================================
--- code/branches/usability/data/gui/scripts/GraphicsMenu.lua	2011-03-05 18:10:31 UTC (rev 8021)
+++ code/branches/usability/data/gui/scripts/GraphicsMenu.lua	2011-03-05 19:39:21 UTC (rev 8022)
@@ -327,7 +327,7 @@
     P.oldHeight = orxonox.GraphicsManager:getInstance():getWindowHeight()
     P.oldFullscreen = orxonox.GraphicsManager:getInstance():isFullScreen()
 
-    P.revertTimerHandle = orxonox.CommandExecutor:query("delay 10 \"hideGUI DecisionPopup; GraphicsManager setScreenResolution " .. P.oldWidth .. " " .. P.oldHeight .. " " .. tostring(P.oldFullscreen) .. "\"")
+    P.revertTimerHandle = orxonox.CommandExecutor:query("delayreal 10 \"hideGUI DecisionPopup; GraphicsManager setScreenResolution " .. P.oldWidth .. " " .. P.oldHeight .. " " .. tostring(P.oldFullscreen) .. "\"")
 
     -- change settings
     orxonox.CommandExecutor:execute("GraphicsManager setScreenResolution " .. widthEditbox:getText() .. " " .. heightEditbox:getText() .. " " .. checkedFullscreen)

Modified: code/branches/usability/src/libraries/tools/Timer.cc
===================================================================
--- code/branches/usability/src/libraries/tools/Timer.cc	2011-03-05 18:10:31 UTC (rev 8021)
+++ code/branches/usability/src/libraries/tools/Timer.cc	2011-03-05 19:39:21 UTC (rev 8022)
@@ -42,10 +42,12 @@
 #include "core/command/ConsoleCommand.h"
 #include "core/command/CommandExecutor.h"
 #include "core/command/Functor.h"
+#include "tools/interfaces/TimeFactorListener.h"
 
 namespace orxonox
 {
     SetConsoleCommand("delay", &delay).argumentCompleter(1, autocompletion::command());
+    SetConsoleCommand("delayreal", &delayreal).argumentCompleter(1, autocompletion::command());
     SetConsoleCommand("killdelay", &killdelay);
     SetConsoleCommand("killdelays", &killdelays);
 
@@ -53,19 +55,41 @@
     static unsigned int delayHandleCounter = 0;
 
     /**
-        @brief Console-command: Calls another console command after @a delay seconds.
+        @brief Console-command: Calls another console command after @a delay seconds (game time).
         @param delay The delay in seconds
         @param command The console command
         @return The handle of the delayed command, can be used as argument for killdelay()
     */
     unsigned int delay(float delay, const std::string& command)
     {
-        Timer* delaytimer = new Timer();
-        delaytimers.insert(boost::bimap<unsigned int, Timer*>::value_type(++delayHandleCounter, delaytimer));
+        return addDelayedCommand(new Timer(), delay, command);
+    }
 
+    /**
+        @brief Console-command: Calls another console command after @a delay seconds (real time)
+        @param delay The delay in seconds
+        @param command The console command
+        @return The handle of the delayed command, can be used as argument for killdelay()
+    */
+    unsigned int delayreal(float delay, const std::string& command)
+    {
+        return addDelayedCommand(new RealTimer(), delay, command);
+    }
+
+    /**
+        @brief Helper function, used by delay() and delayreal() to add a delayed command.
+        @param timer The timer which will execute the command
+        @param delay The delay in seconds
+        @param command The console command
+        @return The handle of the delayed command, can be used as argument for killdelay()
+    */
+    unsigned int addDelayedCommand(Timer* timer, float delay, const std::string& command)
+    {
+        delaytimers.insert(boost::bimap<unsigned int, Timer*>::value_type(++delayHandleCounter, timer));
+
         const ExecutorStaticPtr& delayexecutor = createExecutor(createFunctor(&executeDelayedCommand));
-        delayexecutor->setDefaultValues(delaytimer, command);
-        delaytimer->setTimer(delay, false, delayexecutor);
+        delayexecutor->setDefaultValues(timer, command);
+        timer->setTimer(delay, false, delayexecutor);
 
         return delayHandleCounter;
     }
@@ -112,7 +136,7 @@
     Timer::Timer()
     {
         this->init();
-        RegisterObject(Timer);
+        RegisterRootObject(Timer);
     }
 
     /**
@@ -125,7 +149,7 @@
     Timer::Timer(float interval, bool bLoop, const ExecutorPtr& executor, bool bKillAfterCall)
     {
         this->init();
-        RegisterObject(Timer);
+        RegisterRootObject(Timer);
 
         this->setTimer(interval, bLoop, executor, bKillAfterCall);
     }
@@ -145,6 +169,14 @@
     }
 
     /**
+        @brief Returns the current time factor of the game.
+    */
+    float Timer::getTimeFactor()
+    {
+        return TimeFactorListener::getTimeFactor();
+    }
+
+    /**
         @brief Calls the executor and destroys the timer if requested.
     */
     void Timer::run()
@@ -187,4 +219,25 @@
             }
         }
     }
+
+    ///////////////
+    // RealTimer //
+    ///////////////
+    /// @copydoc Timer::Timer
+    RealTimer::RealTimer()
+    {
+        RegisterObject(RealTimer);
+    }
+
+    /// @copydoc Timer::Timer(float, bool, const ExecutorPtr&, bool)
+    RealTimer::RealTimer(float interval, bool bLoop, const ExecutorPtr& executor, bool bKillAfterCall) : Timer(interval, bLoop, executor, bKillAfterCall)
+    {
+        RegisterObject(RealTimer);
+    }
+
+    /// Returns always 1 because RealTimer doesn't depend on the game time.
+    float RealTimer::getTimeFactor()
+    {
+        return 1;
+    }
 }

Modified: code/branches/usability/src/libraries/tools/Timer.h
===================================================================
--- code/branches/usability/src/libraries/tools/Timer.h	2011-03-05 18:10:31 UTC (rev 8021)
+++ code/branches/usability/src/libraries/tools/Timer.h	2011-03-05 19:39:21 UTC (rev 8022)
@@ -80,21 +80,28 @@
 
 #include "core/OrxonoxClass.h"
 #include "core/command/Executor.h"
-#include "tools/interfaces/TimeFactorListener.h"
 
 namespace orxonox
 {
     unsigned int delay(float delay, const std::string& command);
+    unsigned int delayreal(float delay, const std::string& command);
+
+    unsigned int addDelayedCommand(Timer* timer, float delay, const std::string& command);
+    void executeDelayedCommand(Timer* timer, const std::string& command);
+
     void killdelay(unsigned int handle);
     void killdelays();
-    void executeDelayedCommand(Timer* timer, const std::string& command);
 
     /**
-        @brief Timer is a helper class that executes a function after a given amount of time.
+        @brief Timer is a helper class that executes a function after a given amount of seconds in game-time.
 
         @see See @ref TimerExample "Timer.h" for an example.
+
+        The time interval of Timer depends on the game time, hence it stops if the game is paused or runs
+        slower/faster if the game-speed is modified. See RealTimer for a timer class which doesn't depend
+        on the game time.
     */
-    class _ToolsExport Timer : public TimeFactorListener
+    class _ToolsExport Timer : virtual public OrxonoxClass
     {
         public:
             Timer();
@@ -123,28 +130,28 @@
 
             void run();
 
-            /// Re-starts the Timer: The executor will be called after @a interval seconds.
+            /// Re-starts the timer: The executor will be called after @a interval seconds.
             inline void startTimer()
                 { this->bActive_ = true; this->time_ = this->interval_; }
-            /// Stops the Timer.
+            /// Stops the timer.
             inline void stopTimer()
                 { this->bActive_ = false; this->time_ = this->interval_; }
-            /// Pauses the Timer - it will continue with the actual state if you call unpauseTimer().
+            /// Pauses the timer - it will continue with the actual state if you call unpauseTimer().
             inline void pauseTimer()
                 { this->bActive_ = false; }
-            /// Unpauses the Timer - continues with the given state.
+            /// Unpauses the timer - continues with the given state.
             inline void unpauseTimer()
                 { this->bActive_ = true; }
-            /// Returns true if the Timer is active (neither stopped nor paused).
+            /// Returns true if the timer is active (neither stopped nor paused).
             inline bool isActive() const
                 { return this->bActive_; }
-            /// Returns the remaining time until the Timer calls the executor.
+            /// Returns the remaining time until the timer calls the executor.
             inline float getRemainingTime() const
                 { return static_cast<float>(this->time_ / 1000000.0f); }
-            /// Increases the remaining time of the Timer by the given amount of time (in seconds).
+            /// Increases the remaining time of the timer by the given amount of time (in seconds).
             inline void addTime(float time)
                 { if (time > 0.0f) this->time_ += static_cast<long long>(time * 1000000.0f); }
-            /// Decreases the remaining time of the Timer by the given amount of time (in seconds)
+            /// Decreases the remaining time of the timer by the given amount of time (in seconds)
             inline void removeTime(float time)
                 { if (time > 0.0f) this->time_ -= static_cast<long long>(time * 1000000.0f); }
             /// Changes the calling interval.
@@ -156,6 +163,9 @@
 
             void tick(const Clock& time);
 
+        protected:
+            virtual float getTimeFactor();
+
         private:
             void init();
 
@@ -163,11 +173,27 @@
 
             long long interval_;    //!< The time-interval in micro seconds
             bool bLoop_;            //!< If true, the executor gets called every @a interval seconds
-            bool bActive_;          //!< If true, the Timer ticks and calls the executor if the time's up
+            bool bActive_;          //!< If true, the timer ticks and calls the executor if the time's up
             bool bKillAfterCall_;   //!< If true the timer gets deleted after it expired and called the executor
 
             long long time_;        //!< Internal variable, counting the time untill the next executor-call
     };
+
+    /**
+        @brief RealTimer is a helper class that executes a function after a given amount of seconds in real-time.
+
+        The time interval of RealTimer doesn't depend on the game time, it will also call the function
+        if the game is paused. See Timer for a timer class that depends on the game time.
+    */
+    class _ToolsExport RealTimer : public Timer
+    {
+        public:
+            RealTimer();
+            RealTimer(float interval, bool bLoop, const ExecutorPtr& executor, bool bKillAfterCall = false);
+
+        protected:
+            virtual float getTimeFactor();
+    };
 }
 
 #endif /* _Timer_H__ */

Modified: code/branches/usability/src/libraries/tools/ToolsPrereqs.h
===================================================================
--- code/branches/usability/src/libraries/tools/ToolsPrereqs.h	2011-03-05 18:10:31 UTC (rev 8021)
+++ code/branches/usability/src/libraries/tools/ToolsPrereqs.h	2011-03-05 19:39:21 UTC (rev 8022)
@@ -84,6 +84,7 @@
     class BillboardSet;
     class Mesh;
     class ParticleInterface;
+    class RealTimer;
     class ResourceCollection;
     class ResourceLocation;
     class Shader;




More information about the Orxonox-commit mailing list