2019-10-20 05:19:50 +00:00
|
|
|
pub mod entity_sync;
|
2019-10-15 04:06:14 +00:00
|
|
|
pub mod message;
|
2019-11-04 00:57:36 +00:00
|
|
|
pub mod sentinel;
|
2019-10-15 04:06:14 +00:00
|
|
|
pub mod subscription;
|
2019-10-20 05:19:50 +00:00
|
|
|
pub mod terrain;
|
|
|
|
pub mod terrain_sync;
|
2019-10-15 04:06:14 +00:00
|
|
|
|
|
|
|
use specs::DispatcherBuilder;
|
2019-10-20 07:20:21 +00:00
|
|
|
use std::{marker::PhantomData, time::Instant};
|
|
|
|
|
|
|
|
pub type EntitySyncTimer = SysTimer<entity_sync::Sys>;
|
|
|
|
pub type MessageTimer = SysTimer<message::Sys>;
|
2019-11-04 00:57:36 +00:00
|
|
|
pub type SentinelTimer = SysTimer<sentinel::Sys>;
|
2019-10-20 07:20:21 +00:00
|
|
|
pub type SubscriptionTimer = SysTimer<subscription::Sys>;
|
|
|
|
pub type TerrainTimer = SysTimer<terrain::Sys>;
|
|
|
|
pub type TerrainSyncTimer = SysTimer<terrain_sync::Sys>;
|
2019-10-15 04:06:14 +00:00
|
|
|
|
|
|
|
// System names
|
2019-10-20 05:19:50 +00:00
|
|
|
const ENTITY_SYNC_SYS: &str = "server_entity_sync_sys";
|
2019-11-04 00:57:36 +00:00
|
|
|
const SENTINEL_SYS: &str = "sentinel_sys";
|
2019-10-15 04:06:14 +00:00
|
|
|
const SUBSCRIPTION_SYS: &str = "server_subscription_sys";
|
2019-10-20 05:19:50 +00:00
|
|
|
const TERRAIN_SYNC_SYS: &str = "server_terrain_sync_sys";
|
|
|
|
const TERRAIN_SYS: &str = "server_terrain_sys";
|
2019-10-15 04:06:14 +00:00
|
|
|
const MESSAGE_SYS: &str = "server_message_sys";
|
|
|
|
|
|
|
|
pub fn add_server_systems(dispatch_builder: &mut DispatcherBuilder) {
|
2019-11-04 00:57:36 +00:00
|
|
|
dispatch_builder.add(sentinel::Sys, SENTINEL_SYS, &[]);
|
2019-10-15 04:06:14 +00:00
|
|
|
dispatch_builder.add(subscription::Sys, SUBSCRIPTION_SYS, &[]);
|
2019-11-04 00:57:36 +00:00
|
|
|
dispatch_builder.add(
|
|
|
|
entity_sync::Sys,
|
|
|
|
ENTITY_SYNC_SYS,
|
|
|
|
&[SUBSCRIPTION_SYS, SENTINEL_SYS],
|
|
|
|
);
|
2019-10-20 05:19:50 +00:00
|
|
|
dispatch_builder.add(terrain_sync::Sys, TERRAIN_SYS, &[]);
|
|
|
|
dispatch_builder.add(terrain::Sys, TERRAIN_SYNC_SYS, &[TERRAIN_SYS]);
|
2019-10-15 04:06:14 +00:00
|
|
|
dispatch_builder.add(message::Sys, MESSAGE_SYS, &[]);
|
|
|
|
}
|
2019-10-20 07:20:21 +00:00
|
|
|
|
|
|
|
/// Used to keep track of how much time each system takes
|
|
|
|
pub struct SysTimer<S> {
|
|
|
|
pub nanos: u64,
|
|
|
|
start: Option<Instant>,
|
|
|
|
_phantom: PhantomData<S>,
|
|
|
|
}
|
|
|
|
impl<S> SysTimer<S> {
|
|
|
|
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<S> Default for SysTimer<S> {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
|
|
|
nanos: 0,
|
|
|
|
start: None,
|
|
|
|
_phantom: PhantomData,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|