Struct specs::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.
Methods
impl<'st, T, D> Storage<'st, T, D> where
T: Component,
D: Deref<Target = MaskedStorage<T>>,
[src]
T: Component,
D: Deref<Target = MaskedStorage<T>>,
pub fn restrict<'rf>(
&'rf self
) -> RestrictedStorage<'rf, 'st, &BitSet, T, &T::Storage, ParallelRestriction>
[src]
&'rf self
) -> RestrictedStorage<'rf, 'st, &BitSet, T, &T::Storage, ParallelRestriction>
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
T: Component,
D: DerefMut<Target = MaskedStorage<T>>,
[src]
T: Component,
D: DerefMut<Target = MaskedStorage<T>>,
pub fn restrict_mut<'rf>(
&'rf mut self
) -> RestrictedStorage<'rf, 'st, &BitSet, T, &mut T::Storage, NormalRestriction>
[src]
&'rf mut self
) -> RestrictedStorage<'rf, 'st, &BitSet, T, &mut T::Storage, NormalRestriction>
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>(
&'rf mut self
) -> RestrictedStorage<'rf, 'st, &BitSet, T, &mut T::Storage, ParallelRestriction>
[src]
&'rf mut self
) -> RestrictedStorage<'rf, 'st, &BitSet, T, &mut T::Storage, ParallelRestriction>
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
T: Component + Deserialize<'e>,
D: DerefMut<Target = MaskedStorage<T>>,
[src]
T: Component + Deserialize<'e>,
D: DerefMut<Target = MaskedStorage<T>>,
pub fn merge<'a>(
&'a mut self,
entities: &'a [Entity],
packed: PackedData<T>
) -> Result<(), MergeError>
[src]
&'a mut self,
entities: &'a [Entity],
packed: PackedData<T>
) -> Result<(), MergeError>
Merges a list of components into the storage.
The list of entities will be used as the base for the offsets of the packed data.
e.g.
rust,ignore let list = vec![Entity(0, 1), Entity(1, 1), Entity(2, 1)]; let packed = PackedData { offsets: [0, 2], components: [ ... ] }; storage.merge(&list, packed);
Would merge the components at offset 0 and 2, which would be Entity(0, 1)
and
Entity(2, 1)
while ignoring
Entity(1, 1)
.
Note:
The entity list should be at least the same size as the packed data. To make sure,
you can call packed.pair_truncate(&entities)
.
If the entity list is larger than the packed data then those entities are ignored.
Packed data should also be sorted in ascending order of offsets. If this is deserialized from data received from serializing a storage it will be in ascending order.
impl<'e, S, T, D> Storage<'e, T, D> where
S: UnprotectedStorage<T> + Send + Sync + 'static,
T: Component<Storage = TrackedStorage<T, S>> + Clone + Send + Sync,
D: Deref<Target = MaskedStorage<T>>,
[src]
S: UnprotectedStorage<T> + Send + Sync + 'static,
T: Component<Storage = TrackedStorage<T, S>> + Clone + Send + Sync,
D: Deref<Target = MaskedStorage<T>>,
pub fn change_events_tracked(&self) -> &[Change]
[src]
Returns the change events generated by the TrackedStorage
.
See Change
for more explanations.
The elements are mapped to entity indices, that means the Change
for entity with id 5
will be the 6th element of this slice.
Examples
use specs::{Change, Component, TrackedStorage, World}; #[derive(Clone, PartialEq)] // `PartialEq` is only necessary for maintain struct Comp(u8); impl Component for Comp { // Will use `DenseVecStorage` by default. type Storage = TrackedStorage<Self>; } let mut w = World::new(); w.register::<Comp>(); let a = w.create_entity().with(Comp(1)).build(); let change = w.read::<Comp>().change_events_tracked()[a.id() as usize]; assert_eq!(change, Change::Inserted);
impl<'e, S, T, D> Storage<'e, T, D> where
S: UnprotectedStorage<T> + Send + Sync + 'static,
T: Component<Storage = TrackedStorage<T, S>> + Clone + Send + Sync,
D: DerefMut<Target = MaskedStorage<T>>,
[src]
S: UnprotectedStorage<T> + Send + Sync + 'static,
T: Component<Storage = TrackedStorage<T, S>> + Clone + Send + Sync,
D: DerefMut<Target = MaskedStorage<T>>,
pub fn maintain_tracked(&mut self) where
T: PartialEq,
[src]
T: PartialEq,
Maintains the TrackedStorage
.
You can only call this in case your component implements PartialEq
.
This will compare the cache with the current storage and generate change events
in case the PartialEq
implementation says that two components are different.
If you don't care about Change::Modified
events, you don't have to call this method.
When should I call this method?
You should make sure that it gets called before you need the information which component
has been modified. E.g. in case you have several systems writing to the component, then
several reading from it, you can just call maintain_tracked
once in between.
pub fn reset_tracked(&mut self)
[src]
Resets the tracked storage. This clears all change events. You most likely want to do this at the end of every frame.
impl<'e, T, D> Storage<'e, T, D>
[src]
pub fn new(entities: Fetch<'e, EntitiesRes>, data: D) -> Storage<'e, T, D>
[src]
Create a new Storage
impl<'e, T, D> Storage<'e, T, D> where
T: Component,
D: Deref<Target = MaskedStorage<T>>,
[src]
T: Component,
D: Deref<Target = MaskedStorage<T>>,
pub fn get(&self, e: Entity) -> Option<&T>
[src]
Tries to read the data associated with an Entity
.
pub fn check(&self) -> BitSet
[src]
Returns a copy of the BitSet
of the storage. This allows you to
do some methods on the actual storage without worrying about borrowing
semantics.
This bitset can be invalidated here if insertion or removal methods
are used after the call to get the BitSet
, so there is no guarantee
that the storage will have a component for a specific entity.
impl<'e, T, D> Storage<'e, T, D> where
T: Component,
D: DerefMut<Target = MaskedStorage<T>>,
[src]
T: Component,
D: DerefMut<Target = MaskedStorage<T>>,
pub fn get_mut(&mut self, e: Entity) -> Option<&mut T>
[src]
Tries to mutate the data associated with an Entity
.
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 insert(&mut self, e: Entity, v: T) -> InsertResult<T>
[src]
Inserts new data for a given Entity
.
Returns the result of the operation as a InsertResult<T>
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<'e, T, D> Serialize for Storage<'e, T, D> where
T: Component + Serialize,
D: Deref<Target = MaskedStorage<T>>,
[src]
T: Component + Serialize,
D: Deref<Target = MaskedStorage<T>>,
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>
[src]
Serialize this value into the given Serde serializer. Read more
impl<'a, T: Component, D> DistinctStorage for Storage<'a, T, D> where
T::Storage: DistinctStorage,
[src]
T::Storage: DistinctStorage,
impl<'a, 'e, T, D> Join for &'a Storage<'e, T, D> where
T: Component,
D: Deref<Target = MaskedStorage<T>>,
[src]
T: Component,
D: Deref<Target = MaskedStorage<T>>,
type Type = &'a T
Type of joined components.
type Value = &'a T::Storage
Type of joined storages.
type Mask = &'a BitSet
Type of joined bit mask.
fn open(self) -> (Self::Mask, Self::Value)
[src]
Open this join by returning the mask and the storages.
unsafe fn get(v: &mut Self::Value, i: Index) -> &'a T
[src]
Get a joined component value by a given index.
fn join(self) -> JoinIter<Self> where
Self: Sized,
[src]
Self: Sized,
Create a joined iterator over the contents.
impl<'a, 'e, T, D> Not for &'a Storage<'e, T, D> where
T: Component,
D: Deref<Target = MaskedStorage<T>>,
[src]
T: Component,
D: Deref<Target = MaskedStorage<T>>,
type Output = AntiStorage<'a>
The resulting type after applying the !
operator.
fn not(self) -> Self::Output
[src]
Performs the unary !
operation.
impl<'a, 'e, T, D> ParJoin for &'a Storage<'e, T, D> where
T: Component,
D: Deref<Target = MaskedStorage<T>>,
T::Storage: Sync,
[src]
T: Component,
D: Deref<Target = MaskedStorage<T>>,
T::Storage: Sync,
fn par_join(self) -> JoinParIter<Self> where
Self: Sized,
[src]
Self: Sized,
Create a joined parallel iterator over the contents.
impl<'a, 'e, T, D> Join for &'a mut Storage<'e, T, D> where
T: Component,
D: DerefMut<Target = MaskedStorage<T>>,
[src]
T: Component,
D: DerefMut<Target = MaskedStorage<T>>,
type Type = &'a mut T
Type of joined components.
type Value = &'a mut T::Storage
Type of joined storages.
type Mask = &'a BitSet
Type of joined bit mask.
fn open(self) -> (Self::Mask, Self::Value)
[src]
Open this join by returning the mask and the storages.
unsafe fn get(v: &mut Self::Value, i: Index) -> &'a mut T
[src]
Get a joined component value by a given index.
fn join(self) -> JoinIter<Self> where
Self: Sized,
[src]
Self: Sized,
Create a joined iterator over the contents.
impl<'a, 'e, T, D> ParJoin for &'a mut Storage<'e, T, D> where
T: Component,
D: DerefMut<Target = MaskedStorage<T>>,
T::Storage: Sync + DistinctStorage,
[src]
T: Component,
D: DerefMut<Target = MaskedStorage<T>>,
T::Storage: Sync + DistinctStorage,
fn par_join(self) -> JoinParIter<Self> where
Self: Sized,
[src]
Self: Sized,
Create a joined parallel iterator over the contents.