Skip to main content

ursus_ecs/
tick.rs

1use crate::systems::SyncTransformInterpolation;
2use hecs::World;
3
4pub trait TickSystem: Send + Sync {
5    fn tick(&self, world: &mut World, dt: f32);
6    fn name(&self) -> &'static str;
7}
8
9pub struct TickSchedule {
10    systems: Vec<Box<dyn TickSystem>>,
11}
12
13impl TickSchedule {
14    pub fn new() -> Self {
15        Self { systems: Vec::new() }
16    }
17
18    pub fn add(&mut self, system: impl TickSystem + 'static) {
19        self.systems.push(Box::new(system));
20    }
21
22    pub fn run(&self, world: &mut World, dt: f32) {
23        for system in &self.systems {
24            puffin::profile_scope!("tick_system", system.name());
25            system.tick(world, dt);
26        }
27    }
28}
29
30impl Default for TickSchedule {
31    fn default() -> Self {
32        Self::new()
33    }
34}
35
36pub fn default_tick_schedule() -> TickSchedule {
37    let mut schedule = TickSchedule::new();
38    schedule.add(SyncTransformInterpolation);
39    schedule
40}