mod system_data;
pub use system_data::{DynamicSystemData, SystemData};
use futures::future::BoxFuture;
use crate::{
access::{Accessor, AccessorCow, AccessorType},
world::World,
};
pub trait System<'a>: Sized {
type SystemData: DynamicSystemData<'a>;
fn init(&mut self) {}
fn run(&mut self, data: Self::SystemData);
fn accessor<'b>(&'b self) -> AccessorCow<'a, 'b, Self::SystemData> {
AccessorCow::Owned(
AccessorType::<'a, Self::SystemData>::try_new()
.expect("Missing implementation for `accessor`"),
)
}
fn setup(&mut self, world: &mut World) {
self.init();
<Self::SystemData as DynamicSystemData>::setup(&self.accessor(), world)
}
fn dispose(self, world: &mut World)
where
Self: Sized,
{
let _ = world;
}
}
pub trait AsyncSystem<'a>: Sized {
type SystemData: DynamicSystemData<'a>;
fn init(&mut self) {}
fn run_async(&mut self, data: Self::SystemData) -> BoxFuture<'a, ()>;
fn accessor<'b>(&'b self) -> AccessorCow<'a, 'b, Self::SystemData> {
AccessorCow::Owned(
AccessorType::<'a, Self::SystemData>::try_new()
.expect("Missing implementation for `accessor`"),
)
}
fn setup(&mut self, world: &mut World) {
self.init();
<Self::SystemData as DynamicSystemData>::setup(&self.accessor(), world)
}
fn dispose(self, world: &mut World)
where
Self: Sized,
{
let _ = world;
}
}