diff options
author | HampusM <hampus@hampusmat.com> | 2024-08-18 21:15:02 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2024-08-18 21:15:02 +0200 |
commit | adae9bb8a47071cae274886e777a51df54f27665 (patch) | |
tree | c9f9d9e53e3d00c12cd68a808445454d46f33131 /ecs/src/relationship.rs | |
parent | ad238a5b3c49ec8e12463a43db9b3a726d1a7657 (diff) |
perf(ecs): make Relation get method use entity archetype lookup
Diffstat (limited to 'ecs/src/relationship.rs')
-rw-r--r-- | ecs/src/relationship.rs | 24 |
1 files changed, 7 insertions, 17 deletions
diff --git a/ecs/src/relationship.rs b/ecs/src/relationship.rs index fa3f761..e49bde7 100644 --- a/ecs/src/relationship.rs +++ b/ecs/src/relationship.rs @@ -3,11 +3,9 @@ use std::marker::PhantomData; use crate::component::storage::Storage as ComponentStorage; use crate::component::{ - is_optional as component_is_optional, Component, FromOptional as ComponentFromOptional, Id as ComponentId, - Metadata as ComponentMetadata, }; use crate::entity::Uid as EntityUid; use crate::lock::ReadGuard; @@ -122,21 +120,13 @@ where /// Retrieves the related-to component. pub fn get(&self) -> Option<ComponentRefMut<'_, ComponentT>> { - let mut archetype_iter = - self.component_storage_lock - .find_entities([ComponentMetadata { - id: ComponentId::of::<ComponentT>(), - is_optional: component_is_optional::<ComponentT>().into(), - }]); - - let (entity, archetype) = archetype_iter.find_map(|archetype| { - let Some(entity) = archetype.get_entity(self.relationship_comp.entity_uid) - else { - return None; - }; - - Some((entity, archetype)) - })?; + let archetype = self + .component_storage_lock + .get_entity_archetype(self.relationship_comp.entity_uid)?; + + let entity = archetype + .get_entity(self.relationship_comp.entity_uid) + .expect("Entity is gone"); let component_index = archetype.get_index_for_component(&ComponentId::of::<ComponentT>())?; |