pub struct Entity {
pub id: u64,
pub name: String,
pub transform: Transform2D,
pub active: bool,
pub components: Vec<ComponentRc>,
pub tags: Vec<String>,
}Expand description
The fundamental entity in the engine, combining a transform with a collection of behavior-defining components.
Fields§
§id: u64The unique identifier of this entity.
get_id is public because tests/entity/fn.rs, tests/pool/fn.rs reads this field from
outside this crate. get_mut / set stay crate-internal.
name: StringThe human-readable name of this entity.
get_name is public because tests/entity/fn.rs, tests/pool/fn.rs, tests/remaining/fn.rs reads this field from
outside this crate. get_mut / set stay crate-internal.
transform: Transform2DThe world-space transform (position, rotation, scale).
get_transform is public because tests/entity/fn.rs, tests/pool/fn.rs reads this field from
outside this crate. get_mut / set stay crate-internal.
active: boolWhether this entity is active and should receive updates.
get_active / set_active are public because tests/entity/fn.rs, tests/pool/fn.rs reads this field from
outside this crate. get_mut / set stay crate-internal.
components: Vec<ComponentRc>The list of components attached to this entity.
get_components is public because tests/entity/fn.rs, tests/pool/fn.rs reads this field from
outside this crate. get_mut / set stay crate-internal.
Optional tags for grouping and querying entities.
get_tags is public because tests/entity/fn.rs, tests/pool/fn.rs reads this field from
outside this crate. get_mut / set stay crate-internal.
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_name(&self) -> &String
pub fn get_transform(&self) -> Transform2D
pub fn get_active(&self) -> bool
pub fn set_active(&mut self, val: bool) -> &mut Self
pub fn get_components(&self) -> &Vec<ComponentRc> ⓘ
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.