pub struct Entity { /* private fields */ }Expand description
The fundamental entity in the engine, combining a transform with a collection of behavior-defining components.
Implementations§
Source§impl Entity
Implements static factory and ID generation methods for Entity.
impl Entity
Implements static factory and ID generation methods for Entity.
Source§impl Entity
Implements pooled entity lifecycle methods for Entity.
impl Entity
Implements pooled entity lifecycle methods for Entity.
These pair ObjectPool with Entity so a spawn/despawn cycle reuses
the same allocation instead of dropping the entity and building a new one.
A recycled entity is reset to a clean state and given a fresh id, so a
stale reference held elsewhere can never alias a live entity.
Sourcepub fn create_pooled<N>(name: N, pool: &mut ObjectPool<Entity>) -> Self
pub fn create_pooled<N>(name: N, pool: &mut ObjectPool<Entity>) -> Self
Sourcepub fn create_pooled_at(
position: Vector2D,
pool: &mut ObjectPool<Entity>,
) -> Self
pub fn create_pooled_at( position: Vector2D, pool: &mut ObjectPool<Entity>, ) -> Self
Checks an entity out of the pool and places it at position.
The position is applied after the recycle reset, so a recycled entity never keeps the position it was last drawn at.
§Arguments
Vector2D- Where the entity should sit.&mut ObjectPool<Entity>- The pool the entity is checked out from.
§Returns
Entity- A ready-to-use entity at the requested position.
Sourcepub fn prewarm_pool(count: usize, pool: &mut ObjectPool<Entity>) -> usize
pub fn prewarm_pool(count: usize, pool: &mut ObjectPool<Entity>) -> usize
Builds count entities into the pool’s free list.
Only the shortfall is built, so prewarming an already-warm pool costs nothing and a spawn burst does not grow the pool mid-frame.
§Arguments
usize- How many free entities the pool should hold.&mut ObjectPool<Entity>- The pool to prewarm.
§Returns
usize- The number of entities that were built.
Sourcepub fn release_to_pool(entity: &mut Entity, pool: &mut ObjectPool<Entity>)
pub fn release_to_pool(entity: &mut Entity, pool: &mut ObjectPool<Entity>)
Resets an entity and hands it back to the pool.
Components, tags and transform are cleared before the entity is released so a recycled entity never inherits stale state. A fresh id is assigned on the next checkout, so the released entity’s id is not reused.
§Arguments
&mut Entity- The entity to recycle.&mut ObjectPool<Entity>- The pool to return it to.
Source§impl Entity
Implements lifecycle and component management methods for Entity.
impl Entity
Implements lifecycle and component management methods for Entity.
Sourcepub fn add_component(&mut self, component: ComponentRc)
pub fn add_component(&mut self, component: ComponentRc)
Adds a component to this entity and calls its on_start lifecycle method.
§Arguments
ComponentRc- The component to add.
Sourcepub fn remove_component_by_name<N>(&mut self, name: N) -> Option<ComponentRc>
pub fn remove_component_by_name<N>(&mut self, name: N) -> Option<ComponentRc>
Sourcepub fn get_component_by_name<N>(&self, name: N) -> Option<ComponentRc>
pub fn get_component_by_name<N>(&self, name: N) -> Option<ComponentRc>
Sourcepub fn render(&self, draw_list: &mut DrawList)
pub fn render(&self, draw_list: &mut DrawList)
Calls on_render on all active components, recording into the draw list.
§Arguments
&mut DrawList- The draw list to record commands into.
Source§impl Entity
impl Entity
pub fn get_id(&self) -> u64
pub fn get_mut_id(&mut self) -> &mut u64
pub fn set_id(&mut self, val: u64) -> &mut Self
pub fn get_name(&self) -> &String
pub fn get_mut_name(&mut self) -> &mut String
pub fn set_name(&mut self, val: String) -> &mut Self
pub fn get_transform(&self) -> Transform2D
pub fn set_transform(&mut self, val: Transform2D) -> &mut Self
pub fn get_active(&self) -> bool
pub fn get_mut_active(&mut self) -> &mut bool
pub fn set_active(&mut self, val: bool) -> &mut Self
pub fn get_components(&self) -> &Vec<ComponentRc> ⓘ
pub fn set_components(&mut self, val: Vec<ComponentRc>) -> &mut Self
Trait Implementations§
Source§impl Updatable for Entity
Forwards Entity::update through the Updatable trait so that collections
of heterogeneous updateable objects can be driven by the scheduler.
impl Updatable for Entity
Forwards Entity::update through the Updatable trait so that collections
of heterogeneous updateable objects can be driven by the scheduler.
The inherent Entity::update method is the canonical implementation;
this impl exists purely for trait dispatch. The inherent call resolves
first when both are in scope, so there is no recursion.