1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
//! A fast and flexible [entity component system](https://en.wikipedia.org/wiki/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`](https://crates.io/crates/serde), providing pain-free
//! serialization and deserialization of `World` containers.
//! - Inner- and outer-parallelism using [`rayon`](https://crates.io/crates/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`.
//!
//! ``` rust
//! 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](https://doc.rust-lang.org/rust-by-example/generics/new_types.html) 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`.
//!
//! ``` rust
//! # use brood::Registry;
//! #
//! # struct Position {
//! # x: f32,
//! # y: f32,
//! # }
//! #
//! # struct Velocity {
//! # x: f32,
//! # y: f32,
//! # }
//! #
//! # type Registry = Registry!(Position, Velocity);
//! #
//! 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](https://doc.rust-lang.org/cargo/reference/features.html#dependency-features) to your
//! `Cargo.toml`.
//!
//! ## serde
//! Enabling the feature flag `serde` allows [`World`]s to be serializable and deserializable using
//! the [`serde`](https://crates.io/crates/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`](https://doc.rust-lang.org/alloc/index.html) is available.
//!
//! [`Registry`]: crate::registry::Registry
extern crate alloc;
pub use Query;
pub use World;