Class Timer¶
Defined in File timer.hpp
Class Documentation¶
-
class Timer
A timing class based on SDL’s high performance time counter.
Used to track delta time or set a framerate.
This class is based on using
SDL_GetPerformanceCounter
to track the time. The time taken between calls to sync() is tracked. This is used to determine the real framerate if requested.You must add
#include <libtcod/timer.hpp>
to include ths class.int desired_fps = 30; auto timer = tcod::Timer(); while (1) { float delta_time = timer.sync(desired_fps); // desired_fps is optional. // ...
New in version 1.19.
Public Functions
-
inline Timer()
Construct a new Timer object.
-
inline float sync(int desired_fps = 0)
Sync the time to a given framerate (if provided) and return the delta time compared to the previous call.
If
desired_fps
is non-zero then this function will block until the desired framerate is reached.Timing starts once the Timer is constructed.
- Parameters
desired_fps – The desired framerate in frames-per-second, or zero to disable framerate limiting.
- Returns
The delta time in seconds since the last call to sync is returned as a float.
-
inline float get_mean_fps() const noexcept
Return the mean framerate.
This is the average of all samples combined.
-
inline float get_last_fps() const noexcept
Return the framerate of the last call to sync().
-
inline float get_min_fps() const noexcept
Return the lowest framerate recently sampled.
-
inline float get_max_fps() const noexcept
Return the highest framerate recently sampled.
-
inline float get_median_fps() const noexcept
Return the median framerate.
This is the framerate of the middle sample when all samples are sorted.
-
inline Timer()