diff options
author | HampusM <hampus@hampusmat.com> | 2024-08-04 17:39:07 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2024-08-04 17:39:07 +0200 |
commit | 1e2e8d585e06d51708d02162bee1a4bd16962626 (patch) | |
tree | b9b83d2c04f8a807f162dc961f94da4e635cefeb /ecs/src | |
parent | 900bc3b6c6b79f91a01a24fcda841808d13e2048 (diff) |
perf(ecs): remove clearing archetype lookup table
Diffstat (limited to 'ecs/src')
-rw-r--r-- | ecs/src/component/storage.rs | 38 |
1 files changed, 18 insertions, 20 deletions
diff --git a/ecs/src/component/storage.rs b/ecs/src/component/storage.rs index b227337..e909395 100644 --- a/ecs/src/component/storage.rs +++ b/ecs/src/component/storage.rs @@ -123,41 +123,39 @@ impl Storage pub fn make_archetype_lookup_entries(&mut self) { - // 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 ids = pending_entry.iter().filter_map(|component_metadata| { - if component_metadata.is_optional == ComponentIsOptional::Yes { - return None; - } - - Some(component_metadata.id) - }); + let pending_entry_ids_set = pending_entry + .iter() + .filter_map(|component_metadata| { + if component_metadata.is_optional == ComponentIsOptional::Yes { + return None; + } - let ids_set: HashSet<_> = ids.collect(); + Some(component_metadata.id) + }) + .collect::<HashSet<_>>(); let matching_archetype_indices = self .archetypes .iter() .enumerate() .filter_map(|(index, archetype)| { - if archetype.component_ids_is_superset(&ids_set) { + if archetype.component_ids_is_superset(&pending_entry_ids_set) { return Some(index); } None }); - let archetype_indices = self - .archetype_lookup - .entry(ArchetypeId::from_components_metadata( - pending_entry.into_iter(), - )) - .or_default(); + let archetype_id = + ArchetypeId::from_components_metadata(pending_entry.into_iter()); - archetype_indices.extend(matching_archetype_indices); + if self.archetype_lookup.contains_key(&archetype_id) { + continue; + } + + self.archetype_lookup + .insert(archetype_id, matching_archetype_indices.collect()); } } } |