use crate::ecs::commands::Commands;
use crate::ecs::component::{Component, ComponentId, ComponentIdRegistry};
use crate::ecs::universe::Universe;
pub trait AllowRead<T: Component> {}
pub trait AllowWrite<T: Component> {}
pub trait Processor: Send + Sync + 'static {
fn reads(&self, registry: &ComponentIdRegistry) -> Vec<ComponentId>;
fn writes(&self, registry: &ComponentIdRegistry) -> Vec<ComponentId>;
fn run(&mut self, ctx: &mut ProcessorContext);
fn processor_name(&self) -> &'static str { "" }
fn execute_after(&self) -> Vec<&'static str> { vec![] }
fn execute_before(&self) -> Vec<&'static str> { vec![] }
fn processor_tag(&self) -> Option<&'static str> { None }
}
pub struct ProcessorContext<'a> {
universe: &'a mut Universe,
commands: &'a Commands,
}
impl<'a> ProcessorContext<'a> {
pub fn new(universe: &'a mut Universe, commands: &'a Commands) -> Self {
Self { universe, commands }
}
pub fn commands(&self) -> &Commands {
self.commands
}
pub fn universe(&self) -> &Universe {
self.universe
}
pub fn universe_mut(&mut self) -> &mut Universe {
self.universe
}
}
pub fn run_processors(processors: &mut [Box<dyn Processor>], universe: &mut Universe) {
let commands = Commands::new();
for proc in processors.iter_mut() {
let mut ctx = ProcessorContext::new(universe, &commands);
proc.run(&mut ctx);
}
commands.apply(universe);
}