- Timestamp:
- Mar 5, 2011, 8:39:21 PM (14 years ago)
- Location:
- code/branches/usability
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/usability/data/gui/scripts/GraphicsMenu.lua
r8021 r8022 328 328 P.oldFullscreen = orxonox.GraphicsManager:getInstance():isFullScreen() 329 329 330 P.revertTimerHandle = orxonox.CommandExecutor:query("delay 10 \"hideGUI DecisionPopup; GraphicsManager setScreenResolution " .. P.oldWidth .. " " .. P.oldHeight .. " " .. tostring(P.oldFullscreen) .. "\"")330 P.revertTimerHandle = orxonox.CommandExecutor:query("delayreal 10 \"hideGUI DecisionPopup; GraphicsManager setScreenResolution " .. P.oldWidth .. " " .. P.oldHeight .. " " .. tostring(P.oldFullscreen) .. "\"") 331 331 332 332 -- change settings -
code/branches/usability/src/libraries/tools/Timer.cc
r8020 r8022 43 43 #include "core/command/CommandExecutor.h" 44 44 #include "core/command/Functor.h" 45 #include "tools/interfaces/TimeFactorListener.h" 45 46 46 47 namespace orxonox 47 48 { 48 49 SetConsoleCommand("delay", &delay).argumentCompleter(1, autocompletion::command()); 50 SetConsoleCommand("delayreal", &delayreal).argumentCompleter(1, autocompletion::command()); 49 51 SetConsoleCommand("killdelay", &killdelay); 50 52 SetConsoleCommand("killdelays", &killdelays); … … 54 56 55 57 /** 56 @brief Console-command: Calls another console command after @a delay seconds .58 @brief Console-command: Calls another console command after @a delay seconds (game time). 57 59 @param delay The delay in seconds 58 60 @param command The console command … … 61 63 unsigned int delay(float delay, const std::string& command) 62 64 { 63 Timer* delaytimer = new Timer(); 64 delaytimers.insert(boost::bimap<unsigned int, Timer*>::value_type(++delayHandleCounter, delaytimer)); 65 return addDelayedCommand(new Timer(), delay, command); 66 } 67 68 /** 69 @brief Console-command: Calls another console command after @a delay seconds (real time) 70 @param delay The delay in seconds 71 @param command The console command 72 @return The handle of the delayed command, can be used as argument for killdelay() 73 */ 74 unsigned int delayreal(float delay, const std::string& command) 75 { 76 return addDelayedCommand(new RealTimer(), delay, command); 77 } 78 79 /** 80 @brief Helper function, used by delay() and delayreal() to add a delayed command. 81 @param timer The timer which will execute the command 82 @param delay The delay in seconds 83 @param command The console command 84 @return The handle of the delayed command, can be used as argument for killdelay() 85 */ 86 unsigned int addDelayedCommand(Timer* timer, float delay, const std::string& command) 87 { 88 delaytimers.insert(boost::bimap<unsigned int, Timer*>::value_type(++delayHandleCounter, timer)); 65 89 66 90 const ExecutorStaticPtr& delayexecutor = createExecutor(createFunctor(&executeDelayedCommand)); 67 delayexecutor->setDefaultValues( delaytimer, command);68 delaytimer->setTimer(delay, false, delayexecutor);91 delayexecutor->setDefaultValues(timer, command); 92 timer->setTimer(delay, false, delayexecutor); 69 93 70 94 return delayHandleCounter; … … 113 137 { 114 138 this->init(); 115 Register Object(Timer);139 RegisterRootObject(Timer); 116 140 } 117 141 … … 126 150 { 127 151 this->init(); 128 Register Object(Timer);152 RegisterRootObject(Timer); 129 153 130 154 this->setTimer(interval, bLoop, executor, bKillAfterCall); … … 143 167 144 168 this->time_ = 0; 169 } 170 171 /** 172 @brief Returns the current time factor of the game. 173 */ 174 float Timer::getTimeFactor() 175 { 176 return TimeFactorListener::getTimeFactor(); 145 177 } 146 178 … … 188 220 } 189 221 } 222 223 /////////////// 224 // RealTimer // 225 /////////////// 226 /// @copydoc Timer::Timer 227 RealTimer::RealTimer() 228 { 229 RegisterObject(RealTimer); 230 } 231 232 /// @copydoc Timer::Timer(float, bool, const ExecutorPtr&, bool) 233 RealTimer::RealTimer(float interval, bool bLoop, const ExecutorPtr& executor, bool bKillAfterCall) : Timer(interval, bLoop, executor, bKillAfterCall) 234 { 235 RegisterObject(RealTimer); 236 } 237 238 /// Returns always 1 because RealTimer doesn't depend on the game time. 239 float RealTimer::getTimeFactor() 240 { 241 return 1; 242 } 190 243 } -
code/branches/usability/src/libraries/tools/Timer.h
r8020 r8022 81 81 #include "core/OrxonoxClass.h" 82 82 #include "core/command/Executor.h" 83 #include "tools/interfaces/TimeFactorListener.h"84 83 85 84 namespace orxonox 86 85 { 87 86 unsigned int delay(float delay, const std::string& command); 87 unsigned int delayreal(float delay, const std::string& command); 88 89 unsigned int addDelayedCommand(Timer* timer, float delay, const std::string& command); 90 void executeDelayedCommand(Timer* timer, const std::string& command); 91 88 92 void killdelay(unsigned int handle); 89 93 void killdelays(); 90 void executeDelayedCommand(Timer* timer, const std::string& command);91 94 92 95 /** 93 @brief Timer is a helper class that executes a function after a given amount of time.96 @brief Timer is a helper class that executes a function after a given amount of seconds in game-time. 94 97 95 98 @see See @ref TimerExample "Timer.h" for an example. 99 100 The time interval of Timer depends on the game time, hence it stops if the game is paused or runs 101 slower/faster if the game-speed is modified. See RealTimer for a timer class which doesn't depend 102 on the game time. 96 103 */ 97 class _ToolsExport Timer : public TimeFactorListener104 class _ToolsExport Timer : virtual public OrxonoxClass 98 105 { 99 106 public: … … 124 131 void run(); 125 132 126 /// Re-starts the Timer: The executor will be called after @a interval seconds.133 /// Re-starts the timer: The executor will be called after @a interval seconds. 127 134 inline void startTimer() 128 135 { this->bActive_ = true; this->time_ = this->interval_; } 129 /// Stops the Timer.136 /// Stops the timer. 130 137 inline void stopTimer() 131 138 { this->bActive_ = false; this->time_ = this->interval_; } 132 /// Pauses the Timer - it will continue with the actual state if you call unpauseTimer().139 /// Pauses the timer - it will continue with the actual state if you call unpauseTimer(). 133 140 inline void pauseTimer() 134 141 { this->bActive_ = false; } 135 /// Unpauses the Timer - continues with the given state.142 /// Unpauses the timer - continues with the given state. 136 143 inline void unpauseTimer() 137 144 { this->bActive_ = true; } 138 /// Returns true if the Timer is active (neither stopped nor paused).145 /// Returns true if the timer is active (neither stopped nor paused). 139 146 inline bool isActive() const 140 147 { return this->bActive_; } 141 /// Returns the remaining time until the Timer calls the executor.148 /// Returns the remaining time until the timer calls the executor. 142 149 inline float getRemainingTime() const 143 150 { return static_cast<float>(this->time_ / 1000000.0f); } 144 /// Increases the remaining time of the Timer by the given amount of time (in seconds).151 /// Increases the remaining time of the timer by the given amount of time (in seconds). 145 152 inline void addTime(float time) 146 153 { if (time > 0.0f) this->time_ += static_cast<long long>(time * 1000000.0f); } 147 /// Decreases the remaining time of the Timer by the given amount of time (in seconds)154 /// Decreases the remaining time of the timer by the given amount of time (in seconds) 148 155 inline void removeTime(float time) 149 156 { if (time > 0.0f) this->time_ -= static_cast<long long>(time * 1000000.0f); } … … 157 164 void tick(const Clock& time); 158 165 166 protected: 167 virtual float getTimeFactor(); 168 159 169 private: 160 170 void init(); … … 164 174 long long interval_; //!< The time-interval in micro seconds 165 175 bool bLoop_; //!< If true, the executor gets called every @a interval seconds 166 bool bActive_; //!< If true, the Timer ticks and calls the executor if the time's up176 bool bActive_; //!< If true, the timer ticks and calls the executor if the time's up 167 177 bool bKillAfterCall_; //!< If true the timer gets deleted after it expired and called the executor 168 178 169 179 long long time_; //!< Internal variable, counting the time untill the next executor-call 170 180 }; 181 182 /** 183 @brief RealTimer is a helper class that executes a function after a given amount of seconds in real-time. 184 185 The time interval of RealTimer doesn't depend on the game time, it will also call the function 186 if the game is paused. See Timer for a timer class that depends on the game time. 187 */ 188 class _ToolsExport RealTimer : public Timer 189 { 190 public: 191 RealTimer(); 192 RealTimer(float interval, bool bLoop, const ExecutorPtr& executor, bool bKillAfterCall = false); 193 194 protected: 195 virtual float getTimeFactor(); 196 }; 171 197 } 172 198 -
code/branches/usability/src/libraries/tools/ToolsPrereqs.h
r7163 r8022 85 85 class Mesh; 86 86 class ParticleInterface; 87 class RealTimer; 87 88 class ResourceCollection; 88 89 class ResourceLocation;
Note: See TracChangeset
for help on using the changeset viewer.