The intention of this crate is that a basic ECS is provided, where
you will be required to exercise a little additional control. This is
somewhat due to some limitations, and also due to trying to maintain
as little overhead as possible - this means no unneccesary copies/clones.

Where most other ECS crates provide a mechanism for inserting "systems"
in to the ECS to run against entities, this one leaves it out - you can
think of it as a "system for entity/components". You will need to create
external systems; these can be a function, a loop, or anything else.

The basis of this ECS is the use of bitmasks. Each entity ID is in
practice an internal index number in to an array which contains bitmasks.
The bitmasks themselves keep track of what components the entity has.
For the most part, bitmasks are handled for you, and some helper methods
are available to hide their use, but there are also methods to get the
bitmask for any ID if you are inclined to do some manual management.

// To get access to a part belonging to an entity you need// first to get the partmap created for the part type// You need to 'anchor' this with a let or the ref is// dropped before you can use itletmutpartmap=entities.get_map_mut::<Vector3>()
.expect("No part found for entity");
// You can then use the part by getting a referenceletmutpart=partmap.get_part_mut(entity_1).unwrap();
assert_eq!(part.z, -12);

// You can check if an entity contains a part with the type signatureifentities.entity_contains::<Vector1>(entity_1) {
assert!(entities.rm_part::<Vector1>(entity_1));
}
assert_eq!(entities.entity_contains::<Vector1>(entity_1), false);

usestd::cell::RefMut;
// Make a system of some form that takes a `PartMap<T>` argfnsome_system(mutpartmap: &mutPartMap<Vector1>) {
// You can then iterate over the parts directlyfor (k, v) inpartmap.iter_mut() {
v.x+=1;
assert!(v.x>*kasi32);
}
}
some_system(&mutpartmap);

// Or a system handles the `Entities` container directlyfnother_system(active_ents: &[u32], entities: &mutEntities) {
// You can mutably borrow multiple part types at onceletmutv1_partmap=entities.get_map_mut::<Vector1>()
.expect("No part found for entity");
letmutv2_partmap=entities.get_map_mut::<Vector2>()
.expect("No part found for entity");
// But not have a mutable borrow and immutable borrow to the same// Fails at runtime!// let v2_partmap = entities.get_map_ref::<Vector2>().unwrap();// But you can have multiple immutable references to the same partforidinactive_ents {
ifentities.entity_contains::<Vector1>(*id) &&entities.entity_contains::<Vector2>(*id) {
letv1_part=v1_partmap.get_part_mut(*id).unwrap();
letv2_part=v2_partmap.get_part_mut(*id).unwrap();
v1_part.x=42;
assert_ne!(v1_part.x, 43);
assert_eq!(v1_part.x, 42);
}
}
}
other_system(&[0, 1, 2], &mutentities);