diff options
Diffstat (limited to 'ecs/src/component')
-rw-r--r-- | ecs/src/component/storage.rs | 37 |
1 files changed, 15 insertions, 22 deletions
diff --git a/ecs/src/component/storage.rs b/ecs/src/component/storage.rs index 1bb7fb5..00ba330 100644 --- a/ecs/src/component/storage.rs +++ b/ecs/src/component/storage.rs @@ -38,12 +38,12 @@ impl Storage components_metadata.sort_by_key_b(|component_metadata| component_metadata.id); let archetype_id = ArchetypeId::from_components_metadata( - components_metadata.borrow().into_iter().cloned(), + components_metadata.borrow().iter().cloned(), ); // This looks stupid but the borrow checker complains otherwise if self.archetype_lookup.borrow().contains_key(&archetype_id) { - return self.iter_archetypes_by_lookup(&archetype_id); + return self.iter_archetypes_by_lookup(archetype_id); } let comp_ids_set = create_non_opt_component_id_set(components_metadata.borrow()); @@ -69,7 +69,7 @@ impl Storage }, ); - self.iter_archetypes_by_lookup(&archetype_id) + self.iter_archetypes_by_lookup(archetype_id) } pub fn get_entity_archetype(&self, entity_uid: EntityUid) -> Option<&Archetype> @@ -150,8 +150,7 @@ impl Storage let contains_component_already = components .iter() - .find(|component| archetype.component_ids.contains_key(&component.id())) - .is_some(); + .any(|component| archetype.component_ids.contains_key(&component.id())); if contains_component_already { let component_cnt = components.len(); @@ -162,8 +161,7 @@ impl Storage entity_uid, components .iter() - .map(|component| [component.type_name(), ", "]) - .flatten() + .flat_map(|component| [component.type_name(), ", "]) .enumerate() .take_while(|(index, _)| { *index < (component_cnt * 2) - 1 }) .map(|(_, component)| component) @@ -179,7 +177,7 @@ impl Storage .components .into_iter() .map(|component| component.component.into_inner()) - .chain(components.into_iter().map(|component| component.into())) + .chain(components) .collect(), ); @@ -234,7 +232,7 @@ impl Storage continue; } - if lookup_entry.component_ids.is_subset(&comp_ids_set) { + if lookup_entry.component_ids.is_subset(comp_ids_set) { lookup_entry.archetype_indices.push(archetype_index); } } @@ -293,13 +291,11 @@ impl Storage archetype.has_entity(entity_uid) }) - .map(|archetype_index| *archetype_index) + .copied() } - fn iter_archetypes_by_lookup( - &self, - archetype_id: &ArchetypeId, - ) -> ArchetypeRefIter<'_> + fn iter_archetypes_by_lookup(&self, archetype_id: ArchetypeId) + -> ArchetypeRefIter<'_> { let archetype_lookup = self.archetype_lookup.borrow(); @@ -307,15 +303,15 @@ impl Storage // iterations are nested. The panic happens because the archetype_lookup RefCell // is borrowed and it tries to mutably borrow it let archetype_indices = archetype_lookup - .get(archetype_id) + .get(&archetype_id) .unwrap() .archetype_indices .clone(); - return ArchetypeRefIter { + ArchetypeRefIter { indices: archetype_indices.into_iter(), archetypes: &self.archetypes, - }; + } } } @@ -396,10 +392,7 @@ impl Archetype { self.entities.push(ArchetypeEntity { uid: entity_uid, - components: components - .into_iter() - .map(|component| component.into()) - .collect(), + components: components.into_iter().map(Into::into).collect(), }); } @@ -488,7 +481,7 @@ impl<'archetype> Iterator for EntityIter<'archetype> } } -fn create_non_opt_component_id_set<'a, Item>( +fn create_non_opt_component_id_set<Item>( component_metadata_iter: impl IntoIterator<Item = Item>, ) -> HashSet<ComponentId> where |