diff --git a/README.md b/README.md index 276e71b..bf928ec 100644 --- a/README.md +++ b/README.md @@ -2,4 +2,44 @@ This is an experimental ECS library intended to be more compiler-friendly. Archetypes are static, and queries are checked at compile-time. -Check out [this blog post](https://nertsal.github.io/blog/so-i-wrote-my-own-ecs/) for a quick intro. +**Static compiler-checked ECS\*** + +For an introduction into the idea, see [this blogpost](https://nertsal.github.io/blog/so-i-wrote-my-own-ecs/). + +This library attempts to bridge the gap between +- compile-time guarantees, that are one of the important points of Rust; +- performance benefits of [SoA](https://en.wikipedia.org/wiki/AoS_and_SoA) (Struct of Array); +- and ease of use of ECS libraries + +*Note: technically this library likely does not qualify as a proper ECS. +What this library actually is, is a generalized SoA derive +(For an example of a non-general one, see [soa_derive](https://crates.io/crates/soa_derive) or [soa-rs](https://crates.io/crates/soa-rs/)). + +See [crate documentation](todo) for more information. + +# Example + +[See more examples here](examples/). + +```rust +#[derive(SplitFields)] +struct Player { + position: f64, + health: Option, +} + +struct World { + players: StructOf>, +} + +let mut world = World { players: Default::default() }; +world.insert(Player { + position: 1, + health: Some(5), +}); + +for (pos, health) in query!(world.players, (&position, &mut health.Get.Some)) { + println!("player at {}; health: {}", position, health); + *health -= 1; +} +``` diff --git a/src/lib.rs b/src/lib.rs index 8d64ce9..6cd9605 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -19,7 +19,7 @@ //! #[derive(SplitFields)] //! struct Player { //! position: f64, -//! health: i64, +//! health: Option, //! } //! //! struct World { @@ -29,10 +29,11 @@ //! let mut world = World { players: Default::default() }; //! world.insert(Player { //! position: 1, -//! health: 5, +//! health: Some(5), //! }); //! -//! for health in query!(world.players, (&mut health)) { +//! for (pos, health) in query!(world.players, (&position, &mut health.Get.Some)) { +//! println!("player at {}; health: {}", position, health); //! *health -= 1; //! } //! ```