Crates.io | advancedresearch-nano_ecs |
lib.rs | advancedresearch-nano_ecs |
version | 0.9.0 |
source | src |
created_at | 2020-08-21 13:12:32.036397 |
updated_at | 2020-08-29 08:29:28.081266 |
description | A bare-bones macro-based Entity-Component-System |
homepage | https://github.com/advancedresearch/nano_ecs |
repository | https://github.com/advancedresearch/nano_ecs.git |
max_upload_size | |
id | 279185 |
size | 43,960 |
A bare-bones macro-based Entity-Component-System
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;
});
}
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.
World
.