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::Timer Class Referencefinal

Asynchronous timer class. More...

#include <Timer.hpp>

+ Collaboration diagram for galaxy::Timer:

Public Types

using Function = std::move_only_function<void(void)>
 Timer callback type.
 

Public Member Functions

 Timer () noexcept
 Constructor.
 
 ~Timer () noexcept
 Destructor.
 
void set (Timer::Function &&func, const std::uint64_t delay) noexcept
 Run a function on a precision timer.
 
void start (const bool repeat=false)
 Start timer.
 
void stop () noexcept
 Stop timer.
 
void pause (const bool pause) noexcept
 Pause the timer.
 
bool stopped () const noexcept
 Is the timer finished?
 
bool paused () const noexcept
 Is the timer paused?
 

Private Member Functions

 Timer (const Timer &)=delete
 Copy constructor.
 
Timeroperator= (const Timer &)=delete
 Copy assignment operator.
 

Private Attributes

std::atomic_bool m_started
 Has the timer been started.
 
std::atomic_bool m_paused
 Is timer paused.
 
std::atomic_bool m_repeat
 Is timer looping.
 
std::uint64_t m_delay
 Current delay on timer.
 
std::future< void > m_handle
 Thread running task.
 
Timer::Function m_callback
 Callback function.
 

Detailed Description

Asynchronous timer class.

Definition at line 18 of file Timer.hpp.

Member Typedef Documentation

◆ Function

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

Timer callback type.

Definition at line 24 of file Timer.hpp.

Constructor & Destructor Documentation

◆ Timer() [1/2]

galaxy::Timer::Timer ( )
noexcept

Constructor.

Definition at line 19 of file Timer.cpp.

◆ ~Timer()

galaxy::Timer::~Timer ( )
noexcept

Destructor.

Definition at line 29 of file Timer.cpp.

+ Here is the call graph for this function:

◆ Timer() [2/2]

galaxy::Timer::Timer ( const Timer & )
privatedelete

Copy constructor.

Member Function Documentation

◆ set()

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

Run a function on a precision timer.

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

Definition at line 34 of file Timer.cpp.

◆ start()

void galaxy::Timer::start ( const bool repeat = false)

Start timer.

Parameters
repeatTrue to repeat. Defaults to false.

Definition at line 40 of file Timer.cpp.

+ Here is the caller graph for this function:

◆ stop()

void galaxy::Timer::stop ( )
noexcept

Stop timer.

Definition at line 67 of file Timer.cpp.

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

◆ pause()

void galaxy::Timer::pause ( const bool pause)
noexcept

Pause the timer.

Parameters
Trueto pause, False to unpause.

Definition at line 79 of file Timer.cpp.

+ Here is the caller graph for this function:

◆ stopped()

bool galaxy::Timer::stopped ( ) const
nodiscardnoexcept

Is the timer finished?

Returns
True if timer is stopped (finished).

Definition at line 84 of file Timer.cpp.

+ Here is the caller graph for this function:

◆ paused()

bool galaxy::Timer::paused ( ) const
nodiscardnoexcept

Is the timer paused?

Returns
True if timer is paused.

Definition at line 89 of file Timer.cpp.

+ Here is the caller graph for this function:

◆ operator=()

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

Copy assignment operator.

Member Data Documentation

◆ m_started

std::atomic_bool galaxy::Timer::m_started
private

Has the timer been started.

Definition at line 94 of file Timer.hpp.

◆ m_paused

std::atomic_bool galaxy::Timer::m_paused
private

Is timer paused.

Definition at line 99 of file Timer.hpp.

◆ m_repeat

std::atomic_bool galaxy::Timer::m_repeat
private

Is timer looping.

Definition at line 104 of file Timer.hpp.

◆ m_delay

std::uint64_t galaxy::Timer::m_delay
private

Current delay on timer.

Definition at line 109 of file Timer.hpp.

◆ m_handle

std::future<void> galaxy::Timer::m_handle
private

Thread running task.

Definition at line 114 of file Timer.hpp.

◆ m_callback

Timer::Function galaxy::Timer::m_callback
private

Callback function.

Definition at line 119 of file Timer.hpp.


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