Skip to main content

Timer.ixx File

A game timer that tracks elapsed time and supports state transitions. More...

Included Headers

Namespaces Index

namespacehelios
namespaceengine
namespaceruntime
namespacetiming

Classes Index

classTimer

A game timer identified by a TimerId. More...

Description

A game timer that tracks elapsed time and supports state transitions.

File Listing

The file content with the documentation metadata removed is:

1
5module;
6
7export module helios.engine.runtime.timing.Timer;
8
9import helios.engine.runtime.timing.types.TimerId;
10
11import helios.engine.runtime.timing.types;
12
15
16export namespace helios::engine::runtime::timing {
17
27 class Timer {
28
32 TimerRevision timerRevision_{};
33
37 TimerId timerId_;
38
42 float elapsed_{};
43
47 TimerState timerState_{};
48
52 float duration_ = 0.0f;
53
54 public:
55
62 : timerId_{timerId} {}
63
70 return timerId_;
71 }
72
78 void reset(const TimerState state = TimerState::Undefined) noexcept {
79 elapsed_ = 0.0f;
81 }
82
90 reset(TimerState::Running);
91 }
92
98 void cancel() noexcept {
99 reset(TimerState::Cancelled);
100 }
101
107 void setDuration(float duration) {
108 duration_ = duration;
109 }
110
117 return duration_;
118 }
119
126 return elapsed_;
127 }
128
135 return timerState_;
136 }
137
143 void setState(const TimerState state) noexcept {
144 timerState_ = state;
145 timerRevision_++;
146 }
147
154 return (timerState_ == TimerState::Running);
155 }
156
163 return (timerState_ == TimerState::Finished);
164 }
165
172 return timerRevision_;
173 }
174
183 void update(const float ft) {
184 if (!shouldUpdate() || ft == 0.0f) {
185 return;
186 }
187 timerRevision_++;
188 elapsed_ += ft;
189 }
190
191 };
192
193}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.