[][src]Struct rinecs::EntityBuilder

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

Methods

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

Builds the entity after adding all the components

Adds a Send Component to the entity.

There can only be one component of each type per entity

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.

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

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

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

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

Adds a one to n hierarchy

Adds a non Send one to n hierarchy

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

Optionally add a non Send component

See add_option for more information

Optionally add a child component

See add_option for more information

Optionally add a child non Send component

See add_option for more information

Optionally add a slice component

See add_option for more information

Optionally add a slice non Send component

See add_option for more information

Auto Trait Implementations

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

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

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[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.