Crates.io | stecs |
lib.rs | stecs |
version | 0.1.1 |
source | src |
created_at | 2024-09-22 12:49:58.9651 |
updated_at | 2024-09-22 13:12:14.362872 |
description | Experimental static compiler-checked ECS library |
homepage | https://github.com/Nertsal/stecs |
repository | https://github.com/Nertsal/stecs |
max_upload_size | |
id | 1382939 |
size | 62,692 |
This is an experimental ECS library intended to be more compiler-friendly. Archetypes are static, and queries are checked at compile-time. For an introduction into the idea, see this blogpost.
This library attempts to bridge the gap between
*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 or soa-rs).
This library contains and also generates snippets of unsafe code to support mutable querying. It could be avoided by using lending iterators, but they are much less convenient to use in for-loops. However, if possible, the goal is for the library to contain no unsafe code.
See crate documentation for more information. And see Horns of Combustion for an example of a game using this library.
use stecs::prelude::*;
#[derive(SplitFields)]
struct Player {
position: f64,
health: Option<i64>,
}
struct World {
players: StructOf<Vec<Player>>,
}
fn main() {
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;
}
}
gecs
provides similar functionality with static archetypes and checked queries. It has a more conventional to ECS layout, where all archetypes get queried at the same time.