pub struct SparseSet<T> { /* private fields */ }
Expand description
Default component storage.
Implementations
sourceimpl<T> SparseSet<T>
impl<T> SparseSet<T>
sourcepub fn index_of(&self, entity: EntityId) -> Option<usize>
pub fn index_of(&self, entity: EntityId) -> Option<usize>
Returns the index of entity
’s component in the dense
and data
vectors.
This index is only valid for this storage and until a modification happens.
sourcepub unsafe fn index_of_unchecked(&self, entity: EntityId) -> usize
pub unsafe fn index_of_unchecked(&self, entity: EntityId) -> usize
Returns the index of entity
’s component in the dense
and data
vectors.
This index is only valid for this storage and until a modification happens.
Safety
entity
has to own a component of this type.
The index is only valid until a modification occurs in the storage.
sourceimpl<T> SparseSet<T>
impl<T> SparseSet<T>
sourcepub fn is_inserted(&self, entity: EntityId) -> bool
pub fn is_inserted(&self, entity: EntityId) -> bool
Returns true
if entity
’s component was inserted since the last clear_inserted
or clear_all_inserted
call.
Returns false
if entity
does not have a component in this storage.
sourcepub fn is_modified(&self, entity: EntityId) -> bool
pub fn is_modified(&self, entity: EntityId) -> bool
Returns true
if entity
’s component was modified since the last clear_modified
or clear_all_modified
call.
Returns false
if entity
does not have a component in this storage.
sourcepub fn is_inserted_or_modified(&self, entity: EntityId) -> bool
pub fn is_inserted_or_modified(&self, entity: EntityId) -> bool
Returns true
if entity
’s component was inserted or modified since the last clear call.
Returns false
if entity
does not have a component in this storage.
sourcepub fn deleted(&self) -> &[(EntityId, T)]
pub fn deleted(&self) -> &[(EntityId, T)]
Returns the deleted components of a storage tracking deletion.
Panics
- Storage does not track deletion. Start tracking by calling
track_deletion
ortrack_all
.
sourcepub fn removed(&self) -> &[EntityId]
pub fn removed(&self) -> &[EntityId]
Returns the ids of removed components of a storage tracking removal.
Panics
- Storage does not track removal. Start tracking by calling
track_removal
ortrack_all
.
sourcepub fn removed_or_deleted(&self) -> impl Iterator<Item = EntityId>
pub fn removed_or_deleted(&self) -> impl Iterator<Item = EntityId>
Returns the ids of removed or deleted components of a storage tracking removal and/or deletion.
Panics
- Storage does not track removal nor deletion. Start tracking by calling
track_removal
,track_deletion
ortrack_all
.
sourcepub fn take_deleted(&mut self) -> Vec<(EntityId, T), Global>
pub fn take_deleted(&mut self) -> Vec<(EntityId, T), Global>
Takes ownership of the deleted components of a storage tracking deletion.
Panics
- Storage does not track deletion. Start tracking by calling
track_deletion
ortrack_all
.
sourcepub fn take_removed(&mut self) -> Vec<EntityId, Global>
pub fn take_removed(&mut self) -> Vec<EntityId, Global>
Takes ownership of the ids of removed components of a storage tracking removal.
Panics
- Storage does not track removal. Start tracking by calling
track_removal
ortrack_all
.
sourcepub fn take_removed_and_deleted(
&mut self
) -> (Vec<EntityId, Global>, Vec<(EntityId, T), Global>)
pub fn take_removed_and_deleted(
&mut self
) -> (Vec<EntityId, Global>, Vec<(EntityId, T), Global>)
Takes ownership of the removed and deleted components of a storage tracking removal and/or deletion.
Panics
- Storage does not track removal nor deletion. Start tracking by calling
track_removal
,track_deletion
ortrack_all
.
sourcepub fn clear_inserted(&mut self, entity: EntityId)
pub fn clear_inserted(&mut self, entity: EntityId)
Removes the inserted flag on entity
’s component.
Panics
- Storage does not track insertion. Start tracking by calling
track_insertion
ortrack_all
.
sourcepub fn clear_all_inserted(&mut self)
pub fn clear_all_inserted(&mut self)
Removes the inserted flag on all components of this storage.
Panics
- Storage does not track insertion. Start tracking by calling
track_insertion
ortrack_all
.
sourcepub fn clear_modified(&mut self, entity: EntityId)
pub fn clear_modified(&mut self, entity: EntityId)
Removes the modified flag on entity
’s component.
Panics
- Storage does not track modification. Start tracking by calling
track_modification
ortrack_all
.
sourcepub fn clear_all_modified(&mut self)
pub fn clear_all_modified(&mut self)
Removes the modified flag on all components of this storage.
Panics
- Storage does not track modification. Start tracking by calling
track_modification
ortrack_all
.
sourcepub fn clear_inserted_and_modified(&mut self, entity: EntityId)
pub fn clear_inserted_and_modified(&mut self, entity: EntityId)
Removes the inserted and modified flags on entity
’s component.
Panics
- Storage does not track insertion not modification. Start tracking by calling
track_insertion
,track_modification
ortrack_all
.
sourcepub fn clear_all_inserted_and_modified(&mut self)
pub fn clear_all_inserted_and_modified(&mut self)
Removes the inserted and modified flags on all components of this storage.
Panics
- Storage does not track insertion not modification. Start tracking by calling
track_insertion
,track_modification
ortrack_all
.
sourcepub fn track_insertion(&mut self) -> &mut SparseSet<T>
pub fn track_insertion(&mut self) -> &mut SparseSet<T>
Flags components when they are inserted.
To check the flag use is_inserted
, is_inserted_or_modified
or iterate over the storage after calling inserted
.
To clear the flag use clear_inserted
or clear_all_inserted
.
sourcepub fn track_modification(&mut self) -> &mut SparseSet<T>
pub fn track_modification(&mut self) -> &mut SparseSet<T>
Flags components when they are modified. Will not flag components already flagged inserted.
To check the flag use is_modified
, is_inserted_or_modified
or iterate over the storage after calling modified
.
To clear the flag use clear_modified
or clear_all_modified
.
sourcepub fn track_deletion(&mut self) -> &mut SparseSet<T>
pub fn track_deletion(&mut self) -> &mut SparseSet<T>
Stores components and their EntityId
when they are deleted.
You can access them with deleted
or removed_or_deleted
.
You can clear them and get back a Vec
with take_deleted
or take_removed_and_deleted
.
sourcepub fn track_removal(&mut self) -> &mut SparseSet<T>
pub fn track_removal(&mut self) -> &mut SparseSet<T>
Stores EntityId
of deleted components.
You can access them with removed
or removed_or_deleted
.
You can clear them and get back a Vec
with take_removed
or take_removed_and_deleted
.
sourcepub fn track_all(&mut self)
pub fn track_all(&mut self)
Flags component insertion, modification, deletion and removal.
Same as calling track_insertion
, track_modification
, track_deletion
and track_removal
.
sourcepub fn is_tracking_insertion(&self) -> bool
pub fn is_tracking_insertion(&self) -> bool
Returns true
if the storage tracks insertion.
sourcepub fn is_tracking_modification(&self) -> bool
pub fn is_tracking_modification(&self) -> bool
Returns true
if the storage tracks modification.
sourcepub fn is_tracking_deletion(&self) -> bool
pub fn is_tracking_deletion(&self) -> bool
Returns true
if the storage tracks deletion.
sourcepub fn is_tracking_removal(&self) -> bool
pub fn is_tracking_removal(&self) -> bool
Returns true
if the storage tracks removal.
sourcepub fn is_tracking_any(&self) -> bool
pub fn is_tracking_any(&self) -> bool
Returns true
if the storage tracks insertion, modification, deletion or removal.
sourceimpl<T> SparseSet<T>
impl<T> SparseSet<T>
sourcepub fn reserve(&mut self, additional: usize)
pub fn reserve(&mut self, additional: usize)
Reserves memory for at least additional
components. Adding components can still allocate though.
sourcepub fn apply<R, F>(&mut self, a: EntityId, b: EntityId, f: F) -> R where
F: FnOnce(&mut T, &T) -> R,
pub fn apply<R, F>(&mut self, a: EntityId, b: EntityId, f: F) -> R where
F: FnOnce(&mut T, &T) -> R,
Applies the given function f
to the entities a
and b
.
The two entities shouldn’t point to the same component.
Panics
- MissingComponent - if one of the entity doesn’t have any component in the storage.
- IdenticalIds - if the two entities point to the same component.
sourcepub fn apply_mut<R, F>(&mut self, a: EntityId, b: EntityId, f: F) -> R where
F: FnOnce(&mut T, &mut T) -> R,
pub fn apply_mut<R, F>(&mut self, a: EntityId, b: EntityId, f: F) -> R where
F: FnOnce(&mut T, &mut T) -> R,
Applies the given function f
to the entities a
and b
.
The two entities shouldn’t point to the same component.
Panics
- MissingComponent - if one of the entity doesn’t have any component in the storage.
- IdenticalIds - if the two entities point to the same component.
sourcepub fn drain(&mut self) -> SparseSetDrain<'_, T>ⓘNotable traits for SparseSetDrain<'a, T>impl<'a, T> Iterator for SparseSetDrain<'a, T> type Item = T;
pub fn drain(&mut self) -> SparseSetDrain<'_, T>ⓘNotable traits for SparseSetDrain<'a, T>impl<'a, T> Iterator for SparseSetDrain<'a, T> type Item = T;
Creates a draining iterator that empties the storage and yields the removed items.
sourceimpl<T> SparseSet<T> where
T: Ord,
impl<T> SparseSet<T> where
T: Ord,
sourcepub fn sort_unstable(&mut self)
pub fn sort_unstable(&mut self)
Sorts the SparseSet
, but may not preserve the order of equal elements.
Trait Implementations
sourceimpl<T> Storage for SparseSet<T> where
T: 'static,
impl<T> Storage for SparseSet<T> where
T: 'static,
sourcefn memory_usage(&self) -> Option<StorageMemoryUsage>
fn memory_usage(&self) -> Option<StorageMemoryUsage>
Returns how much memory this storage uses.
sourcefn sparse_array(&self) -> Option<&SparseArray<[EntityId; 32]>>
fn sparse_array(&self) -> Option<&SparseArray<[EntityId; 32]>>
Returns a SparseSet
’s internal SparseArray
. Read more
Auto Trait Implementations
impl<T> RefUnwindSafe for SparseSet<T> where
T: RefUnwindSafe,
impl<T> Send for SparseSet<T> where
T: Send,
impl<T> Sync for SparseSet<T> where
T: Sync,
impl<T> Unpin for SparseSet<T> where
T: Unpin,
impl<T> UnwindSafe for SparseSet<T> where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T> Pointable for T
impl<T> Pointable for T
impl<SS, SP> SupersetOf<SS> for SP where
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SP where
SS: SubsetOf<SP>,
fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct self
from the equivalent element of its
superset. Read more
fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if self
is actually part of its subset T
(and can be converted to it).
fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as self.to_subset
but without any property checks. Always succeeds.
fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts self
to the equivalent element of its superset.