source: nrEngine/include/TimeSource.h @ 22

Revision 22, 4.6 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_I_TIMESOURCE_H_
15#define _NR_I_TIMESOURCE_H_
16
17/*!
18* \defgroup time Clock and Timers
19*
20* This groups contains all classes and interfaces you will need by working with the time.
21* Time is relative like Einstein said. So this part of the engine allows you to use
22* this aspect in your applications.
23* To use this you have to derive a time source class and bind it to any clock. Then
24* the clock should ticks and will give you always right time. Now you create any timer
25* from the clock. The timer has its own speed relative to the clock. This allows you
26* to use one timer for GUI and one for your game. If you pause the game timer gui
27* is still working. Also some nice effects are possible by using more than one
28* timer in you rapplication.
29**/
30
31//----------------------------------------------------------------------------------
32// Includes
33//----------------------------------------------------------------------------------
34#include "Prerequisities.h"
35
36namespace nrEngine{
37               
38       
39        //! Interface for time source give clock a current time
40        /**
41        * \par
42        * TimeSource is an interface for each time emitter. You have to bind any time source to
43        * the clock to have possibility to know the current time. You can think on time source
44        * as on tick mechanism in every clock.<br>
45        * In our default imlementation of the time source, we use a high performance tick counter
46        * provided by the cpu if such one exists. So you will be able to get more precise time
47        * results as usual.
48        *
49        * \par
50        * Each time source should be able to provide real system time (real does not mean absolute).
51        * The provided time has to be computed through system clock or similar techniques
52        * without using of high performance tick counters (e.g. rdtsc). We need this to be able
53        * to sync nrEngine's Clock-System for the current CPU-Speed. Because today's CPU does
54        * support frequency scaling, so we need somewhere to sync the time.
55        *
56        * \ingroup time
57        **/
58        class _NRExport TimeSource {
59        public:
60               
61                /**
62                * Create an instance of the time source object.
63                **/
64                TimeSource();
65
66                /**
67                * Release used memory
68                **/
69                virtual ~TimeSource();
70               
71                /**
72                * Get the current time in seconds. Returned time is not the same as system time.
73                * @return current time in seconds
74                **/
75                virtual float64 getTime();
76
77                /**
78                * Get current system time as it is provided through system functions without
79                * using of high performance tick counter (like rdtsc).
80                **/
81                virtual float64 getSystemTime();
82               
83                /**
84                * Reset the time source, so it can start reading the time from the beginning.
85                * You do not have to call this method, clock will do it automaticaly, if
86                * it is needed.
87                **/
88                virtual void reset();
89
90                /**
91                * Syncing the time source means we get the current time store it as sync time point
92                * caluclate the new start point do all calculations again.
93                * This syncing can help us to sync clock for example if the cpu speed changes.
94                * If no new calculation about the cpu speed is done and we use rdtsc to compute
95                * the current time, so we will get wrong time steps. Syncing should prevent this.<br>
96                * Clock-Engine will decide by itself when to sync, so time source shouldn't do it.
97                **/
98                virtual void sync();
99
100                /**
101                * Call this method to notify the time source, that new frame beginns.
102                * This method is usefull if we are using non-time based time sources.
103                * So the time source could read time from some file, which is based
104                * on frames.
105                **/
106                virtual void notifyNextFrame();
107               
108        protected:
109
110                //! Store here time value given by gettimeofday - function
111                struct timeval _startTime;
112
113                //! Store the current time in seconds, since the source was resetted
114                float64 _currentTime;
115
116                //! Here we store the sncying time point. This will help us to sync the source
117                float64 _syncTime;
118               
119        };
120       
121}; // end namespace
122
123#endif
Note: See TracBrowser for help on using the repository browser.