|
libecs-cpp 2.1.0
Entity Component System library in C++
|
A callback that fires after a length of time, owned by a System. More...
#include <System.hpp>
Public Member Functions | |
| Timer (std::string name, std::function< void()> callback, std::chrono::microseconds interval=std::chrono::seconds(30), bool repeat=true) | |
| Creates a timer from a name, a callback, a length and whether it repeats. | |
| template<std::integral T> | |
| Timer (std::string name, std::function< void()> callback, T seconds, bool repeat=true) | |
| Creates a timer whose length is a bare number of seconds. | |
| bool | CallbackRun () |
| Runs the callback if the timer is due by the real steady clock, and says whether it ran. | |
Public Attributes | |
| std::string | Name |
| The name that System::TimerClear() cancels the timer by. | |
| bool | Repeat |
| True for a timer that fires every length, false for one that fires once. | |
A callback that fires after a length of time, owned by a System.
A repeating timer (the default) fires every length until it is cleared. A one-shot timer fires once and is then discarded; if its callback adds a new timer under the same name, the new timer is kept.
The length is a std::chrono duration, for example std::chrono::hours(2), from zero up to ecs::MAX_INTERVAL. A timer first fires one full length after it is added with System::TimerAdd(), and not before. A length of zero fires once on every update of the system. A length outside the range is rejected by TimerAdd() with std::runtime_error.
A bare number in place of a duration means seconds. That form is deprecated.
|
inline |
Creates a timer from a name, a callback, a length and whether it repeats.
The length is checked when the timer is added with System::TimerAdd().
|
inline |
Creates a timer whose length is a bare number of seconds.
Deprecated since 1.8.0: pass a std::chrono duration instead. A negative number or one above the maximum is kept as an out-of-range length, which System::TimerAdd() rejects; it never wraps around.
|
inline |
Runs the callback if the timer is due by the real steady clock, and says whether it ran.
This is for a timer that is not owned by a system. A timer added to a system is driven by the system, with the system's clock, and must not be run through this.
| std::string ecs::Timer::Name |
The name that System::TimerClear() cancels the timer by.
Several timers may share a name.
| bool ecs::Timer::Repeat |
True for a timer that fires every length, false for one that fires once.