pub struct World { /* private fields */ }
Expand description
The World
is the entry point to an ecs
Implementations§
Source§impl World
impl World
pub fn new() -> Self
Sourcepub fn kill(&mut self, ent_id: EntityId)
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.
Sourcepub fn kill_and_keep(&mut self, ent_id: EntityId)
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).
Sourcepub fn free_id(&mut self, ent_id: EntityId)
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.
Sourcepub fn is_alive(&mut self, ent_id: EntityId) -> bool
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
.
Sourcepub fn entity_count(&self) -> usize
pub fn entity_count(&self) -> usize
Returns the amount of entities that are alive
Sourcepub fn get_component<T: Component + 'static>(&self, entity: EntityId) -> &T
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
Sourcepub fn get_component_mut<T: Component + 'static>(
&mut self,
entity: EntityId,
) -> &mut T
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
Sourcepub fn set_component<T: Component + 'static>(
&mut self,
entity: EntityId,
comp: T,
)
pub fn set_component<T: Component + 'static>( &mut self, entity: EntityId, comp: T, )
Sourcepub fn has_component<C: Component>(&self, entity: EntityId) -> bool
pub fn has_component<C: Component>(&self, entity: EntityId) -> bool
Check whether an entity contains the given component
Sourcepub fn has_flag<F: Flag>(&self, entity: EntityId, flag: F) -> bool
pub fn has_flag<F: Flag>(&self, entity: EntityId, flag: F) -> bool
Returns whether the entity has the specified flag set.
Sourcepub fn set_flag<F: Flag>(&mut self, entity: EntityId, flag: F)
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.
Sourcepub fn unset_flag<F: Flag>(&mut self, entity: EntityId, flag: F)
pub fn unset_flag<F: Flag>(&mut self, entity: EntityId, flag: F)
Remove a flag from an entity