Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Nertsal committed Sep 21, 2024
1 parent 6fa3283 commit bbd3e9a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
42 changes: 41 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<i64>,
}

struct World {
players: StructOf<Vec<Player>>,
}

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;
}
```
7 changes: 4 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
//! #[derive(SplitFields)]
//! struct Player {
//! position: f64,
//! health: i64,
//! health: Option<i64>,
//! }
//!
//! struct World {
Expand All @@ -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;
//! }
//! ```
Expand Down

0 comments on commit bbd3e9a

Please sign in to comment.