mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
rename TrueTime to ProgramTime and don't share it
This commit is contained in:
parent
7d37646dac
commit
d638215b88
@ -376,7 +376,6 @@ impl Client {
|
|||||||
let ServerInit::GameSync {
|
let ServerInit::GameSync {
|
||||||
entity_package,
|
entity_package,
|
||||||
time_of_day,
|
time_of_day,
|
||||||
true_time,
|
|
||||||
max_group_size,
|
max_group_size,
|
||||||
client_timeout,
|
client_timeout,
|
||||||
world_map,
|
world_map,
|
||||||
@ -415,7 +414,6 @@ impl Client {
|
|||||||
state.ecs_mut().register::<comp::Last<CharacterState>>();
|
state.ecs_mut().register::<comp::Last<CharacterState>>();
|
||||||
let entity = state.ecs_mut().apply_entity_package(entity_package);
|
let entity = state.ecs_mut().apply_entity_package(entity_package);
|
||||||
*state.ecs_mut().write_resource() = time_of_day;
|
*state.ecs_mut().write_resource() = time_of_day;
|
||||||
*state.ecs_mut().write_resource() = true_time;
|
|
||||||
*state.ecs_mut().write_resource() = PlayerEntity(Some(entity));
|
*state.ecs_mut().write_resource() = PlayerEntity(Some(entity));
|
||||||
state.ecs_mut().insert(material_stats);
|
state.ecs_mut().insert(material_stats);
|
||||||
state.ecs_mut().insert(ability_map);
|
state.ecs_mut().insert(ability_map);
|
||||||
@ -1931,9 +1929,9 @@ impl Client {
|
|||||||
self.tick_terrain()?;
|
self.tick_terrain()?;
|
||||||
|
|
||||||
// Send a ping to the server once every second
|
// Send a ping to the server once every second
|
||||||
if self.state.get_true_time() - self.last_server_ping > 1. {
|
if self.state.get_program_time() - self.last_server_ping > 1. {
|
||||||
self.send_msg_err(PingMsg::Ping)?;
|
self.send_msg_err(PingMsg::Ping)?;
|
||||||
self.last_server_ping = self.state.get_true_time();
|
self.last_server_ping = self.state.get_program_time();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 6) Update the server about the player's physics attributes.
|
// 6) Update the server about the player's physics attributes.
|
||||||
@ -2268,16 +2266,9 @@ impl Client {
|
|||||||
return Err(Error::Other("Failed to find entity from uid.".into()));
|
return Err(Error::Other("Failed to find entity from uid.".into()));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ServerGeneral::TimeOfDay(
|
ServerGeneral::TimeOfDay(time_of_day, calendar, new_time, time_scale) => {
|
||||||
time_of_day,
|
|
||||||
calendar,
|
|
||||||
new_time,
|
|
||||||
new_true_time,
|
|
||||||
time_scale,
|
|
||||||
) => {
|
|
||||||
self.target_time_of_day = Some(time_of_day);
|
self.target_time_of_day = Some(time_of_day);
|
||||||
*self.state.ecs_mut().write_resource() = calendar;
|
*self.state.ecs_mut().write_resource() = calendar;
|
||||||
*self.state.ecs_mut().write_resource() = new_true_time;
|
|
||||||
*self.state.ecs_mut().write_resource() = time_scale;
|
*self.state.ecs_mut().write_resource() = time_scale;
|
||||||
let mut time = self.state.ecs_mut().write_resource::<Time>();
|
let mut time = self.state.ecs_mut().write_resource::<Time>();
|
||||||
// Avoid side-eye from Einstein
|
// Avoid side-eye from Einstein
|
||||||
@ -2601,8 +2592,8 @@ impl Client {
|
|||||||
self.send_msg_err(PingMsg::Pong)?;
|
self.send_msg_err(PingMsg::Pong)?;
|
||||||
},
|
},
|
||||||
PingMsg::Pong => {
|
PingMsg::Pong => {
|
||||||
self.last_server_pong = self.state.get_true_time();
|
self.last_server_pong = self.state.get_program_time();
|
||||||
self.last_ping_delta = self.state.get_true_time() - self.last_server_ping;
|
self.last_ping_delta = self.state.get_program_time() - self.last_server_ping;
|
||||||
|
|
||||||
// Maintain the correct number of deltas for calculating the rolling average
|
// Maintain the correct number of deltas for calculating the rolling average
|
||||||
// ping. The client sends a ping to the server every second so we should be
|
// ping. The client sends a ping to the server every second so we should be
|
||||||
@ -2673,18 +2664,18 @@ impl Client {
|
|||||||
// Check that we have an valid connection.
|
// Check that we have an valid connection.
|
||||||
// Use the last ping time as a 1s rate limiter, we only notify the user once per
|
// Use the last ping time as a 1s rate limiter, we only notify the user once per
|
||||||
// second
|
// second
|
||||||
if self.state.get_true_time() - self.last_server_ping > 1. {
|
if self.state.get_program_time() - self.last_server_ping > 1. {
|
||||||
let duration_since_last_pong = self.state.get_true_time() - self.last_server_pong;
|
let duration_since_last_pong = self.state.get_program_time() - self.last_server_pong;
|
||||||
|
|
||||||
// Dispatch a notification to the HUD warning they will be kicked in {n} seconds
|
// Dispatch a notification to the HUD warning they will be kicked in {n} seconds
|
||||||
const KICK_WARNING_AFTER_REL_TO_TIMEOUT_FRACTION: f64 = 0.75;
|
const KICK_WARNING_AFTER_REL_TO_TIMEOUT_FRACTION: f64 = 0.75;
|
||||||
if duration_since_last_pong
|
if duration_since_last_pong
|
||||||
>= (self.client_timeout.as_secs() as f64
|
>= (self.client_timeout.as_secs() as f64
|
||||||
* KICK_WARNING_AFTER_REL_TO_TIMEOUT_FRACTION)
|
* KICK_WARNING_AFTER_REL_TO_TIMEOUT_FRACTION)
|
||||||
&& self.state.get_true_time() - duration_since_last_pong > 0.
|
&& self.state.get_program_time() - duration_since_last_pong > 0.
|
||||||
{
|
{
|
||||||
frontend_events.push(Event::DisconnectionNotification(
|
frontend_events.push(Event::DisconnectionNotification(
|
||||||
(self.state.get_true_time() - duration_since_last_pong).round() as u64,
|
(self.state.get_program_time() - duration_since_last_pong).round() as u64,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2692,10 +2683,10 @@ impl Client {
|
|||||||
let msg_count = self.handle_messages(&mut frontend_events)?;
|
let msg_count = self.handle_messages(&mut frontend_events)?;
|
||||||
|
|
||||||
if msg_count == 0
|
if msg_count == 0
|
||||||
&& self.state.get_true_time() - self.last_server_pong
|
&& self.state.get_program_time() - self.last_server_pong
|
||||||
> self.client_timeout.as_secs() as f64
|
> self.client_timeout.as_secs() as f64
|
||||||
{
|
{
|
||||||
dbg!(self.state.get_true_time());
|
dbg!(self.state.get_program_time());
|
||||||
dbg!(self.last_server_pong);
|
dbg!(self.last_server_pong);
|
||||||
return Err(Error::ServerTimeout);
|
return Err(Error::ServerTimeout);
|
||||||
}
|
}
|
||||||
@ -2896,9 +2887,18 @@ impl Client {
|
|||||||
// Advance state time manually since we aren't calling `State::tick`
|
// Advance state time manually since we aren't calling `State::tick`
|
||||||
self.state
|
self.state
|
||||||
.ecs()
|
.ecs()
|
||||||
.write_resource::<common::resources::TrueTime>()
|
.write_resource::<common::resources::ProgramTime>()
|
||||||
.0 += dt.as_secs_f64();
|
.0 += dt.as_secs_f64();
|
||||||
|
|
||||||
|
let time_scale = *self
|
||||||
|
.state
|
||||||
|
.ecs()
|
||||||
|
.read_resource::<common::resources::TimeScale>();
|
||||||
|
self.state
|
||||||
|
.ecs()
|
||||||
|
.write_resource::<common::resources::Time>()
|
||||||
|
.0 += dt.as_secs_f64() * time_scale.0;
|
||||||
|
|
||||||
// Handle new messages from the server.
|
// Handle new messages from the server.
|
||||||
self.handle_new_messages()?;
|
self.handle_new_messages()?;
|
||||||
|
|
||||||
@ -2922,9 +2922,9 @@ impl Client {
|
|||||||
drop(terrain);
|
drop(terrain);
|
||||||
|
|
||||||
// Send a ping to the server once every second
|
// Send a ping to the server once every second
|
||||||
if self.state.get_time() - self.last_server_ping > 1. {
|
if self.state.get_program_time() - self.last_server_ping > 1. {
|
||||||
self.send_msg_err(PingMsg::Ping)?;
|
self.send_msg_err(PingMsg::Ping)?;
|
||||||
self.last_server_ping = self.state.get_time();
|
self.last_server_ping = self.state.get_program_time();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 6) Update the server about the player's physics attributes.
|
// 6) Update the server about the player's physics attributes.
|
||||||
|
@ -11,7 +11,7 @@ use common::{
|
|||||||
lod,
|
lod,
|
||||||
outcome::Outcome,
|
outcome::Outcome,
|
||||||
recipe::{ComponentRecipeBook, RecipeBook, RepairRecipeBook},
|
recipe::{ComponentRecipeBook, RecipeBook, RepairRecipeBook},
|
||||||
resources::{Time, TimeOfDay, TimeScale, TrueTime},
|
resources::{Time, TimeOfDay, TimeScale},
|
||||||
shared_server_config::ServerConstants,
|
shared_server_config::ServerConstants,
|
||||||
terrain::{Block, TerrainChunk, TerrainChunkMeta, TerrainChunkSize},
|
terrain::{Block, TerrainChunk, TerrainChunkMeta, TerrainChunkSize},
|
||||||
trade::{PendingTrade, SitePrices, TradeId, TradeResult},
|
trade::{PendingTrade, SitePrices, TradeId, TradeResult},
|
||||||
@ -60,7 +60,6 @@ pub enum ServerInit {
|
|||||||
GameSync {
|
GameSync {
|
||||||
entity_package: sync::EntityPackage<EcsCompPacket>,
|
entity_package: sync::EntityPackage<EcsCompPacket>,
|
||||||
time_of_day: TimeOfDay,
|
time_of_day: TimeOfDay,
|
||||||
true_time: TrueTime,
|
|
||||||
max_group_size: u32,
|
max_group_size: u32,
|
||||||
client_timeout: Duration,
|
client_timeout: Duration,
|
||||||
world_map: crate::msg::world_msg::WorldMapMsg,
|
world_map: crate::msg::world_msg::WorldMapMsg,
|
||||||
@ -196,7 +195,7 @@ pub enum ServerGeneral {
|
|||||||
ChatMsg(comp::ChatMsg),
|
ChatMsg(comp::ChatMsg),
|
||||||
ChatMode(comp::ChatMode),
|
ChatMode(comp::ChatMode),
|
||||||
SetPlayerEntity(Uid),
|
SetPlayerEntity(Uid),
|
||||||
TimeOfDay(TimeOfDay, Calendar, Time, TrueTime, TimeScale),
|
TimeOfDay(TimeOfDay, Calendar, Time, TimeScale),
|
||||||
EntitySync(sync::EntitySyncPackage),
|
EntitySync(sync::EntitySyncPackage),
|
||||||
CompSync(sync::CompSyncPackage<EcsCompPacket>, u64),
|
CompSync(sync::CompSyncPackage<EcsCompPacket>, u64),
|
||||||
CreateEntity(sync::EntityPackage<EcsCompPacket>),
|
CreateEntity(sync::EntityPackage<EcsCompPacket>),
|
||||||
@ -343,7 +342,7 @@ impl ServerMsg {
|
|||||||
| ServerGeneral::ChatMsg(_)
|
| ServerGeneral::ChatMsg(_)
|
||||||
| ServerGeneral::ChatMode(_)
|
| ServerGeneral::ChatMode(_)
|
||||||
| ServerGeneral::SetPlayerEntity(_)
|
| ServerGeneral::SetPlayerEntity(_)
|
||||||
| ServerGeneral::TimeOfDay(_, _, _, _, _)
|
| ServerGeneral::TimeOfDay(_, _, _, _)
|
||||||
| ServerGeneral::EntitySync(_)
|
| ServerGeneral::EntitySync(_)
|
||||||
| ServerGeneral::CompSync(_, _)
|
| ServerGeneral::CompSync(_, _)
|
||||||
| ServerGeneral::CreateEntity(_)
|
| ServerGeneral::CreateEntity(_)
|
||||||
|
@ -11,9 +11,9 @@ pub struct TimeOfDay(pub f64);
|
|||||||
#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, PartialEq)]
|
#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, PartialEq)]
|
||||||
pub struct Time(pub f64);
|
pub struct Time(pub f64);
|
||||||
|
|
||||||
/// A resource that stores the real tick, unaffected by `TimeScale`.
|
/// A resource that stores the real tick, local to the server/client.
|
||||||
#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, PartialEq)]
|
#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, PartialEq)]
|
||||||
pub struct TrueTime(pub f64);
|
pub struct ProgramTime(pub f64);
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
|
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
|
||||||
pub struct TimeScale(pub f64);
|
pub struct TimeScale(pub f64);
|
||||||
|
@ -13,8 +13,8 @@ use common::{
|
|||||||
mounting::{Mount, Rider, VolumeRider, VolumeRiders},
|
mounting::{Mount, Rider, VolumeRider, VolumeRiders},
|
||||||
outcome::Outcome,
|
outcome::Outcome,
|
||||||
resources::{
|
resources::{
|
||||||
DeltaTime, EntitiesDiedLastTick, GameMode, PlayerEntity, PlayerPhysicsSettings, Time,
|
DeltaTime, EntitiesDiedLastTick, GameMode, PlayerEntity, PlayerPhysicsSettings,
|
||||||
TimeOfDay, TimeScale, TrueTime,
|
ProgramTime, Time, TimeOfDay, TimeScale,
|
||||||
},
|
},
|
||||||
shared_server_config::ServerConstants,
|
shared_server_config::ServerConstants,
|
||||||
slowjob::SlowJobPool,
|
slowjob::SlowJobPool,
|
||||||
@ -269,7 +269,7 @@ impl State {
|
|||||||
ecs.insert(Calendar::default());
|
ecs.insert(Calendar::default());
|
||||||
ecs.insert(WeatherGrid::new(Vec2::zero()));
|
ecs.insert(WeatherGrid::new(Vec2::zero()));
|
||||||
ecs.insert(Time(0.0));
|
ecs.insert(Time(0.0));
|
||||||
ecs.insert(TrueTime(0.0));
|
ecs.insert(ProgramTime(0.0));
|
||||||
ecs.insert(TimeScale(1.0));
|
ecs.insert(TimeScale(1.0));
|
||||||
|
|
||||||
// Register unsynced resources used by the ECS.
|
// Register unsynced resources used by the ECS.
|
||||||
@ -441,7 +441,7 @@ impl State {
|
|||||||
/// Get the current true in-game time, unaffected by time_scale.
|
/// Get the current true in-game time, unaffected by time_scale.
|
||||||
///
|
///
|
||||||
/// Note that this does not correspond to the time of day.
|
/// Note that this does not correspond to the time of day.
|
||||||
pub fn get_true_time(&self) -> f64 { self.ecs.read_resource::<TrueTime>().0 }
|
pub fn get_program_time(&self) -> f64 { self.ecs.read_resource::<ProgramTime>().0 }
|
||||||
|
|
||||||
/// Get the current delta time.
|
/// Get the current delta time.
|
||||||
pub fn get_delta_time(&self) -> f32 { self.ecs.read_resource::<DeltaTime>().0 }
|
pub fn get_delta_time(&self) -> f32 { self.ecs.read_resource::<DeltaTime>().0 }
|
||||||
@ -643,7 +643,7 @@ impl State {
|
|||||||
self.ecs.write_resource::<TimeOfDay>().0 +=
|
self.ecs.write_resource::<TimeOfDay>().0 +=
|
||||||
dt.as_secs_f64() * server_constants.day_cycle_coefficient * time_scale;
|
dt.as_secs_f64() * server_constants.day_cycle_coefficient * time_scale;
|
||||||
self.ecs.write_resource::<Time>().0 += dt.as_secs_f64() * time_scale;
|
self.ecs.write_resource::<Time>().0 += dt.as_secs_f64() * time_scale;
|
||||||
self.ecs.write_resource::<TrueTime>().0 += dt.as_secs_f64();
|
self.ecs.write_resource::<ProgramTime>().0 += dt.as_secs_f64();
|
||||||
|
|
||||||
// Update delta time.
|
// Update delta time.
|
||||||
// Beyond a delta time of MAX_DELTA_TIME, start lagging to avoid skipping
|
// Beyond a delta time of MAX_DELTA_TIME, start lagging to avoid skipping
|
||||||
|
@ -203,7 +203,7 @@ impl Client {
|
|||||||
| ServerGeneral::ChatMsg(_)
|
| ServerGeneral::ChatMsg(_)
|
||||||
| ServerGeneral::ChatMode(_)
|
| ServerGeneral::ChatMode(_)
|
||||||
| ServerGeneral::SetPlayerEntity(_)
|
| ServerGeneral::SetPlayerEntity(_)
|
||||||
| ServerGeneral::TimeOfDay(_, _, _, _, _)
|
| ServerGeneral::TimeOfDay(_, _, _, _)
|
||||||
| ServerGeneral::EntitySync(_)
|
| ServerGeneral::EntitySync(_)
|
||||||
| ServerGeneral::CompSync(_, _)
|
| ServerGeneral::CompSync(_, _)
|
||||||
| ServerGeneral::CreateEntity(_)
|
| ServerGeneral::CreateEntity(_)
|
||||||
|
@ -43,7 +43,7 @@ use common::{
|
|||||||
npc::{self, get_npc_name},
|
npc::{self, get_npc_name},
|
||||||
outcome::Outcome,
|
outcome::Outcome,
|
||||||
parse_cmd_args,
|
parse_cmd_args,
|
||||||
resources::{BattleMode, PlayerPhysicsSettings, Secs, Time, TimeOfDay, TimeScale, TrueTime},
|
resources::{BattleMode, PlayerPhysicsSettings, Secs, Time, TimeOfDay, TimeScale},
|
||||||
rtsim::{Actor, Role},
|
rtsim::{Actor, Role},
|
||||||
terrain::{Block, BlockKind, CoordinateConversions, SpriteKind, TerrainChunkSize},
|
terrain::{Block, BlockKind, CoordinateConversions, SpriteKind, TerrainChunkSize},
|
||||||
uid::Uid,
|
uid::Uid,
|
||||||
@ -1092,7 +1092,6 @@ fn handle_time(
|
|||||||
|
|
||||||
server.state.mut_resource::<TimeOfDay>().0 = new_time;
|
server.state.mut_resource::<TimeOfDay>().0 = new_time;
|
||||||
let time = server.state.ecs().read_resource::<Time>();
|
let time = server.state.ecs().read_resource::<Time>();
|
||||||
let true_time = server.state.ecs().read_resource::<TrueTime>();
|
|
||||||
|
|
||||||
// Update all clients with the new TimeOfDay (without this they would have to
|
// Update all clients with the new TimeOfDay (without this they would have to
|
||||||
// wait for the next 100th tick to receive the update).
|
// wait for the next 100th tick to receive the update).
|
||||||
@ -1106,7 +1105,6 @@ fn handle_time(
|
|||||||
TimeOfDay(new_time),
|
TimeOfDay(new_time),
|
||||||
(*calendar).clone(),
|
(*calendar).clone(),
|
||||||
*time,
|
*time,
|
||||||
*true_time,
|
|
||||||
*time_scale,
|
*time_scale,
|
||||||
))
|
))
|
||||||
});
|
});
|
||||||
@ -1160,7 +1158,6 @@ fn handle_time_scale(
|
|||||||
let mut tod_lazymsg = None;
|
let mut tod_lazymsg = None;
|
||||||
let clients = server.state.ecs().read_storage::<Client>();
|
let clients = server.state.ecs().read_storage::<Client>();
|
||||||
let time = server.state.ecs().read_resource::<Time>();
|
let time = server.state.ecs().read_resource::<Time>();
|
||||||
let true_time = server.state.ecs().read_resource::<TrueTime>();
|
|
||||||
let time_of_day = server.state.ecs().read_resource::<TimeOfDay>();
|
let time_of_day = server.state.ecs().read_resource::<TimeOfDay>();
|
||||||
let calendar = server.state.ecs().read_resource::<Calendar>();
|
let calendar = server.state.ecs().read_resource::<Calendar>();
|
||||||
for client in (&clients).join() {
|
for client in (&clients).join() {
|
||||||
@ -1169,7 +1166,6 @@ fn handle_time_scale(
|
|||||||
*time_of_day,
|
*time_of_day,
|
||||||
(*calendar).clone(),
|
(*calendar).clone(),
|
||||||
*time,
|
*time,
|
||||||
*true_time,
|
|
||||||
TimeScale(scale),
|
TimeScale(scale),
|
||||||
))
|
))
|
||||||
});
|
});
|
||||||
|
@ -8,7 +8,7 @@ use common::{
|
|||||||
mounting::Rider,
|
mounting::Rider,
|
||||||
outcome::Outcome,
|
outcome::Outcome,
|
||||||
region::{Event as RegionEvent, RegionMap},
|
region::{Event as RegionEvent, RegionMap},
|
||||||
resources::{PlayerPhysicsSettings, Time, TimeOfDay, TimeScale, TrueTime},
|
resources::{PlayerPhysicsSettings, Time, TimeOfDay, TimeScale},
|
||||||
terrain::TerrainChunkSize,
|
terrain::TerrainChunkSize,
|
||||||
uid::Uid,
|
uid::Uid,
|
||||||
vol::RectVolSize,
|
vol::RectVolSize,
|
||||||
@ -32,7 +32,6 @@ impl<'a> System<'a> for Sys {
|
|||||||
TrackedStorages<'a>,
|
TrackedStorages<'a>,
|
||||||
ReadExpect<'a, TimeOfDay>,
|
ReadExpect<'a, TimeOfDay>,
|
||||||
ReadExpect<'a, Time>,
|
ReadExpect<'a, Time>,
|
||||||
ReadExpect<'a, TrueTime>,
|
|
||||||
ReadExpect<'a, Calendar>,
|
ReadExpect<'a, Calendar>,
|
||||||
ReadExpect<'a, TimeScale>,
|
ReadExpect<'a, TimeScale>,
|
||||||
ReadExpect<'a, RegionMap>,
|
ReadExpect<'a, RegionMap>,
|
||||||
@ -66,7 +65,6 @@ impl<'a> System<'a> for Sys {
|
|||||||
tracked_storages,
|
tracked_storages,
|
||||||
time_of_day,
|
time_of_day,
|
||||||
time,
|
time,
|
||||||
true_time,
|
|
||||||
calendar,
|
calendar,
|
||||||
time_scale,
|
time_scale,
|
||||||
region_map,
|
region_map,
|
||||||
@ -436,7 +434,6 @@ impl<'a> System<'a> for Sys {
|
|||||||
*time_of_day,
|
*time_of_day,
|
||||||
(*calendar).clone(),
|
(*calendar).clone(),
|
||||||
*time,
|
*time,
|
||||||
*true_time,
|
|
||||||
*time_scale,
|
*time_scale,
|
||||||
))
|
))
|
||||||
});
|
});
|
||||||
|
@ -2,7 +2,7 @@ use crate::client::Client;
|
|||||||
use common::{
|
use common::{
|
||||||
comp::{ChatMode, ChatType, Content, Group, Player},
|
comp::{ChatMode, ChatType, Content, Group, Player},
|
||||||
event::{EventBus, ServerEvent},
|
event::{EventBus, ServerEvent},
|
||||||
resources::TrueTime,
|
resources::ProgramTime,
|
||||||
uid::Uid,
|
uid::Uid,
|
||||||
};
|
};
|
||||||
use common_ecs::{Job, Origin, Phase, System};
|
use common_ecs::{Job, Origin, Phase, System};
|
||||||
@ -81,7 +81,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
type SystemData = (
|
type SystemData = (
|
||||||
Entities<'a>,
|
Entities<'a>,
|
||||||
Read<'a, EventBus<ServerEvent>>,
|
Read<'a, EventBus<ServerEvent>>,
|
||||||
Read<'a, TrueTime>,
|
Read<'a, ProgramTime>,
|
||||||
ReadStorage<'a, Uid>,
|
ReadStorage<'a, Uid>,
|
||||||
ReadStorage<'a, ChatMode>,
|
ReadStorage<'a, ChatMode>,
|
||||||
ReadStorage<'a, Player>,
|
ReadStorage<'a, Player>,
|
||||||
@ -95,7 +95,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
|
|
||||||
fn run(
|
fn run(
|
||||||
_job: &mut Job<Self>,
|
_job: &mut Job<Self>,
|
||||||
(entities, server_event_bus, time, uids, chat_modes, players, groups, mut clients): Self::SystemData,
|
(entities, server_event_bus, program_time, uids, chat_modes, players, groups, mut clients): Self::SystemData,
|
||||||
) {
|
) {
|
||||||
(&entities, &mut clients, players.maybe())
|
(&entities, &mut clients, players.maybe())
|
||||||
.par_join()
|
.par_join()
|
||||||
@ -117,7 +117,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
|
|
||||||
if let Ok(1_u64..=u64::MAX) = res {
|
if let Ok(1_u64..=u64::MAX) = res {
|
||||||
// Update client ping.
|
// Update client ping.
|
||||||
client.last_ping = time.0
|
client.last_ping = program_time.0
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::{client::Client, Settings};
|
use crate::{client::Client, Settings};
|
||||||
use common::{
|
use common::{
|
||||||
event::{EventBus, ServerEvent},
|
event::{EventBus, ServerEvent},
|
||||||
resources::TrueTime,
|
resources::ProgramTime,
|
||||||
};
|
};
|
||||||
use common_ecs::{Job, Origin, Phase, System};
|
use common_ecs::{Job, Origin, Phase, System};
|
||||||
use common_net::msg::PingMsg;
|
use common_net::msg::PingMsg;
|
||||||
@ -26,7 +26,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
type SystemData = (
|
type SystemData = (
|
||||||
Entities<'a>,
|
Entities<'a>,
|
||||||
Read<'a, EventBus<ServerEvent>>,
|
Read<'a, EventBus<ServerEvent>>,
|
||||||
Read<'a, TrueTime>,
|
Read<'a, ProgramTime>,
|
||||||
WriteStorage<'a, Client>,
|
WriteStorage<'a, Client>,
|
||||||
Read<'a, Settings>,
|
Read<'a, Settings>,
|
||||||
);
|
);
|
||||||
@ -37,7 +37,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
|
|
||||||
fn run(
|
fn run(
|
||||||
_job: &mut Job<Self>,
|
_job: &mut Job<Self>,
|
||||||
(entities, server_event_bus, time, mut clients, settings): Self::SystemData,
|
(entities, server_event_bus, program_time, mut clients, settings): Self::SystemData,
|
||||||
) {
|
) {
|
||||||
(&entities, &mut clients).par_join().for_each_init(
|
(&entities, &mut clients).par_join().for_each_init(
|
||||||
|| server_event_bus.emitter(),
|
|| server_event_bus.emitter(),
|
||||||
@ -59,11 +59,11 @@ impl<'a> System<'a> for Sys {
|
|||||||
},
|
},
|
||||||
Ok(1_u64..=u64::MAX) => {
|
Ok(1_u64..=u64::MAX) => {
|
||||||
// Update client ping.
|
// Update client ping.
|
||||||
client.last_ping = time.0
|
client.last_ping = program_time.0
|
||||||
},
|
},
|
||||||
Ok(0) => {
|
Ok(0) => {
|
||||||
let last_ping: f64 = client.last_ping;
|
let last_ping: f64 = client.last_ping;
|
||||||
if time.0 - last_ping > settings.client_timeout.as_secs() as f64
|
if program_time.0 - last_ping > settings.client_timeout.as_secs() as f64
|
||||||
// Timeout
|
// Timeout
|
||||||
{
|
{
|
||||||
info!(?entity, "timeout error with client, disconnecting");
|
info!(?entity, "timeout error with client, disconnecting");
|
||||||
@ -71,7 +71,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
entity,
|
entity,
|
||||||
common::comp::DisconnectReason::Timeout,
|
common::comp::DisconnectReason::Timeout,
|
||||||
));
|
));
|
||||||
} else if time.0 - last_ping
|
} else if program_time.0 - last_ping
|
||||||
> settings.client_timeout.as_secs() as f64 * 0.5
|
> settings.client_timeout.as_secs() as f64 * 0.5
|
||||||
{
|
{
|
||||||
// Try pinging the client if the timeout is nearing.
|
// Try pinging the client if the timeout is nearing.
|
||||||
|
@ -9,7 +9,7 @@ use common::{
|
|||||||
comp::{self, Admin, Player, Stats},
|
comp::{self, Admin, Player, Stats},
|
||||||
event::{EventBus, ServerEvent},
|
event::{EventBus, ServerEvent},
|
||||||
recipe::{default_component_recipe_book, default_recipe_book, default_repair_recipe_book},
|
recipe::{default_component_recipe_book, default_recipe_book, default_repair_recipe_book},
|
||||||
resources::{TimeOfDay, TrueTime},
|
resources::TimeOfDay,
|
||||||
shared_server_config::ServerConstants,
|
shared_server_config::ServerConstants,
|
||||||
uid::{IdMaps, Uid},
|
uid::{IdMaps, Uid},
|
||||||
};
|
};
|
||||||
@ -48,7 +48,6 @@ pub struct ReadData<'a> {
|
|||||||
settings: ReadExpect<'a, Settings>,
|
settings: ReadExpect<'a, Settings>,
|
||||||
editable_settings: ReadExpect<'a, EditableSettings>,
|
editable_settings: ReadExpect<'a, EditableSettings>,
|
||||||
time_of_day: Read<'a, TimeOfDay>,
|
time_of_day: Read<'a, TimeOfDay>,
|
||||||
true_time: Read<'a, TrueTime>,
|
|
||||||
material_stats: ReadExpect<'a, comp::item::MaterialStatManifest>,
|
material_stats: ReadExpect<'a, comp::item::MaterialStatManifest>,
|
||||||
ability_map: ReadExpect<'a, comp::item::tool::AbilityMap>,
|
ability_map: ReadExpect<'a, comp::item::tool::AbilityMap>,
|
||||||
map: ReadExpect<'a, WorldMapMsg>,
|
map: ReadExpect<'a, WorldMapMsg>,
|
||||||
@ -330,7 +329,6 @@ impl<'a> System<'a> for Sys {
|
|||||||
.trackers
|
.trackers
|
||||||
.create_entity_package_with_uid(entity, *uid, None, None, None),
|
.create_entity_package_with_uid(entity, *uid, None, None, None),
|
||||||
time_of_day: *read_data.time_of_day,
|
time_of_day: *read_data.time_of_day,
|
||||||
true_time: *read_data.true_time,
|
|
||||||
max_group_size: read_data.settings.max_player_group_size,
|
max_group_size: read_data.settings.max_player_group_size,
|
||||||
client_timeout: read_data.settings.client_timeout,
|
client_timeout: read_data.settings.client_timeout,
|
||||||
world_map: (*read_data.map).clone(),
|
world_map: (*read_data.map).clone(),
|
||||||
|
Loading…
Reference in New Issue
Block a user