From 93f9f840da11b82c8a13f31f0ba5db8b10e4e9ad Mon Sep 17 00:00:00 2001 From: HampusM Date: Sat, 29 Jun 2024 18:41:04 +0200 Subject: refactor(ecs): pass World ref to system run & param new functions --- ecs/src/system.rs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'ecs/src/system.rs') 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( system: &'world impl System<'world, SystemImpl>, - world_data: &'world WorldData, + world: &'world World, ) -> Self; fn is_compatible>() -> bool; -- cgit v1.2.3-18-g5258