|
Vulkan Schnee 0.0.1 (22840dc8)
High-performance rendering engine
|
Schedules one-shot callbacks against engine time. More...
#include <TimerManager.h>
Classes | |
| struct | TimerEvent |
| struct | TimerHandle |
| Opaque identifier for a scheduled timer. More... | |
Public Types | |
| using | Callback = std::function<void()> |
| Callback type used by unowned timers. | |
Public Member Functions | |
| TimerManager ()=default | |
| Creates a standalone timer manager. | |
| TimerManager (EngineKern *engine) | |
| Creates an engine-owned timer manager. | |
| TimerHandle | setTimer (double delaySeconds, Callback callback) |
| Schedules a one-shot callback after delaySeconds. | |
| TimerHandle | setActorTimer (Entities::Actor *owner, double delaySeconds, std::function< void(Entities::Actor &)> callback) |
| Schedules a one-shot callback tied to an actor's lifetime. | |
| void | cancelTimer (TimerHandle handle) |
| Cancels a scheduled timer. | |
| void | cancelTimersFor (const Entities::Actor *owner) |
| Cancels every actor-owned timer registered for owner. | |
| void | clear () |
| Removes all pending timers without running callbacks. | |
| void | tick (double nowSeconds) |
| Executes all timers due at or before nowSeconds. | |
Private Member Functions | |
| double | getCurrentTimeSeconds () const |
| bool | isEventStillValid (const TimerEvent &event) const |
| void | insertTimer (TimerEvent event) |
Private Attributes | |
| EngineKern * | engine_ = nullptr |
| std::vector< TimerEvent > | timers_ |
| uint64_t | nextTimerId_ = 1 |
| double | currentTimeSeconds_ = 0.0 |
Schedules one-shot callbacks against engine time.
TimerManager stores delayed callbacks and executes expired callbacks when tick() advances past their fire time. Engine-owned managers use EngineKern::getGlobalTimeSeconds() when scheduling new timers. Standalone managers use the last time value passed to tick().
Timers fire once. Schedule a new timer from the callback when repeated work is required.
Definition at line 32 of file TimerManager.h.
| using Engine::Core::TimerManager::Callback = std::function<void()> |
Callback type used by unowned timers.
Definition at line 61 of file TimerManager.h.
|
default |
Creates a standalone timer manager.
Standalone instances use the time supplied to tick() as their current time base. This constructor is useful for tools and tests that drive time manually.
|
explicit |
Creates an engine-owned timer manager.
New timers use engine global time as their scheduling base. Passing nullptr creates a manager that behaves like a standalone manager.
| engine | Engine instance used to read the current global time. |
| void Engine::Core::TimerManager::cancelTimer | ( | TimerHandle | handle | ) |
Cancels a scheduled timer.
Invalid handles, unknown handles, and handles for already-fired timers are ignored.
| handle | Timer handle returned by setTimer() or setActorTimer(). |
| void Engine::Core::TimerManager::cancelTimersFor | ( | const Entities::Actor * | owner | ) |
Cancels every actor-owned timer registered for owner.
This does not cancel unowned timers created with setTimer(), even if their callback captures owner.
| owner | Actor whose pending timers should be removed. nullptr is ignored. |
| void Engine::Core::TimerManager::clear | ( | ) |
Removes all pending timers without running callbacks.
Existing handles become stale after this call.
|
nodiscardprivate |
|
private |
|
nodiscardprivate |
| TimerHandle Engine::Core::TimerManager::setActorTimer | ( | Entities::Actor * | owner, |
| double | delaySeconds, | ||
| std::function< void(Entities::Actor &)> | callback ) |
Schedules a one-shot callback tied to an actor's lifetime.
The callback runs only if owner is still backed by a valid ECS entity when the timer expires. Passing nullptr returns an invalid handle and schedules no timer.
Actor::onEngineEndPlay() cancels actor timers for that actor before endPlay() runs.
| owner | Actor that owns the timer. |
| delaySeconds | Delay in seconds. Negative values are clamped to zero. |
| callback | Function called with the owning actor when the timer expires. |
| TimerHandle Engine::Core::TimerManager::setTimer | ( | double | delaySeconds, |
| Callback | callback ) |
Schedules a one-shot callback after delaySeconds.
Use this for callbacks whose captured data outlives the timer, or cancel the returned handle before captured data is destroyed. Prefer setActorTimer() for actor-owned gameplay logic.
| delaySeconds | Delay in seconds. Negative values are clamped to zero. |
| callback | Function called when the timer expires. Empty callbacks are allowed. |
| void Engine::Core::TimerManager::tick | ( | double | nowSeconds | ) |
Executes all timers due at or before nowSeconds.
Timers scheduled for the same fire time run in creation order. Timers scheduled by a callback for the current time can run during the same tick. Callbacks can cancel pending timers.
Game code normally does not call this on the engine-owned manager. EngineKern calls tick() after postTick() callbacks and before pending actor destruction is flushed.
| nowSeconds | Absolute time in seconds for this tick. |
|
private |
Definition at line 169 of file TimerManager.h.
|
private |
Definition at line 166 of file TimerManager.h.
|
private |
Definition at line 168 of file TimerManager.h.
|
private |
Definition at line 167 of file TimerManager.h.