Crate ecmap [] [src]

Entity component system.

Using TypeIDs, no macros. Influenced by rustic-ecs but should be more memory efficient (we use one box per component only)

License: Apache2.0/MIT

Example

// A simple component.
#[derive(Debug, Clone)]
struct Sound(String);

let mut map = ecmap::ECMap::new();
// Enable debugging for the Sound component.
map.insert_component::<Sound>();

// Generate an entity ID.
let cat = map.insert_entity();
// Insert an entity component.
map.insert(cat, Sound("Meow".into()));

// Prints "ECMap {1: (Sound("Meow"))}"
println!("{:?}", map);
// Modify component
map.get_mut::<Sound>(cat).unwrap().0 = "Voof".into();

// Add another entity
let computer = map.insert_entity();
map.insert(computer, Sound("Hello world".into()));

// Access all entities that has a certain component.
for (id, sound) in map.iter_with::<Sound>() {
   println!("{} says {}!", id, sound.0);
}

// After this call, only the 'computer' entity remains. 
map.remove_entity(cat);

Structs

ECMap

Entity-Component map, implemented as a double HashMap (first over component, then over entity).

Iter

Iterator struct returned by ECMap::iter_with().

IterMut

Iterator struct returned by ECMap::iter_mut_with().