Skip to main content

Crate cheecs

Crate cheecs 

Source
Expand description

cheecs is a small, dependency-free Entity Component System (ECS) built on sparse-set storage.

§Quick start

use cheecs::prelude::*;

struct Position { x: f32, y: f32 }
struct Velocity { dx: f32, dy: f32 }

let mut world = World::default();

let entity = world.spawn();
world.add_component(entity, Position { x: 0.0, y: 0.0 }).unwrap();
world.add_component(entity, Velocity { dx: 1.0, dy: 0.0 }).unwrap();

for (pos, vel) in world.query::<(&Position, &Velocity)>() {
    let _ = (pos, vel);
}

§Design

Every component type gets its own sparse_set keyed by Entity, rather than grouping entities into archetypes. This keeps add_component / remove_component cheap (they only touch one sparse set) at the cost of some indirection when iterating queries over many component types at once. See the crate README for a longer comparison with archetype-based ECS designs.

Entities are Entity handles carrying a generation counter, so a stale handle to a despawned entity is rejected rather than silently aliasing a reused slot.

Re-exports§

pub use prelude::*;

Modules§

entity
Entity identifiers.
error
Error types returned by fallible World operations.
prelude
Convenience re-export of the crate’s public API.
world

Macros§

generate_query_data
impl_query_data
min_entities