- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

# D:/Programmation/Sources/Tensor2/Utils/include/frost_utils_timers.h

Go to the documentation of this file.

    00001 /* ###################################### */
    00002 /* ###     Frost Engine, by Kalith    ### */
    00003 /* ###################################### */
    00004 /*             Timers header              */
    00005 /*                                        */
    00006 /*                                        */
    00007
    00008
    00009 #ifndef FROST_TIMERS_H
    00010 #define FROST_TIMERS_H
    00011
    00012 #include "frost_utils_types.h"
    00013
    00014 namespace Frost
    00015 {
    00016     /// A... periodic timer
    00017     /** This timer is meant to tick periodicaly,
    00018     *   so you can use it for any periodic event
    00019     *   such as key repetition or a count down.
    00020     */
    00021     class PeriodicTimer
    00022     {
    00023     public :
    00024
    00025         enum StartType
    00026         {
    00027             /// The timer will start if you call Start()
    00028             START_PAUSED,
    00029             /// The timer starts immediatly after it is created
    00030             START_NOW,
    00031             /// The timer will start when you first call Ticks()
    00032             START_FIRST_TICK
    00033         };
    00034
    00035         /// Default constructor
    00036         /** \param dDuration The time interval between each tick
    00037         *   \param mType     See TimerType
    00038         *   \param bTicks    The timer ticks immediately
    00039         */
    00040         PeriodicTimer(const s_double& dDuration, StartType mType, const s_bool& bTicks);
    00041
    00042         /// Returns the time elapsed since the last tick.
    00043         /** \return The time elapsed since last tick
    00044         */
    00045         s_double        GetElapsed();
    00046
    00047         /// Returns the period of the PeriodicTimer.
    00048         /** \return The period of the PeriodicTimer
    00049         */
    00050         const s_double& GetPeriod() const;
    00051
    00052         /// Cheks if this PeriodicTimer is paused.
    00053         /** \return 'true' if this PeriodicTimer is paused
    00054         */
    00055         const s_bool&   IsPaused() const;
    00056
    00057         /// Checks if the timer's period has been reached.
    00058         /** \return 'true' if the period has been reached
    00059         */
    00060         s_bool          Ticks();
    00061
    00062         /// Pauses the timer and resets it.
    00063         void            Stop();
    00064
    00065         /// Starts the timer but doesn't reset it.
    00066         void            Start();
    00067
    00068         /// Pauses the timer.
    00069         void            Pause();
    00070
    00071         /// Resets the timer but doesn't pause it.
    00072         void            Zero();
    00073
    00074         static const s_str CLASS_NAME;
    00075
    00076     private :
    00077
    00078         s_double dElapsed_;
    00079         s_double dStart_;
    00080         s_double dDuration_;
    00081         s_bool   bPaused_;
    00082         s_bool   bFirstTick_;
    00083
    00084         StartType mType_;
    00085     };
    00086
    00087
    00088     /// A simple timer
    00089     class Timer
    00090     {
    00091     public :
    00092
    00093         enum StartType
    00094         {
    00095             /// The timer will start if you call Start()
    00096             START_PAUSED,
    00097             /// The timer starts immediatly after it is created
    00098             START_NOW,
    00099         };
    00100
    00101         /// Constructor.
    00102         Timer(const StartType& mType = START_PAUSED);
    00103
    00104         /// Adds time to this Timer.
    00105         /** \param dAdditionnalTime The time to add (can be negative)
    00106         */
    00107         void          AddTime(const s_double& dAdditionnalTime);
    00108
    00109         /// Sets the current elapsed time for this Timer.
    00110         /** \param dTime The new elapsed time
    00111         */
    00112         void          SetTime(const s_double& dTime);
    00113
    00114         /// Returns the total time elapsed.
    00115         /** \return The total time elapsed.
    00116         */
    00117         s_double      GetElapsed();
    00118
    00119         /// Cheks if this Timer is paused.
    00120         /** \return 'true' if this Timer is paused
    00121         */
    00122         const s_bool& IsPaused() const;
    00123
    00124         /// Starts this timer.
    00125         void          Start(const s_bool& bReset = false);
    00126
    00127         /// Pauses this timer.
    00128         void          Pause();
    00129
    00130         /// Stops this timer.
    00131         void          Stop();
    00132
    00133         /// Resets this timer (doesn't pause it).
    00134         void          Zero();
    00135
    00136         static const s_str CLASS_NAME;
    00137
    00138     private :
    00139
    00140         s_double dElapsed_;
    00141         s_double dStart_;
    00142         s_bool   bPaused_;
    00143
    00144     };
    00145 }
    00146
    00147 #endif