simplecs

Crates.iosimplecs
lib.rssimplecs
version0.1.2
created_at2025-06-21 22:55:30.105218+00
updated_at2025-06-22 19:06:10.404061+00
descriptionA simple entity-component system, focusing on simplicity and ergonomics.
homepage
repository
max_upload_size
id1721156
size15,167
(vinibuzzacaro)

documentation

README

simplecs

simplecs

Crates.io Documentation License: MIT OR Apache-2.0

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 + Any internally 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 {}

component_list!(Position, Velocity);

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 components T
  • Without<T> – selects entities that lack T
  • 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 + Hash type (e.g. u32)

🛠 License

Licensed under either of:


🦀 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

License: MIT OR Apache-2.0

Commit count: 0

cargo fmt