Umasoft
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
FrameTimer.h
1 //
2 // FrameTimer.h
3 //
4 // Copyright (c) 2001 Virtual Terrain Project
5 // Free for all uses, see license.txt for details.
6 //
7 
8 #ifndef FRAMETIMER_H
9 #define FRAMETIMER_H
10 
11 #ifdef WIN32
12 #define TLONG __int64
13 #else
14 #define TLONG long
15 #endif
16 
17 #define AVGLEN 8
18 
20 {
21 public:
22  // initialize the clock.
23  TLONG Init();
24  // time since Init() in seconds.
25  float clockSeconds();
26 
27  // update the number of ticks since the last frame update.
28  void updateFrameTick();
29  // time from the current frame update and the previous one in seconds.
30  float frameSeconds() { return (float)frameTick()/(float)_tickRatePerSecond; }
31  float frameRate();
32  float frameRateAverge() { return m_avg; }
33 
34  TLONG _tickRatePerSecond;
35  TLONG _initialTick;
36  TLONG _lastFrameTick;
37  TLONG _frameTick;
38 
39  // system tick.
40  TLONG clockTick();
41  TLONG frameTick();
42  TLONG _tick();
43 
44  // for keeping an average framerate
45  TLONG m_previous[AVGLEN];
46  int m_pos;
47  float m_avg;
48 };
49 
50 #endif