Skip to main content

World

Struct World 

Source
pub struct World {
    pub job_system: JobPool,
    /* private fields */
}

Fields§

§job_system: JobPool

Implementations§

Source§

impl World

Source

pub fn new(initial_capacity: u32) -> Self

Source

pub fn reserve_entities(&mut self, additional: u32)

Source

pub fn entity_capacity(&self) -> usize

Source

pub fn write_entities(&self, w: impl Write) -> Result<()>

Writes entity ids and their archetype hash

Source

pub fn num_entities(&self) -> usize

Source

pub fn is_id_valid(&self, id: EntityId) -> bool

Source

pub fn apply_commands(&mut self) -> Result<(), CommandError>

Source

pub fn insert_entity(&mut self) -> EntityId

Source

pub fn delete_entity(&mut self, id: EntityId) -> WorldResult<()>

Source

pub fn set_bundle<T: Bundle>( &mut self, entity_id: EntityId, bundle: T, ) -> WorldResult<()>

Source

pub fn set_component<T: Component>( &mut self, entity_id: EntityId, component: T, ) -> WorldResult<()>

Source

pub fn get_component<T: Component>(&self, entity_id: EntityId) -> Option<&T>

Source

pub fn get_component_mut<T: Component>( &self, entity_id: EntityId, ) -> Option<&mut T>

Source

pub fn remove_component<T: Component>( &mut self, entity_id: EntityId, ) -> WorldResult<()>

Source

pub fn insert_resource<T: Component>(&mut self, value: T)

Source

pub fn remove_resource<T: 'static>(&mut self) -> Option<Box<T>>

Source

pub fn get_resource<T: 'static>(&self) -> Option<&T>

Source

pub fn get_resource_mut<T: 'static>(&mut self) -> Option<&mut T>

Source

pub fn get_resource_or_default<T: Default + Component>(&mut self) -> &mut T

Source

pub fn get_or_insert_resource<T: Component>( &mut self, init: impl FnOnce() -> T, ) -> &mut T

Source

pub fn add_stage<'a>(&mut self, stage: impl Into<SystemStage<'a>>)

System stages are executed in the order they were added to the World

Source

pub fn run_stage<'a>( &mut self, stage: impl Into<SystemStage<'a>>, ) -> RunStageReturn<'a>

Run a single stage withouth adding it to the World

Return the command result and the stage that was ran, so the stage can be reused

Source

pub fn run_system<'a, S, P, R>(&mut self, system: S) -> Result<R, CommandError>
where S: IntoOnceSystem<'a, P, R>,

Run a system and apply any commands before returning

Returns the commands result

Source

pub fn run_view_system<'a, S, P, R>(&self, system: S) -> R
where S: IntoOnceSystem<'a, P, R>,

Run a system that only gets a read-only view of the world. All mutable access is forbidden, including Commands

Panics if the system does not conform to the requirements

Source

pub fn tick(&mut self)

Source

pub fn ensure_commands(&mut self) -> Commands<'_>

Constructs a new crate::commands::Commands instance with initialized buffers in this world

Source

pub fn get_entity_ty(&self, id: EntityId) -> Option<u128>

Return the “type” of the Entity. Type itself is an opaque hash.

This function is meant to be used to test successful saving/loading of entities

Source

pub fn get_entity_component_types(&self, id: EntityId) -> Option<Vec<TypeId>>

Source

pub fn get_entity_component_names( &self, id: EntityId, ) -> Option<Vec<&'static str>>

Source

pub fn checksum(&self) -> u64

Compute a checksum of the World

Note that only entities and their archetypes are considered, the contents of the components themselves are ignored

Source

pub fn merge_entities( &mut self, lhs: EntityId, rhs: EntityId, ) -> WorldResult<()>

Move all components from lhs to rhs, overrinding components rhs already has. Then delete the lhs entity

Source

pub fn insert_id(&mut self, id: EntityId) -> Result<(), InsertError>

Insert a pre-allocated entity id into the world.

Insert is an O(n) operation that walks a linked-list. Prefer [[insert_entity]]

Source

pub fn archetypes(&self) -> &BTreeMap<u128, Pin<Box<EntityTable>>>

Source

pub fn entity_table(&self, id: EntityId) -> Option<&EntityTable>

Source

pub fn vacuum(&mut self)

Remove empty archetypes

Source

pub fn clear_deleted(&mut self)

Source

pub fn iter_deleted(&self) -> impl Iterator<Item = EntityId>

Source

pub fn update_deleted(&mut self)

Apply pending deleted list additions

Trait Implementations§

Source§

impl Clone for World

Available on crate feature clone only.
Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Send for World

Source§

impl Sync for World

Auto Trait Implementations§

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§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

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

impl<T> Component for T
where T: 'static + Clone + ParallelComponent,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

Source§

impl<T> ParallelComponent for T
where T: Send + Sync,

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

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>,

Source§

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>,

Source§

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

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more