summaryrefslogtreecommitdiff
path: root/ecs
diff options
context:
space:
mode:
Diffstat (limited to 'ecs')
-rw-r--r--ecs/src/component.rs23
-rw-r--r--ecs/src/lib.rs3
2 files changed, 19 insertions, 7 deletions
diff --git a/ecs/src/component.rs b/ecs/src/component.rs
index 9310995..3399183 100644
--- a/ecs/src/component.rs
+++ b/ecs/src/component.rs
@@ -191,13 +191,7 @@ macro_rules! inner {
for comp in components {
#(
if comp.id == TypeId::of::<Comp~I::Component>() {
- let comp_ref = comp.component
- .write_nonblock()
- .expect(
- "Failed to acquire read-write component lock"
- );
-
- comp_~I = Some(comp_ref);
+ comp_~I = Some(lock_component(comp));
continue;
}
)*
@@ -215,3 +209,18 @@ macro_rules! inner {
seq!(C in 0..=64 {
inner!(C);
});
+
+fn lock_component(
+ entity_component: &EntityComponent,
+) -> WriteGuard<'_, Box<dyn Component>>
+{
+ entity_component
+ .component
+ .write_nonblock()
+ .unwrap_or_else(|_| {
+ panic!(
+ "Failed to acquire read-write lock to component {}",
+ entity_component.name
+ );
+ })
+}
diff --git a/ecs/src/lib.rs b/ecs/src/lib.rs
index fbcc451..0bc7aa6 100644
--- a/ecs/src/lib.rs
+++ b/ecs/src/lib.rs
@@ -48,6 +48,7 @@ struct Entity
pub struct EntityComponent
{
pub id: TypeId,
+ pub name: &'static str,
pub component: Lock<Box<dyn Component>>,
pub drop_last: bool,
}
@@ -90,6 +91,7 @@ impl World
ManuallyDrop::new(EntityComponent {
id: (*component).type_id(),
+ name: component.type_name(),
component: Lock::new(component),
drop_last,
})
@@ -187,6 +189,7 @@ impl World
ManuallyDrop::new(EntityComponent {
id: (*component).type_id(),
+ name: component.type_name(),
component: Lock::new(component),
drop_last,
})