diff options
author | HampusM <hampus@hampusmat.com> | 2024-06-06 22:27:03 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2024-06-06 22:27:03 +0200 |
commit | 8adf787bca7744344b83dace7997031b07785a25 (patch) | |
tree | 4b510178e39593f08e548972f493e1856f703a15 /ecs/src | |
parent | cb1ff29c8c7fa77bbb4e532eaa7e45df717a58ef (diff) |
refactor(ecs): rename tuple filter to tuple reduce
Diffstat (limited to 'ecs/src')
-rw-r--r-- | ecs/src/actions.rs | 4 | ||||
-rw-r--r-- | ecs/src/query.rs | 4 | ||||
-rw-r--r-- | ecs/src/sole.rs | 4 | ||||
-rw-r--r-- | ecs/src/system.rs | 8 | ||||
-rw-r--r-- | ecs/src/system/stateful.rs | 12 | ||||
-rw-r--r-- | ecs/src/tuple.rs | 30 |
6 files changed, 30 insertions, 32 deletions
diff --git a/ecs/src/actions.rs b/ecs/src/actions.rs index cc27f09..9d3eb4e 100644 --- a/ecs/src/actions.rs +++ b/ecs/src/actions.rs @@ -5,7 +5,7 @@ use std::sync::{Arc, Weak}; use crate::component::{Component, Sequence as ComponentSequence}; use crate::lock::{Lock, WriteGuard}; use crate::system::{NoInitParamFlag, Param as SystemParam, System}; -use crate::tuple::FilterExclude as TupleFilterExclude; +use crate::tuple::ReduceNoOp as TupleReduceNoOp; use crate::{ActionQueue, WorldData}; /// Used to to queue up actions for a [`World`] to perform. @@ -56,7 +56,7 @@ impl<'world> Actions<'world> unsafe impl<'world> SystemParam<'world> for Actions<'world> { type Flags = NoInitParamFlag; - type Input = TupleFilterExclude; + type Input = TupleReduceNoOp; fn initialize<SystemImpl>( _system: &mut impl System<'world, SystemImpl>, diff --git a/ecs/src/query.rs b/ecs/src/query.rs index 90e6169..dae451a 100644 --- a/ecs/src/query.rs +++ b/ecs/src/query.rs @@ -13,7 +13,7 @@ use crate::system::{ Param as SystemParam, System, }; -use crate::tuple::FilterExclude as TupleFilterExclude; +use crate::tuple::ReduceNoOp as TupleReduceNoOp; use crate::{ComponentStorage, WorldData}; #[derive(Debug)] @@ -83,7 +83,7 @@ where Comps: ComponentSequence, { type Flags = NoInitSystemParamFlag; - type Input = TupleFilterExclude; + type Input = TupleReduceNoOp; fn initialize<SystemImpl>( _system: &mut impl System<'world, SystemImpl>, diff --git a/ecs/src/sole.rs b/ecs/src/sole.rs index e84e2a9..332b5f5 100644 --- a/ecs/src/sole.rs +++ b/ecs/src/sole.rs @@ -6,7 +6,7 @@ use std::sync::{Arc, Weak}; use crate::lock::{Lock, WriteGuard}; use crate::system::{NoInitParamFlag, Param as SystemParam, System}; -use crate::tuple::FilterExclude as TupleFilterExclude; +use crate::tuple::ReduceNoOp as TupleReduceNoOp; use crate::type_name::TypeName; use crate::WorldData; @@ -94,7 +94,7 @@ where SoleT: Sole, { type Flags = NoInitParamFlag; - type Input = TupleFilterExclude; + type Input = TupleReduceNoOp; fn initialize<SystemImpl>( _system: &mut impl System<'world, SystemImpl>, diff --git a/ecs/src/system.rs b/ecs/src/system.rs index 3c44148..6846a16 100644 --- a/ecs/src/system.rs +++ b/ecs/src/system.rs @@ -11,7 +11,7 @@ use seq_macro::seq; use crate::component::{Component, FromOptionalComponent}; use crate::lock::WriteGuard; use crate::system::util::check_params_are_compatible; -use crate::tuple::{FilterElement as TupleFilterElement, With as TupleWith}; +use crate::tuple::{ReduceElement as TupleReduceElement, With as TupleWith}; use crate::WorldData; pub mod stateful; @@ -186,11 +186,11 @@ pub struct NoInitParamFlag {} /// A type which can be used as input to a [`System`]. pub trait Input: 'static {} -impl<InputT: Input, Tup> TupleFilterElement<Tup> for InputT +impl<InputT: Input, Accumulator> TupleReduceElement<Accumulator> for InputT where - Tup: TupleWith<Self>, + Accumulator: TupleWith<Self>, { - type Tuple = Tup::With; + type Return = Accumulator::With; } #[derive(Debug)] diff --git a/ecs/src/system/stateful.rs b/ecs/src/system/stateful.rs index 8d56a13..e74c0ee 100644 --- a/ecs/src/system/stateful.rs +++ b/ecs/src/system/stateful.rs @@ -9,9 +9,9 @@ use crate::lock::Lock; use crate::system::util::check_params_are_compatible; use crate::system::{ComponentRefMut, Into as IntoSystem, Param, System, TypeErased}; use crate::tuple::{ - Filter as TupleFilter, - FilterExclude as TupleFilterExclude, IntoInOptions as TupleIntoInOptions, + Reduce as TupleReduce, + ReduceNoOp as TupleReduceNoOp, TakeOptionElementResult as TupleTakeOptionElementResult, WithOptionElements as TupleWithOptionElements, }; @@ -33,10 +33,10 @@ macro_rules! impl_system { Func: Fn(#(TParam~I,)*) + Copy + RefUnwindSafe + UnwindSafe + 'static, #(TParam~I: Param<'world>,)* #(TParam~I::Input: 'static,)* - (#(TParam~I::Input,)*): TupleFilter, - <(#(TParam~I::Input,)*) as TupleFilter>::Out: TupleIntoInOptions + (#(TParam~I::Input,)*): TupleReduce, + <(#(TParam~I::Input,)*) as TupleReduce>::Out: TupleIntoInOptions { - type Input = <(#(TParam~I::Input,)*) as TupleFilter>::Out; + type Input = <(#(TParam~I::Input,)*) as TupleReduce>::Out; fn initialize(mut self, input: Self::Input) -> Self { @@ -44,7 +44,7 @@ macro_rules! impl_system { #( if TypeId::of::<TParam~I::Input>() != - TypeId::of::<TupleFilterExclude>() + TypeId::of::<TupleReduceNoOp>() { let input = match option_input.take::<TParam~I::Input>() { TupleTakeOptionElementResult::Found(input) => input, diff --git a/ecs/src/tuple.rs b/ecs/src/tuple.rs index bb27f58..5ed8993 100644 --- a/ecs/src/tuple.rs +++ b/ecs/src/tuple.rs @@ -25,17 +25,16 @@ pub trait WithOptionElements fn take<Element: 'static>(&mut self) -> TakeOptionElementResult<Element>; } -/// Used to filter the elements of a tuple type. -pub trait Filter +/// Using the type system, reduces the elements of a tuple to a single one. Each element +/// determines itself how it is handled. +pub trait Reduce { type Out; } -/// Used by implementations of [`Filter`] to know whether this element should be -/// filtered out or not. -pub trait FilterElement<Tup> +pub trait ReduceElement<Accumulator> { - type Tuple; + type Return; } /// The result of trying to [`take`] a element from a implementation of @@ -54,24 +53,23 @@ pub enum TakeOptionElementResult<Element> AlreadyTaken, } -/// Zero-sized struct excluded when filtering the elements of a tuple type using -/// implementations of [`Filter`]. +/// Zero-sized struct implementing [`ReduceElement`] and just returns the accumulator. #[derive(Debug, Clone, Copy)] -pub struct FilterExclude; +pub struct ReduceNoOp; -impl<Tup> FilterElement<Tup> for FilterExclude +impl<Accumulator> ReduceElement<Accumulator> for ReduceNoOp { - type Tuple = Tup; + type Return = Accumulator; } -macro_rules! tuple_filter_elem_tuple { +macro_rules! tuple_reduce_elem_tuple { (overflow) => { () }; ($index: tt) => { paste! { - [<Elem $index>]::Tuple + [<Elem $index>]::Return } }; } @@ -121,11 +119,11 @@ macro_rules! impl_tuple_traits { } paste! { - impl<#(Elem~I,)*> Filter for (#(Elem~I,)*) + impl<#(Elem~I,)*> Reduce for (#(Elem~I,)*) where - #(Elem~I: FilterElement<sub!(I - 1, tuple_filter_elem_tuple)>,)* + #(Elem~I: ReduceElement<sub!(I - 1, tuple_reduce_elem_tuple)>,)* { - type Out = sub!($cnt - 1, tuple_filter_elem_tuple); + type Out = sub!($cnt - 1, tuple_reduce_elem_tuple); } } }); |