1 unstable release
0.1.0 | Mar 15, 2023 |
---|
#65 in #foo
26KB
593 lines
Tombstone
My attempt at making ECS in rust.
Installation
[dependencies]
tombstone = "0.1"
Usage
See crate docs or example.
lib.rs
:
Tombstone
My attempt at making ECS in rust.
#
#
fn main() {
let mut w = World::new();
w.spawn().add(Foo::new(1, 3.6));
w.spawn().add(Foo::new(2, 5.2));
let mut ex = Executor::new();
ex.register(system);
let mut sum = 0.;
for i in 1..=5 {
println!("Iter{i}:");
ex.run_with_state(&mut w, &mut sum);
}
assert_eq!(sum, (3.6 + 5.2) * 5.);
}
fn system(mut q: Query<(Foo,), f32>) {
for &id in q.ids() {
let (foo,) = q.select_mut(id);
println!("Entity{id}: ({}, {})", foo.a, foo.b);
foo.a += 1;
*q.state() += foo.b;
}
}
Dependencies
~425KB