From c9a07ff61b607478e264fc0581076643c750fe98 Mon Sep 17 00:00:00 2001 From: HampusM Date: Sat, 16 Nov 2024 17:14:20 +0100 Subject: refactor(ecs): remove system param compatability checking --- ecs/src/actions.rs | 15 -------------- ecs/src/component/local.rs | 18 ----------------- ecs/src/query.rs | 49 +--------------------------------------------- ecs/src/sole.rs | 24 +---------------------- ecs/src/system.rs | 14 ------------- ecs/src/system/stateful.rs | 5 ----- ecs/src/system/util.rs | 16 --------------- 7 files changed, 2 insertions(+), 139 deletions(-) delete mode 100644 ecs/src/system/util.rs (limited to 'ecs/src') diff --git a/ecs/src/actions.rs b/ecs/src/actions.rs index 72cc95d..f7b00d3 100644 --- a/ecs/src/actions.rs +++ b/ecs/src/actions.rs @@ -1,4 +1,3 @@ -use std::any::Any; use std::marker::PhantomData; use std::sync::{Arc, Weak}; @@ -95,18 +94,6 @@ unsafe impl<'world> SystemParam<'world> for Actions<'world> { Self::new(&world.data.action_queue) } - - fn is_compatible>() -> bool - { - let other_comparable = Other::get_comparable(); - - other_comparable.downcast_ref::().is_none() - } - - fn get_comparable() -> Box - { - Box::new(()) - } } #[derive(Debug, Clone)] @@ -157,5 +144,3 @@ pub(crate) enum Action RemoveComponents(Uid, Vec), Stop, } - -struct Comparable; diff --git a/ecs/src/component/local.rs b/ecs/src/component/local.rs index 9d32d47..20627bf 100644 --- a/ecs/src/component/local.rs +++ b/ecs/src/component/local.rs @@ -1,8 +1,6 @@ -use std::any::Any; use std::ops::{Deref, DerefMut}; use crate::component::Component; -use crate::uid::Uid; use crate::system::{ComponentRefMut, Param as SystemParam, System}; use crate::World; @@ -39,22 +37,6 @@ where Self { local_component } } - - fn is_compatible>() -> bool - { - let other_comparable = Other::get_comparable(); - - let Some(other_id) = other_comparable.downcast_ref::() else { - return true; - }; - - LocalComponent::id() != *other_id - } - - fn get_comparable() -> Box - { - Box::new(LocalComponent::id()) - } } impl<'world, LocalComponent> Deref for Local<'world, LocalComponent> diff --git a/ecs/src/query.rs b/ecs/src/query.rs index 69bb35d..253398d 100644 --- a/ecs/src/query.rs +++ b/ecs/src/query.rs @@ -1,5 +1,3 @@ -use std::any::Any; -use std::collections::HashSet; use std::iter::{Filter, Flatten, Map}; use std::marker::PhantomData; @@ -10,11 +8,7 @@ use crate::component::storage::{ EntityIter, Storage as ComponentStorage, }; -use crate::component::{ - Component, - Metadata as ComponentMetadata, - Sequence as ComponentSequence, -}; +use crate::component::{Component, Sequence as ComponentSequence}; use crate::lock::{ReadGuard, WriteGuard}; use crate::query::options::Options; use crate::system::{ @@ -149,24 +143,6 @@ where { Self::new(world) } - - fn is_compatible>() -> bool - { - let other_comparable = Other::get_comparable(); - - let Some(other_query_component_ids) = - other_comparable.downcast_ref::() - else { - return true; - }; - - !other_query_component_ids.contains_component_in::() - } - - fn get_comparable() -> Box - { - Box::new(QueryComponentIds { component_ids: Comps::metadata() }) - } } type ComponentIterMapFn = for<'a> fn(&'a Archetype) -> EntityIter<'a>; @@ -259,26 +235,3 @@ fn lock_component_ro( ); }) } - -#[derive(Debug)] -struct QueryComponentIds -{ - component_ids: Vec, -} - -impl QueryComponentIds -{ - fn contains_component_in(&self) -> bool - where - OtherComps: ComponentSequence, - { - let other_ids = OtherComps::metadata() - .into_iter() - .map(|component_metadata| component_metadata.id) - .collect::>(); - - self.component_ids - .iter() - .all(|component_metadata| other_ids.contains(&component_metadata.id)) - } -} diff --git a/ecs/src/sole.rs b/ecs/src/sole.rs index 4a4f3af..084a06b 100644 --- a/ecs/src/sole.rs +++ b/ecs/src/sole.rs @@ -1,4 +1,4 @@ -use std::any::{type_name, Any, TypeId}; +use std::any::{type_name, Any}; use std::fmt::Debug; use std::marker::PhantomData; use std::ops::{Deref, DerefMut}; @@ -113,23 +113,6 @@ where Self::new(sole) } - - fn is_compatible>() -> bool - { - let other_comparable = Other::get_comparable(); - - let Some(comparable) = other_comparable.downcast_ref::() else { - // The other system param is not Single - return true; - }; - - TypeId::of::() != comparable.sole_type_id - } - - fn get_comparable() -> Box - { - Box::new(Comparable { sole_type_id: TypeId::of::() }) - } } impl<'world, SoleT> Deref for Single<'world, SoleT> @@ -201,8 +184,3 @@ where Single::new(&self.sole) } } - -struct Comparable -{ - sole_type_id: TypeId, -} diff --git a/ecs/src/system.rs b/ecs/src/system.rs index afb5aac..046d25b 100644 --- a/ecs/src/system.rs +++ b/ecs/src/system.rs @@ -13,14 +13,11 @@ use crate::component::{ FromOptionalMut as FromOptionalMutComponent, }; use crate::lock::{ReadGuard, WriteGuard}; -use crate::system::util::check_params_are_compatible; use crate::tuple::{ReduceElement as TupleReduceElement, With as TupleWith}; use crate::World; pub mod stateful; -mod util; - pub trait System<'world, Impl>: 'static { type Input; @@ -64,10 +61,6 @@ macro_rules! impl_system { where 'this: 'world { - #( - check_params_are_compatible!(I, TParam~I, $c); - )* - let func = *self; func(#({ @@ -159,9 +152,6 @@ impl Debug for TypeErased type TypeErasedRunFn = dyn Fn(&dyn Any, &World) + RefUnwindSafe + UnwindSafe; /// A parameter to a [`System`]. -/// -/// # Safety -/// The `is_compatible` function is used for safety so it must be implemented properly. pub unsafe trait Param<'world> { type Input; @@ -176,10 +166,6 @@ pub unsafe trait Param<'world> system: &'world impl System<'world, SystemImpl>, world: &'world World, ) -> Self; - - fn is_compatible>() -> bool; - - fn get_comparable() -> Box; } pub struct NoInitParamFlag {} diff --git a/ecs/src/system/stateful.rs b/ecs/src/system/stateful.rs index 810a071..536e6ed 100644 --- a/ecs/src/system/stateful.rs +++ b/ecs/src/system/stateful.rs @@ -6,7 +6,6 @@ use seq_macro::seq; use crate::component::Component; use crate::lock::Lock; -use crate::system::util::check_params_are_compatible; use crate::system::{ ComponentRefMut, Into as IntoSystem, @@ -90,10 +89,6 @@ macro_rules! impl_system { where 'this: 'world { - #( - check_params_are_compatible!(I, TParam~I, $c); - )* - let func = self.func; func(#({ diff --git a/ecs/src/system/util.rs b/ecs/src/system/util.rs deleted file mode 100644 index 54fff0e..0000000 --- a/ecs/src/system/util.rs +++ /dev/null @@ -1,16 +0,0 @@ -macro_rules! check_params_are_compatible { - ($excluded_index: tt, $param: ident, $cnt: tt) => { - #[cfg(feature = "system-param-compat-checks")] - { - seq!(N in 0..$cnt { - if N != $excluded_index { - if !$param::is_compatible::() { - panic!("Atleast two parameters are incompatible"); - } - } - }); - } - }; -} - -pub(crate) use check_params_are_compatible; -- cgit v1.2.3-18-g5258