Struct bones_lib::ecs::World

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 Cloneed 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§

§

impl World

pub fn new() -> World

Create a new World.

pub fn with_entities(entities: AtomicResource<Entities>) -> World

Create a new world that uses the provided entities resource.

This allows multiple worlds to avoid allocating the same entity IDs.

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.

pub fn run_system<'system, R, In, Out, S>(&self, system: S, input: In) -> Out
where In: 'system, Out: 'system, S: IntoSystem<R, In, Out>, <S as IntoSystem<R, In, Out>>::Sys: 'system,

Run a system once.

This is good for initializing the world with setup systems.

pub fn entity_components<Q>( &self, entity: Entity, query: Q, ) -> <<Q as QueryItem>::Iter as Iterator>::Item
where Q: QueryItem,

Get an entity’s components.

§Panics

Panics if the entity does not have the required components from the query.

pub fn get_entity_components<Q>( &self, entity: Entity, query: Q, ) -> Option<<<Q as QueryItem>::Iter as Iterator>::Item>
where Q: QueryItem,

Get an entity’s components.

pub fn init_resource<R>(&mut self) -> RefMut<'_, R>
where R: HasSchema + FromWorld,

Initialize a resource of type T by inserting it’s default value.

pub fn insert_resource<R>(&mut self, resource: R) -> Option<R>
where R: HasSchema,

Insert a resource.

pub fn resource<T>(&self) -> Ref<'_, T>
where T: HasSchema,

Borrow a resource from the world.

§Panics

Panics if the resource does not exist in the store.

pub fn resource_mut<T>(&self) -> RefMut<'_, T>
where T: HasSchema,

Borrow a resource from the world.

§Panics

Panics if the resource does not exist in the store.

pub fn get_resource<T>(&self) -> Option<Ref<'_, T>>
where T: HasSchema,

Borrow a resource from the world, if it exists.

pub fn get_resource_mut<T>(&mut self) -> Option<RefMut<'_, T>>
where T: HasSchema,

Borrow a resource from the world, if it exists.

pub fn component<T>(&self) -> Ref<'_, ComponentStore<T>>
where T: HasSchema,

Borrow a component store from the world.

§Panics

Panics if the component store does not exist in the world.

pub fn component_mut<T>(&self) -> RefMut<'_, ComponentStore<T>>
where T: HasSchema,

Mutably borrow a component store from the world.

§Panics

Panics if the component store does not exist in the world.

pub fn reset_internals(&mut self, reset_components: bool, reset_entities: bool)

Provides an interface for resetting entities, and components.

Trait Implementations§

§

impl Clone for World

§

fn clone(&self) -> World

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for World

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl Default for World

§

fn default() -> World

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

impl SystemParam for &World

§

type State = ()

The intermediate state for the parameter, that may be extracted from the world.
§

type Param<'s> = &'s World

The type of the parameter, ranging over the lifetime of the intermediate state. Read more
§

fn get_state(_world: &World) -> <&World as SystemParam>::State

This is called to produce the intermediate state of the system parameter. Read more
§

fn borrow<'s>( world: &'s World, _state: &'s mut <&World as SystemParam>::State, ) -> <&World as SystemParam>::Param<'s>

This is used create an instance of the system parame, possibly borrowed from the intermediate parameter state.

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> 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> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FromWorld for T
where T: Default,

§

fn from_world(_world: &World) -> T

Creates Self using data from the given World.
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.

§

impl<T> RawClone for T
where T: Clone,

§

unsafe fn raw_clone(src: *const c_void, dst: *mut c_void)

Write the default value of the type to the pointer. Read more
§

fn raw_clone_cb() -> Unsafe<&'static (dyn Fn(*const c_void, *mut c_void) + Send + Sync)>

Get a callback suitable for [SchemaData].
§

impl<T> RawDefault for T
where T: Default,

§

unsafe fn raw_default(dst: *mut c_void)

Write the default value of the type to the pointer. Read more
§

fn raw_default_cb() -> Unsafe<&'static (dyn Fn(*mut c_void) + Send + Sync)>

Get a callback suitable for [SchemaData].
§

impl<T> RawDrop for T

§

unsafe fn raw_drop(ptr: *mut c_void)

Write the default value of the type to the pointer. Read more
§

fn raw_drop_cb() -> Unsafe<&'static (dyn Fn(*mut c_void) + Send + Sync)>

Get a callback suitable for [SchemaData].
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V