[][src]Struct rinecs::Entities

pub struct Entities<'a> { /* fields omitted */ }

Allows to access and modify the Send components of the entities in the world.

Methods

impl<'a> Entities<'a>
[src]

Iterator over all the components that match the operator

for (pos, vel) in entities.iter_for::<(Write<Position>, Read<Velocity>)>(){
    pos.x += vel.x;
    pos.y += vel.y;
}

Will iterate over all the entities that have both position and velocity and update the position by adding the velocity to it. In this example position can be modified cause we use the Write operator but velocity can only be read.

Parallel iterator over all the components that match the operator

Similar to iter_for but iterates through all the compoenents in parallel potentically running many iterations of the loop simultaneously.

extern crate rayon;
use rayon::prelude::*;
entities.par_iter_for::<(Write<Position>, Read<Velocity>)>().for_each( |(pos,vel)| {
    pos.x += vel.x;
    pos.y += vel.y;
});

Will do the same as the example in iter_for but the update will be done in parallel for many components at the same time

To use parallel iterators one must import the rayon crate in the application

Iterator over ordered data

Similar to iter_for but to be used with operators that specify an order like ReadAndParent in which parents will be processed first and then their children

Iterator for the specified operators over a set of entities instead of every entity in the world

It's usage is similar to iter_for but instead of iterating over all the entities it only returns components that match the operators for the entities passed as parameter

let e1 = world.new_entity()
    .add(Position{x: 0., y: 0.})
    .build();
let e2 = world.new_entity()
    .add(Position{x: 0., y: 0.})
    .build();
let e3 = world.new_entity()
    .add(Position{x: 0., y: 0.})
    .build();
let entities = world.entities();
for pos in entities.iter_for_entities::<Read<Position>, _>(vec![e1, e2]){
    //...
}

The operators parameter in this method needs a second type for the entities iterator type which can jsut be elided with a _ since it'll be guessed from the passed parameter

Similar to iter_for_entities but for one entity instead of several

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

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();

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();

Returns the node for a hierarchical component

Returns the node for a hierarchical component for writing

Trait Implementations

impl<'a> EntitiesT<'a> for Entities<'a>
[src]

impl<'a> Sync for Entities<'a>
[src]

impl<'a> Send for Entities<'a>
[src]

impl<'a> Clone for Entities<'a>
[src]

Performs copy-assignment from source. Read more

impl<'a> Copy for Entities<'a>
[src]

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

impl<T> From for T
[src]

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: Any
[src]

impl<T> SetParameter for T
[src]

Sets value as a parameter of self.