Add a ServerConstants to Client and Server structs and sync on register.

This commit is contained in:
Sophia Waggoner 2023-03-21 20:28:08 -07:00
parent b649774316
commit 7e4ea483e0
5 changed files with 25 additions and 1 deletions

View File

@ -50,6 +50,7 @@ use common::{
uid::{Uid, UidAllocator}, uid::{Uid, UidAllocator},
vol::RectVolSize, vol::RectVolSize,
weather::{Weather, WeatherGrid}, weather::{Weather, WeatherGrid},
shared_server_config::ServerConstants,
}; };
#[cfg(feature = "tracy")] use common_base::plot; #[cfg(feature = "tracy")] use common_base::plot;
use common_base::{prof_span, span}; use common_base::{prof_span, span};
@ -264,6 +265,8 @@ pub struct Client {
pending_chunks: HashMap<Vec2<i32>, Instant>, pending_chunks: HashMap<Vec2<i32>, Instant>,
target_time_of_day: Option<TimeOfDay>, target_time_of_day: Option<TimeOfDay>,
connected_server_constants: ServerConstants
} }
/// Holds data related to the current players characters, as well as some /// Holds data related to the current players characters, as well as some
@ -355,6 +358,7 @@ impl Client {
component_recipe_book, component_recipe_book,
material_stats, material_stats,
ability_map, ability_map,
server_constants,
} = loop { } = loop {
tokio::select! { tokio::select! {
// Spawn in a blocking thread (leaving the network thread free). This is mostly // Spawn in a blocking thread (leaving the network thread free). This is mostly
@ -744,6 +748,8 @@ impl Client {
pending_chunks: HashMap::new(), pending_chunks: HashMap::new(),
target_time_of_day: None, target_time_of_day: None,
connected_server_constants: server_constants
}) })
} }

View File

@ -17,6 +17,7 @@ use common::{
uid::Uid, uid::Uid,
uuid::Uuid, uuid::Uuid,
weather::WeatherGrid, weather::WeatherGrid,
shared_server_config::ServerConstants,
}; };
use hashbrown::HashMap; use hashbrown::HashMap;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -66,6 +67,7 @@ pub enum ServerInit {
component_recipe_book: ComponentRecipeBook, component_recipe_book: ComponentRecipeBook,
material_stats: MaterialStatManifest, material_stats: MaterialStatManifest,
ability_map: comp::item::tool::AbilityMap, ability_map: comp::item::tool::AbilityMap,
server_constants: ServerConstants
}, },
} }

View File

@ -1,4 +1,7 @@
use serde::{Serialize, Deserialize};
/// Per-server constant data (configs) that stays the same for the server's life. /// Per-server constant data (configs) that stays the same for the server's life.
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct ServerConstants { pub struct ServerConstants {
day_cycle_coefficient: f64, pub day_cycle_coefficient: f64,
} }

View File

@ -82,6 +82,7 @@ use common::{
slowjob::SlowJobPool, slowjob::SlowJobPool,
terrain::{TerrainChunk, TerrainChunkSize}, terrain::{TerrainChunk, TerrainChunkSize},
vol::RectRasterableVol, vol::RectRasterableVol,
shared_server_config::ServerConstants,
}; };
use common_ecs::run_now; use common_ecs::run_now;
use common_net::{ use common_net::{
@ -205,6 +206,8 @@ pub struct Server {
metrics_shutdown: Arc<Notify>, metrics_shutdown: Arc<Notify>,
database_settings: Arc<RwLock<DatabaseSettings>>, database_settings: Arc<RwLock<DatabaseSettings>>,
disconnect_all_clients_requested: bool, disconnect_all_clients_requested: bool,
server_constants: ServerConstants,
} }
impl Server { impl Server {
@ -561,6 +564,10 @@ impl Server {
#[cfg(not(feature = "worldgen"))] #[cfg(not(feature = "worldgen"))]
rtsim::init(&mut state); rtsim::init(&mut state);
let server_constants = ServerConstants {
day_cycle_coefficient: 1400.0 / settings.day_length
};
let this = Self { let this = Self {
state, state,
world, world,
@ -571,6 +578,8 @@ impl Server {
metrics_shutdown, metrics_shutdown,
database_settings, database_settings,
disconnect_all_clients_requested: false, disconnect_all_clients_requested: false,
server_constants,
}; };
debug!(?settings, "created veloren server with"); debug!(?settings, "created veloren server with");

View File

@ -11,6 +11,7 @@ use common::{
recipe::{default_component_recipe_book, default_recipe_book}, recipe::{default_component_recipe_book, default_recipe_book},
resources::TimeOfDay, resources::TimeOfDay,
uid::{Uid, UidAllocator}, uid::{Uid, UidAllocator},
shared_server_config::ServerConstants,
}; };
use common_base::prof_span; use common_base::prof_span;
use common_ecs::{Job, Origin, Phase, System}; use common_ecs::{Job, Origin, Phase, System};
@ -349,6 +350,9 @@ impl<'a> System<'a> for Sys {
component_recipe_book: default_component_recipe_book().cloned(), component_recipe_book: default_component_recipe_book().cloned(),
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 {
day_cycle_coefficient: 1400.0 / read_data.settings.day_length
},
})?; })?;
debug!("Done initial sync with client."); debug!("Done initial sync with client.");