Struct rin::ecs::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]

pub fn build(self) -> Entity[src]

Builds the entity after adding all the components

pub fn add<'r, C>(self, component: C) -> EntityBuilder<'a> where
    C: ComponentSend,
    <C as Component>::Storage: for<'s> Storage<'s, C>,
    <<C as Component>::Storage as Storage<'r, C>>::Get: DebugParameter
[src]

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>(self, component: C) -> EntityBuilder<'a> where
    C: ComponentThreadLocal,
    <C as Component>::Storage: for<'s> Storage<'s, C>,
    <<C as Component>::Storage as Storage<'r, C>>::Get: DebugParameter
[src]

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>(self) -> EntityBuilder<'a> where
    C: 'static, 
[src]

Adds a Tag to the entity.

There can only be one tag of each type per entity

pub fn add_child<'r, C>(
    self,
    parent: &Entity,
    component: C
) -> EntityBuilder<'a> where
    C: ComponentSend,
    <C as Component>::Storage: for<'b> HierarchicalStorage<'b, C>,
    <<C as Component>::Storage as Storage<'r, C>>::Get: DebugParameter
[src]

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>(
    self,
    parent: &Entity,
    component: C
) -> EntityBuilder<'a> where
    C: ComponentThreadLocal,
    <C as Component>::Storage: for<'b> HierarchicalStorage<'b, C>,
    <<C as Component>::Storage as Storage<'r, C>>::Get: DebugParameter
[src]

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) -> EntityBuilder<'a> where
    C: OneToNComponentSend,
    I: IntoIterator<Item = C>,
    <C as Component>::Storage: for<'b> OneToNStorage<'b, C>,
    <<C as Component>::Storage as Storage<'s, C>>::Get: DebugParameter
[src]

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) -> EntityBuilder<'a> where
    C: OneToNComponentThreadLocal,
    I: IntoIterator<Item = C>,
    <C as Component>::Storage: for<'b> OneToNStorage<'b, C>,
    <<C as Component>::Storage as Storage<'r, C>>::Get: DebugParameter
[src]

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>(&mut self) -> HierarchyBuilder<'_, C> where
    C: HierarchicalOneToNComponentSend, 
[src]

Adds a one to n hierarchy

pub fn add_hierarchy_thread_local<C>(&mut self) -> HierarchyBuilder<'_, C> where
    C: HierarchicalOneToNComponentThreadLocal, 
[src]

Adds a non Send one to n hierarchy

pub fn add_option<'r, C>(self, component: Option<C>) -> EntityBuilder<'a> where
    C: ComponentSend,
    <C as Component>::Storage: for<'s> Storage<'s, C>,
    <<C as Component>::Storage as Storage<'r, C>>::Get: DebugParameter
[src]

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>(self, cond: bool) -> EntityBuilder<'a> where
    C: 'static, 
[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>(
    self,
    component: Option<C>
) -> EntityBuilder<'a> where
    C: ComponentThreadLocal,
    <C as Component>::Storage: for<'s> Storage<'s, C>,
    <<C as Component>::Storage as Storage<'r, C>>::Get: DebugParameter
[src]

Optionally add a non Send component

See add_option for more information

pub fn add_child_option<'r, C>(
    self,
    parent: &Entity,
    component: Option<C>
) -> EntityBuilder<'a> where
    C: ComponentSend,
    <C as Component>::Storage: for<'s> HierarchicalStorage<'s, C>,
    <<C as Component>::Storage as Storage<'r, C>>::Get: DebugParameter
[src]

Optionally add a child component

See add_option for more information

pub fn add_child_thread_local_option<'r, C>(
    self,
    parent: &Entity,
    component: Option<C>
) -> EntityBuilder<'a> where
    C: ComponentThreadLocal,
    <C as Component>::Storage: for<'s> HierarchicalStorage<'s, C>,
    <<C as Component>::Storage as Storage<'r, C>>::Get: DebugParameter
[src]

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>
) -> EntityBuilder<'a> where
    C: OneToNComponentSend,
    I: IntoIterator<Item = C>,
    <C as Component>::Storage: for<'s> OneToNStorage<'s, C>,
    <<C as Component>::Storage as Storage<'r, C>>::Get: DebugParameter
[src]

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>
) -> EntityBuilder<'a> where
    C: OneToNComponentThreadLocal,
    I: IntoIterator<Item = C>,
    <C as Component>::Storage: for<'s> OneToNStorage<'s, C>,
    <<C as Component>::Storage as Storage<'r, C>>::Get: DebugParameter
[src]

Optionally add a slice non Send component

See add_option for more information

Auto Trait Implementations

impl<'a> !RefUnwindSafe for EntityBuilder<'a>

impl<'a> !Send for EntityBuilder<'a>

impl<'a> !Sync for EntityBuilder<'a>

impl<'a> Unpin for EntityBuilder<'a>

impl<'a> !UnwindSafe for EntityBuilder<'a>

Blanket Implementations

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

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

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

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

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

impl<T> From<T> for T[src]

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

impl<V> IntoPnt<V> for V[src]

impl<V> IntoVec<V> for V[src]

impl<T> Pointable for T[src]

type Init = T

The type for initializers.

impl<T> Same<T> for T[src]

type Output = T

Should always be Self

impl<SS, SP> SupersetOf<SS> for SP where
    SS: SubsetOf<SP>, 
[src]

impl<SS, SP> SupersetOf<SS> for SP where
    SS: SubsetOf<SP>, 
[src]

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

type Error = Infallible

The type returned in the event of a conversion error.

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

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 
[src]