forked from panda3d/panda3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclockObject.I
More file actions
318 lines (297 loc) · 12.5 KB
/
clockObject.I
File metadata and controls
318 lines (297 loc) · 12.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
// Filename: clockObject.I
// Created by: drose (17Feb00)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) Carnegie Mellon University. All rights reserved.
//
// All use of this software is subject to the terms of the revised BSD
// license. You should have received a copy of this license along
// with this source code in a file named "LICENSE."
//
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// Function: ClockObject::Destructor
// Access: Published
// Description:
////////////////////////////////////////////////////////////////////
INLINE ClockObject::
~ClockObject() {
}
////////////////////////////////////////////////////////////////////
// Function: ClockObject::get_mode
// Access: Published
// Description: Returns the current mode of the clock. See
// set_mode().
////////////////////////////////////////////////////////////////////
INLINE ClockObject::Mode ClockObject::
get_mode() const {
return _mode;
}
////////////////////////////////////////////////////////////////////
// Function: ClockObject::get_frame_time
// Access: Published
// Description: Returns the time in seconds as of the last time
// tick() was called (typically, this will be as of the
// start of the current frame).
//
// This is generally the kind of time you want to ask
// for in most rendering and animation contexts, since
// it's important that all of the animation for a given
// frame remains in sync with each other.
////////////////////////////////////////////////////////////////////
INLINE double ClockObject::
get_frame_time(Thread *current_frame) const {
CDReader cdata(_cycler, current_frame);
return cdata->_reported_frame_time;
}
////////////////////////////////////////////////////////////////////
// Function: ClockObject::get_real_time
// Access: Published
// Description: Returns the actual number of seconds elapsed since
// the ClockObject was created, or since it was last
// reset. This is useful for doing real timing
// measurements, e.g. for performance statistics.
//
// This returns the most precise timer we have for short
// time intervals, but it may tend to drift over the
// long haul. If more accurate timekeeping is needed
// over a long period of time, use get_long_time()
// instead.
////////////////////////////////////////////////////////////////////
INLINE double ClockObject::
get_real_time() const {
return (_true_clock->get_short_time() - _start_short_time);
}
////////////////////////////////////////////////////////////////////
// Function: ClockObject::get_long_time
// Access: Published
// Description: Returns the actual number of seconds elapsed since
// the ClockObject was created, or since it was last
// reset.
//
// This is similar to get_real_time(), except that it
// uses the most accurate counter we have over a long
// period of time, and so it is less likely to drift.
// However, it may not be very precise for measuring
// short intervals. On Windows, for instace, this is
// only accurate to within about 55 milliseconds.
////////////////////////////////////////////////////////////////////
INLINE double ClockObject::
get_long_time() const {
return (_true_clock->get_long_time() - _start_long_time);
}
////////////////////////////////////////////////////////////////////
// Function: ClockObject::reset
// Access: Published
// Description: Simultaneously resets both the time and the frame
// count to zero.
////////////////////////////////////////////////////////////////////
INLINE void ClockObject::
reset() {
set_real_time(0.0);
set_frame_time(0.0);
set_frame_count(0);
}
////////////////////////////////////////////////////////////////////
// Function: ClockObject::get_frame_count
// Access: Published
// Description: Returns the number of times tick() has been called
// since the ClockObject was created, or since it was
// last reset. This is generally the number of frames
// that have been rendered.
////////////////////////////////////////////////////////////////////
INLINE int ClockObject::
get_frame_count(Thread *current_thread) const {
CDReader cdata(_cycler, current_thread);
return cdata->_frame_count;
}
////////////////////////////////////////////////////////////////////
// Function: ClockObject::get_net_frame_rate
// Access: Published
// Description: Returns the average frame rate since the last reset.
// This is simply the total number of frames divided by
// the total elapsed time. This reports the virtual
// frame rate if the clock is in (or has been in)
// M_non_real_time mode.
////////////////////////////////////////////////////////////////////
INLINE double ClockObject::
get_net_frame_rate(Thread *current_thread) const {
CDReader cdata(_cycler, current_thread);
return (double)cdata->_frame_count / cdata->_reported_frame_time;
}
////////////////////////////////////////////////////////////////////
// Function: ClockObject::get_dt
// Access: Published
// Description: Returns the elapsed time for the previous frame: the
// number of seconds elapsed between the last two calls
// to tick().
////////////////////////////////////////////////////////////////////
INLINE double ClockObject::
get_dt(Thread *current_thread) const {
CDReader cdata(_cycler, current_thread);
if (_max_dt > 0.0) {
return min(_max_dt, cdata->_dt);
}
return cdata->_dt;
}
////////////////////////////////////////////////////////////////////
// Function: ClockObject::get_max_dt
// Access: Published
// Description: Returns the current maximum allowable time elapsed
// between any two frames. See set_max_dt().
////////////////////////////////////////////////////////////////////
INLINE double ClockObject::
get_max_dt() const {
return _max_dt;
}
////////////////////////////////////////////////////////////////////
// Function: ClockObject::set_max_dt
// Access: Published
// Description: Sets a limit on the value returned by get_dt(). If
// this value is less than zero, no limit is imposed;
// otherwise, this is the maximum value that will ever
// be returned by get_dt(), regardless of how much time
// has actually elapsed between frames.
//
// This limit is only imposed in real-time mode; in
// non-real-time mode, the dt is fixed anyway and max_dt
// is ignored.
//
// This is generally used to guarantee reasonable
// behavior even in the presence of a very slow or
// chuggy frame rame.
////////////////////////////////////////////////////////////////////
INLINE void ClockObject::
set_max_dt(double max_dt) {
_max_dt = max_dt;
}
////////////////////////////////////////////////////////////////////
// Function: ClockObject::get_degrade_factor
// Access: Published
// Description: In degrade mode, returns the ratio by which the
// performance is degraded. A value of 2.0 causes the
// clock to be slowed down by a factor of two (reducing
// performance to 1/2 what would be otherwise).
//
// This has no effect if mode is not M_degrade.
////////////////////////////////////////////////////////////////////
INLINE double ClockObject::
get_degrade_factor() const {
return _degrade_factor;
}
////////////////////////////////////////////////////////////////////
// Function: ClockObject::set_degrade_factor
// Access: Published
// Description: In degrade mode, sets the ratio by which the
// performance is degraded. A value of 2.0 causes the
// clock to be slowed down by a factor of two (reducing
// performance to 1/2 what would be otherwise).
//
// This has no effect if mode is not M_degrade.
////////////////////////////////////////////////////////////////////
INLINE void ClockObject::
set_degrade_factor(double degrade_factor) {
_degrade_factor = degrade_factor;
}
////////////////////////////////////////////////////////////////////
// Function: ClockObject::set_average_frame_rate_interval
// Access: Published
// Description: Specifies the interval of time (in seconds) over
// which get_average_frame_rate() averages the number of
// frames per second to compute the frame rate.
// Changing this does not necessarily immediately change
// the result of get_average_frame_rate(), until this
// interval of time has elapsed again.
//
// Setting this to zero disables the computation of
// get_average_frame_rate().
////////////////////////////////////////////////////////////////////
INLINE void ClockObject::
set_average_frame_rate_interval(double time) {
_average_frame_rate_interval = time;
if (_average_frame_rate_interval == 0.0) {
_ticks.clear();
}
}
////////////////////////////////////////////////////////////////////
// Function: ClockObject::get_average_frame_rate_interval
// Access: Published
// Description: Returns the interval of time (in seconds) over
// which get_average_frame_rate() averages the number of frames
// per second to compute the frame rate.
////////////////////////////////////////////////////////////////////
INLINE double ClockObject::
get_average_frame_rate_interval() const {
return _average_frame_rate_interval;
}
////////////////////////////////////////////////////////////////////
// Function: ClockObject::check_errors
// Access: Published
// Description: Returns true if a clock error was detected since the
// last time check_errors() was called. A clock error
// means that something happened, an OS or BIOS bug, for
// instance, that makes the current value of the clock
// somewhat suspect, and an application may wish to
// resynchronize with any external clocks.
////////////////////////////////////////////////////////////////////
INLINE bool ClockObject::
check_errors(Thread *current_thread) {
CDReader cdata(_cycler, current_thread); // Just to hold a mutex.
int orig_error_count = _error_count;
_error_count = _true_clock->get_error_count();
return (_error_count != orig_error_count);
}
////////////////////////////////////////////////////////////////////
// Function: ClockObject::get_global_clock
// Access: Published
// Description: Returns a pointer to the global ClockObject. This is
// the ClockObject that most code should use for
// handling scene graph rendering and animation.
////////////////////////////////////////////////////////////////////
INLINE ClockObject *ClockObject::
get_global_clock() {
if (_global_clock == (ClockObject *)NULL) {
make_global_clock();
}
return _global_clock;
}
////////////////////////////////////////////////////////////////////
// Function: ClockObject::CData::Copy Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
INLINE ClockObject::CData::
CData(const ClockObject::CData ©) :
_frame_count(copy._frame_count),
_reported_frame_time(copy._reported_frame_time),
_dt(copy._dt)
{
}
////////////////////////////////////////////////////////////////////
// Function: TimeVal::contructor
// Access: Published
// Description:
////////////////////////////////////////////////////////////////////
INLINE TimeVal::
TimeVal() {
}
////////////////////////////////////////////////////////////////////
// Function: TimeVal::get_sec
// Access: Published
// Description:
////////////////////////////////////////////////////////////////////
INLINE ulong TimeVal::
get_sec() const {
return tv[0];
}
////////////////////////////////////////////////////////////////////
// Function: TimeVal::get_usec
// Access: Published
// Description:
////////////////////////////////////////////////////////////////////
INLINE ulong TimeVal::
get_usec() const {
return tv[1];
}