pub struct Context {
pub time: Time,
pub events: Events,
pub globals: Globals,
/* private fields */
}Expand description
Main context passed to all systems
Centralizes engine state
time- Frame timing (delta, fps, frame count)events- Event queue for inter-system communicationglobals- Type-erased resource storage
Access via system parameter:
ⓘ
#[system]
fn my_system(ctx: &mut Context) {
let delta = ctx.time.delta();
for event in ctx.events.read::<CollisionEvent>() {
// handle collision
}
let mut world = ctx.world();
world.spawn().insert(Health(100));
}Fields§
§time: TimeFrame timing information
events: EventsEvent queue
globals: GlobalsShared resource storage
Implementations§
Source§impl Context
impl Context
Sourcepub fn quit(&mut self)
pub fn quit(&mut self)
Signals the engine to stop after the current frame completes
The main loop will exit gracefully after all systems finish execution.
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Returns true if the engine is still running
Sourcepub fn register<G>(&mut self, global: G)
pub fn register<G>(&mut self, global: G)
Registers a global resource (shorthand for globals.register())
If a resource of this type already exists, it will be replaced.
Trait Implementations§
Source§impl ContextEcsExt for Context
impl ContextEcsExt for Context
Source§impl ContextInputExt for Context
impl ContextInputExt for Context
Auto Trait Implementations§
impl Freeze for Context
impl !RefUnwindSafe for Context
impl Send for Context
impl !Sync for Context
impl Unpin for Context
impl !UnwindSafe for Context
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.