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,
None,
&self.connected_server_constants
);
// TODO: avoid emitting these in the first place
let _ = self

View File

@ -4,4 +4,12 @@ use serde::{Serialize, Deserialize};
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct ServerConstants {
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,
vol::{ReadVol, WriteVol},
weather::{Weather, WeatherGrid},
shared_server_config::ServerConstants,
};
use common_base::span;
use common_ecs::{PhysicsMetrics, SysMetrics};
@ -39,9 +40,6 @@ use std::{sync::Arc, time::Instant};
use timer_queue::TimerQueue;
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
/// we speed physics up too fast, we'd skip important physics events like
/// collisions. This constant determines the upper limit. If delta time exceeds
@ -597,6 +595,7 @@ impl State {
add_systems: impl Fn(&mut DispatcherBuilder),
update_terrain_and_regions: bool,
mut metrics: Option<&mut StateTickMetrics>,
server_constants: &ServerConstants
) {
span!(_guard, "tick", "State::tick");
@ -610,8 +609,7 @@ impl State {
}
// Change the time accordingly.
self.ecs.write_resource::<TimeOfDay>().0 += dt.as_secs_f64() * DAY_CYCLE_FACTOR;
self.ecs.write_resource::<Time>().0 += dt.as_secs_f64();
self.ecs.write_resource::<TimeOfDay>().0 += dt.as_secs_f64() * server_constants.day_cycle_coefficient;
// Update delta time.
// Beyond a delta time of MAX_DELTA_TIME, start lagging to avoid skipping

View File

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

View File

@ -1,6 +1,10 @@
use crate::utils;
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 std::error::Error;
use utils::{DT, DT_F64, EPSILON};
@ -18,6 +22,7 @@ fn simple_run() {
},
false,
None,
&ServerConstants::default(),
);
}

View File

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

View File

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