Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 5, 2011, 8:39:21 PM (13 years ago)
Author:
landauf
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/usability/src/libraries/tools/Timer.h

    r8020 r8022  
    8181#include "core/OrxonoxClass.h"
    8282#include "core/command/Executor.h"
    83 #include "tools/interfaces/TimeFactorListener.h"
    8483
    8584namespace orxonox
    8685{
    8786    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
    8892    void killdelay(unsigned int handle);
    8993    void killdelays();
    90     void executeDelayedCommand(Timer* timer, const std::string& command);
    9194
    9295    /**
    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.
    9497
    9598        @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.
    96103    */
    97     class _ToolsExport Timer : public TimeFactorListener
     104    class _ToolsExport Timer : virtual public OrxonoxClass
    98105    {
    99106        public:
     
    124131            void run();
    125132
    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.
    127134            inline void startTimer()
    128135                { this->bActive_ = true; this->time_ = this->interval_; }
    129             /// Stops the Timer.
     136            /// Stops the timer.
    130137            inline void stopTimer()
    131138                { 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().
    133140            inline void pauseTimer()
    134141                { this->bActive_ = false; }
    135             /// Unpauses the Timer - continues with the given state.
     142            /// Unpauses the timer - continues with the given state.
    136143            inline void unpauseTimer()
    137144                { 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).
    139146            inline bool isActive() const
    140147                { 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.
    142149            inline float getRemainingTime() const
    143150                { 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).
    145152            inline void addTime(float time)
    146153                { 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)
    148155            inline void removeTime(float time)
    149156                { if (time > 0.0f) this->time_ -= static_cast<long long>(time * 1000000.0f); }
     
    157164            void tick(const Clock& time);
    158165
     166        protected:
     167            virtual float getTimeFactor();
     168
    159169        private:
    160170            void init();
     
    164174            long long interval_;    //!< The time-interval in micro seconds
    165175            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 up
     176            bool bActive_;          //!< If true, the timer ticks and calls the executor if the time's up
    167177            bool bKillAfterCall_;   //!< If true the timer gets deleted after it expired and called the executor
    168178
    169179            long long time_;        //!< Internal variable, counting the time untill the next executor-call
    170180    };
     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    };
    171197}
    172198
Note: See TracChangeset for help on using the changeset viewer.