Clean up day coefficient code

This commit is contained in:
Joshua Barretto 2023-05-14 22:10:37 +01:00
parent 9f52e49e78
commit 140927cbe7
5 changed files with 9 additions and 11 deletions

View File

@ -139,7 +139,7 @@ hashbrown = { version = "0.13", features = ["rayon", "serde", "nightly"] }
fxhash = { version = "0.2.1" } fxhash = { version = "0.2.1" }
crossbeam-utils = { version = "0.8.1"} crossbeam-utils = { version = "0.8.1"}
crossbeam-channel = { version = "0.5"} crossbeam-channel = { version = "0.5"}
ordered-float = { version = "3", default-features = false } ordered-float = { version = "3", default-features = false, features = ["std"] }
num = { version = "0.4" } num = { version = "0.4" }
num-traits = { version = "0.2" } num-traits = { version = "0.2" }
vek = { version = "0.15.8", features = ["serde"] } vek = { version = "0.15.8", features = ["serde"] }

View File

@ -4,13 +4,7 @@ use serde::{Deserialize, Serialize};
/// life. /// life.
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone)]
pub struct ServerConstants { pub struct ServerConstants {
/// How many times faster the in-game day/night cycle should be compared to
/// real time.
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

@ -573,7 +573,7 @@ impl Server {
} }
let server_constants = ServerConstants { let server_constants = ServerConstants {
day_cycle_coefficient: 1440.0 / settings.day_length, day_cycle_coefficient: settings.day_cycle_coefficient(),
}; };
let this = Self { let this = Self {

View File

@ -324,6 +324,10 @@ impl Settings {
self.day_length = default_values.day_length; self.day_length = default_values.day_length;
} }
} }
/// Derive a coefficient that is the relatively speed of the in-game
/// day/night cycle compared to reality.
pub fn day_cycle_coefficient(&self) -> f64 { 1440.0 / self.day_length }
} }
pub enum InvalidSettingsError { pub enum InvalidSettingsError {

View File

@ -352,7 +352,7 @@ impl<'a> System<'a> for Sys {
material_stats: (*read_data.material_stats).clone(), material_stats: (*read_data.material_stats).clone(),
ability_map: (*read_data.ability_map).clone(), ability_map: (*read_data.ability_map).clone(),
server_constants: ServerConstants { server_constants: ServerConstants {
day_cycle_coefficient: 1440.0 / read_data.settings.day_length day_cycle_coefficient: read_data.settings.day_cycle_coefficient()
}, },
})?; })?;
debug!("Done initial sync with client."); debug!("Done initial sync with client.");