diff options
| author | HampusM <hampus@hampusmat.com> | 2024-05-24 19:15:23 +0200 | 
|---|---|---|
| committer | HampusM <hampus@hampusmat.com> | 2024-05-24 19:15:23 +0200 | 
| commit | 8af5413b0fd2b06f71098c1230f79b3e6beb037d (patch) | |
| tree | e1a3000c19b4e568890b2a0d246334f8debfe0c8 /ecs/src/component.rs | |
| parent | b8417d20765755cfa2cecacb11c77e3abbafd546 (diff) | |
feat(ecs): add component name to component locking panic message
Diffstat (limited to 'ecs/src/component.rs')
| -rw-r--r-- | ecs/src/component.rs | 23 | 
1 files changed, 16 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 +            ); +        }) +} | 
