Skip to main content

SimTable

Struct SimTable 

pub struct SimTable<T, const CAP: usize = 256>
where T: Copy,
{ pub entities: [u32; CAP], pub sparse: [u32; CAP], pub components: [T; CAP], pub added_ticks: [Tick; CAP], pub changed_ticks: [Tick; CAP], pub len: usize, }
Expand description

Fixed-capacity SOA component table with dense storage and per-row change-detection ticks.

Fields§

§entities: [u32; CAP]

Dense row index -> entity ID (0..len valid).

§sparse: [u32; CAP]

Entity ID -> dense row index (INVALID_ROW when absent).

§components: [T; CAP]

Dense contiguous component storage (0..len valid).

§added_ticks: [Tick; CAP]

Per-dense-row tick when the component was inserted.

§changed_ticks: [Tick; CAP]

Per-dense-row tick when the component was last mutably accessed.

§len: usize

Number of active dense rows.

Implementations§

§

impl<T, const CAP: usize> SimTable<T, CAP>
where T: Copy,

pub const fn new(fill_default: T) -> SimTable<T, CAP>

Creates an empty SimTable initialized with fill_default.

pub const fn len(&self) -> usize

Number of active entities stored in this table.

pub const fn is_empty(&self) -> bool

Returns true if no entities are stored in this table.

pub const fn capacity(&self) -> usize

Maximum capacity of the table.

pub const fn contains(&self, entity: u32) -> bool

Returns true if entity is stored in this table.

pub fn insert( &mut self, entity: u32, value: T, current_tick: Tick, ) -> Result<usize, SimTableError>

Inserts or overwrites the component for entity at current_tick in $O(1)$ time.

If entity was not present, both added_tick and changed_tick are set to current_tick. If entity was already present, changed_tick is updated to current_tick.

pub fn remove(&mut self, entity: u32) -> Option<T>

Removes entity from the table in $O(1)$ time via dense swap-remove.

pub fn get(&self, entity: u32) -> Option<&T>

Shared $O(1)$ component lookup by entity ID.

pub fn get_mut(&mut self, entity: u32, current_tick: Tick) -> Option<&mut T>

Mutable $O(1)$ component lookup by entity ID; stamps changed_ticks[row] = current_tick.

pub fn get_ticks(&self, entity: u32) -> Option<(Tick, Tick)>

Returns (added_tick, changed_tick) for entity.

pub fn active_entities(&self) -> &[u32]

Returns the dense slice of active (entity_id)s (&[u32]).

pub fn active_components(&self) -> &[T]

Returns the dense slice of active components (&[T]).

pub fn active_components_mut(&mut self, current_tick: Tick) -> &mut [T]

Returns the mutable dense slice of active components (&mut [T]) and stamps all active rows with current_tick.

pub fn iter_changed( &self, last_run: Tick, this_run: Tick, ) -> Changed<'_, T, CAP> ⓘ

Zero-heap iterator over (entity_id, &T) for components changed after last_run.

pub fn iter_added(&self, last_run: Tick, this_run: Tick) -> Added<'_, T, CAP> ⓘ

Zero-heap iterator over (entity_id, &T) for components added after last_run.

Trait Implementations§

§

impl<T, const CAP: usize> Clone for SimTable<T, CAP>
where T: Clone + Copy,

§

fn clone(&self) -> SimTable<T, CAP>

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
§

impl<T, const CAP: usize> Debug for SimTable<T, CAP>
where T: Debug + Copy,

§

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

Formats the value using the given formatter. Read more
§

impl<T, const CAP: usize> Default for SimTable<T, CAP>
where T: Copy + Default,

§

fn default() -> SimTable<T, CAP>

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

Auto Trait Implementations§

§

impl<T, const CAP: usize> Freeze for SimTable<T, CAP>
where T: Freeze,

§

impl<T, const CAP: usize> RefUnwindSafe for SimTable<T, CAP>
where T: RefUnwindSafe,

§

impl<T, const CAP: usize> Send for SimTable<T, CAP>
where T: Send,

§

impl<T, const CAP: usize> Sync for SimTable<T, CAP>
where T: Sync,

§

impl<T, const CAP: usize> Unpin for SimTable<T, CAP>
where T: Unpin,

§

impl<T, const CAP: usize> UnsafeUnpin for SimTable<T, CAP>
where T: UnsafeUnpin,

§

impl<T, const CAP: usize> UnwindSafe for SimTable<T, CAP>
where T: UnwindSafe,

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

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.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSendSync for T
where T: WasmNotSend + WasmNotSync,

§

impl<T> WasmNotSync for T
where T: Sync,