#include <clockObject.h>
Public Types | |
enum | Mode { M_normal, M_non_real_time } |
Public Member Functions | |
ClockObject () | |
~ClockObject () | |
void | set_mode (Mode mode) |
Changes the mode of the clock, e.g. | |
Mode | get_mode () const |
Returns the current mode of the clock. | |
double | get_frame_time () const |
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). | |
double | get_real_time () const |
Returns the actual number of seconds elapsed since the ClockObject was created, or since it was last reset. | |
double | get_long_time () const |
Returns the actual number of seconds elapsed since the ClockObject was created, or since it was last reset. | |
void | reset () |
Simultaneously resets both the time and the frame count to zero. | |
void | set_real_time (double time) |
Resets the clock to the indicated time. | |
void | set_frame_time (double time) |
Changes the time as reported for the current frame to the indicated time. | |
void | set_frame_count (int frame_count) |
Resets the number of frames counted to the indicated number. | |
int | get_frame_count () const |
Returns the number of times tick() has been called since the ClockObject was created, or since it was last reset. | |
double | get_frame_rate () const |
Returns the average frame rate since the last reset. | |
double | get_dt () const |
Returns the elapsed time for the previous frame: the number of seconds elapsed between the last two calls to tick(). | |
void | set_dt (double dt) |
In non-real-time mode, sets the number of seconds that should appear to elapse between frames. | |
double | get_max_dt () const |
Returns the current maximum allowable time elapsed between any two frames. | |
void | set_max_dt (double max_dt) |
Sets a limit on the value returned by get_dt(). | |
void | tick () |
Instructs the clock that a new frame has just begun. | |
void | sync_frame_time () |
Resets the frame time to the current real time. | |
Static Public Member Functions | |
ClockObject * | get_global_clock () |
Returns a pointer to the global ClockObject. | |
Private Attributes | |
TrueClock * | _true_clock |
Mode | _mode |
double | _start_short_time |
double | _start_long_time |
int | _frame_count |
double | _actual_frame_time |
double | _reported_frame_time |
double | _dt |
double | _max_dt |
Static Private Attributes | |
ClockObject * | _global_clock = (ClockObject *)NULL |
It can run in two modes: In normal mode, get_frame_time() returns the time as of the last time tick() was called. This is the "discrete" time, and is usually used to get the time as of, for instance, the beginning of the current frame. In non-real-time mode, get_frame_time() returns a constant increment since the last time tick() was called; this is useful when it is desirable to fake the clock out, for instance for non-real-time animation rendering.
In both modes, get_real_time() always returns the elapsed real time in seconds since the ClockObject was constructed, or since it was last reset.
You can create your own ClockObject whenever you want to have your own local timer. There is also a default, global ClockObject intended to represent global time for the application; this is normally set up to tick every frame so that its get_frame_time() will return the time for the current frame.
Definition at line 93 of file clockObject.h.
|
Definition at line 95 of file clockObject.h. |
|
Definition at line 37 of file clockObject.cxx. References _actual_frame_time, _dt, _frame_count, _max_dt, and _reported_frame_time. |
|
Definition at line 30 of file clockObject.I. |
|
Returns the elapsed time for the previous frame: the number of seconds elapsed between the last two calls to tick().
Definition at line 228 of file clockObject.I. References INLINE. Referenced by herc_idle(). |
|
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. Definition at line 194 of file clockObject.I. References _max_dt, and INLINE. Referenced by ClientBase::is_forked(), and set_frame_time(). |
|
Returns the average frame rate since the last reset. This is simply the total number of frames divided by the total elapsed time. Definition at line 211 of file clockObject.I. References _global_clock, INLINE, and NULL. |
|
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. Definition at line 96 of file clockObject.I. References _start_long_time, _true_clock, TrueClock::get_long_time(), and INLINE. Referenced by SequenceNode::CData::CData(), PGEntry::get_text(), AnimControl::loop(), AnimControl::pingpong(), AnimControl::play(), TimedCycle::set_element_count(), and set_real_time(). |
|
Returns a pointer to the global ClockObject. This is the ClockObject that most code should use for handling scene graph rendering and animation. Definition at line 318 of file clockObject.I. Referenced by SequenceNode::CData::CData(), CullResult::get_binary_state(), PGEntry::get_text(), herc_idle(), ClientBase::is_forked(), AnimControl::loop(), AnimControl::pingpong(), AnimControl::play(), Connection::set_collect_tcp(), SequenceNode::set_visible_child(), QueuedConnectionReader::stop_delay(), TimedCycle::TimedCycle(), and TimedCycle::write_datagram(). |
|
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. Definition at line 158 of file clockObject.I. |
|
Returns the current maximum allowable time elapsed between any two frames. See set_max_dt(). Definition at line 264 of file clockObject.I. |
|
Returns the current mode of the clock. See set_mode(). Definition at line 69 of file clockObject.I. References _reported_frame_time. |
|
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. Definition at line 127 of file clockObject.I. References _frame_count, and INLINE. Referenced by CullResult::get_binary_state(), Connection::set_collect_tcp(), QueuedConnectionReader::stop_delay(), tick(), and TimedCycle::write_datagram(). |
|
Simultaneously resets both the time and the frame count to zero.
Definition at line 173 of file clockObject.I. References _dt. |
|
In non-real-time mode, sets the number of seconds that should appear to elapse between frames.
Definition at line 243 of file clockObject.I. |
|
Resets the number of frames counted to the indicated number. Also see reset(), set_real_time(), and set_frame_time(). Definition at line 120 of file clockObject.cxx. |
|
Changes the time as reported for the current frame to the indicated time. Normally, the way to adjust the frame time is via tick(); this function is provided only for occasional special adjustments. Definition at line 95 of file clockObject.cxx. References _frame_count, _global_clock, and get_frame_count(). |
|
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. Definition at line 301 of file clockObject.I. |
|
Changes the mode of the clock, e.g. from normal (real-time) to non-real-time. In non-real-time mode, tick() will add the value of dt to the value returned by get_frame_time(), regardless of how much time has actually passed. In normal, real-time mode, tick() will set the value returned by get_frame_time() to the current real time. Definition at line 54 of file clockObject.I. References INLINE. |
|
Resets the clock to the indicated time. This changes only the real time of the clock as reported by get_real_time(), but does not immediately change the time reported by get_frame_time()--that will change after the next call to tick(). Also see reset(), set_frame_time(), and set_frame_count(). Definition at line 68 of file clockObject.cxx. References _actual_frame_time, _global_clock, _reported_frame_time, and get_frame_time(). |
|
Resets the frame time to the current real time. This is similar to tick(), except that it does not advance the frame counter and does not affect dt. This is intended to be used in the middle of a particularly long frame to compensate for the time that has already elapsed. In non-real-time mode, this function has no effect (because in this mode all frames take the same length of time). Definition at line 198 of file clockObject.cxx. |
|
Instructs the clock that a new frame has just begun. In normal, real-time mode, get_frame_time() will henceforth report the time as of this instant as the current start-of-frame time. In non-real-time mode, get_frame_time() will be incremented by the value of dt. Definition at line 150 of file clockObject.cxx. References _mode, _reported_frame_time, get_real_time(), and M_normal. |
|
Definition at line 135 of file clockObject.h. Referenced by ClockObject(), and set_real_time(). |
|
Definition at line 137 of file clockObject.h. Referenced by ClockObject(), reset(), and set_frame_count(). |
|
Definition at line 134 of file clockObject.h. Referenced by ClockObject(), get_real_time(), and set_frame_time(). |
|
Definition at line 26 of file clockObject.cxx. Referenced by get_frame_rate(), set_frame_time(), and set_real_time(). |
|
Definition at line 138 of file clockObject.h. Referenced by ClockObject(), get_frame_count(), and set_frame_count(). |
|
Definition at line 131 of file clockObject.h. Referenced by tick(), and ~ClockObject(). |
|
Definition at line 136 of file clockObject.h. Referenced by ClockObject(), get_mode(), set_real_time(), and tick(). |
|
Definition at line 133 of file clockObject.h. Referenced by get_frame_time(). |
|
Definition at line 132 of file clockObject.h. |
|
Definition at line 130 of file clockObject.h. Referenced by get_frame_time(). |