summaryrefslogtreecommitdiff
path: root/ecs/src
diff options
context:
space:
mode:
Diffstat (limited to 'ecs/src')
-rw-r--r--ecs/src/component/storage.rs38
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());
}
}
}