Trait rin::ecs::entity::EntityStoragesExt[][src]

pub trait EntityStoragesExt<'a> {
    pub fn component_for<C>(&self, entity: &Entity) -> Option<Ptr<'_, C>>
    where
        C: ComponentSend,
        <C as Component>::Storage: for<'s> Storage<'s, C>
;
pub fn component_for_mut<C>(&self, entity: &Entity) -> Option<PtrMut<'_, C>>
    where
        C: ComponentSend,
        <C as Component>::Storage: for<'s> Storage<'s, C>
;
pub fn has_component<C>(&self, entity: &Entity) -> bool
    where
        C: 'static
;
pub fn tree_node_for<C>(&self, entity: &Entity) -> Option<NodePtr<'_, C>>
    where
        C: ComponentSend,
        <C as Component>::Storage: for<'b> HierarchicalStorage<'b, C>
;
pub fn tree_node_for_mut<C>(
        &self,
        entity: &Entity
    ) -> Option<NodePtrMut<'_, C>>
    where
        C: ComponentSend,
        <C as Component>::Storage: for<'b> HierarchicalStorage<'b, C>
;
pub fn storage_for<'r, S>(&'r self) -> Sto<'r, S>
    where
        S: UnorderedDataSend<'r>
; }

Common trait for all Entities like objects.

Allows access and modification of Send components. Useful to create functions that can be used from different systems and need an Entities like parameter.

Required methods

pub fn component_for<C>(&self, entity: &Entity) -> Option<Ptr<'_, C>> where
    C: ComponentSend,
    <C as Component>::Storage: for<'s> Storage<'s, C>, 
[src]

Returns a component for reading for the passed entity

let e1 = world.new_entity()
    .add(Position{x: 0., y: 0.})
    .build();
let entities = world.entities();
let pos = entities.component_for::<Position>(&e1).unwrap();

pub fn component_for_mut<C>(&self, entity: &Entity) -> Option<PtrMut<'_, C>> where
    C: ComponentSend,
    <C as Component>::Storage: for<'s> Storage<'s, C>, 
[src]

Returns a component for writing for the passed entity

let e1 = world.new_entity()
    .add(Position{x: 0., y: 0.})
    .build();
let entities = world.entities();
let mut pos = entities.component_for_mut::<Position>(&e1).unwrap();

pub fn has_component<C>(&self, entity: &Entity) -> bool where
    C: 'static, 
[src]

Returns true if the entity has the specified component

let e1 = world.new_entity()
    .add(Position{x: 0., y: 0.})
    .build();
let entities = world.entities();
assert!(entities.has_component::<Position>(&e1));

pub fn tree_node_for<C>(&self, entity: &Entity) -> Option<NodePtr<'_, C>> where
    C: ComponentSend,
    <C as Component>::Storage: for<'b> HierarchicalStorage<'b, C>, 
[src]

Returns the node for a hierarchical component

pub fn tree_node_for_mut<C>(&self, entity: &Entity) -> Option<NodePtrMut<'_, C>> where
    C: ComponentSend,
    <C as Component>::Storage: for<'b> HierarchicalStorage<'b, C>, 
[src]

Returns the node for a hierarchical component for writing

pub fn storage_for<'r, S>(&'r self) -> Sto<'r, S> where
    S: UnorderedDataSend<'r>, 
[src]

Storage for the operator passed as type parameter

Calling iter_for can be slow if it needs to be called lots of times. In those cases calling instead storage_for once and then iter() on it multiple times can make performance much better

let mut storage = entities.storage_for_mut::<(Write<Position>, Read<Velocity>)>().unwrap();
for i in 0..1000000 {
    for (pos, vel) in storage.iter_mut() {
        pos.x += vel.x;
        pos.y += vel.y;
    }
}
Loading content...

Implementors

impl<'a> EntityStoragesExt<'a> for CreationStorages<'a>[src]

impl<'a> EntityStoragesExt<'a> for EntityStorages<'a>[src]

impl<'a> EntityStoragesExt<'a> for EntityStoragesCreation<'a>[src]

impl<'a> EntityStoragesExt<'a> for EntityStoragesThreadLocal<'a>[src]

Loading content...