Struct rinecs::entity::EntityBuilder [−][src]
pub struct EntityBuilder<'a> { /* fields omitted */ }
Adds an entity and it’s components to the world.
It’s methods can be chain called to add several components and finally build the entity.
let e = world.new_entity() .add(Position{x: 0., y: 0.}) .add(Velocity{x: 0., y: 0.}) .build();
Implementations
impl<'a> EntityBuilder<'a>
[src]
impl<'a> EntityBuilder<'a>
[src]pub fn build(self) -> Entity
[src]
Builds the entity after adding all the components
pub fn add<'r, C: ComponentSend>(self, component: C) -> Self where
<C as Component>::Storage: Storage<'s, C>,
<<C as Component>::Storage as Storage<'r, C>>::Get: DebugParameter,
[src]
<C as Component>::Storage: Storage<'s, C>,
<<C as Component>::Storage as Storage<'r, C>>::Get: DebugParameter,
Adds a Send
Component
to the entity.
There can only be one component of each type per entity
pub fn add_thread_local<'r, C: ComponentThreadLocal>(self, component: C) -> Self where
<C as Component>::Storage: Storage<'s, C>,
<<C as Component>::Storage as Storage<'r, C>>::Get: DebugParameter,
[src]
<C as Component>::Storage: Storage<'s, C>,
<<C as Component>::Storage as Storage<'r, C>>::Get: DebugParameter,
Adds a non Send
Component
to the entity.
There can only be one component of each type per entity.
Non Send
components, or thread local, can only be accessed
from systems that run from the main thread, namely SystemThreadLocal
CreationSystem and DebugSystem.
pub fn add_tag<C: 'static>(self) -> Self
[src]
Adds a Tag
to the entity.
There can only be one tag of each type per entity
pub fn add_child<'r, C: ComponentSend>(
self,
parent: &Entity,
component: C
) -> Self where
<C as Component>::Storage: HierarchicalStorage<'b, C>,
<<C as Component>::Storage as Storage<'r, C>>::Get: DebugParameter,
[src]
self,
parent: &Entity,
component: C
) -> Self where
<C as Component>::Storage: HierarchicalStorage<'b, C>,
<<C as Component>::Storage as Storage<'r, C>>::Get: DebugParameter,
Adds a Send
component as a child of another entity.
This can only be used with types that derive HierarchicalComponent.
It allows to create a hierarchy of entities compoenents that can then
be iterated as a tree allowing to update this compoenents taking into
account that hierarchy. See also the ReadHierarchical
, WriteHierarchical
ReadAndParent
and WriteAndParent
operators.
#[derive(HierarchicalComponent, Debug)] struct Position{ x: f32, y: f32, } let parent = world.new_entity() .add(Position{x: 0., y: 0.}) .build(); let child = world.new_entity() .add_child(&parent, Position{x: 10., y: 10.}) .build();
pub fn add_child_thread_local<'r, C: ComponentThreadLocal>(
self,
parent: &Entity,
component: C
) -> Self where
<C as Component>::Storage: HierarchicalStorage<'b, C>,
<<C as Component>::Storage as Storage<'r, C>>::Get: DebugParameter,
[src]
self,
parent: &Entity,
component: C
) -> Self where
<C as Component>::Storage: HierarchicalStorage<'b, C>,
<<C as Component>::Storage as Storage<'r, C>>::Get: DebugParameter,
Adds a non Send
component as a child of another entity.
This can only be used with types that derive HierarchicalComponent.
It allows to create a hierarchy of entities compoenents that can then
be iterated as a tree allowing to update this compoenents taking into
account that hierarchy. See also the ReadHierarchical
, WriteHierarchical
ReadAndParent
and WriteAndParent
operators.
#[derive(HierarchicalComponent, Debug)] struct Position{ x: f32, y: f32, } let parent = world.new_entity() .add_thread_local(Position{x: 0., y: 0.}) .build(); let child = world.new_entity() .add_child_thread_local(&parent, Position{x: 10., y: 10.}) .build();
pub fn add_slice<'s, C, I>(self, component: I) -> Self where
C: OneToNComponentSend,
<C as Component>::Storage: OneToNStorage<'b, C>,
<<C as Component>::Storage as Storage<'s, C>>::Get: DebugParameter,
I: IntoIterator<Item = C>,
[src]
C: OneToNComponentSend,
<C as Component>::Storage: OneToNStorage<'b, C>,
<<C as Component>::Storage as Storage<'s, C>>::Get: DebugParameter,
I: IntoIterator<Item = C>,
Adds a slice of components to an entity
This can only be used with types that derive OneToNComponent
It allows to store more than one element per entity instead of only one. All the elements for all the entities are stored contiguously.
Slice components can be accessed lateer with the normal operators that will return a slice instead of a reference to one compoenent
pub fn add_slice_thread_local<'r, C, I>(self, component: I) -> Self where
C: OneToNComponentThreadLocal,
<C as Component>::Storage: OneToNStorage<'b, C>,
<<C as Component>::Storage as Storage<'r, C>>::Get: DebugParameter,
I: IntoIterator<Item = C>,
[src]
C: OneToNComponentThreadLocal,
<C as Component>::Storage: OneToNStorage<'b, C>,
<<C as Component>::Storage as Storage<'r, C>>::Get: DebugParameter,
I: IntoIterator<Item = C>,
Adds a slice of non Send
components to an entity
This can only be used with types that derive OneToNComponent
It allows to store more than one element per entity instead of only one. All the elements for all the entities are stored contiguously.
Slice components can be accessed lateer with the normal operators that will return a slice instead of a reference to one compoenent
pub fn add_hierarchy<C: HierarchicalOneToNComponentSend>(
&mut self
) -> HierarchyBuilder<'_, C>
[src]
&mut self
) -> HierarchyBuilder<'_, C>
Adds a one to n hierarchy
pub fn add_hierarchy_thread_local<C: HierarchicalOneToNComponentThreadLocal>(
&mut self
) -> HierarchyBuilder<'_, C>
[src]
&mut self
) -> HierarchyBuilder<'_, C>
Adds a non Send
one to n hierarchy
pub fn add_option<'r, C: ComponentSend>(self, component: Option<C>) -> Self where
<C as Component>::Storage: Storage<'s, C>,
<<C as Component>::Storage as Storage<'r, C>>::Get: DebugParameter,
[src]
<C as Component>::Storage: Storage<'s, C>,
<<C as Component>::Storage as Storage<'r, C>>::Get: DebugParameter,
Optionally add a Send
component
Since the entity builder takes ownership of itself when adding new components, in cases where we are adding components to entities that might or might not have them, this allows to avoid an if else structure and instead pass an option.
The component will only be added if the passed parameter is Some
eg: Instead of doing:
let builder = world.new_entity() .add(Position{x: 0., y: 0.}); let builder = if has_velocity { builder.add(Velocity{x: 0., y: 0.}) }else{ builder }; let e = builder.build();
you can do:
let velocity = if has_velocity { Some(Velocity{x: 0., y: 0.}) }else{ None }; let e = world.new_entity() .add(Position{x: 0., y: 0.}) .add_option(velocity) .build();
pub fn add_tag_if<C: 'static>(self, cond: bool) -> Self
[src]
Adds a Tag
to the entity if the condition is true.
There can only be one tag of each type per entity
pub fn add_thread_local_option<'r, C: ComponentThreadLocal>(
self,
component: Option<C>
) -> Self where
<C as Component>::Storage: Storage<'s, C>,
<<C as Component>::Storage as Storage<'r, C>>::Get: DebugParameter,
[src]
self,
component: Option<C>
) -> Self where
<C as Component>::Storage: Storage<'s, C>,
<<C as Component>::Storage as Storage<'r, C>>::Get: DebugParameter,
Optionally add a non Send
component
See add_option for more information
pub fn add_child_option<'r, C: ComponentSend>(
self,
parent: &Entity,
component: Option<C>
) -> Self where
<C as Component>::Storage: HierarchicalStorage<'s, C>,
<<C as Component>::Storage as Storage<'r, C>>::Get: DebugParameter,
[src]
self,
parent: &Entity,
component: Option<C>
) -> Self where
<C as Component>::Storage: HierarchicalStorage<'s, C>,
<<C as Component>::Storage as Storage<'r, C>>::Get: DebugParameter,
Optionally add a child component
See add_option for more information
pub fn add_child_thread_local_option<'r, C: ComponentThreadLocal>(
self,
parent: &Entity,
component: Option<C>
) -> Self where
<C as Component>::Storage: HierarchicalStorage<'s, C>,
<<C as Component>::Storage as Storage<'r, C>>::Get: DebugParameter,
[src]
self,
parent: &Entity,
component: Option<C>
) -> Self where
<C as Component>::Storage: HierarchicalStorage<'s, C>,
<<C as Component>::Storage as Storage<'r, C>>::Get: DebugParameter,
Optionally add a child non Send
component
See add_option for more information
pub fn add_slice_option<'r, C, I>(self, component: Option<I>) -> Self where
C: OneToNComponentSend,
<C as Component>::Storage: OneToNStorage<'s, C>,
<<C as Component>::Storage as Storage<'r, C>>::Get: DebugParameter,
I: IntoIterator<Item = C>,
[src]
C: OneToNComponentSend,
<C as Component>::Storage: OneToNStorage<'s, C>,
<<C as Component>::Storage as Storage<'r, C>>::Get: DebugParameter,
I: IntoIterator<Item = C>,
Optionally add a slice component
See add_option for more information
pub fn add_slice_thread_local_option<'r, C, I>(
self,
component: Option<I>
) -> Self where
C: OneToNComponentThreadLocal,
<C as Component>::Storage: OneToNStorage<'s, C>,
<<C as Component>::Storage as Storage<'r, C>>::Get: DebugParameter,
I: IntoIterator<Item = C>,
[src]
self,
component: Option<I>
) -> Self where
C: OneToNComponentThreadLocal,
<C as Component>::Storage: OneToNStorage<'s, C>,
<<C as Component>::Storage as Storage<'r, C>>::Get: DebugParameter,
I: IntoIterator<Item = C>,
Optionally add a slice non Send
component
See add_option for more information