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

Asynchronous timer class. More...

#include <Timer.hpp>

+ Collaboration diagram for galaxy::async::Timer:

Public Types

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

Public Member Functions

 Timer () noexcept
 Constructor.
 
 Timer (Timer::Function &&func, const std::uint32_t delay) noexcept
 Set constructor.
 
 ~Timer () noexcept
 Destructor.
 
void set (Timer::Function &&func, const std::uint32_t delay) noexcept
 Run a function on a precision timer.
 
void repeat (const bool repeat) noexcept
 Make function repeat itself instead of running once.
 
void start ()
 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_stopped
 Is timer stopped.
 
std::atomic_bool m_paused
 Is timer paused.
 
std::atomic_bool m_repeat
 Is function repeating?
 
std::uint32_t m_delay
 Current delay on timer.
 
double m_time_passed
 Time passed.
 
std::future< void > m_handle
 Thread running task.
 
Timer::Function m_callback
 Callback function.
 

Detailed Description

Asynchronous timer class.

Definition at line 21 of file Timer.hpp.

Member Typedef Documentation

◆ Function

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

Timer callback type.

Definition at line 27 of file Timer.hpp.

Constructor & Destructor Documentation

◆ Timer() [1/3]

galaxy::async::Timer::Timer ( )
noexcept

Constructor.

Definition at line 21 of file Timer.cpp.

◆ Timer() [2/3]

galaxy::async::Timer::Timer ( Timer::Function && func,
const std::uint32_t delay )
noexcept

Set constructor.

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

Definition at line 32 of file Timer.cpp.

◆ ~Timer()

galaxy::async::Timer::~Timer ( )
noexcept

Destructor.

Definition at line 44 of file Timer.cpp.

+ Here is the call graph for this function:

◆ Timer() [3/3]

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

Copy constructor.

Member Function Documentation

◆ set()

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

Run a function on a precision timer.

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

Definition at line 49 of file Timer.cpp.

◆ repeat()

void galaxy::async::Timer::repeat ( const bool repeat)
noexcept

Make function repeat itself instead of running once.

Parameters
repeatTrue to repeat.

Definition at line 55 of file Timer.cpp.

◆ start()

void galaxy::async::Timer::start ( )

Start timer.

Definition at line 60 of file Timer.cpp.

◆ stop()

void galaxy::async::Timer::stop ( )
noexcept

Stop timer.

Definition at line 86 of file Timer.cpp.

+ Here is the caller graph for this function:

◆ pause()

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

Pause the timer.

Parameters
Trueto pause, False to unpause.

Definition at line 96 of file Timer.cpp.

◆ stopped()

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

Is the timer finished?

Returns
True if timer is stopped (finished).

Definition at line 101 of file Timer.cpp.

◆ paused()

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

Is the timer paused?

Returns
True if timer is paused.

Definition at line 106 of file Timer.cpp.

◆ operator=()

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

Copy assignment operator.

Member Data Documentation

◆ m_stopped

std::atomic_bool galaxy::async::Timer::m_stopped
private

Is timer stopped.

Definition at line 110 of file Timer.hpp.

◆ m_paused

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

Is timer paused.

Definition at line 115 of file Timer.hpp.

◆ m_repeat

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

Is function repeating?

Definition at line 120 of file Timer.hpp.

◆ m_delay

std::uint32_t galaxy::async::Timer::m_delay
private

Current delay on timer.

Definition at line 125 of file Timer.hpp.

◆ m_time_passed

double galaxy::async::Timer::m_time_passed
private

Time passed.

Definition at line 130 of file Timer.hpp.

◆ m_handle

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

Thread running task.

Definition at line 135 of file Timer.hpp.

◆ m_callback

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

Callback function.

Definition at line 140 of file Timer.hpp.


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