summaryrefslogtreecommitdiff
path: root/ecs/src/system.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2024-02-21 23:54:37 +0100
committerHampusM <hampus@hampusmat.com>2024-02-22 19:27:52 +0100
commit9f65dba3afd4e8f20881914fc86fa997cb64a13d (patch)
treed760f8f478af6591648ef3f53d4e0cb34ee76908 /ecs/src/system.rs
parentb0ef7f2cf8787c5732e0eb5554161ad75179a4b3 (diff)
feat(ecs): add support for system local components
Diffstat (limited to 'ecs/src/system.rs')
-rw-r--r--ecs/src/system.rs24
1 files changed, 22 insertions, 2 deletions
diff --git a/ecs/src/system.rs b/ecs/src/system.rs
index ecf1885..8f4d0b0 100644
--- a/ecs/src/system.rs
+++ b/ecs/src/system.rs
@@ -1,14 +1,21 @@
use std::any::Any;
+use std::convert::Infallible;
use std::fmt::Debug;
use crate::component::Sequence as ComponentSequence;
use crate::{ComponentStorage, Query};
+pub mod stateful;
+
pub trait System<Impl>: 'static
{
type Query<'a>;
- fn run(&self, component_storage: &mut ComponentStorage);
+ type Input;
+
+ fn initialize(self, input: Self::Input) -> Self;
+
+ fn run(&mut self, component_storage: &mut ComponentStorage);
fn into_type_erased(self) -> TypeErased;
}
@@ -18,9 +25,15 @@ where
Func: Fn(Query<Comps>) + 'static,
Comps: ComponentSequence,
{
+ type Input = Infallible;
type Query<'a> = Query<'a, Comps>;
- fn run(&self, component_storage: &mut ComponentStorage)
+ fn initialize(self, _input: Self::Input) -> Self
+ {
+ self
+ }
+
+ fn run(&mut self, component_storage: &mut ComponentStorage)
{
self(Query::new(component_storage));
}
@@ -38,6 +51,13 @@ where
}
}
+pub trait Into<Impl>
+{
+ type System;
+
+ fn into_system(self) -> Self::System;
+}
+
pub struct TypeErased
{
data: Box<dyn Any>,