fix: the ecs will now create all the archetypes for any combination of components that entities have on them

This commit is contained in:
lisk77 2025-05-05 13:27:49 +02:00
parent 7d351ced62
commit c1d41323f9
4 changed files with 55 additions and 12 deletions

View file

@ -20,6 +20,24 @@ impl ComponentSet {
}
}
pub fn powerset(ids: Vec<TypeId>) -> Vec<HashSet<TypeId>> {
let n = ids.len();
let mut subsets: Vec<HashSet<TypeId>> = Vec::with_capacity(1 << n);
for mask in 0..(1 << n) {
let mut subset = HashSet::new();
for i in 0..n {
if (mask & (1 << i)) != 0 {
subset.insert(ids[i].clone());
}
}
subsets.push(subset);
}
subsets.remove(0);
subsets
}
pub fn is_subset(&self, other: &ComponentSet) -> bool {
self.set.is_subset(&other.set)
}