pub struct World {
pub resources: Resources,
/* private fields */
}Expand description
The central ECS container: archetypes, entity allocator, resources, events.
Fields§
§resources: ResourcesGlobal singleton resources.
Implementations§
Source§impl World
impl World
Sourcepub fn increment_tick(&mut self)
pub fn increment_tick(&mut self)
Advances the tick counter by 1.
Sourcepub fn spawn<B: Bundle>(&mut self, bundle: B) -> Entity
pub fn spawn<B: Bundle>(&mut self, bundle: B) -> Entity
Spawns an entity with the given bundle and returns its handle.
Sourcepub fn despawn(&mut self, entity: Entity) -> bool
pub fn despawn(&mut self, entity: Entity) -> bool
Despawns an entity, returning true if it was alive.
Sourcepub fn insert<C: Component>(&mut self, entity: Entity, component: C)
pub fn insert<C: Component>(&mut self, entity: Entity, component: C)
Inserts component C onto an entity, migrating its archetype if needed.
Sourcepub fn get_mut<C: Component>(&mut self, entity: Entity) -> Option<&mut C>
pub fn get_mut<C: Component>(&mut self, entity: Entity) -> Option<&mut C>
Returns &mut C for entity, updating changed tick.
Sourcepub fn entity_ref(&self, entity: Entity) -> Option<EntityRef<'_>>
pub fn entity_ref(&self, entity: Entity) -> Option<EntityRef<'_>>
Read-only view of an entity’s components.
Sourcepub fn entity_mut(&mut self, entity: Entity) -> Option<EntityMut<'_>>
pub fn entity_mut(&mut self, entity: Entity) -> Option<EntityMut<'_>>
Read-write view of an entity’s components.
Sourcepub fn query<Q: WorldQuery, F: QueryFilter>(&self) -> QueryIter<'_, Q, F> ⓘ
pub fn query<Q: WorldQuery, F: QueryFilter>(&self) -> QueryIter<'_, Q, F> ⓘ
Returns an iterator over entities matching Q and filter F.
Sourcepub fn query_single<Q: WorldQuery>(&self) -> Option<Q::Item<'_>>
pub fn query_single<Q: WorldQuery>(&self) -> Option<Q::Item<'_>>
Returns the single matching entity, or None if zero or multiple.
Sourcepub fn insert_resource<T: 'static + Send + Sync>(&mut self, v: T)
pub fn insert_resource<T: 'static + Send + Sync>(&mut self, v: T)
Inserts a resource.
Sourcepub fn resource_mut<T: 'static + Send + Sync>(
&mut self,
) -> Option<ResMut<'_, T>>
pub fn resource_mut<T: 'static + Send + Sync>( &mut self, ) -> Option<ResMut<'_, T>>
Returns ResMut<T>.
Sourcepub fn remove_resource<T: 'static + Send + Sync>(&mut self) -> Option<T>
pub fn remove_resource<T: 'static + Send + Sync>(&mut self) -> Option<T>
Removes and returns T.
Sourcepub fn events_mut<E: 'static + Send + Sync>(&mut self) -> Option<&mut Events<E>>
pub fn events_mut<E: 'static + Send + Sync>(&mut self) -> Option<&mut Events<E>>
Returns &mut Events<E>.
Sourcepub fn send_event<E: 'static + Send + Sync>(&mut self, event: E)
pub fn send_event<E: 'static + Send + Sync>(&mut self, event: E)
Sends event E (auto-creates queue).
Sourcepub fn entity_count(&self) -> usize
pub fn entity_count(&self) -> usize
Total number of live entities.
Sourcepub fn archetype_count(&self) -> usize
pub fn archetype_count(&self) -> usize
Number of archetypes.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for World
impl !RefUnwindSafe for World
impl Send for World
impl Sync for World
impl Unpin for World
impl UnsafeUnpin for World
impl !UnwindSafe for World
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.