![]() |
galaxy 1.0.0
Real-Time C++23 Game Programming Framework. Built on data-driven design principles and agile software engineering.
|
Synchronous stopwatch. More...
#include <Stopwatch.hpp>
Public Types | |
using | Function = std::move_only_function<void(void)> |
Stopwatch callback type. | |
Public Member Functions | |
Stopwatch () | |
Constructor. | |
~Stopwatch () | |
Destructor. | |
void | set (Stopwatch::Function &&func, const std::uint64_t delay) |
Run a function on a precision Stopwatch. | |
void | repeat (const bool repeat) |
Make function repeat itself instead of running once. | |
void | start () |
Start Stopwatch. | |
void | stop () |
Stop Stopwatch. | |
void | pause () |
Pause the Stopwatch. | |
void | unpause () |
Resume the Stopwatch. | |
void | update () |
Call this if you want to trigger the callback after delay has passed. | |
bool | stopped () const |
Is the Stopwatch finished? | |
bool | paused () const |
Is the Stopwatch paused? | |
std::uint64_t | get_time_passed () const noexcept |
Time passed in milliseconds. | |
Private Member Functions | |
Stopwatch (const Stopwatch &)=delete | |
Copy constructor. | |
Stopwatch & | operator= (const Stopwatch &)=delete |
Copy assignment operator. | |
Private Attributes | |
bool | m_stopped |
Is Stopwatch stopped. | |
bool | m_paused |
Is Stopwatch paused. | |
bool | m_repeat |
Is function repeating? | |
std::uint64_t | m_start_ticks |
The clock time when the timer started. | |
std::uint64_t | m_paused_ticks |
The ticks stored when the timer was paused. | |
std::uint64_t | m_delay |
Duration before callback is invoked. | |
Stopwatch::Function | m_callback |
Callback function. | |
Synchronous stopwatch.
Definition at line 18 of file Stopwatch.hpp.
using galaxy::Stopwatch::Function = std::move_only_function<void(void)> |
Stopwatch callback type.
Definition at line 24 of file Stopwatch.hpp.
galaxy::Stopwatch::Stopwatch | ( | ) |
Constructor.
Definition at line 14 of file Stopwatch.cpp.
galaxy::Stopwatch::~Stopwatch | ( | ) |
|
privatedelete |
Copy constructor.
void galaxy::Stopwatch::set | ( | Stopwatch::Function && | func, |
const std::uint64_t | delay ) |
Run a function on a precision Stopwatch.
func | Function to call. |
delay | Delay until function is called. In milliseconds. |
Definition at line 30 of file Stopwatch.cpp.
void galaxy::Stopwatch::repeat | ( | const bool | repeat | ) |
Make function repeat itself instead of running once.
repeat | True to repeat. |
Definition at line 36 of file Stopwatch.cpp.
void galaxy::Stopwatch::start | ( | ) |
Start Stopwatch.
Definition at line 41 of file Stopwatch.cpp.
void galaxy::Stopwatch::stop | ( | ) |
Stop Stopwatch.
Definition at line 50 of file Stopwatch.cpp.
void galaxy::Stopwatch::pause | ( | ) |
Pause the Stopwatch.
Definition at line 59 of file Stopwatch.cpp.
void galaxy::Stopwatch::unpause | ( | ) |
Resume the Stopwatch.
Definition at line 70 of file Stopwatch.cpp.
void galaxy::Stopwatch::update | ( | ) |
Call this if you want to trigger the callback after delay has passed.
Not required if you just want to get time passed. Stops the stopwatch unless repeat is set.
Definition at line 81 of file Stopwatch.cpp.
|
nodiscard |
Is the Stopwatch finished?
Definition at line 97 of file Stopwatch.cpp.
|
nodiscard |
Is the Stopwatch paused?
Definition at line 102 of file Stopwatch.cpp.
|
nodiscardnoexcept |
Time passed in milliseconds.
Definition at line 107 of file Stopwatch.cpp.
Copy assignment operator.
|
private |
Is Stopwatch stopped.
Definition at line 118 of file Stopwatch.hpp.
|
private |
Is Stopwatch paused.
Definition at line 123 of file Stopwatch.hpp.
|
private |
Is function repeating?
Definition at line 128 of file Stopwatch.hpp.
|
private |
The clock time when the timer started.
Definition at line 133 of file Stopwatch.hpp.
|
private |
The ticks stored when the timer was paused.
Definition at line 138 of file Stopwatch.hpp.
|
private |
Duration before callback is invoked.
Definition at line 143 of file Stopwatch.hpp.
|
private |
Callback function.
Definition at line 148 of file Stopwatch.hpp.