summaryrefslogtreecommitdiff
path: root/ecs/src/system
diff options
context:
space:
mode:
Diffstat (limited to 'ecs/src/system')
-rw-r--r--ecs/src/system/stateful.rs60
1 files changed, 27 insertions, 33 deletions
diff --git a/ecs/src/system/stateful.rs b/ecs/src/system/stateful.rs
index 536e6ed..54f6979 100644
--- a/ecs/src/system/stateful.rs
+++ b/ecs/src/system/stateful.rs
@@ -1,13 +1,12 @@
use std::any::{type_name, Any, TypeId};
-use std::collections::HashMap;
use std::panic::{RefUnwindSafe, UnwindSafe};
+use hashbrown::HashMap;
use seq_macro::seq;
-use crate::component::Component;
+use crate::component::{Component, HandleMut as ComponentHandleMut};
use crate::lock::Lock;
use crate::system::{
- ComponentRefMut,
Into as IntoSystem,
Param,
ParamWithInputFilter,
@@ -15,10 +14,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;
@@ -27,7 +25,7 @@ use crate::World;
pub struct Stateful<Func>
{
func: Func,
- local_components: HashMap<Uid, Lock<Box<dyn Component>>>,
+ local_components: HashMap<Uid, Lock<Box<dyn Any>>>,
}
macro_rules! impl_system {
@@ -39,9 +37,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 +49,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;
+ }
}
)*
@@ -118,14 +109,14 @@ macro_rules! impl_system {
fn get_local_component_mut<LocalComponent: Component>(
&self,
- ) -> Option<ComponentRefMut<LocalComponent>>
+ ) -> Option<ComponentHandleMut<LocalComponent>>
{
let local_component = self.local_components
.get(&LocalComponent::id())?
.write_nonblock()
.expect("Failed to aquire read-write local component lock");
- Some(ComponentRefMut::new(local_component))
+ Some(ComponentHandleMut::new(local_component))
}
fn set_local_component<LocalComponent: Component>(
@@ -136,7 +127,10 @@ macro_rules! impl_system {
self.local_components
.insert(
LocalComponent::id(),
- Lock::new(Box::new(local_component))
+ Lock::new(
+ Box::new(local_component),
+ type_name::<LocalComponent>()
+ )
);
}
}