pub struct World {
pub resources: Resources,
pub components: ComponentStores,
}
Expand description
The World
is simply a collection of Resources
, and ComponentStores
.
Also stored in the world is the Entities
, but it is stored as a resource.
World
is designed to be trivially Clone
ed to allow for snapshotting the world state. The
is especially useful in the context of rollback networking, which requires the ability to
snapshot and restore state.
Fields§
§resources: Resources
Stores the world resources.
components: ComponentStores
Stores the world components.
Implementations§
source§impl World
impl World
sourcepub fn with_entities(entities: AtomicResource<Entities>) -> Self
pub fn with_entities(entities: AtomicResource<Entities>) -> Self
Create a new world that uses the provided entities resource.
This allows multiple worlds to avoid allocating the same entity IDs.
sourcepub fn maintain(&self)
pub fn maintain(&self)
Remove the component info for dead entities.
This should be called every game frame to cleanup entities that have been killed.
This will remove the component storage for all killed entities, and allow their slots to be re-used for any new entities.
sourcepub fn run_system<'system, R, In, Out, S>(&self, system: S, input: In) -> Outwhere
In: 'system,
Out: 'system,
S: IntoSystem<R, In, Out>,
S::Sys: 'system,
pub fn run_system<'system, R, In, Out, S>(&self, system: S, input: In) -> Outwhere
In: 'system,
Out: 'system,
S: IntoSystem<R, In, Out>,
S::Sys: 'system,
Run a system once.
This is good for initializing the world with setup systems.
sourcepub fn entity_components<Q: QueryItem>(
&self,
entity: Entity,
query: Q,
) -> <Q::Iter as Iterator>::Item
pub fn entity_components<Q: QueryItem>( &self, entity: Entity, query: Q, ) -> <Q::Iter as Iterator>::Item
Get an entity’s components.
§Panics
Panics if the entity does not have the required components from the query.
sourcepub fn get_entity_components<Q: QueryItem>(
&self,
entity: Entity,
query: Q,
) -> Option<<Q::Iter as Iterator>::Item>
pub fn get_entity_components<Q: QueryItem>( &self, entity: Entity, query: Q, ) -> Option<<Q::Iter as Iterator>::Item>
Get an entity’s components.
sourcepub fn init_resource<R: HasSchema + FromWorld>(&mut self) -> RefMut<'_, R>
pub fn init_resource<R: HasSchema + FromWorld>(&mut self) -> RefMut<'_, R>
Initialize a resource of type T
by inserting it’s default value.
sourcepub fn insert_resource<R: HasSchema>(&mut self, resource: R) -> Option<R>
pub fn insert_resource<R: HasSchema>(&mut self, resource: R) -> Option<R>
Insert a resource.
sourcepub fn resource_mut<T: HasSchema>(&self) -> RefMut<'_, T>
pub fn resource_mut<T: HasSchema>(&self) -> RefMut<'_, T>
sourcepub fn get_resource<T: HasSchema>(&self) -> Option<Ref<'_, T>>
pub fn get_resource<T: HasSchema>(&self) -> Option<Ref<'_, T>>
Borrow a resource from the world, if it exists.
sourcepub fn get_resource_mut<T: HasSchema>(&mut self) -> Option<RefMut<'_, T>>
pub fn get_resource_mut<T: HasSchema>(&mut self) -> Option<RefMut<'_, T>>
Borrow a resource from the world, if it exists.
sourcepub fn component<T: HasSchema>(&self) -> Ref<'_, ComponentStore<T>>
pub fn component<T: HasSchema>(&self) -> Ref<'_, ComponentStore<T>>
Borrow a component store from the world.
§Panics
Panics if the component store does not exist in the world.
sourcepub fn component_mut<T: HasSchema>(&self) -> RefMut<'_, ComponentStore<T>>
pub fn component_mut<T: HasSchema>(&self) -> RefMut<'_, ComponentStore<T>>
Mutably borrow a component store from the world.
§Panics
Panics if the component store does not exist in the world.
sourcepub fn reset_internals(&mut self, reset_components: bool, reset_entities: bool)
pub fn reset_internals(&mut self, reset_components: bool, reset_entities: bool)
Provides an interface for resetting entities, and components.
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 !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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
source§fn from_world(_world: &World) -> T
fn from_world(_world: &World) -> T
Self
using data from the given World
.