libtcod
Loading...
Searching...
No Matches
tcod::Timer Class Reference

A timing class based on SDL's high performance time counter. More...

#include <timer.hpp>

Public Member Functions

 Timer ()
 Construct a new Timer object.
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.
float get_mean_fps () const noexcept
 Return the mean framerate.
float get_last_fps () const noexcept
 Return the framerate of the last call to sync().
float get_min_fps () const noexcept
 Return the lowest framerate recently sampled.
float get_max_fps () const noexcept
 Return the highest framerate recently sampled.
float get_median_fps () const noexcept
 Return the median framerate.

Detailed Description

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.
// ...
A timing class based on SDL's high performance time counter.
Definition timer.hpp:70
embed:rst:leading-asterisk 
.. versionadded:: 1.19

Member Function Documentation

◆ get_mean_fps()

float tcod::Timer::get_mean_fps ( ) const
inlinenodiscardnoexcept

Return the mean framerate.

This is the average of all samples combined.

◆ get_median_fps()

float tcod::Timer::get_median_fps ( ) const
inlinenodiscardnoexcept

Return the median framerate.

This is the framerate of the middle sample when all samples are sorted.

◆ sync()

float tcod::Timer::sync ( int desired_fps = 0)
inline

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_fpsThe 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.

The documentation for this class was generated from the following file:
  • C:/Users/4b796/Projects/libtcod/src/libtcod/timer.hpp