Struct specs::FlaggedStorage
[−]
[src]
pub struct FlaggedStorage<C, T> { /* fields omitted */ }
Wrapper storage that stores modifications to components in a bitset.
Note: Joining over all components of a FlaggedStorage
mutably will flag all components.**
What you want to instead is to use check()
to first get the entities which contain
the component, and then conditionally set the component after a call to get_mut_unchecked()
.
# Examples
extern crate specs; use specs::{Component, FlaggedStorage, Join, System, VecStorage, WriteStorage}; pub struct Comp(u32); impl Component for Comp { // `FlaggedStorage` acts as a wrapper around another storage. // You can put any store inside of here (e.g. HashMapStorage, VecStorage, etc.) type Storage = FlaggedStorage<Self, VecStorage<Self>>; } pub struct CompSystem; impl<'a> System<'a> for CompSystem { type SystemData = WriteStorage<'a, Comp>; fn run(&mut self, mut comps: WriteStorage<'a, Comp>) { // Iterates over all components like normal. for comp in (&comps).join() { // ... } // **Never do this** // This will flag all components as modified regardless of whether the inner loop // did modify their data. for comp in (&mut comps).join() { // ... } // Instead do something like: for mut entry in (&comps.check()).join() { if true { // check whether this component should be modified. let mut comp = comps.get_mut_unchecked(&mut entry); // ... } } // To iterate over the flagged/modified components: for flagged_comp in ((&comps).open().1).join() { // ... } // Clears the tracked storage every frame with this system. (&mut comps).open().1.clear_flags(); } }
Methods
impl<C, T: UnprotectedStorage<C>> FlaggedStorage<C, T>
[src]
fn flagged<E: EntityIndex>(&self, entity: E) -> bool
Whether the component that belongs to the given entity was flagged or not.
fn clear_flags(&mut self)
All components will be cleared of being flagged.
fn unflag<E: EntityIndex>(&mut self, entity: E)
Removes the flag for the component of the given entity.
fn flag<E: EntityIndex>(&mut self, entity: E)
Flags a single component.
Trait Implementations
impl<C, T: UnprotectedStorage<C>> UnprotectedStorage<C> for FlaggedStorage<C, T>
[src]
fn new() -> Self
Creates a new Storage<T>
. This is called when you register a new component type within the world. Read more
unsafe fn clean<F>(&mut self, has: F) where
F: Fn(Index) -> bool,
F: Fn(Index) -> bool,
Clean the storage given a check to figure out if an index is valid or not. Allows us to safely drop the storage. Read more
unsafe fn get(&self, id: Index) -> &C
Tries reading the data associated with an Index
. This is unsafe because the external set used to protect this storage is absent. Read more
unsafe fn get_mut(&mut self, id: Index) -> &mut C
Tries mutating the data associated with an Index
. This is unsafe because the external set used to protect this storage is absent. Read more
unsafe fn insert(&mut self, id: Index, comp: C)
Inserts new data for a given Index
.
unsafe fn remove(&mut self, id: Index) -> C
Removes the data associated with an Index
.
impl<'a, C, T: UnprotectedStorage<C>> Join for &'a FlaggedStorage<C, T>
[src]
type Type = &'a C
Type of joined components.
type Value = &'a T
Type of joined storages.
type Mask = &'a BitSet
Type of joined bit mask.
fn open(self) -> (Self::Mask, Self::Value)
Open this join by returning the mask and the storages.
unsafe fn get(v: &mut Self::Value, id: Index) -> &'a C
Get a joined component value by a given index.
fn join(self) -> JoinIter<Self> where
Self: Sized,
Self: Sized,
Create a joined iterator over the contents.
impl<'a, C, T: UnprotectedStorage<C>> Join for &'a mut FlaggedStorage<C, T>
[src]
type Type = &'a mut C
Type of joined components.
type Value = &'a mut T
Type of joined storages.
type Mask = &'a BitSet
Type of joined bit mask.
fn open(self) -> (Self::Mask, Self::Value)
Open this join by returning the mask and the storages.
unsafe fn get(v: &mut Self::Value, id: Index) -> &'a mut C
Get a joined component value by a given index.
fn join(self) -> JoinIter<Self> where
Self: Sized,
Self: Sized,
Create a joined iterator over the contents.