Skip to main content

TaskRegistry

Struct TaskRegistry 

Source
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.

Source

pub fn register<T>(&mut self, task: T) -> TaskHandle
where 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 implement Updatable and be 'static so it can be boxed into the heterogeneous task list.
§Returns
  • TaskHandle - A handle used to unregister the task.
Source

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
§Returns
  • bool - true if a task was removed, false if the handle did not match any registered task.
Source

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.
Source

pub fn len(&self) -> usize

Returns the number of registered tasks.

§Returns
  • usize - The task count.
Source

pub fn is_empty(&self) -> bool

Returns whether the registry holds no tasks.

§Returns
  • bool - true if no tasks are registered.
Source

pub fn clear(&mut self)

Removes every registered task.

Source§

impl TaskRegistry

Source

pub fn get_tasks(&self) -> &Vec<Box<dyn Updatable + 'static>>

Source

pub fn set_tasks(&mut self, val: Vec<Box<dyn Updatable + 'static>>) -> &mut Self

Source§

impl TaskRegistry

Source

pub fn new(tasks: Vec<Box<dyn Updatable>>) -> Self

Trait Implementations§

Source§

impl Default for TaskRegistry

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more