refactor(ecs): another small speedup for archetypes

This commit is contained in:
lisk77 2025-11-26 00:38:07 +01:00
parent 64bf88c229
commit 053f1f48da

View file

@ -357,18 +357,25 @@ impl Scene {
return; return;
} }
let entities = self.get_entities_with(vec![C::type_id(), K::type_id()]); let required = ComponentSet::from_ids(vec![C::type_id(), K::type_id()]);
for entity in entities { let (c_set, k_set) = self
let (c_set, k_set) = self .components
.components .get_two_mut(&C::type_id(), &K::type_id());
.get_two_mut(&C::type_id(), &K::type_id());
let idx = entity.index as usize; if let (Some(c_store), Some(k_store)) = (c_set, k_set) {
let c_opt = c_set.and_then(|set| set.get_mut::<C>(idx)); for archetype_set in self.archetypes.component_sets() {
let k_opt = k_set.and_then(|set| set.get_mut::<K>(idx)); if required.is_subset(archetype_set) {
if let Some(entities) = self.archetypes.get_archetype(archetype_set) {
if let (Some(c), Some(k)) = (c_opt, k_opt) { for &idx in entities {
func(c, k); let idx = idx as usize;
if let (Some(c), Some(k)) =
(c_store.get_mut::<C>(idx), k_store.get_mut::<K>(idx))
{
func(c, k);
}
}
}
}
} }
} }
} }