summaryrefslogtreecommitdiff
path: root/ecs/src/lib.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2024-03-29 17:17:43 +0100
committerHampusM <hampus@hampusmat.com>2024-03-29 17:17:43 +0100
commit7be43acdaf026e4bfb81aedf6767b02cfc0ee020 (patch)
tree4125a201e67c0cac66354a7f1d724e2b2c4cb0df /ecs/src/lib.rs
parentec57daa9ef43eafea82769cee348da4dab192f16 (diff)
fix(ecs): prevent silently ignoring component if lock is occupied
Diffstat (limited to 'ecs/src/lib.rs')
-rw-r--r--ecs/src/lib.rs11
1 files changed, 7 insertions, 4 deletions
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<Box<dyn Component>>,
}
@@ -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::<HashSet<_>>();
if component_type_ids