Ultimately use setting in day cycle updates.

(First functional commit.)
This commit is contained in:
Sophia Waggoner 2023-03-21 21:32:05 -07:00
parent 7e4ea483e0
commit 4a3d1bbb86
7 changed files with 24 additions and 7 deletions

View File

@ -1804,6 +1804,7 @@ impl Client {
}, },
true, true,
None, None,
&self.connected_server_constants
); );
// TODO: avoid emitting these in the first place // TODO: avoid emitting these in the first place
let _ = self let _ = self

View File

@ -4,4 +4,12 @@ use serde::{Serialize, Deserialize};
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone)]
pub struct ServerConstants { pub struct ServerConstants {
pub day_cycle_coefficient: f64, pub day_cycle_coefficient: f64,
}
impl Default for ServerConstants {
fn default() -> Self {
ServerConstants {
// == 30.0 via server settings (the default)
day_cycle_coefficient: 24.0 * 2.0,
}
}
} }

View File

@ -22,6 +22,7 @@ use common::{
trade::Trades, trade::Trades,
vol::{ReadVol, WriteVol}, vol::{ReadVol, WriteVol},
weather::{Weather, WeatherGrid}, weather::{Weather, WeatherGrid},
shared_server_config::ServerConstants,
}; };
use common_base::span; use common_base::span;
use common_ecs::{PhysicsMetrics, SysMetrics}; use common_ecs::{PhysicsMetrics, SysMetrics};
@ -39,9 +40,6 @@ use std::{sync::Arc, time::Instant};
use timer_queue::TimerQueue; use timer_queue::TimerQueue;
use vek::*; use vek::*;
/// How much faster should an in-game day be compared to a real day?
// TODO: Don't hard-code this.
const DAY_CYCLE_FACTOR: f64 = 24.0 * 2.0;
/// At what point should we stop speeding up physics to compensate for lag? If /// At what point should we stop speeding up physics to compensate for lag? If
/// we speed physics up too fast, we'd skip important physics events like /// we speed physics up too fast, we'd skip important physics events like
/// collisions. This constant determines the upper limit. If delta time exceeds /// collisions. This constant determines the upper limit. If delta time exceeds
@ -597,6 +595,7 @@ impl State {
add_systems: impl Fn(&mut DispatcherBuilder), add_systems: impl Fn(&mut DispatcherBuilder),
update_terrain_and_regions: bool, update_terrain_and_regions: bool,
mut metrics: Option<&mut StateTickMetrics>, mut metrics: Option<&mut StateTickMetrics>,
server_constants: &ServerConstants
) { ) {
span!(_guard, "tick", "State::tick"); span!(_guard, "tick", "State::tick");
@ -610,8 +609,7 @@ impl State {
} }
// Change the time accordingly. // Change the time accordingly.
self.ecs.write_resource::<TimeOfDay>().0 += dt.as_secs_f64() * DAY_CYCLE_FACTOR; self.ecs.write_resource::<TimeOfDay>().0 += dt.as_secs_f64() * server_constants.day_cycle_coefficient;
self.ecs.write_resource::<Time>().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

View File

@ -9,7 +9,7 @@ mod tests {
terrain::{MapSizeLg, TerrainChunk}, terrain::{MapSizeLg, TerrainChunk},
uid::Uid, uid::Uid,
util::Dir, util::Dir,
SkillSetBuilder, SkillSetBuilder, shared_server_config::ServerConstants,
}; };
use common_ecs::dispatch; use common_ecs::dispatch;
use common_state::State; use common_state::State;
@ -81,6 +81,8 @@ mod tests {
}, },
false, false,
None, None,
// Dummy ServerConstants
&ServerConstants::default(),
); );
} }

View File

@ -1,6 +1,10 @@
use crate::utils; use crate::utils;
use approx::assert_relative_eq; use approx::assert_relative_eq;
use common::{comp::Controller, resources::Time}; use common::{
comp::Controller,
resources::Time,
shared_server_config::ServerConstants,
};
use specs::WorldExt; use specs::WorldExt;
use std::error::Error; use std::error::Error;
use utils::{DT, DT_F64, EPSILON}; use utils::{DT, DT_F64, EPSILON};
@ -18,6 +22,7 @@ fn simple_run() {
}, },
false, false,
None, None,
&ServerConstants::default(),
); );
} }

View File

@ -11,6 +11,7 @@ use common::{
terrain::{ terrain::{
Block, BlockKind, MapSizeLg, SpriteKind, TerrainChunk, TerrainChunkMeta, TerrainGrid, Block, BlockKind, MapSizeLg, SpriteKind, TerrainChunk, TerrainChunkMeta, TerrainGrid,
}, },
shared_server_config::ServerConstants,
}; };
use common_ecs::{dispatch, System}; use common_ecs::{dispatch, System};
use common_net::sync::WorldSyncExt; use common_net::sync::WorldSyncExt;
@ -64,6 +65,7 @@ pub fn tick(state: &mut State, dt: Duration) {
}, },
false, false,
None, None,
&ServerConstants::default(),
); );
} }

View File

@ -710,6 +710,7 @@ impl Server {
}, },
false, false,
Some(&mut state_tick_metrics), Some(&mut state_tick_metrics),
&self.server_constants
); );
let before_handle_events = Instant::now(); let before_handle_events = Instant::now();