summaryrefslogtreecommitdiff
path: root/ecs/src/system
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2024-03-29 14:20:21 +0100
committerHampusM <hampus@hampusmat.com>2024-03-29 14:20:21 +0100
commit61dfcf1ba2049bf0375821652e49b0e4c4147623 (patch)
tree3eaa2624523c893cb12b08595c4dd9e5250728c4 /ecs/src/system
parent96ba84e42c77147d297b358c944a48fee3785ae1 (diff)
feat(ecs): make World unwind safe
Diffstat (limited to 'ecs/src/system')
-rw-r--r--ecs/src/system/stateful.rs17
1 files changed, 8 insertions, 9 deletions
diff --git a/ecs/src/system/stateful.rs b/ecs/src/system/stateful.rs
index 7ce87fa..8d56a13 100644
--- a/ecs/src/system/stateful.rs
+++ b/ecs/src/system/stateful.rs
@@ -1,10 +1,11 @@
use std::any::{type_name, Any, TypeId};
-use std::cell::{RefCell, RefMut};
use std::collections::HashMap;
+use std::panic::{RefUnwindSafe, UnwindSafe};
use seq_macro::seq;
use crate::component::Component;
+use crate::lock::Lock;
use crate::system::util::check_params_are_compatible;
use crate::system::{ComponentRefMut, Into as IntoSystem, Param, System, TypeErased};
use crate::tuple::{
@@ -20,7 +21,7 @@ use crate::WorldData;
pub struct Stateful<Func>
{
func: Func,
- local_components: HashMap<TypeId, RefCell<Box<dyn Component>>>,
+ local_components: HashMap<TypeId, Lock<Box<dyn Component>>>,
}
macro_rules! impl_system {
@@ -29,7 +30,7 @@ macro_rules! impl_system {
impl<'world, Func, #(TParam~I,)*> System<'world, fn(&'world (), #(TParam~I,)*)>
for Stateful<Func>
where
- Func: Fn(#(TParam~I,)*) + Copy + 'static,
+ Func: Fn(#(TParam~I,)*) + Copy + RefUnwindSafe + UnwindSafe + 'static,
#(TParam~I: Param<'world>,)*
#(TParam~I::Input: 'static,)*
(#(TParam~I::Input,)*): TupleFilter,
@@ -119,12 +120,10 @@ macro_rules! impl_system {
{
let local_component = self.local_components
.get(&TypeId::of::<LocalComponent>())?
- .borrow_mut();
+ .write_nonblock()
+ .expect("Failed to aquire read-write local component lock");
- Some(ComponentRefMut::new(RefMut::filter_map(
- local_component,
- |local_component| local_component.downcast_mut()
- ).ok()?))
+ Some(ComponentRefMut::new(local_component))
}
fn set_local_component<LocalComponent: Component>(
@@ -135,7 +134,7 @@ macro_rules! impl_system {
self.local_components
.insert(
TypeId::of::<LocalComponent>(),
- RefCell::new(Box::new(local_component))
+ Lock::new(Box::new(local_component))
);
}
}