2020-11-16 04:32:23 +00:00
|
|
|
use crate::{ArchetypeComponent, Resources, TypeAccess, World};
|
2020-08-29 00:08:51 +00:00
|
|
|
use std::{any::TypeId, borrow::Cow};
|
2020-07-10 04:18:35 +00:00
|
|
|
|
2020-08-09 23:13:04 +00:00
|
|
|
/// Determines the strategy used to run the `run_thread_local` function in a [System]
|
2020-07-30 20:19:55 +00:00
|
|
|
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
|
2020-07-10 04:18:35 +00:00
|
|
|
pub enum ThreadLocalExecution {
|
|
|
|
Immediate,
|
|
|
|
NextFlush,
|
2020-07-10 08:37:06 +00:00
|
|
|
}
|
2020-07-10 04:18:35 +00:00
|
|
|
|
|
|
|
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
|
2020-09-18 00:16:38 +00:00
|
|
|
pub struct SystemId(pub usize);
|
2020-07-10 04:18:35 +00:00
|
|
|
|
|
|
|
impl SystemId {
|
2020-08-16 07:30:04 +00:00
|
|
|
#[allow(clippy::new_without_default)]
|
2020-07-10 04:18:35 +00:00
|
|
|
pub fn new() -> Self {
|
2020-09-18 00:16:38 +00:00
|
|
|
SystemId(rand::random::<usize>())
|
2020-07-10 04:18:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-16 03:27:41 +00:00
|
|
|
/// An ECS system that can be added to a [Schedule](crate::Schedule)
|
2020-07-10 04:18:35 +00:00
|
|
|
pub trait System: Send + Sync {
|
|
|
|
fn name(&self) -> Cow<'static, str>;
|
|
|
|
fn id(&self) -> SystemId;
|
2020-11-08 20:34:05 +00:00
|
|
|
fn is_initialized(&self) -> bool;
|
2020-10-30 06:39:55 +00:00
|
|
|
fn update(&mut self, world: &World);
|
|
|
|
fn archetype_component_access(&self) -> &TypeAccess<ArchetypeComponent>;
|
|
|
|
fn resource_access(&self) -> &TypeAccess<TypeId>;
|
2020-07-10 04:18:35 +00:00
|
|
|
fn thread_local_execution(&self) -> ThreadLocalExecution;
|
|
|
|
fn run(&mut self, world: &World, resources: &Resources);
|
|
|
|
fn run_thread_local(&mut self, world: &mut World, resources: &mut Resources);
|
2020-09-18 00:16:38 +00:00
|
|
|
fn initialize(&mut self, _world: &mut World, _resources: &mut Resources) {}
|
2020-07-10 04:18:35 +00:00
|
|
|
}
|