pub mod agent; pub mod entity_sync; pub mod invite_timeout; pub mod metrics; pub mod msg; pub mod object; pub mod persistence; pub mod sentinel; pub mod subscription; pub mod terrain; pub mod terrain_sync; pub mod waypoint; pub mod wiring; use common_ecs::{dispatch, run_now, System}; use common_systems::{melee, projectile}; use specs::DispatcherBuilder; use std::{ marker::PhantomData, time::{Duration, Instant}, }; pub type PersistenceScheduler = SysScheduler; pub fn add_server_systems(dispatch_builder: &mut DispatcherBuilder) { dispatch::(dispatch_builder, &[&projectile::Sys::sys_name()]); //Note: server should not depend on interpolation system dispatch::(dispatch_builder, &[]); dispatch::(dispatch_builder, &[]); dispatch::(dispatch_builder, &[]); dispatch::(dispatch_builder, &[]); dispatch::(dispatch_builder, &[]); dispatch::(dispatch_builder, &[]); dispatch::(dispatch_builder, &[]); } pub fn run_sync_systems(ecs: &mut specs::World) { // Setup for entity sync // If I'm not mistaken, these two could be ran in parallel run_now::(ecs); run_now::(ecs); // Sync run_now::(ecs); run_now::(ecs); } /// Used to schedule systems to run at an interval pub struct SysScheduler { interval: Duration, last_run: Instant, _phantom: PhantomData, } impl SysScheduler { pub fn every(interval: Duration) -> Self { Self { interval, last_run: Instant::now(), _phantom: PhantomData, } } pub fn should_run(&mut self) -> bool { if self.last_run.elapsed() > self.interval { self.last_run = Instant::now(); true } else { false } } } impl Default for SysScheduler { fn default() -> Self { Self { interval: Duration::from_secs(30), last_run: Instant::now(), _phantom: PhantomData, } } }