[][src]Trait rinecs::CreationContext

pub trait CreationContext {
    fn iter_for<'e, S: UnorderedDataLocal<'e> + 'e>(
        &'e self
    ) -> <S as UnorderedDataLocal<'e>>::Iter;
fn ordered_iter_for<'e, S: OrderedDataLocal<'e> + 'e>(
        &'e self
    ) -> <S as OrderedDataLocal<'e>>::Iter;
fn iter_for_entities<'e, S, E>(
        &'e self,
        entities: E
    ) -> <S as EntitiesDataLocal<'e, E>>::Iter
    where
        S: UnorderedDataLocal<'e> + 'e,
        E: IntoIterator<Item = Entity>
;
fn entity_components<'e, S>(
        &'e self,
        entity: &Entity
    ) -> Option<<S as EntitiesComponentsLocal<'e>>::Components>
    where
        S: UnorderedDataLocal<'e> + 'e
;
fn component_for<C: Component>(&self, entity: &Entity) -> Option<Ptr<C>>;
fn component_for_mut<C: Component>(
        &self,
        entity: &Entity
    ) -> Option<PtrMut<C>>;
fn tree_node_for<'e, C: Component>(
        &'e self,
        entity: &Entity
    ) -> Option<NodePtr<'e, C>>
    where
        <C as Component>::Storage: HierarchicalStorage<'e, C>
;
fn tree_node_for_mut<'e, C: Component>(
        &'e self,
        entity: &Entity
    ) -> Option<NodePtrMut<'e, C>>
    where
        <C as Component>::Storage: HierarchicalStorage<'e, C>
;
fn new_entity(&mut self) -> EntityBuilder;
fn add_component_to<C: ComponentSend>(
        &mut self,
        entity: &Entity,
        component: C
    );
fn add_component_to_thread_local<C: ComponentThreadLocal>(
        &mut self,
        entity: &Entity,
        component: C
    );
fn add_slice_component_to<C, I>(&mut self, entity: &Entity, component: I)
    where
        C: OneToNComponentSend,
        <C as Component>::Storage: OneToNStorage<'a, C>,
        I: IntoIterator<Item = C>
;
fn add_slice_component_to_thread_local<C, I>(
        &mut self,
        entity: &Entity,
        component: I
    )
    where
        C: OneToNComponentThreadLocal,
        <C as Component>::Storage: OneToNStorage<'a, C>,
        I: IntoIterator<Item = C>
;
fn remove_component_from<C: Component>(&mut self, entity: &Entity);
fn remove_entity(&mut self, entity: &Entity);
fn resource<T: 'static>(&self) -> Option<RwLockReadGuard<T>>;
fn resource_mut<T: 'static>(&self) -> Option<RwLockWriteGuard<T>>;
fn add_resource<T: 'static + Send>(&mut self, resource: T);
fn add_resource_thread_local<T: 'static>(&mut self, resource: T);
fn remove_resource<T: 'static>(&mut self) -> Option<T>;
fn register<'e, T: ComponentSend>(&'e mut self)
    where
        <<T as Component>::Storage as Storage<'e, T>>::Get: DebugParameter
;
fn register_thread_local<'e, T: ComponentThreadLocal>(&'e mut self)
    where
        <<T as Component>::Storage as Storage<'e, T>>::Get: DebugParameter
; }

Trait implemented by World and CreationProxy allows to create functions that can create new entities, components and resources without relying on an specific object

That way a such function can be called during initialization passing a World as parameter or during run time passing a CreationProxy

Wrappers for World should implement this trait

Required Methods

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.

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

Returns an EntityBuilder that allows to create an entity and it's components.

let e = world.new_entity()
    .add(Position{x: 0., y: 0.})
    .add(Velocity{x: 0., y: 0.})
    .build();

Adds a Send Component to an already existing Entity.

Adds a non Send Component to an already existing Entity.

Adds a Send OneToNComponent to an already existing Entity.

This allows to add a slice of components to an entity instead of only one component. This components are stored contiguously in memory for all the entities.

Adds a non Send OneToNComponent to an already existing Entity.

This allows to add a slice of components to an entity instead of only one component. This components are stored contiguously in memory for all the entities.

Removes a compoenent of the specified type from an entity.

Removes an Entity and all it's compoenents.

Returns a resource of the specified type if it exists for reading.

Returns a resource of the specified type if it exists for writing.

Adds a Send resource to the world.

Resources are globally accesible by any system through the Resources object passed as parameter to them.

Adds a non Send resource to the world.

Non Send resources are globally accesible by any SystemThreadLocal through the ResourcesThreadLocal object passed as parameter to them.

Removes a resource of the specified type.

Implementors

impl CreationContext for World
[src]

impl<'a> CreationContext for CreationProxy<'a>
[src]