- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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

Go to the documentation of this file.

    00001 /* ###################################### */
    00002 /* ###     Frost Engine, by Kalith    ### */
    00003 /* ###################################### */
    00004 /*            TimeManager header          */
    00005 /*                                        */
    00006 /*                                        */
    00007 /*                                        */
    00008
    00009
    00010 #ifndef FROST_TIMEMANAGER_H
    00011 #define FROST_TIMEMANAGER_H
    00012
    00013 #include "frost_utils_manager.h"
    00014 #include "frost_utils_types.h"
    00015
    00016 namespace Ogre
    00017 {
    00018     class Timer;
    00019 }
    00020
    00021 namespace Frost
    00022 {
    00023     class Profiler;
    00024     class Timer;
    00025
    00026     /// Keeper of time :)
    00027     /** This class manages everything that is related
    00028     *   to time : FPS, date and profiling.
    00029     */
    00030     class TimeManager : public Manager<TimeManager>
    00031     {
    00032     friend class Manager<TimeManager>;
    00033     public :
    00034
    00035         typedef s_double (*GetTimeFunction)();
    00036
    00037         /// Sets the timing function to use.
    00038         /** \param pFunc The get time function
    00039         *   \note This function will be used by GetTime().<br>
    00040         *         Its signature must be :<br>
    00041         *         &nsbp&nsbp&nsbps_double Func();<br>
    00042         *         and it must return time in seconds.
    00043         */
    00044         void SetGetTimeFunction(GetTimeFunction pFunc);
    00045
    00046         /// Initializes this manager
    00047         /** \note Should be called just before entering
    00048         *         the main loop.
    00049         */
    00050         void          Initialize();
    00051
    00052         /// Updates delta time and FPS.
    00053         void          Update();
    00054
    00055         /// Returns the time elapsed since last frame.
    00056         /** \return Elapsed time since last frame
    00057         */
    00058         s_double      GetDelta() const;
    00059
    00060         /// Returns the current Frame Per Second (FPS) count.
    00061         /** \return Average number of frame per second over a second
    00062         */
    00063         const s_uint& GetFPS() const;
    00064
    00065         /// Returns average frame per second since game launch.
    00066         /** \return Average frame per second since game launch
    00067         */
    00068         s_uint        GetAverageFPS() const;
    00069
    00070         /// Returns the highest Frame Per Second (FPS) count.
    00071         /** \return Highest number of frame per second over a second
    00072         */
    00073         const s_uint& GetBestFPS() const;
    00074
    00075         /// Returns the lowest Frame Per Second (FPS) count.
    00076         /** \return Lowest number of frame per second over a second
    00077         */
    00078         const s_uint& GetWorstFPS() const;
    00079
    00080         /// Returns the current time in seconds.
    00081         /** \return Current time (origin : game's start)
    00082         */
    00083         s_double      GetTime() const;
    00084
    00085         /// Returns the current time (year).
    00086         /** \return The current year
    00087         */
    00088         s_uint        GetYear() const;
    00089
    00090         /// Returns the current time (month).
    00091         /** \return The current month
    00092         */
    00093         s_uint        GetMonth() const;
    00094
    00095         /// Returns the current time (day name code).
    00096         /** \return The current day name code
    00097         */
    00098         s_uint        GetDayName() const;
    00099
    00100         /// Returns the current time (day).
    00101         /** \return The current day number
    00102         */
    00103         s_uint        GetDay() const;
    00104
    00105         /// Returns the current time (hours).
    00106         /** \return The current hour
    00107         */
    00108         s_uint        GetHour() const;
    00109
    00110         /// Returns the current time (minutes).
    00111         /** \return The current minutes
    00112         */
    00113         s_uint        GetMinutes() const;
    00114
    00115         /// Returns the current time (microseconds).
    00116         /** \return The current microseconds
    00117         *   \note On windows, this function only has milisecond
    00118         *         resolution.
    00119         */
    00120         s_uint        GetMicroseconds() const;
    00121
    00122         /// Returns the time elapsed since game's start.
    00123         /** \return The elapsed time since the game has started,
    00124         *   formated : "[h.:m.:s.:ms.]"
    00125         */
    00126         s_str         GetPlayTime() const;
    00127
    00128         /// Returns the current time (seconds).
    00129         /** \return The current seconds
    00130         */
    00131         s_uint        GetSeconds() const;
    00132
    00133         /// Starts or stops profiling.
    00134         /** \param bProfiling Starts profiling
    00135         */
    00136         void          SetProfiling(const s_bool& bProfiling);
    00137
    00138         /// Checks if the manager is currently profiling.
    00139         /** \return 'true' if it is profiling
    00140         */
    00141         s_bool        IsProfiling() const;
    00142
    00143         /// Creates a profiler with the given parameters.
    00144         /** \param iGroup  The group to which it belongs (used to group prints later)
    00145         *   \param sName   The name of this Profiler (usualy the name of the function
    00146         *                  it profiles)
    00147         *   \param bRecord Store all timings in a list to print them later
    00148         *   \note If this profiler already exists, this function returns a pointer to it.
    00149         */
    00150         s_ptr<Profiler> GetProfiler(const s_uint& iGroup, const s_str& sName, const s_bool& bRecord);
    00151
    00152         /// Prints in the log all timing infos.
    00153         /** \param iGroup Filter output by group number
    00154         */
    00155         void          Print(const s_uint& iGroup = s_uint::INF);
    00156
    00157         static const s_str CLASS_NAME;
    00158
    00159     protected :
    00160
    00161         /// Default constructor
    00162         /** \note This is a singleton class. That means that there can
    00163         *         only be a single instance at the same time. That's why
    00164         *         the constructor is not in public scope.<br>
    00165         *         If you need to get a pointer to that unique instance,
    00166         *         call TimeManager::GetSingleton().<br>
    00167         *         Note that, if GetSingleton() has been called at least once,
    00168         *         you'll have to delete the returned pointer when you close
    00169         *         your program by calling TimeManager::Delete() (this is
    00170         *         automatically done by Engine).
    00171         */
    00172         TimeManager();
    00173
    00174         /// Destructor
    00175         /** \note If GetSingleton() has been called at least once,
    00176         *         you'll have to delete the returned pointer when
    00177         *         you close your program by calling Delete() (this is
    00178         *         automatically done by Engine).
    00179         */
    00180         ~TimeManager();
    00181
    00182         /// Copy constructor
    00183         TimeManager(const TimeManager& mMgr);
    00184
    00185         /// Assignment operator
    00186         TimeManager& operator = (const TimeManager& mMgr);
    00187
    00188     private :
    00189
    00190         GetTimeFunction pGetTimeFunction_;
    00191
    00192         s_refptr<Timer> pFPSTimer_;
    00193
    00194         s_bool bProfiled_;
    00195         s_bool bProfiling_;
    00196
    00197         s_uint   uiFPS_;
    00198         s_double dDelta_;
    00199
    00200         s_uint uiFrameNbr_;
    00201         s_uint uiAvgFPS_;
    00202         s_uint uiBestFPS_;
    00203         s_uint uiWorstFPS_;
    00204
    00205         s_double dStart_;
    00206
    00207         s_double dLastTime_;
    00208         s_double dCurTime_;
    00209
    00210         s_double dLast_;
    00211         s_double dProfileTime_;
    00212
    00213         s_map<s_str, Profiler> lProfilerList_;
    00214     };
    00215 }
    00216
    00217 #endif