diff options
author | HampusM <hampus@hampusmat.com> | 2024-06-29 18:41:04 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2024-06-29 18:41:04 +0200 |
commit | 93f9f840da11b82c8a13f31f0ba5db8b10e4e9ad (patch) | |
tree | f92798d7c1efcaa1b4e8d44215c7e3459f349498 /ecs/src/system.rs | |
parent | 4793e4411d98d97f879023dc072f3847201d49da (diff) |
refactor(ecs): pass World ref to system run & param new functions
Diffstat (limited to 'ecs/src/system.rs')
-rw-r--r-- | ecs/src/system.rs | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/ecs/src/system.rs b/ecs/src/system.rs index 57b0756..aaf09fb 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::WorldData; +use crate::{World, WorldData}; pub mod stateful; @@ -26,7 +26,7 @@ pub trait System<'world, Impl>: 'static fn prepare(&self, world_data: &WorldData); - fn run<'this>(&'this self, world_data: &'world WorldData) + fn run<'this>(&'this self, world: &'world World) where 'this: 'world; @@ -65,7 +65,7 @@ macro_rules! impl_system { )* } - fn run<'this>(&'this self, world_data: &'world WorldData) + fn run<'this>(&'this self, world: &'world World) where 'this: 'world { @@ -76,7 +76,7 @@ macro_rules! impl_system { let func = *self; func(#({ - TParam~I::new(self, world_data) + TParam~I::new(self, world) },)*); } @@ -84,7 +84,7 @@ macro_rules! impl_system { { TypeErased { data: Box::new(self), - run: Box::new(|data, world_data| { + run: Box::new(|data, world| { // SAFETY: The caller of TypeErased::run ensures the lifetime // is correct let data = unsafe { &*std::ptr::from_ref(data) }; @@ -95,11 +95,11 @@ macro_rules! impl_system { // SAFETY: The caller of TypeErased::run ensures the lifetime // is correct - let world_data = unsafe { &*std::ptr::from_ref(world_data) }; + let world = unsafe { &*std::ptr::from_ref(world) }; - me.run(world_data); + me.run(world); }), - prepare: Box::new(|data, world_data| { + prepare: Box::new(|data, world| { // SAFETY: The caller of TypeErased::run ensures the lifetime // is correct let data = unsafe { &*std::ptr::from_ref(data) }; @@ -110,9 +110,9 @@ macro_rules! impl_system { // SAFETY: The caller of TypeErased::run ensures the lifetime // is correct - let world_data = unsafe { &*std::ptr::from_ref(world_data) }; + let world = unsafe { &*std::ptr::from_ref(world) }; - me.prepare(world_data); + me.prepare(world); }), } } @@ -159,12 +159,12 @@ impl TypeErased /// /// # Safety /// `world_data` must live at least as long as the [`World`] the system belongs to. - pub unsafe fn run(&self, world_data: &WorldData) + pub unsafe fn run(&self, world: &World) { // You have to dereference for downcasting to work for some reason let data = &*self.data; - (self.run)(data, world_data); + (self.run)(data, world); } /// Prepares the system. @@ -189,7 +189,7 @@ impl Debug for TypeErased } /// Function in [`TypeErased`] used to run the system. -type TypeErasedRunFn = dyn Fn(&dyn Any, &WorldData) + RefUnwindSafe + UnwindSafe; +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; @@ -210,7 +210,7 @@ pub unsafe trait Param<'world> fn new<SystemImpl>( system: &'world impl System<'world, SystemImpl>, - world_data: &'world WorldData, + world: &'world World, ) -> Self; fn is_compatible<Other: Param<'world>>() -> bool; |