From ab2fa8a93de33ccb17ee1efd6f9b8858a8b79253 Mon Sep 17 00:00:00 2001 From: HampusM Date: Fri, 10 Jan 2025 15:09:33 +0100 Subject: refactor(ecs): add struct for querying using component metadata --- ecs/src/component/storage.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'ecs/src/component/storage.rs') diff --git a/ecs/src/component/storage.rs b/ecs/src/component/storage.rs index 4b7a6b4..5ce587f 100644 --- a/ecs/src/component/storage.rs +++ b/ecs/src/component/storage.rs @@ -14,7 +14,6 @@ use crate::component::{ }; use crate::type_name::TypeName; use crate::uid::Uid; -use crate::util::Sortable; use crate::EntityComponent; #[derive(Debug, Default)] @@ -27,22 +26,21 @@ pub struct Storage impl Storage { - pub fn iter_archetypes_with_comps( + pub fn iter_archetypes_with_comps( &self, - mut comp_metadata_list: CompMetadataList, + comp_metadata: impl AsRef<[ComponentMetadata]>, ) -> ArchetypeRefIter<'_> - where - CompMetadataList: Sortable, - CompMetadataList: AsRef<[ComponentMetadata]>, { - comp_metadata_list.sort_by_key_b(|metadata| metadata.id); + debug_assert!(comp_metadata + .as_ref() + .is_sorted_by_key(|metadata| metadata.id)); - let archetype_id = ArchetypeId::from_components_metadata(&comp_metadata_list); + let archetype_id = ArchetypeId::from_components_metadata(&comp_metadata); if !self.archetype_lookup.borrow().contains_key(&archetype_id) { self.archetype_lookup.borrow_mut().insert( archetype_id, - self.create_populated_archetype_lookup_entry(comp_metadata_list.as_ref()), + self.create_populated_archetype_lookup_entry(comp_metadata.as_ref()), ); } -- cgit v1.2.3-18-g5258