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: usizeNumber of active dense rows.
Implementations§
§impl<T, const CAP: usize> SimTable<T, CAP>where
T: Copy,
impl<T, const CAP: usize> SimTable<T, CAP>where
T: Copy,
pub const fn new(fill_default: T) -> SimTable<T, CAP>
pub const fn new(fill_default: T) -> SimTable<T, CAP>
Creates an empty SimTable initialized with fill_default.
pub fn insert(
&mut self,
entity: u32,
value: T,
current_tick: Tick,
) -> Result<usize, SimTableError>
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>
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_mut(&mut self, entity: u32, current_tick: Tick) -> Option<&mut T>
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)>
pub fn get_ticks(&self, entity: u32) -> Option<(Tick, Tick)>
Returns (added_tick, changed_tick) for entity.
pub fn active_entities(&self) -> &[u32]
pub fn active_entities(&self) -> &[u32]
Returns the dense slice of active (entity_id)s (&[u32]).
pub fn active_components(&self) -> &[T]
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]
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> ⓘ
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> ⓘ
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.