diff options
author | HampusM <hampus@hampusmat.com> | 2024-12-10 21:48:10 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2024-12-13 17:16:34 +0100 |
commit | 9e057e9249fb5a8a9f3b2ba00a993049f733c9dd (patch) | |
tree | 7f8ca6d56438e83cd1d0da2562d18acbd13e5c80 /ecs/src/system/stateful.rs | |
parent | c6de2c7ab9c48223ab307fe0039fae7ab2613e16 (diff) |
refactor(ecs): improve system init param retrieval
Diffstat (limited to 'ecs/src/system/stateful.rs')
-rw-r--r-- | ecs/src/system/stateful.rs | 46 |
1 files changed, 19 insertions, 27 deletions
diff --git a/ecs/src/system/stateful.rs b/ecs/src/system/stateful.rs index 536e6ed..5eae1da 100644 --- a/ecs/src/system/stateful.rs +++ b/ecs/src/system/stateful.rs @@ -1,4 +1,4 @@ -use std::any::{type_name, Any, TypeId}; +use std::any::{Any, TypeId}; use std::collections::HashMap; use std::panic::{RefUnwindSafe, UnwindSafe}; @@ -15,10 +15,9 @@ use crate::system::{ TypeErased, }; use crate::tuple::{ - IntoInOptions as TupleIntoInOptions, Reduce as TupleReduce, - TakeOptionElementResult as TupleTakeOptionElementResult, - WithOptionElements as TupleWithOptionElements, + Tuple, + WithAllElemLtStatic as TupleWithAllElemLtStatic, }; use crate::uid::Uid; use crate::World; @@ -39,9 +38,10 @@ macro_rules! impl_system { Func: Fn(#(TParam~I,)*) + Copy + RefUnwindSafe + UnwindSafe + 'static, #(TParam~I: Param<'world>,)* #(TParam~I::Input: 'static,)* - (#(TParam~I::Input,)*): TupleReduce<ParamWithInputFilter>, - <(#(TParam~I::Input,)*) as TupleReduce<ParamWithInputFilter>>::Out: - TupleIntoInOptions + (#(TParam~I::Input,)*): TupleReduce< + ParamWithInputFilter, + Out: Tuple<InOptions: TupleWithAllElemLtStatic> + >, { type Input = <(#(TParam~I::Input,)*) as TupleReduce<ParamWithInputFilter>>::Out; @@ -50,35 +50,27 @@ macro_rules! impl_system { { let mut option_input = input.into_in_options(); + let mut index = 0; + #( if TypeId::of::<TParam~I::Input>() != TypeId::of::<()>() { - let input = match option_input.take::<TParam~I::Input>() { - TupleTakeOptionElementResult::Found(input) => input, - TupleTakeOptionElementResult::NotFound => { - panic!( - "Parameter input {} not found", - type_name::<TParam~I::Input>() - ); - } - TupleTakeOptionElementResult::AlreadyTaken => { - panic!( - concat!( - "Parameter {} is already initialized. ", - "System cannot contain multiple inputs with ", - "the same type", - ), - type_name::<TParam~I>() - ); - - } - }; + let input = option_input + .get_mut::<Option<TParam~I::Input>>(index) + .expect("Input element index out of range") + .take() + .expect("Input element is already taken"); TParam~I::initialize( &mut self, input ); + + #[allow(unused_assignments)] + { + index += 1; + } } )* |