pub mod entity_sync; pub mod message; pub mod sentinel; pub mod subscription; pub mod terrain; pub mod terrain_sync; use specs::DispatcherBuilder; use std::{marker::PhantomData, time::Instant}; pub type EntitySyncTimer = SysTimer; pub type MessageTimer = SysTimer; pub type SentinelTimer = SysTimer; pub type SubscriptionTimer = SysTimer; pub type TerrainTimer = SysTimer; pub type TerrainSyncTimer = SysTimer; // System names const ENTITY_SYNC_SYS: &str = "server_entity_sync_sys"; const SENTINEL_SYS: &str = "sentinel_sys"; const SUBSCRIPTION_SYS: &str = "server_subscription_sys"; const TERRAIN_SYNC_SYS: &str = "server_terrain_sync_sys"; const TERRAIN_SYS: &str = "server_terrain_sys"; const MESSAGE_SYS: &str = "server_message_sys"; pub fn add_server_systems(dispatch_builder: &mut DispatcherBuilder) { dispatch_builder.add(sentinel::Sys, SENTINEL_SYS, &[]); dispatch_builder.add(subscription::Sys, SUBSCRIPTION_SYS, &[]); dispatch_builder.add( entity_sync::Sys, ENTITY_SYNC_SYS, &[SUBSCRIPTION_SYS, SENTINEL_SYS], ); dispatch_builder.add(terrain_sync::Sys, TERRAIN_SYS, &[]); dispatch_builder.add(terrain::Sys, TERRAIN_SYNC_SYS, &[TERRAIN_SYS]); dispatch_builder.add(message::Sys, MESSAGE_SYS, &[]); } /// Used to keep track of how much time each system takes pub struct SysTimer { pub nanos: u64, start: Option, _phantom: PhantomData, } impl SysTimer { pub fn start(&mut self) { if self.start.is_some() { panic!("Timer already started"); } self.start = Some(Instant::now()); } pub fn end(&mut self) { self.nanos = self .start .take() .expect("Timer ended without starting it") .elapsed() .as_nanos() as u64; } } impl Default for SysTimer { fn default() -> Self { Self { nanos: 0, start: None, _phantom: PhantomData, } } }