Zero_ECS - I created an ECS
Hello,
I've created an ECS, and since there are already 10+ high quality ECS crates in rust I feel I have to defend my ECS's existance :)
A few months ago I discovered rust, and I wanted to write a game to learn rust. (I used to be game developer).
I thought about how to structure the gameplay code and landed in the decision that using an ECS was the correct path.
I checked out some of the existing ECS crates and I didn't find one that was the way I wanted:
- Only use zero cost abstractions. That means no using dyn, Box, anymaps etc.
- Only use safe rust code. No unsafe code.
- Be fast, no point in using an ECS otherwise :)
- Be very user friendly, I need to be able to prototype quickly.
So I created Zero\_ECS and been working on it for a couple of weeks, it is not really done, I discover issues as I'm developing but it is in a state that I would like to show it to someone that isn't me.
So if anyone is interested here it is: Zero\_ECS Github
Define components and entities with simple Rust structs, and systems as simple rust functions:
#[component]
struct Position(f32, f32);
#[component]
struct Velocity(f32, f32);
#[entity]
struct Enemy {
position: Position,
velocity: Velocity,
}
#[system]
fn apply_velocity(world: &mut World, query: Query<(&mut Position, &Velocity)>) {
world
.with_query_mut(query)
.iter_mut()
.for_each(|(position, velocity)| {
position.0 += velocity.0;
position.1 += velocity.1;
});
}
fn main() {
let mut world = World::default();
for _ in 0..10 {
world.create(Enemy {
position: Position(0.0, 0.0),
velocity: Velocity(1.0, 1.0),
});
}
systems_main(&mut world);
}
I've tried to write detailed clear instructions here: README
Any thoughts and/or feedback is welcome :)