Expand description
ยงsimplecs
simplecs is a lightweight, zero-dependency Entity-Component System (ECS) for Rust.
It emphasizes simplicity, type-safety, and ergonomic querying.
ยงโจ Features
- โ Simple API โ no macro-heavy boilerplate
- ๐ง Type-based querying with
With<T>/Without<T> - ๐งฉ Dynamic component registration via
ComponentStorageBuilder - ๐ Uses
TypeId+Anyinternally for type-erased buckets - ๐ฆ Pure safe Rust โ great for learning ECS
ยง๐ Example
use simplecs::*;
W
struct Position(f32, f32);
impl Component for Position {}
struct Velocity(f32, f32);
impl Component for Velocity {}
// For now, you should manually inform
// how many combinations you can use in
// your queries
component_list!(A, B, C, D, E);
fn main() {
let mut storage = ComponentStorageBuilder::<u32>::new()
.with::<Position>()
.with::<Velocity>()
.build();
storage.add_component(1, Position(1.0, 2.0));
storage.add_component(1, Velocity(0.1, 0.1));
storage.add_component(2, Position(5.0, 5.0));
let moving = storage.query::<With<(Position, Velocity)>>();
assert_eq!(moving, vec![1]);
let static_entities = storage.query::<(With<Position>, Without<Velocity>)>();
assert_eq!(static_entities, vec![2]);
}ยง๐ Query API
simplecs uses type-safe static dispatch to query entities:
With<T>โ selects entities with componentsTWithout<T>โ selects entities that lackT- Combinations like
(With<A>, Without<B>)work too
Define component groups with a macro:
component_list!(A, B, C, D, E, F);Then use in queries:
let ids = storage.query::<(With<(Position, Velocity)>, Without<Health>)>();ยง๐งฑ Architecture
- Each component type has a separate
Storage<E, T> - All storages are type-erased into
dyn ComponentBucket<E> - ECS queries are resolved using sets and intersections
- Entities can be any
Copy + Eq + Hashtype (e.g.u32)
ยง๐ License
Licensed under either of:
- MIT license https://opensource.org/licenses/MIT
- Apache License, Version 2.0 https://www.apache.org/licenses/LICENSE-2.0
ยง๐ฆ Created by Buzzac
For questions, ideas, or contributions, feel free to open an issue or PR.
Want to regenerate this README from your docs?
cargo install cargo-readme
cargo readme > README.md