ecs-tiny

Crates.ioecs-tiny
lib.rsecs-tiny
version0.3.0
sourcesrc
created_at2024-05-16 13:33:56.634653
updated_at2024-06-29 11:14:44.477211
descriptionA minimal ECS supporting entity and component insertion/removal, association, and single-type iteration.
homepage
repositoryhttps://github.com/GossiperLoturot/ecs-tiny
max_upload_size
id1242071
size29,485
Takumi Sugimoto (GossiperLoturot)

documentation

README

ecs-tiny

crates.io doc.rs

A minimal ECS supporting entity and component insertion/removal, association, and single-type iteration.

Usages

// Create new ecs instance and inserts new entity:

let mut ecs = ecs_tiny::ECS::new();

let entity_key0 = ecs.insert_entity();
let entity_key1 = ecs.insert_entity();

// Register new component type:

ecs.register::<i32>().unwrap();
ecs.register::<()>().unwrap();

// Inserts new component associated with specified entity:

let comp_key0 = ecs.insert_comp(entity_key0, 42).unwrap();
let comp_key1 = ecs.insert_comp(entity_key0, 63).unwrap();
let comp_key2 = ecs.insert_comp(entity_key1, 42).unwrap();
let comp_key3 = ecs.insert_comp(entity_key1, ()).unwrap();

// Iterates over all components associated with specified entity:

for comp in ecs.iter_comp_mut_by_entity::<i32>(entity_key0).unwrap() {
    *comp += 1;
}

// Iterates over all components of specified type (single type only):

for comp in ecs.iter_comp_mut::<i32>().unwrap() {
    *comp += 1;
}

// Removes specified component:

ecs.remove_comp::<i32>(comp_key0).unwrap();

// Removes specified entity:

ecs.remove_entity(entity_key1).unwrap();
Commit count: 18

cargo fmt