mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Added world settings
This commit is contained in:
parent
bccbbfa3b9
commit
6397e283b2
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -9,6 +9,10 @@ use crate::data::{
|
|||||||
use hashbrown::HashMap;
|
use hashbrown::HashMap;
|
||||||
use rand::prelude::*;
|
use rand::prelude::*;
|
||||||
use tracing::info;
|
use tracing::info;
|
||||||
|
use common::{
|
||||||
|
rtsim::WorldSettings,
|
||||||
|
resources::TimeOfDay,
|
||||||
|
};
|
||||||
use world::{
|
use world::{
|
||||||
site::SiteKind,
|
site::SiteKind,
|
||||||
IndexRef,
|
IndexRef,
|
||||||
@ -16,7 +20,7 @@ use world::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
impl Data {
|
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];
|
let mut seed = [0; 32];
|
||||||
seed.iter_mut().zip(&mut index.seed.to_le_bytes()).for_each(|(dst, src)| *dst = *src);
|
seed.iter_mut().zip(&mut index.seed.to_le_bytes()).for_each(|(dst, src)| *dst = *src);
|
||||||
let mut rng = SmallRng::from_seed(seed);
|
let mut rng = SmallRng::from_seed(seed);
|
||||||
@ -26,7 +30,7 @@ impl Data {
|
|||||||
npcs: Npcs { npcs: Default::default() },
|
npcs: Npcs { npcs: Default::default() },
|
||||||
sites: Sites { sites: Default::default() },
|
sites: Sites { sites: Default::default() },
|
||||||
|
|
||||||
time_of_day: Default::default(),
|
time_of_day: TimeOfDay(settings.start_time),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Register sites with rtsim
|
// Register sites with rtsim
|
||||||
|
@ -459,7 +459,7 @@ impl Server {
|
|||||||
state.ecs_mut().insert(index.clone());
|
state.ecs_mut().insert(index.clone());
|
||||||
|
|
||||||
// Set starting time for the server.
|
// 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
|
// Register trackers
|
||||||
sys::sentinel::UpdateTrackers::register(state.ecs_mut());
|
sys::sentinel::UpdateTrackers::register(state.ecs_mut());
|
||||||
@ -565,7 +565,7 @@ impl Server {
|
|||||||
// Init rtsim, loading it from disk if possible
|
// Init rtsim, loading it from disk if possible
|
||||||
#[cfg(feature = "worldgen")]
|
#[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) => {
|
Ok(rtsim) => {
|
||||||
state.ecs_mut().insert(rtsim.state().data().time_of_day);
|
state.ecs_mut().insert(rtsim.state().data().time_of_day);
|
||||||
state.ecs_mut().insert(rtsim);
|
state.ecs_mut().insert(rtsim);
|
||||||
|
@ -5,7 +5,7 @@ pub mod tick;
|
|||||||
use common::{
|
use common::{
|
||||||
grid::Grid,
|
grid::Grid,
|
||||||
slowjob::SlowJobPool,
|
slowjob::SlowJobPool,
|
||||||
rtsim::{ChunkResource, RtSimEntity},
|
rtsim::{ChunkResource, RtSimEntity, WorldSettings},
|
||||||
terrain::{TerrainChunk, Block},
|
terrain::{TerrainChunk, Block},
|
||||||
vol::RectRasterableVol,
|
vol::RectRasterableVol,
|
||||||
};
|
};
|
||||||
@ -41,7 +41,7 @@ pub struct RtSim {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl 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);
|
let file_path = Self::get_file_path(data_dir);
|
||||||
|
|
||||||
info!("Looking for rtsim data at {}...", file_path.display());
|
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).");
|
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.");
|
info!("Rtsim data generated.");
|
||||||
data
|
data
|
||||||
};
|
};
|
||||||
|
@ -17,6 +17,7 @@ use chrono::Utc;
|
|||||||
use common::{
|
use common::{
|
||||||
calendar::{Calendar, CalendarEvent},
|
calendar::{Calendar, CalendarEvent},
|
||||||
resources::BattleMode,
|
resources::BattleMode,
|
||||||
|
rtsim::WorldSettings,
|
||||||
};
|
};
|
||||||
use core::time::Duration;
|
use core::time::Duration;
|
||||||
use portpicker::pick_unused_port;
|
use portpicker::pick_unused_port;
|
||||||
@ -184,6 +185,9 @@ pub struct Settings {
|
|||||||
pub gameplay: GameplaySettings,
|
pub gameplay: GameplaySettings,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub moderation: ModerationSettings,
|
pub moderation: ModerationSettings,
|
||||||
|
|
||||||
|
#[serde(default)]
|
||||||
|
pub world: WorldSettings,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Settings {
|
impl Default for Settings {
|
||||||
@ -213,6 +217,7 @@ impl Default for Settings {
|
|||||||
experimental_terrain_persistence: false,
|
experimental_terrain_persistence: false,
|
||||||
gameplay: GameplaySettings::default(),
|
gameplay: GameplaySettings::default(),
|
||||||
moderation: ModerationSettings::default(),
|
moderation: ModerationSettings::default(),
|
||||||
|
world: WorldSettings::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -292,7 +297,6 @@ impl Settings {
|
|||||||
},
|
},
|
||||||
server_name: "Singleplayer".to_owned(),
|
server_name: "Singleplayer".to_owned(),
|
||||||
max_players: 100,
|
max_players: 100,
|
||||||
start_time: 9.0 * 3600.0,
|
|
||||||
max_view_distance: None,
|
max_view_distance: None,
|
||||||
client_timeout: Duration::from_secs(180),
|
client_timeout: Duration::from_secs(180),
|
||||||
..load // Fill in remaining fields from server_settings.ron.
|
..load // Fill in remaining fields from server_settings.ron.
|
||||||
|
Loading…
Reference in New Issue
Block a user