Expand description
A fast and flexible entity component system library.
§Design
brood
is built using heterogeneous lists of arbitrary length. This is achieved in Rust using
nested tuples to create lists of components of any length. This allows entities to be made up
of any number of components, removing component size limitations that would normally occur with
regular tuples.
The heterogeneous lists used in this library can easily be defined using declarative macros.
§Key Features
- Entities made up of an arbitrary number of components.
- Built-in support for
serde
, providing pain-free serialization and deserialization ofWorld
containers. - Inner- and outer-parallelism using
rayon
. - Minimal boilerplate.
no_std
compatible.
§Basic Usage
To create a World
to store entities, first define a Registry
type containing the
components you want to store. Only components contained in the Registry
can be stored in a
World
.
use brood::Registry;
struct Position {
x: f32,
y: f32,
}
struct Velocity {
x: f32,
y: f32,
}
type Registry = Registry!(Position, Velocity);
You must define a separate component (meaning a new struct
or enum
) for each component you
want to store. The newtype
pattern is useful to store
multiple components using the same underlying type.
To create a World
, provide the Registry
at construction. Entities made up of any set of
components within the Registry
can then be inserted into the World
.
use brood::{
entity,
World,
};
let mut world = World::<Registry>::new();
// Insert entity with both position and velocity.
world.insert(entity!(
Position { x: 1.5, y: 2.5 },
Velocity { x: 0.0, y: 1.0 }
));
// Insert entity with just position.
world.insert(entity!(Position { x: 1.5, y: 2.5 }));
The entities in the World
can now be manipulated using queries or systems. See the
documentation in the query
and system
modules for examples of this.
§Feature Flags
The following features are provided by this crate and can be enabled by adding the feature
flag to your
Cargo.toml
.
§serde
Enabling the feature flag serde
allows World
s to be serializable and deserializable using
the serde
library, assuming all components in the World
’s
Registry
are also serializable and deserialzable.
§rayon
Enabling the feature flag rayon
allows for parallel operations on components.
§#[no_std]
Support
brood
can be used in no_std
contexts where
alloc
is available.
Modules§
- component
- Types defining a single aspect of an entity.
- entities
- A heterogeneous list of batches of
Component
s stored within aWorld
. - entity
- A heterogeneous list of
Component
s stored within aWorld
. - query
- Queries over
World
s. - registry
- A heterogeneous list of registered
Component
s. - resource
- Types defining resources within a
World
. - system
- Executable types which operate over entities within a
World
. - world
- A container of entities.
Macros§
- Entity
- Defines the type of an entity containing the provided components.
- Registry
- Creates a registry from the provided components.
- Resources
- Defines the type of a list of resources.
- entities
- Creates a batch of entities made from the same components.
- entity
- Creates an entity from the provided components.
- resources
- Creates a list of resources.