source: nrEngine/include/Timer.h @ 1

Revision 1, 4.1 KB checked in by art, 13 years ago (diff)
Line 
1/***************************************************************************
2 *                                                                         *
3 *   (c) Art Tevs, MPI Informatik Saarbruecken                             *
4 *       mailto: <tevs@mpi-sb.mpg.de>                                      *
5 *                                                                         *
6 *   This program is free software; you can redistribute it and/or modify  *
7 *   it under the terms of the GNU General Public License as published by  *
8 *   the Free Software Foundation; either version 2 of the License, or     *
9 *   (at your option) any later version.                                   *
10 *                                                                         *
11 ***************************************************************************/
12
13
14#ifndef _NR_C_TIMER_H_
15#define _NR_C_TIMER_H_
16
17
18//----------------------------------------------------------------------------------
19// Includes
20//----------------------------------------------------------------------------------
21#include "Prerequisities.h"
22#include "Clock.h"
23#include "ITimeObserver.h"
24
25namespace nrEngine{
26
27        //! Timers are used to retrieve time. You can hav emore than one timer in your app
28        /**
29        * Timer is an standard timer shipped with the engine. You can
30        * create your own timers because they are specialized for your application.
31        * This timer can only ticks and provide user with information he/she need.
32        * Also this timer supports scaling and pausing, so you are able to use
33        * at lesser speed or hold on parts of your game using this timer.
34        *
35        * @note Because each timer is created from the clock, so the timer lifespan
36        * is the same as from the clock. So if clock is destroyed, timer will also
37        * be killed. You also can not destroy the timer object, only clock can do this.
38        *
39        * \ingroup time
40        **/
41        class _NRExport Timer: public ITimeObserver {
42        public:
43       
44                /**
45                * Define default values and set clock for using with this timer.
46                * This timer will automaticly be added to the clock as observer.
47                **/
48                Timer(Clock& clock);   
49               
50                /**
51                * Release used memory and remove this timer from observer list of
52                * the clock.
53                **/
54                virtual ~Timer();
55               
56                /**
57                * Returns current time since this timer is started
58                **/
59                float64 getTime() const { return _currentTime; }
60               
61                /**
62                * Returns the time interval between two frames
63                * Frame interval depends on the scale value you set for
64                * this timer. So it can be different for different timers
65                **/
66                float32 getFrameInterval() const { return static_cast<float32>(_frameTime); }
67       
68                /**
69                * Returns true if this timer is currently sleeping/paused
70                **/
71                bool isPaused () const{ return _bPaused; }
72                       
73                /**
74                * Returns the time scale value of this timer. Each timer can have each own
75                * opinion how much time is passed. This is done by setting the scale value
76                * of the timer. This scale shows how much faster/slower this timer runs
77                **/
78                float32 getScale () const{ return _fScale; }
79       
80                /**
81                * This will hold on this timer so time stops
82                * @param bOn if true timer stops, otherwise it runs
83                **/
84                void setPause (bool bOn){ _bPaused = bOn; }
85               
86                /**
87                * Set time scale value for this timer. With the help of this value you have
88                * the possibility to run your local time at different speed
89                **/
90                void    setScale (float32 fScale){ _fScale = fScale; }
91               
92                /**
93                * This function will be always called by clock. Here the main update of the timer
94                * is done.
95                **/
96                virtual void notifyTimeObserver();
97
98                /**
99                * If you set this to true so fix frame rate will be used. This helps us
100                * to run our application on console or do internal calculations based
101                * on fix frame rate like Doom3 does.
102                * @param setFixRate if true fix frame rate will be used.
103                * @param fixFrameRate frame rate to be used
104                **/
105                void    setFixFrameRate(bool setFixRate, float32 fixFrameRate = 60.0f);
106
107        private:
108               
109                // clock to be used with this timer     
110                Clock& _clock;
111               
112                // current time and interval
113                float64 _currentTime;
114                float64 _frameTime;
115                float64 _fixFrameTime;
116               
117                // pausing and scaling
118                bool            _bPaused;
119                float32         _fScale;
120                bool            _bFixFrameRate;
121               
122        };
123       
124}; // end namespace
125
126#endif
Note: See TracBrowser for help on using the repository browser.