macro_rules! entities {
    (($component:expr $(,$components:expr)* $(,)?); $n:expr) => { ... };
    ($(($($components:expr),*)),+ $(,)?) => { ... };
    ((); $n:expr) => { ... };
    () => { ... };
    (@cloned ($component:expr $(,$components:expr)* $(,)?); $n:expr) => { ... };
    (@cloned (); $n:expr) => { ... };
    (@transpose [$([$($column:expr),*])*] $(($component:expr $(,$components:expr)*  $(,)?)),*) => { ... };
    (@transpose [$([$($column:expr),*])*] $(()),*) => { ... };
    (@as_vec (($($column:expr),*) $(,($($columns:expr),*))* $(,)?)) => { ... };
    (@as_vec ()) => { ... };
}
Expand description

Creates a batch of entities made from the same components.

This macro allows multiple entities to be defined for efficient storage within a World. The syntax is similar to an array expression or the vec! macro. There are two forms of this macro:

Create entities given a list of tuples of components

use brood::entities;

// Define components `Foo` and `Bar`.
struct Foo(u16);
struct Bar(f32);

let my_entities = entities![(Foo(42), Bar(1.5)), (Foo(4), Bar(1.0))];

Note that all tuples must be made from the same components in the same order.

Create entities from a tuple of components and a size

use brood::entities;

// Define components `Foo` and `Bar`.
#[derive(Clone)]
struct Foo(u16);

#[derive(Clone)]
struct Bar(f32);

let my_entities = entities![(Foo(42), Bar(1.5)); 3];

This syntax only supports entities made from components that implement Clone, and the size does not have to be a constant value.

This will call clone() to duplicate each component, so one should be careful with types that have a nonstandard Clone implementation. For example, using Rc as a component value in this context will create multiple entities with references to the same boxed value, not multiple references to independently boxed values.

Using 0 as a size is allowed, and produces a container of no entities. This will still evaluate all expressions passed as components, however, and immediately drop the resulting values, so be mindful of side effects.