[−][src]Crate nano_ecs
Nano-ECS
A bare-bones macro-based Entity-Component-System
- Maximum 64 components per entity
- Stores components sequentially in same array
- Masks for enabled/disabled components
use nano_ecs::*; #[derive(Clone)] pub struct Position(pub f32); #[derive(Clone)] pub struct Velocity(pub f32); ecs!{4: Position, Velocity} fn main() { let mut world = World::new(); world.push(Position(0.0)); world.push((Position(0.0), Velocity(0.0))); let dt = 1.0; system!(world, |pos: &mut Position, vel: &Velocity| { pos.0 = pos.0 + vel.0 * dt; }); }
Design
The ecs!
macro generates a World
and Component
object.
Can be used with any Rust data structure that implements Clone
.
The order of declared components is used to assign every component an index. This index is used in the mask per entity and to handle slice memory correctly.
- All components are stored in one array inside
World
. - All entities have a slice refering to components
- All entities have a mask that enable/disable components
Macros
ecs | Creates an Entity-Component-System. |
entity | Accesses a single entity. |
entity_access | Accesses an entity. |
entity_ids | Enumerates indices of entities only. |
entity_unchecked_access | Accesses an entity, but without checking active mask. |
ind | Generates |
mask_pat | Generates mask pattern based on a set of components. |
mask_pre | Used internally by other macros. |
push | Generates |
push_impl | Calls |
system | Declares and executes a system. |
system_ids | Same as |
tup_count | Helper macro for counting size of a tuple. |
Structs
MaskStorage | Stores masks efficiently and allows fast iteration. |
Traits
Get | Gets a component type |
Ind | The index of a component type |
Push | Creates a new entity from a set of components. |