Gamedev Framework (gf)  0.11.0 A C++14 framework for 2D games
gf::Clock Class Reference

Utility class that measures the elapsed time. More...

#include <gf/Clock.h>

## Public Member Functions

Clock ()
Default constructor. More...

Time getElapsedTime () const
Get the elapsed time. More...

Time restart ()
Restart the clock. More...

## Detailed Description

Utility class that measures the elapsed time.

gf::Clock is a lightweight class for measuring time. It is a thin wrapper around C++11 std::chrono::steady_clock.

Its provides the most precise time that the underlying OS can achieve (generally microseconds or nanoseconds). It also ensures monotonicity, which means that the returned time can never go backward, even if the system time is changed.

Usage example:

gf::Clock clock;
...
gf::Time time1 = clock.getElapsedTime();
...
gf::Time time2 = clock.restart();

The gf::Time value returned by the clock can then be converted to a number of seconds, milliseconds or even microseconds.

gf::Time

## ◆ Clock()

 gf::Clock::Clock ( )

Default constructor.

The clock starts automatically after being constructed.

## ◆ getElapsedTime()

 Time gf::Clock::getElapsedTime ( ) const

Get the elapsed time.

This function returns the time elapsed since the last call to restart() (or the construction of the instance if restart() has not been called).

Returns
Time elapsed

## ◆ restart()

 Time gf::Clock::restart ( )

Restart the clock.

This function puts the time counter back to zero. It also returns the time elapsed since the clock was started.

Returns
Time elapsed