ECSTASY
All in the name
Loading...
Searching...
No Matches
Timer.hpp
Go to the documentation of this file.
1
11
12#ifndef ECSTASY_SYSTEM_TIMER_HPP_
13#define ECSTASY_SYSTEM_TIMER_HPP_
14
15#include <chrono>
16#include <cstdint>
17#include <ctime>
18
19namespace ecstasy
20{
22 class Registry;
23
32 class Timer {
33 public:
38
39 private:
40 struct TimeInterval {
42 };
43
44 struct Rate {
47 };
48
49 public:
56 enum class Type {
58 Rate,
59 };
60
69 Timer();
70
79 Timer(Interval interval);
80
89 Timer(std::uint32_t rate);
90
97 Timer(const Timer &) = default;
98
105 Timer(Timer &&) = default;
106
113 ~Timer() = default;
114
122 Timer &operator=(const Timer &) = default;
123
131 Timer &operator=(Timer &&) = default;
132
141 [[nodiscard]] constexpr Type getType() const noexcept
142 {
143 return _type;
144 }
145
154 [[nodiscard]] constexpr TimePoint getLastTrigger() const noexcept
155 {
156 return _lastTrigger;
157 }
158
167 void setRate(std::uint32_t rate) noexcept;
168
179 [[nodiscard]] std::uint32_t getRate() const;
180
189 void setInterval(Interval interval) noexcept;
190
201 [[nodiscard]] Interval getInterval() const;
202
213 [[nodiscard]] bool trigger() noexcept;
214
215 private:
221 union {
224 };
225 };
226} // namespace ecstasy
227
228#endif /* !ECSTASY_SYSTEM_TIMER_HPP_ */
Timer class to control the execution of systems.
Definition Timer.hpp:32
std::chrono::milliseconds Interval
Type of time intervals.
Definition Timer.hpp:37
constexpr TimePoint getLastTrigger() const noexcept
Get the last time the timer was triggered.
Definition Timer.hpp:154
Timer & operator=(Timer &&)=default
Move assignment operator.
bool trigger() noexcept
Trigger the timer if it is time to do so.
Definition Timer.cpp:64
Timer(Timer &&)=default
Move constructor.
void setRate(std::uint32_t rate) noexcept
Set the Rate of the timer.
Definition Timer.cpp:33
constexpr Type getType() const noexcept
Get the Type of the timer.
Definition Timer.hpp:141
TimePoint _lastTrigger
Last time the timer was triggered.
Definition Timer.hpp:219
void setInterval(Interval interval) noexcept
Set the Interval of the timer.
Definition Timer.cpp:51
Timer()
Construct a new Timer.
Definition Timer.cpp:17
TimeInterval _timer
Definition Timer.hpp:222
std::uint32_t getRate() const
Get the Rate of the timer.
Definition Timer.cpp:44
~Timer()=default
Destroy the Timer.
Interval getInterval() const
Get the Interval of the timer.
Definition Timer.cpp:57
Timer & operator=(const Timer &)=default
Copy assignment operator.
Timer(const Timer &)=default
Copy constructor.
Type
Possible types of timers.
Definition Timer.hpp:56
Type _type
Type of the timer.
Definition Timer.hpp:217
Namespace containing all symbols specific to ecstasy.
Definition ecstasy.hpp:30
std::uint32_t rate
Definition Timer.hpp:45
std::uint32_t triggerCountdown
Definition Timer.hpp:46