Skip to main content

GameWorld

Struct GameWorld 

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

High-performance generational ECS arena managing game entities with O(1) spawn, despawn, and cache-friendly iteration.

Implementations§

Source§

impl GameWorld

Entity spawning, recycling, querying, and lifetime ticking for GameWorld.

Source

pub fn with_capacity(capacity: usize) -> Self

Allocates a GameWorld pre-sized for capacity entities with zero initial allocations during play.

§Arguments
  • usize - Initial entity slot capacity.
§Returns
  • Self - Pre-allocated game world.
Source

pub fn spawn(&mut self, tag: EntityTag, position: Point) -> EntityId

Spawns a new entity at position with tag and returns its generational EntityId.

§Arguments
  • &Self - Mutable game world.
  • EntityTag - Semantic gameplay tag.
  • Point - Initial world-space position.
§Returns
  • EntityId - Generation-checked entity handle.
Source

pub fn despawn(&mut self, id: EntityId) -> bool

Despawns id in O(1), invalidating stale handles and recycling its arena slot.

§Arguments
  • &Self - Mutable game world.
  • EntityId - Target entity handle.
§Returns
  • bool - true if the entity was alive and removed.
Source

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

Returns true when id refers to a currently alive entity.

§Arguments
  • &Self - Game world reference.
  • EntityId - Entity handle to validate.
§Returns
  • bool - Live status.
Source

pub fn get_entity(&self, id: EntityId) -> Option<&EntityRecord>

Returns an immutable reference to the live entity matching id.

§Arguments
  • &Self - Game world reference.
  • EntityId - Entity handle.
§Returns
  • Option<&EntityRecord> - Live entity reference.
Source

pub fn get_entity_mut(&mut self, id: EntityId) -> Option<&mut EntityRecord>

Returns a mutable reference to the live entity matching id.

§Arguments
  • &Self - Mutable game world.
  • EntityId - Entity handle.
§Returns
  • Option<&mut EntityRecord> - Mutable live entity reference.
Source

pub fn tick_lifetimes(&mut self, dt_secs: f32) -> usize

Decrements ttl_secs across all time-limited entities and despawns expired ones.

§Arguments
  • &Self - Mutable game world.
  • f32 - Elapsed timestep in seconds.
§Returns
  • usize - Number of entities expired and despawned.
Source

pub fn clear(&mut self)

Clears all entities while retaining arena backing allocations.

§Arguments
  • &Self - Mutable game world.
Source

pub fn count_by_tag(&self, tag: EntityTag) -> usize

Counts all live entities matching tag.

§Arguments
  • &Self - Game world reference.
  • EntityTag - Target gameplay tag.
§Returns
  • usize - Live entity count matching tag.
Source§

impl GameWorld

Source

pub fn get_entities(&self) -> &Vec<EntityRecord>

Source

pub fn get_mut_entities(&mut self) -> &mut Vec<EntityRecord>

Source

pub fn set_entities(&mut self, val: Vec<EntityRecord>) -> &mut Self

Source

pub fn get_live_count(&self) -> usize

Source

pub fn get_mut_live_count(&mut self) -> &mut usize

Source

pub fn set_live_count(&mut self, val: usize) -> &mut Self

Source

pub fn get_tick(&self) -> u64

Source

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

Source

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

Trait Implementations§

Source§

impl Clone for GameWorld

Source§

fn clone(&self) -> Self

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

impl Debug for GameWorld

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for GameWorld

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.