Struct oxygengine_core::ecs::Storage [−][src]
pub struct Storage<'e, T, D> { /* fields omitted */ }
A wrapper around the masked storage and the generations vector.
Can be used for safe lookup of components, insertions and removes.
This is what World::read/write
fetches for the user.
Implementations
impl<'e, T, D> Storage<'e, T, D> where
D: DerefMut<Target = MaskedStorage<T>>,
T: Component,
[src]
impl<'e, T, D> Storage<'e, T, D> where
D: DerefMut<Target = MaskedStorage<T>>,
T: Component,
[src]pub fn entry<'a>(
&'a mut self,
e: Entity
) -> Result<StorageEntry<'a, 'e, T, D>, WrongGeneration> where
'e: 'a,
[src]
&'a mut self,
e: Entity
) -> Result<StorageEntry<'a, 'e, T, D>, WrongGeneration> where
'e: 'a,
Returns an entry to the component associated to the entity.
Behaves somewhat similarly to std::collections::HashMap
’s entry api.
Example
if let Ok(entry) = storage.entry(entity) { entry.or_insert(Comp { field: 55 }); }
pub fn entries(&'a mut self) -> Entries<'a, 'e, T, D>
[src]
Returns a Join
-able structure that yields all indices, returning
Entry
for all elements
WARNING: Do not have a join of only Entries
s. Otherwise the join will
iterate over every single index of the bitset. If you want a join with
all Entries
s, add an EntitiesRes
to the join as well to bound the
join to all entities that are alive.
Example
for (mut counter, _) in (counters.entries(), &marker).join() { let counter = counter.or_insert_with(Default::default); counter.increase(); if counter.reached_limit() { counter.reset(); // Do something } }
impl<'st, T, D> Storage<'st, T, D> where
D: Deref<Target = MaskedStorage<T>>,
T: Component,
[src]
impl<'st, T, D> Storage<'st, T, D> where
D: Deref<Target = MaskedStorage<T>>,
T: Component,
[src]pub fn restrict(
&'rf self
) -> RestrictedStorage<'rf, 'st, T, &'rf <T as Component>::Storage, &'rf BitSet, ImmutableParallelRestriction>
[src]
&'rf self
) -> RestrictedStorage<'rf, 'st, T, &'rf <T as Component>::Storage, &'rf BitSet, ImmutableParallelRestriction>
Builds an immutable RestrictedStorage
out of a Storage
. Allows
deferred unchecked access to the entity’s component.
This is returned as a ParallelRestriction
version since you can only
get immutable components with this which is safe for parallel by
default.
impl<'st, T, D> Storage<'st, T, D> where
D: DerefMut<Target = MaskedStorage<T>>,
T: Component,
[src]
impl<'st, T, D> Storage<'st, T, D> where
D: DerefMut<Target = MaskedStorage<T>>,
T: Component,
[src]pub fn restrict_mut(
&'rf mut self
) -> RestrictedStorage<'rf, 'st, T, &'rf mut <T as Component>::Storage, &'rf BitSet, SequentialRestriction>
[src]
&'rf mut self
) -> RestrictedStorage<'rf, 'st, T, &'rf mut <T as Component>::Storage, &'rf BitSet, SequentialRestriction>
Builds a mutable RestrictedStorage
out of a Storage
. Allows
restricted access to the inner components without allowing
invalidating the bitset for iteration in Join
.
pub fn par_restrict_mut(
&'rf mut self
) -> RestrictedStorage<'rf, 'st, T, &'rf mut <T as Component>::Storage, &'rf BitSet, MutableParallelRestriction>
[src]
&'rf mut self
) -> RestrictedStorage<'rf, 'st, T, &'rf mut <T as Component>::Storage, &'rf BitSet, MutableParallelRestriction>
Builds a mutable, parallel RestrictedStorage
,
does not allow mutably getting other components
aside from the current iteration.
impl<'e, T, D> Storage<'e, T, D> where
D: Deref<Target = MaskedStorage<T>>,
T: Component,
<T as Component>::Storage: Tracked,
[src]
impl<'e, T, D> Storage<'e, T, D> where
D: Deref<Target = MaskedStorage<T>>,
T: Component,
<T as Component>::Storage: Tracked,
[src]pub fn channel(&self) -> &EventChannel<ComponentEvent>
[src]
Returns the event channel tracking modified components.
impl<'e, T, D> Storage<'e, T, D> where
D: DerefMut<Target = MaskedStorage<T>>,
T: Component,
<T as Component>::Storage: Tracked,
[src]
impl<'e, T, D> Storage<'e, T, D> where
D: DerefMut<Target = MaskedStorage<T>>,
T: Component,
<T as Component>::Storage: Tracked,
[src]pub fn channel_mut(&mut self) -> &mut EventChannel<ComponentEvent>
[src]
Returns the event channel for insertions/removals/modifications of this storage’s components.
pub fn register_reader(&mut self) -> ReaderId<ComponentEvent>
[src]
Starts tracking component events. Note that this reader id should be used every frame, otherwise events will pile up and memory use by the event channel will grow waiting for this reader.
pub fn flag(&mut self, event: ComponentEvent)
[src]
Flags an index with a ComponentEvent
.
impl<'e, T, D> Storage<'e, T, D>
[src]
impl<'e, T, D> Storage<'e, T, D>
[src]pub fn new(entities: Fetch<'e, EntitiesRes>, data: D) -> Storage<'e, T, D>
[src]
Creates a new Storage
from a fetched allocator and a immutable or
mutable MaskedStorage
, named data
.
impl<'e, T, D> Storage<'e, T, D> where
D: Deref<Target = MaskedStorage<T>>,
T: Component,
[src]
impl<'e, T, D> Storage<'e, T, D> where
D: Deref<Target = MaskedStorage<T>>,
T: Component,
[src]pub fn unprotected_storage(&self) -> &<T as Component>::Storage
[src]
Gets the wrapped storage.
pub fn fetched_entities(&self) -> &EntitiesRes
[src]
Returns the EntitiesRes
resource fetched by this storage.
This does not have anything to do with the components inside.
You only want to use this when implementing additional methods
for Storage
via an extension trait.
pub fn get(&self, e: Entity) -> Option<&T>
[src]
Tries to read the data associated with an Entity
.
pub fn count(&self) -> usize
[src]
Computes the number of elements this Storage
contains by counting the
bits in the bit set. This operation will never be performed in
constant time.
pub fn is_empty(&self) -> bool
[src]
Checks whether this Storage
is empty. This operation is very cheap.
pub fn contains(&self, e: Entity) -> bool
[src]
Returns true if the storage has a component for this entity, and that entity is alive.
pub fn mask(&self) -> &BitSet
[src]
Returns a reference to the bitset of this storage which allows filtering by the component type without actually getting the component.
impl<'e, T, D> Storage<'e, T, D> where
D: Deref<Target = MaskedStorage<T>>,
T: Component,
<T as Component>::Storage: SliceAccess<T>,
[src]
impl<'e, T, D> Storage<'e, T, D> where
D: Deref<Target = MaskedStorage<T>>,
T: Component,
<T as Component>::Storage: SliceAccess<T>,
[src]impl<'e, T, D> Storage<'e, T, D> where
D: DerefMut<Target = MaskedStorage<T>>,
T: Component,
<T as Component>::Storage: SliceAccess<T>,
[src]
impl<'e, T, D> Storage<'e, T, D> where
D: DerefMut<Target = MaskedStorage<T>>,
T: Component,
<T as Component>::Storage: SliceAccess<T>,
[src]impl<'e, T, D> Storage<'e, T, D> where
D: DerefMut<Target = MaskedStorage<T>>,
T: Component,
[src]
impl<'e, T, D> Storage<'e, T, D> where
D: DerefMut<Target = MaskedStorage<T>>,
T: Component,
[src]pub unsafe fn unprotected_storage_mut(
&mut self
) -> &mut <T as Component>::Storage
[src]
&mut self
) -> &mut <T as Component>::Storage
Gets mutable access to the wrapped storage.
Safety
This is unsafe because modifying the wrapped storage without also updating the mask bitset accordingly can result in illegal memory access.
pub fn get_mut(&mut self, e: Entity) -> Option<&mut T>
[src]
Tries to mutate the data associated with an Entity
.
pub fn insert(&mut self, e: Entity, v: T) -> Result<Option<T>, Error>
[src]
Inserts new data for a given Entity
.
Returns the result of the operation as a InsertResult<T>
If a component already existed for the given Entity
, then it will
be overwritten with the new component. If it did overwrite, then the
result will contain Some(T)
where T
is the previous component.
pub fn remove(&mut self, e: Entity) -> Option<T>
[src]
Removes the data associated with an Entity
.
pub fn clear(&mut self)
[src]
Clears the contents of the storage.
pub fn drain(&mut self) -> Drain<'_, T>
[src]
Creates a draining storage wrapper which can be .join
ed
to get a draining iterator.
Trait Implementations
impl<'a, T, D> DistinctStorage for Storage<'a, T, D> where
T: Component,
<T as Component>::Storage: DistinctStorage,
[src]
impl<'a, T, D> DistinctStorage for Storage<'a, T, D> where
T: Component,
<T as Component>::Storage: DistinctStorage,
[src]impl<'a, 'b, T> GenericReadStorage for &'b Storage<'a, T, Fetch<'a, MaskedStorage<T>>> where
'a: 'b,
T: Component,
[src]
impl<'a, 'b, T> GenericReadStorage for &'b Storage<'a, T, Fetch<'a, MaskedStorage<T>>> where
'a: 'b,
T: Component,
[src]impl<'a, T> GenericReadStorage for Storage<'a, T, Fetch<'a, MaskedStorage<T>>> where
T: Component,
[src]
impl<'a, T> GenericReadStorage for Storage<'a, T, Fetch<'a, MaskedStorage<T>>> where
T: Component,
[src]impl<'a, 'b, T> GenericReadStorage for &'b Storage<'a, T, FetchMut<'a, MaskedStorage<T>>> where
'a: 'b,
T: Component,
[src]
impl<'a, 'b, T> GenericReadStorage for &'b Storage<'a, T, FetchMut<'a, MaskedStorage<T>>> where
'a: 'b,
T: Component,
[src]impl<'a, T> GenericReadStorage for Storage<'a, T, FetchMut<'a, MaskedStorage<T>>> where
T: Component,
[src]
impl<'a, T> GenericReadStorage for Storage<'a, T, FetchMut<'a, MaskedStorage<T>>> where
T: Component,
[src]impl<'a, 'b, T> GenericWriteStorage for &'b mut Storage<'a, T, FetchMut<'a, MaskedStorage<T>>> where
'a: 'b,
T: Component,
[src]
impl<'a, 'b, T> GenericWriteStorage for &'b mut Storage<'a, T, FetchMut<'a, MaskedStorage<T>>> where
'a: 'b,
T: Component,
[src]type Component = T
The component type of the storage
pub fn get_mut(
&mut self,
entity: Entity
) -> Option<&mut <&'b mut Storage<'a, T, FetchMut<'a, MaskedStorage<T>>> as GenericWriteStorage>::Component>
[src]
&mut self,
entity: Entity
) -> Option<&mut <&'b mut Storage<'a, T, FetchMut<'a, MaskedStorage<T>>> as GenericWriteStorage>::Component>
pub fn get_mut_or_default(
&mut self,
entity: Entity
) -> Option<&mut <&'b mut Storage<'a, T, FetchMut<'a, MaskedStorage<T>>> as GenericWriteStorage>::Component> where
<&'b mut Storage<'a, T, FetchMut<'a, MaskedStorage<T>>> as GenericWriteStorage>::Component: Default,
[src]
&mut self,
entity: Entity
) -> Option<&mut <&'b mut Storage<'a, T, FetchMut<'a, MaskedStorage<T>>> as GenericWriteStorage>::Component> where
<&'b mut Storage<'a, T, FetchMut<'a, MaskedStorage<T>>> as GenericWriteStorage>::Component: Default,
pub fn insert(
&mut self,
entity: Entity,
comp: <&'b mut Storage<'a, T, FetchMut<'a, MaskedStorage<T>>> as GenericWriteStorage>::Component
) -> Result<Option<<&'b mut Storage<'a, T, FetchMut<'a, MaskedStorage<T>>> as GenericWriteStorage>::Component>, Error>
[src]
&mut self,
entity: Entity,
comp: <&'b mut Storage<'a, T, FetchMut<'a, MaskedStorage<T>>> as GenericWriteStorage>::Component
) -> Result<Option<<&'b mut Storage<'a, T, FetchMut<'a, MaskedStorage<T>>> as GenericWriteStorage>::Component>, Error>
pub fn remove(&mut self, entity: Entity)
[src]
pub fn _private() -> Seal
[src]
impl<'a, T> GenericWriteStorage for Storage<'a, T, FetchMut<'a, MaskedStorage<T>>> where
T: Component,
[src]
impl<'a, T> GenericWriteStorage for Storage<'a, T, FetchMut<'a, MaskedStorage<T>>> where
T: Component,
[src]type Component = T
The component type of the storage
pub fn get_mut(
&mut self,
entity: Entity
) -> Option<&mut <Storage<'a, T, FetchMut<'a, MaskedStorage<T>>> as GenericWriteStorage>::Component>
[src]
&mut self,
entity: Entity
) -> Option<&mut <Storage<'a, T, FetchMut<'a, MaskedStorage<T>>> as GenericWriteStorage>::Component>
pub fn get_mut_or_default(
&mut self,
entity: Entity
) -> Option<&mut <Storage<'a, T, FetchMut<'a, MaskedStorage<T>>> as GenericWriteStorage>::Component> where
<Storage<'a, T, FetchMut<'a, MaskedStorage<T>>> as GenericWriteStorage>::Component: Default,
[src]
&mut self,
entity: Entity
) -> Option<&mut <Storage<'a, T, FetchMut<'a, MaskedStorage<T>>> as GenericWriteStorage>::Component> where
<Storage<'a, T, FetchMut<'a, MaskedStorage<T>>> as GenericWriteStorage>::Component: Default,
pub fn insert(
&mut self,
entity: Entity,
comp: <Storage<'a, T, FetchMut<'a, MaskedStorage<T>>> as GenericWriteStorage>::Component
) -> Result<Option<<Storage<'a, T, FetchMut<'a, MaskedStorage<T>>> as GenericWriteStorage>::Component>, Error>
[src]
&mut self,
entity: Entity,
comp: <Storage<'a, T, FetchMut<'a, MaskedStorage<T>>> as GenericWriteStorage>::Component
) -> Result<Option<<Storage<'a, T, FetchMut<'a, MaskedStorage<T>>> as GenericWriteStorage>::Component>, Error>
pub fn remove(&mut self, entity: Entity)
[src]
pub fn _private() -> Seal
[src]
impl<'a, 'e, T, D> Join for &'a mut Storage<'e, T, D> where
D: DerefMut<Target = MaskedStorage<T>>,
T: Component,
[src]
impl<'a, 'e, T, D> Join for &'a mut Storage<'e, T, D> where
D: DerefMut<Target = MaskedStorage<T>>,
T: Component,
[src]type Mask = &'a BitSet
Type of joined bit mask.
type Type = &'a mut T
Type of joined components.
type Value = &'a mut <T as Component>::Storage
Type of joined storages.
pub unsafe fn open(
self
) -> (<&'a mut Storage<'e, T, D> as Join>::Mask, <&'a mut Storage<'e, T, D> as Join>::Value)
[src]
self
) -> (<&'a mut Storage<'e, T, D> as Join>::Mask, <&'a mut Storage<'e, T, D> as Join>::Value)
pub unsafe fn get(
v: &mut <&'a mut Storage<'e, T, D> as Join>::Value,
i: u32
) -> &'a mut T
[src]
v: &mut <&'a mut Storage<'e, T, D> as Join>::Value,
i: u32
) -> &'a mut T
pub fn join(self) -> JoinIter<Self>ⓘ
[src]
pub fn maybe(self) -> MaybeJoin<Self>
[src]
pub fn is_unconstrained() -> bool
[src]
impl<'a, 'e, T, D> Join for &'a Storage<'e, T, D> where
D: Deref<Target = MaskedStorage<T>>,
T: Component,
[src]
impl<'a, 'e, T, D> Join for &'a Storage<'e, T, D> where
D: Deref<Target = MaskedStorage<T>>,
T: Component,
[src]type Mask = &'a BitSet
Type of joined bit mask.
type Type = &'a T
Type of joined components.
type Value = &'a <T as Component>::Storage
Type of joined storages.
pub unsafe fn open(
self
) -> (<&'a Storage<'e, T, D> as Join>::Mask, <&'a Storage<'e, T, D> as Join>::Value)
[src]
self
) -> (<&'a Storage<'e, T, D> as Join>::Mask, <&'a Storage<'e, T, D> as Join>::Value)
pub unsafe fn get(
v: &mut <&'a Storage<'e, T, D> as Join>::Value,
i: u32
) -> &'a T
[src]
v: &mut <&'a Storage<'e, T, D> as Join>::Value,
i: u32
) -> &'a T
pub fn join(self) -> JoinIter<Self>ⓘ
[src]
pub fn maybe(self) -> MaybeJoin<Self>
[src]
pub fn is_unconstrained() -> bool
[src]
impl<'a, 'e, T, D> Not for &'a Storage<'e, T, D> where
D: Deref<Target = MaskedStorage<T>>,
T: Component,
[src]
impl<'a, 'e, T, D> Not for &'a Storage<'e, T, D> where
D: Deref<Target = MaskedStorage<T>>,
T: Component,
[src]impl<'a, T> SystemData<'a> for Storage<'a, T, FetchMut<'a, MaskedStorage<T>>> where
T: Component,
[src]
impl<'a, T> SystemData<'a> for Storage<'a, T, FetchMut<'a, MaskedStorage<T>>> where
T: Component,
[src]impl<'a, T> SystemData<'a> for Storage<'a, T, Fetch<'a, MaskedStorage<T>>> where
T: Component,
[src]
impl<'a, T> SystemData<'a> for Storage<'a, T, Fetch<'a, MaskedStorage<T>>> where
T: Component,
[src]Auto Trait Implementations
impl<'e, T, D> !RefUnwindSafe for Storage<'e, T, D>
impl<'e, T, D> !RefUnwindSafe for Storage<'e, T, D>
impl<'e, T, D> !UnwindSafe for Storage<'e, T, D>
impl<'e, T, D> !UnwindSafe for Storage<'e, T, D>
Blanket Implementations
impl<T> Any for T where
T: Any,
impl<T> Any for T where
T: Any,
pub fn get_type_id(&self) -> TypeId
impl<'a, T> DynamicSystemData<'a> for T where
T: SystemData<'a>,
[src]
impl<'a, T> DynamicSystemData<'a> for T where
T: SystemData<'a>,
[src]type Accessor = StaticAccessor<T>
The accessor of the SystemData
, which specifies the read and write
dependencies and does the fetching. Read more