Trait rinecs::entity::EntityStoragesExt[][src]

pub trait EntityStoragesExt<'a> {
    fn component_for<C: ComponentSend>(
        &self,
        entity: &Entity
    ) -> Option<Ptr<'_, C>>
    where
        <C as Component>::Storage: Storage<'s, C>
;
fn component_for_mut<C: ComponentSend>(
        &self,
        entity: &Entity
    ) -> Option<PtrMut<'_, C>>
    where
        <C as Component>::Storage: Storage<'s, C>
;
fn has_component<C: 'static>(&self, entity: &Entity) -> bool;
fn tree_node_for<C: ComponentSend>(
        &self,
        entity: &Entity
    ) -> Option<NodePtr<'_, C>>
    where
        <C as Component>::Storage: HierarchicalStorage<'b, C>
;
fn tree_node_for_mut<C: ComponentSend>(
        &self,
        entity: &Entity
    ) -> Option<NodePtrMut<'_, C>>
    where
        <C as Component>::Storage: HierarchicalStorage<'b, C>
;
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

fn component_for<C: ComponentSend>(&self, entity: &Entity) -> Option<Ptr<'_, C>> where
    <C as Component>::Storage: 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();

fn component_for_mut<C: ComponentSend>(
    &self,
    entity: &Entity
) -> Option<PtrMut<'_, C>> where
    <C as Component>::Storage: 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();

fn has_component<C: 'static>(&self, entity: &Entity) -> bool[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));

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

Returns the node for a hierarchical component

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

Returns the node for a hierarchical component for writing

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 EntityStorages<'a>[src]

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

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

Loading content...