From 7be43acdaf026e4bfb81aedf6767b02cfc0ee020 Mon Sep 17 00:00:00 2001 From: HampusM Date: Fri, 29 Mar 2024 17:17:43 +0100 Subject: fix(ecs): prevent silently ignoring component if lock is occupied --- ecs/src/lib.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'ecs/src') diff --git a/ecs/src/lib.rs b/ecs/src/lib.rs index 11e67f7..df25f46 100644 --- a/ecs/src/lib.rs +++ b/ecs/src/lib.rs @@ -40,6 +40,7 @@ struct Entity #[derive(Debug)] struct EntityComponent { + id: TypeId, component: Lock>, } @@ -71,7 +72,10 @@ impl World components: components .into_vec() .into_iter() - .map(|component| EntityComponent { component: Lock::new(component) }) + .map(|component| EntityComponent { + id: (*component).type_id(), + component: Lock::new(component), + }) .collect(), }); } @@ -140,6 +144,7 @@ impl World components: components .into_iter() .map(|component| EntityComponent { + id: (*component).type_id(), component: Lock::new(component), }) .collect(), @@ -339,9 +344,7 @@ fn find_entity_with_components<'world>( let entity_components = entity .components .iter() - .filter_map(|component| { - Some(component.component.read_nonblock().ok()?.as_ref().type_id()) - }) + .map(|component| component.id) .collect::>(); if component_type_ids -- cgit v1.2.3-18-g5258