Struct bones_ecs::World

source ·
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§

source§

impl World

source

pub fn new() -> Self

Create a new World.

source

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.

source

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.

source

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.

source

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

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

source

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

Insert a resource.

source

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

Borrow a resource from the world.

Panics

Panics if the resource does not exist in the store.

source

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

Borrow a resource from the world.

Panics

Panics if the resource does not exist in the store.

source

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

Borrow a resource from the world, if it exists.

source

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

Borrow a resource from the world, if it exists.

Trait Implementations§

source§

impl Clone for World

source§

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

impl Debug for World

source§

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

Formats the value using the given formatter. Read more
source§

impl Default for World

source§

fn default() -> Self

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

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

fn get_state(_world: &World) -> Self::State

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

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

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

Auto Trait Implementations§

§

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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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> FromWorld for Twhere T: Default,

source§

fn from_world(_world: &World) -> T

Creates Self using data from the given World.
source§

impl<T, U> Into<U> for Twhere 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 Twhere 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 Twhere 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 Twhere 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 Twhere 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 Twhere 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 Twhere V: MultiLane<T>,

§

fn vzip(self) -> V