From 61ce6ce0a603384b07ede2d149f6ec0542a2d03e Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 16 Jun 2024 19:30:27 +0200 Subject: fix(ecs): update archetype lookups when entity is spawned with Actions --- ecs/src/component/storage.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'ecs/src/component') diff --git a/ecs/src/component/storage.rs b/ecs/src/component/storage.rs index 237dd73..86f28fc 100644 --- a/ecs/src/component/storage.rs +++ b/ecs/src/component/storage.rs @@ -131,9 +131,13 @@ impl ComponentStorage pub fn make_archetype_lookup_entries(&mut self) { - for pending_entry in &self.pending_archetype_lookup_entries { + // TODO: Re-doing the whole archetype lookup table is dumb and slow. Only re-do + // the archetype lookup entries that need to be changed + self.archetype_lookup.clear(); + + for pending_entry in self.pending_archetype_lookup_entries.drain(..) { let components_set: HashSet<_> = pending_entry - .into_iter() + .iter() .map(|component_id| *component_id) .collect(); @@ -151,9 +155,7 @@ impl ComponentStorage let archetype_indices = self .archetype_lookup - .entry(ArchetypeComponentsHash::new( - pending_entry.into_iter().copied().clone(), - )) + .entry(ArchetypeComponentsHash::new(pending_entry.into_iter())) .or_default(); archetype_indices.extend(matching_archetype_indices); -- cgit v1.2.3-18-g5258