Added world settings

This commit is contained in:
Joshua Barretto 2022-08-14 16:38:31 +01:00
parent bccbbfa3b9
commit 6397e283b2
5 changed files with 29 additions and 8 deletions

View File

@ -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
}
}
}

View File

@ -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

View File

@ -459,7 +459,7 @@ impl Server {
state.ecs_mut().insert(index.clone());
// Set starting time for the server.
state.ecs_mut().write_resource::<TimeOfDay>().0 = settings.start_time;
state.ecs_mut().write_resource::<TimeOfDay>().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);

View File

@ -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<Self, ron::Error> {
pub fn new(settings: &WorldSettings, index: IndexRef, world: &World, data_dir: PathBuf) -> Result<Self, ron::Error> {
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
};

View File

@ -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.