diff options
author | HampusM <hampus@hampusmat.com> | 2024-08-10 18:50:45 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2024-08-10 20:56:39 +0200 |
commit | 93f764e1003bb6f35b56b7b91a73ae0ca80282c9 (patch) | |
tree | 1765bd3ba2e61783e3477211eb84550726e0b7d9 /ecs/src/system.rs | |
parent | b4be1c1e9a7e69a86a5aa9be6699847edc2c8d0f (diff) |
refactor(ecs): create archetype lookup entries on-the-go
Diffstat (limited to 'ecs/src/system.rs')
-rw-r--r-- | ecs/src/system.rs | 44 |
1 files changed, 1 insertions, 43 deletions
diff --git a/ecs/src/system.rs b/ecs/src/system.rs index ba5ac96..36359c7 100644 --- a/ecs/src/system.rs +++ b/ecs/src/system.rs @@ -11,7 +11,7 @@ use crate::component::{Component, FromOptional as FromOptionalComponent}; use crate::lock::WriteGuard; use crate::system::util::check_params_are_compatible; use crate::tuple::{ReduceElement as TupleReduceElement, With as TupleWith}; -use crate::{World, WorldData}; +use crate::World; pub mod stateful; @@ -24,8 +24,6 @@ pub trait System<'world, Impl>: 'static #[must_use] fn initialize(self, input: Self::Input) -> Self; - fn prepare(&self, world_data: &WorldData); - fn run<'this>(&'this self, world: &'world World) where 'this: 'world; @@ -58,13 +56,6 @@ macro_rules! impl_system { self } - fn prepare(&self, world_data: &WorldData) - { - #( - TParam~I::prepare(world_data); - )* - } - fn run<'this>(&'this self, world: &'world World) where 'this: 'world @@ -99,21 +90,6 @@ macro_rules! impl_system { me.run(world); }), - prepare: Box::new(|data, world| { - // SAFETY: The caller of TypeErased::run ensures the lifetime - // is correct - let data = unsafe { &*std::ptr::from_ref(data) }; - - let me = data - .downcast_ref::<Func>() - .expect("Function downcast failed"); - - // SAFETY: The caller of TypeErased::run ensures the lifetime - // is correct - let world = unsafe { &*std::ptr::from_ref(world) }; - - me.prepare(world); - }), } } @@ -150,7 +126,6 @@ pub struct TypeErased { data: Box<dyn Any + RefUnwindSafe + UnwindSafe>, run: Box<TypeErasedRunFn>, - prepare: Box<TypeErasedPrepareFn>, } impl TypeErased @@ -166,18 +141,6 @@ impl TypeErased (self.run)(data, world); } - - /// Prepares the system. - /// - /// # Safety - /// `world_data` must live at least as long as the [`World`] the system belongs to. - pub unsafe fn prepare(&self, world_data: &WorldData) - { - // You have to dereference for downcasting to work for some reason - let data = &*self.data; - - (self.prepare)(data, world_data); - } } impl Debug for TypeErased @@ -191,9 +154,6 @@ impl Debug for TypeErased /// Function in [`TypeErased`] used to run the system. type TypeErasedRunFn = dyn Fn(&dyn Any, &World) + RefUnwindSafe + UnwindSafe; -/// Function in [`TypeErased`] used to prepare the system. -type TypeErasedPrepareFn = dyn Fn(&dyn Any, &WorldData) + RefUnwindSafe + UnwindSafe; - /// A parameter to a [`System`]. /// /// # Safety @@ -216,8 +176,6 @@ pub unsafe trait Param<'world> fn is_compatible<Other: Param<'world>>() -> bool; fn get_comparable() -> Box<dyn Any>; - - fn prepare(_world_data: &WorldData) {} } pub struct NoInitParamFlag {} |