doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Timer.h
Go to the documentation of this file.
1 /*
2 ===========================================================================
3 
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
8 
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
21 
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
23 
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
25 
26 ===========================================================================
27 */
28 
29 #ifndef __TIMER_H__
30 #define __TIMER_H__
31 
32 /*
33 ===============================================================================
34 
35  Clock tick counter. Should only be used for profiling.
36 
37 ===============================================================================
38 */
39 
40 class idTimer {
41 public:
42  idTimer( void );
43  idTimer( double clockTicks );
44  ~idTimer( void );
45 
46  idTimer operator+( const idTimer &t ) const;
47  idTimer operator-( const idTimer &t ) const;
48  idTimer & operator+=( const idTimer &t );
49  idTimer & operator-=( const idTimer &t );
50 
51  void Start( void );
52  void Stop( void );
53  void Clear( void );
54  double ClockTicks( void ) const;
55  double Milliseconds( void ) const;
56 
57 private:
58  static double base;
59  enum {
62  } state;
63  double start;
64  double clockTicks;
65 
66  void InitBaseClockTicks( void ) const;
67 };
68 
69 /*
70 =================
71 idTimer::idTimer
72 =================
73 */
74 ID_INLINE idTimer::idTimer( void ) {
75  state = TS_STOPPED;
76  clockTicks = 0.0;
77 }
78 
79 /*
80 =================
81 idTimer::idTimer
82 =================
83 */
84 ID_INLINE idTimer::idTimer( double _clockTicks ) {
85  state = TS_STOPPED;
86  clockTicks = _clockTicks;
87 }
88 
89 /*
90 =================
91 idTimer::~idTimer
92 =================
93 */
94 ID_INLINE idTimer::~idTimer( void ) {
95 }
96 
97 /*
98 =================
99 idTimer::operator+
100 =================
101 */
102 ID_INLINE idTimer idTimer::operator+( const idTimer &t ) const {
103  assert( state == TS_STOPPED && t.state == TS_STOPPED );
104  return idTimer( clockTicks + t.clockTicks );
105 }
106 
107 /*
108 =================
109 idTimer::operator-
110 =================
111 */
112 ID_INLINE idTimer idTimer::operator-( const idTimer &t ) const {
113  assert( state == TS_STOPPED && t.state == TS_STOPPED );
114  return idTimer( clockTicks - t.clockTicks );
115 }
116 
117 /*
118 =================
119 idTimer::operator+=
120 =================
121 */
122 ID_INLINE idTimer &idTimer::operator+=( const idTimer &t ) {
123  assert( state == TS_STOPPED && t.state == TS_STOPPED );
124  clockTicks += t.clockTicks;
125  return *this;
126 }
127 
128 /*
129 =================
130 idTimer::operator-=
131 =================
132 */
133 ID_INLINE idTimer &idTimer::operator-=( const idTimer &t ) {
134  assert( state == TS_STOPPED && t.state == TS_STOPPED );
135  clockTicks -= t.clockTicks;
136  return *this;
137 }
138 
139 /*
140 =================
141 idTimer::Start
142 =================
143 */
144 ID_INLINE void idTimer::Start( void ) {
145  assert( state == TS_STOPPED );
146  state = TS_STARTED;
148 }
149 
150 /*
151 =================
152 idTimer::Stop
153 =================
154 */
155 ID_INLINE void idTimer::Stop( void ) {
156  assert( state == TS_STARTED );
158  if ( base < 0.0 ) {
160  }
161  if ( clockTicks > base ) {
162  clockTicks -= base;
163  }
164  state = TS_STOPPED;
165 }
166 
167 /*
168 =================
169 idTimer::Clear
170 =================
171 */
172 ID_INLINE void idTimer::Clear( void ) {
173  clockTicks = 0.0;
174 }
175 
176 /*
177 =================
178 idTimer::ClockTicks
179 =================
180 */
181 ID_INLINE double idTimer::ClockTicks( void ) const {
182  assert( state == TS_STOPPED );
183  return clockTicks;
184 }
185 
186 /*
187 =================
188 idTimer::Milliseconds
189 =================
190 */
191 ID_INLINE double idTimer::Milliseconds( void ) const {
192  assert( state == TS_STOPPED );
193  return clockTicks / ( idLib::sys->ClockTicksPerSecond() * 0.001 );
194 }
195 
196 
197 /*
198 ===============================================================================
199 
200  Report of multiple named timers.
201 
202 ===============================================================================
203 */
204 
206 public:
207  idTimerReport( void );
208  ~idTimerReport( void );
209 
210  void SetReportName( const char *name );
211  int AddReport( const char *name );
212  void Clear( void );
213  void Reset( void );
214  void PrintReport( void );
215  void AddTime( const char *name, idTimer *time );
216 
217 private:
221 };
222 
223 #endif /* !__TIMER_H__ */
double clockTicks
Definition: Timer.h:64
void InitBaseClockTicks(void) const
Definition: Timer.cpp:40
idStr reportName
Definition: Timer.h:220
~idTimer(void)
Definition: Timer.h:94
assert(prefInfo.fullscreenBtn)
void Reset(void)
Definition: Timer.cpp:115
static double base
Definition: Timer.h:58
Definition: Timer.h:40
idTimerReport(void)
Definition: Timer.cpp:65
idTimer(void)
Definition: Timer.h:74
virtual double ClockTicksPerSecond(void)=0
idTimer & operator-=(const idTimer &t)
Definition: Timer.h:133
void Start(void)
Definition: Timer.h:144
static class idSys * sys
Definition: Lib.h:52
double Milliseconds(void) const
Definition: Timer.h:191
enum idTimer::@65 state
~idTimerReport(void)
Definition: Timer.cpp:82
double start
Definition: Timer.h:63
int AddReport(const char *name)
Definition: Timer.cpp:91
idTimer operator-(const idTimer &t) const
Definition: Timer.h:112
virtual double GetClockTicks(void)=0
idTimer operator+(const idTimer &t) const
Definition: Timer.h:102
void SetReportName(const char *name)
Definition: Timer.cpp:73
void Stop(void)
Definition: Timer.h:155
double ClockTicks(void) const
Definition: Timer.h:181
idList< idTimer * > timers
Definition: Timer.h:218
const GLcharARB * name
Definition: glext.h:3629
void PrintReport(void)
Definition: Timer.cpp:150
idStrList names
Definition: Timer.h:219
Definition: Str.h:116
idTimer & operator+=(const idTimer &t)
Definition: Timer.h:122
void Clear(void)
Definition: Timer.cpp:104
void AddTime(const char *name, idTimer *time)
Definition: Timer.cpp:127
GLuint start
Definition: glext.h:2845
void Clear(void)
Definition: Timer.h:172
GLdouble GLdouble t
Definition: glext.h:2943