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
Timer.hpp
Go to the documentation of this file.
1
7
8#ifndef GALAXY_TIME_TIMER_HPP_
9#define GALAXY_TIME_TIMER_HPP_
10
11#include <future>
12
13namespace galaxy
14{
18 class Timer final
19 {
20 public:
24 using Function = std::move_only_function<void(void)>;
25
29 Timer() noexcept;
30
34 ~Timer() noexcept;
35
42 void set(Timer::Function&& func, const std::uint64_t delay) noexcept;
43
49 void start(const bool repeat = false);
50
54 void stop() noexcept;
55
61 void pause(const bool pause) noexcept;
62
68 [[nodiscard]]
69 bool stopped() const noexcept;
70
76 [[nodiscard]]
77 bool paused() const noexcept;
78
79 private:
83 Timer(const Timer&) = delete;
84
88 Timer& operator=(const Timer&) = delete;
89
90 private:
94 std::atomic_bool m_started;
95
99 std::atomic_bool m_paused;
100
104 std::atomic_bool m_repeat;
105
109 std::uint64_t m_delay;
110
114 std::future<void> m_handle;
115
120 };
121} // namespace galaxy
122
123#endif
Asynchronous timer class.
Definition Timer.hpp:19
std::atomic_bool m_started
Has the timer been started.
Definition Timer.hpp:94
void stop() noexcept
Stop timer.
Definition Timer.cpp:67
std::future< void > m_handle
Thread running task.
Definition Timer.hpp:114
std::atomic_bool m_repeat
Is timer looping.
Definition Timer.hpp:104
Timer() noexcept
Constructor.
Definition Timer.cpp:19
Timer::Function m_callback
Callback function.
Definition Timer.hpp:119
void pause(const bool pause) noexcept
Pause the timer.
Definition Timer.cpp:79
void start(const bool repeat=false)
Start timer.
Definition Timer.cpp:40
std::atomic_bool m_paused
Is timer paused.
Definition Timer.hpp:99
bool paused() const noexcept
Is the timer paused?
Definition Timer.cpp:89
std::move_only_function< void(void)> Function
Timer callback type.
Definition Timer.hpp:24
void set(Timer::Function &&func, const std::uint64_t delay) noexcept
Run a function on a precision timer.
Definition Timer.cpp:34
std::uint64_t m_delay
Current delay on timer.
Definition Timer.hpp:109
bool stopped() const noexcept
Is the timer finished?
Definition Timer.cpp:84
Animated.cpp galaxy.
Definition Animated.cpp:16
STL namespace.