summaryrefslogtreecommitdiff
path: root/ecs/src/system.rs
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.rs
parent96ba84e42c77147d297b358c944a48fee3785ae1 (diff)
feat(ecs): make World unwind safe
Diffstat (limited to 'ecs/src/system.rs')
-rw-r--r--ecs/src/system.rs21
1 files changed, 12 insertions, 9 deletions
diff --git a/ecs/src/system.rs b/ecs/src/system.rs
index 76db2b5..3440a57 100644
--- a/ecs/src/system.rs
+++ b/ecs/src/system.rs
@@ -1,13 +1,15 @@
use std::any::Any;
-use std::cell::RefMut;
use std::convert::Infallible;
use std::fmt::Debug;
+use std::marker::PhantomData;
use std::ops::{Deref, DerefMut};
+use std::panic::{RefUnwindSafe, UnwindSafe};
use std::ptr::addr_of;
use seq_macro::seq;
use crate::component::Component;
+use crate::lock::WriteGuard;
use crate::system::util::check_params_are_compatible;
use crate::tuple::{FilterElement as TupleFilterElement, With as TupleWith};
use crate::WorldData;
@@ -45,7 +47,7 @@ macro_rules! impl_system {
impl<'world, Func, #(TParam~I,)*> System<'world, fn(#(TParam~I,)*)>
for Func
where
- Func: Fn(#(TParam~I,)*) + Copy + 'static,
+ Func: Fn(#(TParam~I,)*) + Copy + RefUnwindSafe + UnwindSafe + 'static,
#(TParam~I: Param<'world, Flags = NoInitParamFlag>,)*
{
type Input = Infallible;
@@ -125,7 +127,7 @@ pub trait Into<Impl>
pub struct TypeErased
{
- data: Box<dyn Any>,
+ data: Box<dyn Any + RefUnwindSafe + UnwindSafe>,
func: Box<TypeErasedFunc>,
}
@@ -153,7 +155,7 @@ impl Debug for TypeErased
}
/// Function in [`TypeErased`] used to run the system.
-type TypeErasedFunc = dyn Fn(&dyn Any, &WorldData);
+type TypeErasedFunc = dyn Fn(&dyn Any, &WorldData) + RefUnwindSafe + UnwindSafe;
/// A parameter to a [`System`].
///
@@ -194,14 +196,15 @@ where
#[derive(Debug)]
pub struct ComponentRefMut<'a, ComponentT: Component>
{
- inner: RefMut<'a, ComponentT>,
+ inner: WriteGuard<'a, Box<dyn Component>>,
+ _ph: PhantomData<ComponentT>,
}
impl<'a, ComponentT: Component> ComponentRefMut<'a, ComponentT>
{
- pub(crate) fn new(inner: RefMut<'a, ComponentT>) -> Self
+ pub(crate) fn new(inner: WriteGuard<'a, Box<dyn Component>>) -> Self
{
- Self { inner }
+ Self { inner, _ph: PhantomData }
}
}
@@ -211,7 +214,7 @@ impl<'a, ComponentT: Component> Deref for ComponentRefMut<'a, ComponentT>
fn deref(&self) -> &Self::Target
{
- &self.inner
+ self.inner.downcast_ref().unwrap()
}
}
@@ -219,6 +222,6 @@ impl<'a, ComponentT: Component> DerefMut for ComponentRefMut<'a, ComponentT>
{
fn deref_mut(&mut self) -> &mut Self::Target
{
- &mut self.inner
+ self.inner.downcast_mut().unwrap()
}
}