pub struct TaskRegistry { /* private fields */ }Expand description
A registry of Updatable tasks driven by the fixed-timestep scheduler.
The scheduler itself only knows how to run a single TickHandler; every
other simulation object in the engine — Timer, Tween,
ParticleEmitter, Entity, Animator, SceneManager, and the
PhysicsWorld2D / PhysicsWorld3D containers — exposes its advancement
through the Updatable trait instead. This registry is the driver that
gives those objects a heartbeat: SchedulerState::tick calls
TaskRegistry::update_all once per fixed step, immediately after the
handler’s on_update callback returns, so gameplay logic registered in
on_update sees task state that has already advanced this step.
Tasks are updated in registration order, which makes the relative ordering of independent tasks explicit and reproducible rather than dependent on container iteration order.
Implementations§
Source§impl TaskRegistry
Implements registration and per-step advancement for TaskRegistry.
impl TaskRegistry
Implements registration and per-step advancement for TaskRegistry.
Sourcepub fn register<T>(&mut self, task: T) -> TaskHandlewhere
T: Updatable + 'static,
pub fn register<T>(&mut self, task: T) -> TaskHandlewhere
T: Updatable + 'static,
Registers an updater and returns a handle that can remove it again.
The returned TaskHandle stores the task’s insertion index, so
unregistering does not scan the task list for a matching pointer.
Because removal preserves the relative order of the surviving
tasks, a handle only stays valid while no earlier task has been
removed; TaskRegistry::unregister re-resolves the index against
the current list rather than trusting a stale one.
§Arguments
T- The updater to drive each fixed step. Must implementUpdatableand be'staticso it can be boxed into the heterogeneous task list.
§Returns
TaskHandle- A handle used to unregister the task.
Sourcepub fn unregister(&mut self, handle: &TaskHandle) -> bool
pub fn unregister(&mut self, handle: &TaskHandle) -> bool
Removes a previously registered task, returning whether it was found.
A task is identified by its TaskHandle. The removal keeps the
insertion order of the remaining tasks intact, which is what the
per-step update contract promises.
§Arguments
&TaskHandle- The handle returned byTaskRegistry::register.
§Returns
bool-trueif a task was removed,falseif the handle did not match any registered task.
Sourcepub fn update_all(&mut self, delta_time: f64)
pub fn update_all(&mut self, delta_time: f64)
Advances every registered task by delta_time seconds.
Tasks are updated in registration order. The whole list is walked even if a task unregisters another one later in the list, because the borrow of the task vector is held for the duration of the walk; deferring mutation to the next step keeps the iteration well-defined.
§Arguments
f64- The fixed delta time in seconds.