From 6397e283b2eef7c74fbd439a02f332db27cea04d Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Sun, 14 Aug 2022 16:38:31 +0100 Subject: [PATCH] Added world settings --- common/src/rtsim.rs | 13 +++++++++++++ rtsim/src/gen/mod.rs | 8 ++++++-- server/src/lib.rs | 4 ++-- server/src/rtsim2/mod.rs | 6 +++--- server/src/settings.rs | 6 +++++- 5 files changed, 29 insertions(+), 8 deletions(-) diff --git a/common/src/rtsim.rs b/common/src/rtsim.rs index de97dc66bc..905a2c0e9b 100644 --- a/common/src/rtsim.rs +++ b/common/src/rtsim.rs @@ -122,3 +122,16 @@ impl Profession { } } } + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct WorldSettings { + pub start_time: f64, +} + +impl Default for WorldSettings { + fn default() -> Self { + Self { + start_time: 9.0 * 3600.0, // 9am + } + } +} diff --git a/rtsim/src/gen/mod.rs b/rtsim/src/gen/mod.rs index 3e14d02963..898d49b055 100644 --- a/rtsim/src/gen/mod.rs +++ b/rtsim/src/gen/mod.rs @@ -9,6 +9,10 @@ use crate::data::{ use hashbrown::HashMap; use rand::prelude::*; use tracing::info; +use common::{ + rtsim::WorldSettings, + resources::TimeOfDay, +}; use world::{ site::SiteKind, IndexRef, @@ -16,7 +20,7 @@ use world::{ }; impl Data { - pub fn generate(world: &World, index: IndexRef) -> Self { + pub fn generate(settings: &WorldSettings, world: &World, index: IndexRef) -> Self { let mut seed = [0; 32]; seed.iter_mut().zip(&mut index.seed.to_le_bytes()).for_each(|(dst, src)| *dst = *src); let mut rng = SmallRng::from_seed(seed); @@ -26,7 +30,7 @@ impl Data { npcs: Npcs { npcs: Default::default() }, sites: Sites { sites: Default::default() }, - time_of_day: Default::default(), + time_of_day: TimeOfDay(settings.start_time), }; // Register sites with rtsim diff --git a/server/src/lib.rs b/server/src/lib.rs index de44b7edc1..94c8dc7efb 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -459,7 +459,7 @@ impl Server { state.ecs_mut().insert(index.clone()); // Set starting time for the server. - state.ecs_mut().write_resource::().0 = settings.start_time; + state.ecs_mut().write_resource::().0 = settings.world.start_time; // Register trackers sys::sentinel::UpdateTrackers::register(state.ecs_mut()); @@ -565,7 +565,7 @@ impl Server { // Init rtsim, loading it from disk if possible #[cfg(feature = "worldgen")] { - match rtsim2::RtSim::new(index.as_index_ref(), &world, data_dir.to_owned()) { + match rtsim2::RtSim::new(&settings.world, index.as_index_ref(), &world, data_dir.to_owned()) { Ok(rtsim) => { state.ecs_mut().insert(rtsim.state().data().time_of_day); state.ecs_mut().insert(rtsim); diff --git a/server/src/rtsim2/mod.rs b/server/src/rtsim2/mod.rs index 6f2faf4357..2df1720c1c 100644 --- a/server/src/rtsim2/mod.rs +++ b/server/src/rtsim2/mod.rs @@ -5,7 +5,7 @@ pub mod tick; use common::{ grid::Grid, slowjob::SlowJobPool, - rtsim::{ChunkResource, RtSimEntity}, + rtsim::{ChunkResource, RtSimEntity, WorldSettings}, terrain::{TerrainChunk, Block}, vol::RectRasterableVol, }; @@ -41,7 +41,7 @@ pub struct RtSim { } impl RtSim { - pub fn new(index: IndexRef, world: &World, data_dir: PathBuf) -> Result { + pub fn new(settings: &WorldSettings, index: IndexRef, world: &World, data_dir: PathBuf) -> Result { let file_path = Self::get_file_path(data_dir); info!("Looking for rtsim data at {}...", file_path.display()); @@ -81,7 +81,7 @@ impl RtSim { warn!("'RTSIM_NOLOAD' is set, skipping loading of rtsim state (old state will be overwritten)."); } - let data = Data::generate(&world, index); + let data = Data::generate(settings, &world, index); info!("Rtsim data generated."); data }; diff --git a/server/src/settings.rs b/server/src/settings.rs index 304a95b24e..a01e420e09 100644 --- a/server/src/settings.rs +++ b/server/src/settings.rs @@ -17,6 +17,7 @@ use chrono::Utc; use common::{ calendar::{Calendar, CalendarEvent}, resources::BattleMode, + rtsim::WorldSettings, }; use core::time::Duration; use portpicker::pick_unused_port; @@ -184,6 +185,9 @@ pub struct Settings { pub gameplay: GameplaySettings, #[serde(default)] pub moderation: ModerationSettings, + + #[serde(default)] + pub world: WorldSettings, } impl Default for Settings { @@ -213,6 +217,7 @@ impl Default for Settings { experimental_terrain_persistence: false, gameplay: GameplaySettings::default(), moderation: ModerationSettings::default(), + world: WorldSettings::default(), } } } @@ -292,7 +297,6 @@ impl Settings { }, server_name: "Singleplayer".to_owned(), max_players: 100, - start_time: 9.0 * 3600.0, max_view_distance: None, client_timeout: Duration::from_secs(180), ..load // Fill in remaining fields from server_settings.ron.