Panda3D
|
A ClockObject keeps track of elapsed real time and discrete time. More...
Public Types | |
enum | Mode { M_normal = 0, M_non_real_time = 1, M_forced = 2, M_degrade = 3, M_slave = 4, M_limited = 5, M_integer = 6, M_integer_limited = 7 } |
Public Member Functions | |
__init__ (const ClockObject copy) | |
__init__ (ClockObject::Mode mode) | |
double | calcFrameRateDeviation (Thread current_thread) |
Returns the standard deviation of the frame times of the frames rendered over the past get_average_frame_rate_interval() seconds. More... | |
bool | checkErrors (Thread current_thread) |
Returns true if a clock error was detected since the last time check_errors() was called. More... | |
double | getAverageFrameRate (Thread current_thread) |
Returns the average frame rate in number of frames per second over the last get_average_frame_rate_interval() seconds. More... | |
double | getAverageFrameRateInterval () |
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. More... | |
double | getDegradeFactor () |
In degrade mode, returns the ratio by which the performance is degraded. More... | |
double | getDt (Thread current_thread) |
Returns the elapsed time for the previous frame: the number of seconds elapsed between the last two calls to tick(). More... | |
int | getFrameCount (Thread current_thread) |
Returns the number of times tick() has been called since the ClockObject was created, or since it was last reset. More... | |
double | getFrameTime (Thread current_thread) |
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). More... | |
double | getLongTime () |
Returns the actual number of seconds elapsed since the ClockObject was created, or since it was last reset. More... | |
double | getMaxDt () |
Returns the current maximum allowable time elapsed between any two frames. More... | |
double | getMaxFrameDuration (Thread current_thread) |
Returns the maximum frame duration over the last get_average_frame_rate_interval() seconds. More... | |
ClockObject::Mode | getMode () |
Returns the current mode of the clock. More... | |
double | getNetFrameRate (Thread current_thread) |
Returns the average frame rate since the last reset. More... | |
double | getRealTime () |
Returns the actual number of seconds elapsed since the ClockObject was created, or since it was last reset. More... | |
reset () | |
Simultaneously resets both the time and the frame count to zero. More... | |
setAverageFrameRateInterval (double time) | |
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. More... | |
setDegradeFactor (double degrade_factor) | |
In degrade mode, sets the ratio by which the performance is degraded. More... | |
setDt (double dt) | |
In non-real-time mode, sets the number of seconds that should appear to elapse between frames. More... | |
setFrameCount (int frame_count, Thread current_thread) | |
Resets the number of frames counted to the indicated number. More... | |
setFrameRate (double frame_rate) | |
In non-real-time mode, sets the number of frames per second that we should appear to be running. More... | |
setFrameTime (double time, Thread current_thread) | |
Changes the time as reported for the current frame to the indicated time. More... | |
setMaxDt (double max_dt) | |
Sets a limit on the value returned by get_dt(). More... | |
setMode (ClockObject::Mode mode) | |
Changes the mode of the clock. More... | |
setRealTime (double time) | |
Resets the clock to the indicated time. More... | |
syncFrameTime (Thread current_thread) | |
Resets the frame time to the current real time. More... | |
tick (Thread current_thread) | |
Instructs the clock that a new frame has just begun. More... | |
![]() | |
int | getRefCount () |
Returns the current reference count. More... | |
ref () | |
Explicitly increments the reference count. More... | |
bool | testRefCountIntegrity () |
Does some easy checks to make sure that the reference count isn't completely bogus. More... | |
bool | testRefCountNonzero () |
Does some easy checks to make sure that the reference count isn't zero, or completely bogus. More... | |
bool | unref () |
Explicitly decrements the reference count. More... | |
Static Public Member Functions | |
static TypeHandle | getClassType () |
static ClockObject | getGlobalClock () |
Returns a pointer to the global ClockObject. More... | |
![]() | |
static TypeHandle | getClassType () |
Public Attributes | |
double | average_frame_rate |
Returns the average frame rate in number of frames per second over the last get_average_frame_rate_interval() seconds. More... | |
double | average_frame_rate_interval |
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. More... | |
double | degrade_factor |
In degrade mode, returns the ratio by which the performance is degraded. More... | |
double | dt |
Returns the elapsed time for the previous frame: the number of seconds elapsed between the last two calls to tick(). More... | |
int | frame_count |
Returns the number of times tick() has been called since the ClockObject was created, or since it was last reset. More... | |
double | frame_time |
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). More... | |
double | long_time |
Returns the actual number of seconds elapsed since the ClockObject was created, or since it was last reset. More... | |
double | max_dt |
Returns the current maximum allowable time elapsed between any two frames. More... | |
double | max_frame_duration |
Returns the maximum frame duration over the last get_average_frame_rate_interval() seconds. More... | |
ClockObject::Mode | mode |
Returns the current mode of the clock. More... | |
double | real_time |
Returns the actual number of seconds elapsed since the ClockObject was created, or since it was last reset. More... | |
![]() | |
int | ref_count |
The current reference count. More... | |
A ClockObject keeps track of elapsed real time and discrete time.
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 other modes, as set by set_mode() or the clock-mode config variable, get_frame_time() may return other values to simulate different timing effects, for instance to perform non-real-time animation. See set_mode().
In all 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.
enum Mode |
__init__ | ( | const ClockObject | copy | ) |
__init__ | ( | ClockObject::Mode | mode | ) |
double calcFrameRateDeviation | ( | Thread | current_thread | ) |
Returns the standard deviation of the frame times of the frames rendered over the past get_average_frame_rate_interval() seconds.
This number gives an estimate of the chugginess of the frame rate; if it is large, there is a large variation in the frame rate; if is small, all of the frames are consistent in length.
A large value might also represent just a recent change in frame rate, for instance, because the camera has just rotated from looking at a simple scene to looking at a more complex scene.
bool checkErrors | ( | Thread | current_thread | ) |
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.
double getAverageFrameRate | ( | Thread | current_thread | ) |
Returns the average frame rate in number of frames per second over the last get_average_frame_rate_interval() seconds.
This measures the virtual frame rate if the clock is in M_non_real_time mode.
double getAverageFrameRateInterval | ( | ) |
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.
|
static |
double getDegradeFactor | ( | ) |
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.
double getDt | ( | Thread | current_thread | ) |
Returns the elapsed time for the previous frame: the number of seconds elapsed between the last two calls to tick().
int getFrameCount | ( | Thread | current_thread | ) |
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.
double getFrameTime | ( | Thread | current_thread | ) |
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.
|
static |
Returns a pointer to the global ClockObject.
This is the ClockObject that most code should use for handling scene graph rendering and animation.
double getLongTime | ( | ) |
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.
double getMaxDt | ( | ) |
Returns the current maximum allowable time elapsed between any two frames.
See set_max_dt().
double getMaxFrameDuration | ( | Thread | current_thread | ) |
Returns the maximum frame duration over the last get_average_frame_rate_interval() seconds.
ClockObject::Mode getMode | ( | ) |
Returns the current mode of the clock.
See set_mode().
double getNetFrameRate | ( | Thread | current_thread | ) |
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.
double getRealTime | ( | ) |
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.
reset | ( | ) |
Simultaneously resets both the time and the frame count to zero.
setAverageFrameRateInterval | ( | double | time | ) |
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().
setDegradeFactor | ( | double | degrade_factor | ) |
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.
setDt | ( | double | dt | ) |
In non-real-time mode, sets the number of seconds that should appear to elapse between frames.
In forced mode or limited mode, sets our target dt. In normal mode, this has no effect.
Also see set_frame_rate(), which is a different way to specify the same quantity.
setFrameCount | ( | int | frame_count, |
Thread | current_thread | ||
) |
Resets the number of frames counted to the indicated number.
Also see reset(), set_real_time(), and set_frame_time().
setFrameRate | ( | double | frame_rate | ) |
In non-real-time mode, sets the number of frames per second that we should appear to be running.
In forced mode or limited mode, sets our target frame rate. In normal mode, this has no effect.
Also see set_dt(), which is a different way to specify the same quantity.
setFrameTime | ( | double | time, |
Thread | current_thread | ||
) |
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.
setMaxDt | ( | double | max_dt | ) |
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.
setMode | ( | ClockObject::Mode | mode | ) |
Changes the mode of the clock.
Normally, the clock is in mode M_normal. In this mode, each call to tick() will set the value returned by get_frame_time() to the current real time; thus, the clock simply reports time advancing.
Other possible modes:
M_non_real_time - the clock ignores real time completely; at each call to tick(), it pretends that exactly dt seconds have elapsed since the last call to tick(). You may set the value of dt with set_dt() or set_frame_rate().
M_limited - the clock will run as fast as it can, as in M_normal, but will not run faster than the rate specified by set_frame_rate(). If the application would run faster than this rate, the clock will slow down the application.
M_integer - the clock will run as fast as it can, but the rate will be constrained to be an integer multiple or divisor of the rate specified by set_frame_rate(). The clock will slow down the application a bit to guarantee this.
M_integer_limited - a combination of M_limited and M_integer; the clock will not run faster than set_frame_rate(), and if it runs slower, it will run at a integer divisor of that rate.
M_forced - the clock forces the application to run at the rate specified by set_frame_rate(). If the application would run faster than this rate, the clock will slow down the application; if the application would run slower than this rate, the clock slows down time so that the application believes it is running at the given rate.
M_degrade - the clock runs at real time, but the application is slowed down by a set factor of its frame rate, specified by set_degrade_factor().
M_slave - the clock does not advance, but relies on the user to call set_frame_time() and/or set_frame_count() each frame.
setRealTime | ( | double | time | ) |
syncFrameTime | ( | Thread | current_thread | ) |
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).
tick | ( | Thread | current_thread | ) |
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.
double average_frame_rate |
Returns the average frame rate in number of frames per second over the last get_average_frame_rate_interval() seconds.
This measures the virtual frame rate if the clock is in M_non_real_time mode.
double average_frame_rate_interval |
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.
double degrade_factor |
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.
double dt |
Returns the elapsed time for the previous frame: the number of seconds elapsed between the last two calls to tick().
int frame_count |
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.
double frame_time |
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.
double long_time |
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.
double max_dt |
Returns the current maximum allowable time elapsed between any two frames.
See set_max_dt().
double max_frame_duration |
Returns the maximum frame duration over the last get_average_frame_rate_interval() seconds.
ClockObject::Mode mode |
Returns the current mode of the clock.
See set_mode().
double real_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.