![]() |
Gamedev Framework (gf)
0.19.0
A C++17 framework for 2D games
|
Represents a time value. More...
#include <gf/Time.h>
Public Member Functions | |
| constexpr | Time () |
| Default constructor. More... | |
| constexpr | Time (std::chrono::steady_clock::duration duration) |
| Constructor with a duration. More... | |
| constexpr float | asSeconds () const |
| Return the time value as a number of seconds. More... | |
| constexpr int32_t | asMilliseconds () const |
| Return the time value as a number of milliseconds. More... | |
| constexpr int64_t | asMicroseconds () const |
| Return the time value as a number of microseconds. More... | |
| constexpr std::chrono::steady_clock::duration | asDuration () const |
| Return the time value as a duration. More... | |
| Time & | addTo (Time other) |
| Add another time. More... | |
| Time & | subTo (Time other) |
| Substract another time. More... | |
Static Public Member Functions | |
| static constexpr Time | zero () |
| Get a time of zero. More... | |
Static Public Attributes | |
| static const Time | Zero |
| A time of zero as a variable. More... | |
Related Functions | |
(Note that these are not member functions.) | |
| constexpr Time | seconds (float amount) |
| Construct a time value from a number of seconds. More... | |
| constexpr Time | milliseconds (int32_t amount) |
| Construct a time value from a number of milliseconds. More... | |
| constexpr Time | microseconds (int64_t amount) |
| Construct a time value from a number of microseconds. More... | |
| constexpr bool | operator== (Time rhs, Time lhs) |
| Equality operator. More... | |
| constexpr bool | operator!= (Time rhs, Time lhs) |
| Inequality operator. More... | |
| constexpr bool | operator< (Time rhs, Time lhs) |
| Lesser than operator. More... | |
| constexpr bool | operator> (Time rhs, Time lhs) |
| Greater than operator. More... | |
| constexpr bool | operator<= (Time rhs, Time lhs) |
| Lesser or equal operator. More... | |
| constexpr bool | operator>= (Time rhs, Time lhs) |
| Greater or equal than operator. More... | |
| constexpr Time | operator+ (Time rhs, Time lhs) |
| Addition of two times. More... | |
| Time | operator+= (Time &rhs, Time lhs) |
| Addition and assignement. More... | |
| constexpr Time | operator- (Time rhs, Time lhs) |
| Substraction of two times. More... | |
| Time | operator-= (Time &rhs, Time lhs) |
| Substraction and assignment. More... | |
Represents a time value.
gf::Time encapsulates a time value in a flexible way. It allows to define a time value either as a number of seconds, milliseconds or microseconds. It also works the other way round: you can read a time value as either a number of seconds, milliseconds or microseconds.
By using such a flexible interface, the API doesn't impose any fixed type or resolution for time values, and let the user choose its own favorite representation.
Since they represent a time span and not an absolute time value, times can also be negative.
gf::Time is a thin wrapper around C++11 std::chrono::steady_clock.
Usage example:
|
inline |
Default constructor.
Sets the time value to zero.
|
inlineexplicit |
Constructor with a duration.
| duration | A duration expressed with a std::chrono type |
Add another time.
| other | The time to add to the current time |
|
inline |
Return the time value as a duration.
std::chrono type)
|
inline |
Return the time value as a number of microseconds.
|
inline |
Return the time value as a number of milliseconds.
|
inline |
Return the time value as a number of seconds.
Substract another time.
| other | The time to substract to the current time |
|
inlinestatic |
|
related |
Construct a time value from a number of microseconds.
| amount | Number of microseconds |
|
related |
Construct a time value from a number of milliseconds.
| amount | Number of milliseconds |
Inequality operator.
| rhs | First time |
| lhs | Second time |
Addition of two times.
| rhs | First time |
| lhs | Second time |
Addition and assignement.
| rhs | First time |
| lhs | Second time |
Substraction of two times.
| rhs | First time |
| lhs | Second time |
Substraction and assignment.
| rhs | First time |
| lhs | Second time |
Lesser than operator.
| rhs | First time |
| lhs | Second time |
Lesser or equal operator.
| rhs | First time |
| lhs | Second time |
Equality operator.
| rhs | First time |
| lhs | Second time |
Greater than operator.
| rhs | First time |
| lhs | Second time |
Greater or equal than operator.
| rhs | First time |
| lhs | Second time |
|
related |
Construct a time value from a number of seconds.
| amount | Number of seconds |
1.8.13