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]

[src]

Whether the component that belongs to the given entity was flagged or not.

[src]

All components will be cleared of being flagged.

[src]

Removes the flag for the component of the given entity.

[src]

Flags a single component.

Trait Implementations

impl<C, T: UnprotectedStorage<C>> UnprotectedStorage<C> for FlaggedStorage<C, T>
[src]

[src]

Creates a new Storage<T>. This is called when you register a new component type within the world. Read more

[src]

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

[src]

Tries reading the data associated with an Index. This is unsafe because the external set used to protect this storage is absent. Read more

[src]

Tries mutating the data associated with an Index. This is unsafe because the external set used to protect this storage is absent. Read more

[src]

Inserts new data for a given Index.

[src]

Removes the data associated with an Index.

impl<'a, C, T: UnprotectedStorage<C>> Join for &'a FlaggedStorage<C, T>
[src]

Type of joined components.

Type of joined storages.

Type of joined bit mask.

[src]

Open this join by returning the mask and the storages.

[src]

Get a joined component value by a given index.

[src]

Create a joined iterator over the contents.

impl<'a, C, T: UnprotectedStorage<C>> Join for &'a mut FlaggedStorage<C, T>
[src]

Type of joined components.

Type of joined storages.

Type of joined bit mask.

[src]

Open this join by returning the mask and the storages.

[src]

Get a joined component value by a given index.

[src]

Create a joined iterator over the contents.