diff options
author | HampusM <hampus@hampusmat.com> | 2024-03-06 00:23:07 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2024-03-06 00:23:07 +0100 |
commit | dba19db5f649f73a5abb1bc3589580721a9a4e32 (patch) | |
tree | 7fe133d807a834919c983ce1e6535b920a46b4bb /ecs/src/system.rs | |
parent | e246f90bc33fd489e300366e30354e34a05b8107 (diff) |
refactor(ecs): pass around all world data and not component storage
Diffstat (limited to 'ecs/src/system.rs')
-rw-r--r-- | ecs/src/system.rs | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/ecs/src/system.rs b/ecs/src/system.rs index a49edda..96f0254 100644 --- a/ecs/src/system.rs +++ b/ecs/src/system.rs @@ -8,7 +8,7 @@ use seq_macro::seq; use crate::component::Component; use crate::system::util::check_params_are_compatible; use crate::tuple::{FilterElement as TupleFilterElement, With as TupleWith}; -use crate::ComponentStorage; +use crate::WorldData; pub mod stateful; @@ -21,7 +21,7 @@ pub trait System<Impl>: 'static #[must_use] fn initialize(self, input: Self::Input) -> Self; - fn run(&mut self, component_storage: &mut ComponentStorage); + fn run(&mut self, world_data: &mut WorldData); fn into_type_erased(self) -> TypeErased; @@ -51,7 +51,7 @@ macro_rules! impl_system { self } - fn run(&mut self, component_storage: &mut ComponentStorage) + fn run(&mut self, world_data: &mut WorldData) { #( check_params_are_compatible!(I, TParam~I, $c); @@ -66,11 +66,11 @@ macro_rules! impl_system { }; // SAFETY: All parameters are compatible so this is fine - let component_storage = unsafe { - &mut *addr_of_mut!(*component_storage) + let world_data = unsafe { + &mut *addr_of_mut!(*world_data) }; - TParam~I::new(this, component_storage) + TParam~I::new(this, world_data) },)*); } @@ -78,10 +78,10 @@ macro_rules! impl_system { { TypeErased { data: Box::new(self), - func: Box::new(|data, component_storage| { + func: Box::new(|data, world_data| { let me = data.downcast_mut::<Func>().unwrap(); - me.run(component_storage); + me.run(world_data); }), } } @@ -123,9 +123,9 @@ pub struct TypeErased impl TypeErased { - pub fn run(&mut self, component_storage: &mut ComponentStorage) + pub fn run(&mut self, world_data: &mut WorldData) { - (self.func)(self.data.as_mut(), component_storage); + (self.func)(self.data.as_mut(), world_data); } } @@ -138,7 +138,7 @@ impl Debug for TypeErased } /// Function in [`TypeErased`] used to run the system. -type TypeErasedFunc = dyn Fn(&mut dyn Any, &mut ComponentStorage); +type TypeErasedFunc = dyn Fn(&mut dyn Any, &mut WorldData); /// A parameter to a [`System`]. /// @@ -153,7 +153,7 @@ pub unsafe trait Param<'world> fn new<SystemImpl>( system: &'world mut impl System<SystemImpl>, - component_storage: &'world mut ComponentStorage, + world_data: &'world mut WorldData, ) -> Self; fn is_compatible<Other: Param<'world>>() -> bool; |