Struct World

Source
pub struct World { /* private fields */ }
Expand description

The World is the entry point to an ecs

Implementations§

Source§

impl World

Source

pub fn new() -> Self

Source

pub fn kill(&mut self, ent_id: EntityId)

Kills an entity

This means the EntityId will be reused for other entities. This also implies that world.is_alive(the_killed_enity_id) will not be accurate. If you want to keep an id killed, use world.kill_and_keep(id). You should still free those ids using world.free_id later so that the memory can be reused.

Source

pub fn kill_and_keep(&mut self, ent_id: EntityId)

Kills an entity without telling the ecs to reuse its id

This means that world.is_alive can be used accurately.

You should use world.free_id(the_killed_entity_id) later to reuse the memory used by the killed entity (64 bits per entity).

Source

pub fn free_id(&mut self, ent_id: EntityId)

Frees an entity id, meaning that the world.is_alive method will no longer be accurate for this entity.

Memory used to store this entity id (64 bits) will be reused.

Source

pub fn is_alive(&mut self, ent_id: EntityId) -> bool

Check whether an entity is alive. This can only be used accurately when world.kill_and_keep is used instead of world.kill.

Source

pub fn entity_count(&self) -> usize

Returns the amount of entities that are alive

Source

pub fn get_component<T: Component + 'static>(&self, entity: EntityId) -> &T

Returns the component of type T for entity with id entity.

§Panics

if the component does not exist for the given entity

Source

pub fn get_component_mut<T: Component + 'static>( &mut self, entity: EntityId, ) -> &mut T

Returns a mutable referencce to the component of type T for entity with id entity

§Panics

if the component does not exist for the given entity

Source

pub fn set_component<T: Component + 'static>( &mut self, entity: EntityId, comp: T, )

Set an entity’s component.

§Panics

if the component does not exist for the given entity

Source

pub fn has_component<C: Component>(&self, entity: EntityId) -> bool

Check whether an entity contains the given component

Source

pub fn has_flag<F: Flag>(&self, entity: EntityId, flag: F) -> bool

Returns whether the entity has the specified flag set.

Source

pub fn set_flag<F: Flag>(&mut self, entity: EntityId, flag: F)

Sets a flag for an entity

Always use the same enum for flags. Don’t mix flag enums, because the id of the enum variant is used to determine whether the entity has a specific flag.

Source

pub fn unset_flag<F: Flag>(&mut self, entity: EntityId, flag: F)

Remove a flag from an entity

Source§

impl World

Source

pub fn query_ids<'a>(&'a self) -> impl Iterator<Item = EntityId> + 'a

Query all entity ids

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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