Skip to main content

Entity

Struct Entity 

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

Source

pub fn generate_id() -> u64

Generates the next unique entity ID using a global atomic counter.

§Returns
  • u64 - The next unique ID.
Source

pub fn create(name: &str) -> Entity

Creates a new entity with the given name and a default identity transform.

§Arguments
  • &str - The name of the entity.
§Returns
  • Entity - The newly created entity.
Source

pub fn create_at(position: Vector2D) -> Entity

Creates a new entity at the specified position with a default name.

§Arguments
  • Vector2D - The initial position.
§Returns
  • Entity - The newly created entity.
Source§

impl Entity

Implements lifecycle and component management methods for Entity.

Source

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

pub fn remove_component_by_name(&mut self, name: &str) -> Option<ComponentRc>

Removes the first component matching the given name.

§Arguments
  • &str - The component name to match.
§Returns
  • Option<ComponentRc> - The removed component, if found.
Source

pub fn get_component_by_name(&self, name: &str) -> Option<ComponentRc>

Returns the first component matching the given name.

§Arguments
  • &str - The component name to match.
§Returns
  • Option<ComponentRc> - The matching component, if found.
Source

pub fn update(&mut self, delta_time: f64)

Calls on_update on all active components.

§Arguments
  • f64 - The delta time in seconds.
Source

pub fn render(&self, context: &CanvasRenderingContext2d)

Calls on_render on all active components.

§Arguments
  • &CanvasRenderingContext2d - The canvas rendering context.
Source

pub fn destroy(&mut self)

Calls on_destroy on all components and clears the component list.

Source

pub fn add_tag(&mut self, tag: String)

Adds a tag string to this entity.

§Arguments
  • String - The tag to add.
Source

pub fn has_tag(&self, tag: &str) -> bool

Tests whether this entity has the given tag.

§Arguments
  • &str - The tag to check.
§Returns
  • bool - True if the tag is present.
Source§

impl Entity

Source

pub fn get_id(&self) -> u64

Source

pub fn get_mut_id(&mut self) -> &mut u64

Source

pub fn set_id(&mut self, val: u64) -> &mut Self

Source

pub fn get_name(&self) -> &String

Source

pub fn get_mut_name(&mut self) -> &mut String

Source

pub fn set_name(&mut self, val: String) -> &mut Self

Source

pub fn get_transform(&self) -> Transform2D

Source

pub fn set_transform(&mut self, val: Transform2D) -> &mut Self

Source

pub fn get_active(&self) -> bool

Source

pub fn get_mut_active(&mut self) -> &mut bool

Source

pub fn set_active(&mut self, val: bool) -> &mut Self

Source

pub fn get_components(&self) -> &Vec<ComponentRc>

Source

pub fn set_components(&mut self, val: Vec<ComponentRc>) -> &mut Self

Source

pub fn get_tags(&self) -> &Vec<String>

Source

pub fn set_tags(&mut self, val: Vec<String>) -> &mut Self

Source§

impl Entity

Source

pub fn new( id: u64, name: String, transform: Transform2D, active: bool, components: Vec<ComponentRc>, tags: Vec<String>, ) -> Self

Trait Implementations§

Source§

impl Clone for Entity

Source§

fn clone(&self) -> Entity

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

Auto Trait Implementations§

§

impl !RefUnwindSafe for Entity

§

impl !Send for Entity

§

impl !Sync for Entity

§

impl !UnwindSafe for Entity

§

impl Freeze for Entity

§

impl Unpin for Entity

§

impl UnsafeUnpin for Entity

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> 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> 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<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more