galaxy 1.0.0
Real-Time C++23 Game Programming Framework. Built on data-driven design principles and agile software engineering.
Loading...
Searching...
No Matches
galaxy::Stopwatch Class Referencefinal

Synchronous stopwatch. More...

#include <Stopwatch.hpp>

+ Collaboration diagram for galaxy::Stopwatch:

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.
 
Stopwatchoperator= (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.
 

Detailed Description

Synchronous stopwatch.

Definition at line 18 of file Stopwatch.hpp.

Member Typedef Documentation

◆ Function

using galaxy::Stopwatch::Function = std::move_only_function<void(void)>

Stopwatch callback type.

Definition at line 24 of file Stopwatch.hpp.

Constructor & Destructor Documentation

◆ Stopwatch() [1/2]

galaxy::Stopwatch::Stopwatch ( )

Constructor.

Definition at line 14 of file Stopwatch.cpp.

◆ ~Stopwatch()

galaxy::Stopwatch::~Stopwatch ( )

Destructor.

Definition at line 25 of file Stopwatch.cpp.

+ Here is the call graph for this function:

◆ Stopwatch() [2/2]

galaxy::Stopwatch::Stopwatch ( const Stopwatch & )
privatedelete

Copy constructor.

Member Function Documentation

◆ set()

void galaxy::Stopwatch::set ( Stopwatch::Function && func,
const std::uint64_t delay )

Run a function on a precision Stopwatch.

Parameters
funcFunction to call.
delayDelay until function is called. In milliseconds.

Definition at line 30 of file Stopwatch.cpp.

◆ repeat()

void galaxy::Stopwatch::repeat ( const bool repeat)

Make function repeat itself instead of running once.

Parameters
repeatTrue to repeat.

Definition at line 36 of file Stopwatch.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ start()

void galaxy::Stopwatch::start ( )

Start Stopwatch.

Definition at line 41 of file Stopwatch.cpp.

+ Here is the caller graph for this function:

◆ stop()

void galaxy::Stopwatch::stop ( )

Stop Stopwatch.

Definition at line 50 of file Stopwatch.cpp.

+ Here is the caller graph for this function:

◆ pause()

void galaxy::Stopwatch::pause ( )

Pause the Stopwatch.

Definition at line 59 of file Stopwatch.cpp.

+ Here is the caller graph for this function:

◆ unpause()

void galaxy::Stopwatch::unpause ( )

Resume the Stopwatch.

Definition at line 70 of file Stopwatch.cpp.

+ Here is the caller graph for this function:

◆ update()

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.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ stopped()

bool galaxy::Stopwatch::stopped ( ) const
nodiscard

Is the Stopwatch finished?

Returns
True if Stopwatch is stopped (finished).

Definition at line 97 of file Stopwatch.cpp.

+ Here is the caller graph for this function:

◆ paused()

bool galaxy::Stopwatch::paused ( ) const
nodiscard

Is the Stopwatch paused?

Returns
True if Stopwatch is paused.

Definition at line 102 of file Stopwatch.cpp.

+ Here is the caller graph for this function:

◆ get_time_passed()

std::uint64_t galaxy::Stopwatch::get_time_passed ( ) const
nodiscardnoexcept

Time passed in milliseconds.

Returns
Milliseconds.

Definition at line 107 of file Stopwatch.cpp.

+ Here is the caller graph for this function:

◆ operator=()

Stopwatch & galaxy::Stopwatch::operator= ( const Stopwatch & )
privatedelete

Copy assignment operator.

Member Data Documentation

◆ m_stopped

bool galaxy::Stopwatch::m_stopped
private

Is Stopwatch stopped.

Definition at line 118 of file Stopwatch.hpp.

◆ m_paused

bool galaxy::Stopwatch::m_paused
private

Is Stopwatch paused.

Definition at line 123 of file Stopwatch.hpp.

◆ m_repeat

bool galaxy::Stopwatch::m_repeat
private

Is function repeating?

Definition at line 128 of file Stopwatch.hpp.

◆ m_start_ticks

std::uint64_t galaxy::Stopwatch::m_start_ticks
private

The clock time when the timer started.

Definition at line 133 of file Stopwatch.hpp.

◆ m_paused_ticks

std::uint64_t galaxy::Stopwatch::m_paused_ticks
private

The ticks stored when the timer was paused.

Definition at line 138 of file Stopwatch.hpp.

◆ m_delay

std::uint64_t galaxy::Stopwatch::m_delay
private

Duration before callback is invoked.

Definition at line 143 of file Stopwatch.hpp.

◆ m_callback

Stopwatch::Function galaxy::Stopwatch::m_callback
private

Callback function.

Definition at line 148 of file Stopwatch.hpp.


The documentation for this class was generated from the following files: