From 84e04fa906a2afde70a268484cd2d574074514ee Mon Sep 17 00:00:00 2001 From: juliancoffee Date: Fri, 29 Oct 2021 23:48:16 +0300 Subject: [PATCH 1/2] Add size parameter to map_file opts --- world/src/sim/mod.rs | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/world/src/sim/mod.rs b/world/src/sim/mod.rs index 01e9984374..48d69accfc 100644 --- a/world/src/sim/mod.rs +++ b/world/src/sim/mod.rs @@ -138,10 +138,10 @@ pub(crate) struct GenCtx { pub enum FileOpts { /// If set, generate the world map and do not try to save to or load from /// file (default). - Generate, + Generate { x_lg: u32, y_lg: u32 }, /// If set, generate the world map and save the world file (path is created /// the same way screenshot paths are). - Save, + Save { x_lg: u32, y_lg: u32 }, /// If set, load the world file from this path in legacy format (errors if /// path not found). This option may be removed at some point, since it /// only applies to maps generated before map saving was merged into @@ -158,7 +158,7 @@ pub enum FileOpts { } impl Default for FileOpts { - fn default() -> Self { Self::Generate } + fn default() -> Self { Self::Generate { x_lg: 10, y_lg: 10 } } } pub struct WorldOpts { @@ -441,7 +441,7 @@ impl WorldSim { return None; }, }, - FileOpts::Generate | FileOpts::Save => return None, + FileOpts::Generate { .. } | FileOpts::Save { .. } => return None, }; match map { @@ -474,7 +474,18 @@ impl WorldSim { None }, }) - .unwrap_or((None, DEFAULT_WORLD_CHUNKS_LG)); + .unwrap_or_else(|| { + let size_lg = match opts.world_file { + FileOpts::Generate { x_lg, y_lg } | FileOpts::Save { x_lg, y_lg } => { + MapSizeLg::new(Vec2 { x: x_lg, y: y_lg }).unwrap_or_else(|e| { + warn!("World size does not satisfy invariants: {:?}", e); + DEFAULT_WORLD_CHUNKS_LG + }) + }, + _ => DEFAULT_WORLD_CHUNKS_LG, + }; + (None, size_lg) + }); let continent_scale_hack = if let Some(map) = &parsed_world_file { map.continent_scale_hack } else { @@ -1107,7 +1118,7 @@ impl WorldSim { basement, }); (|| { - if let FileOpts::Save = opts.world_file { + if let FileOpts::Save { .. } = opts.world_file { use std::time::SystemTime; // Check if folder exists and create it if it does not let mut path = PathBuf::from("./maps"); From e3804250019e514b040f54a6216334d32fe9b4ef Mon Sep 17 00:00:00 2001 From: Treeco <5021038-Treeco@users.noreply.gitlab.com> Date: Sat, 30 Oct 2021 16:14:10 +0100 Subject: [PATCH 2/2] Add continent_scale_hack setting --- world/examples/water.rs | 2 +- world/src/sim/mod.rs | 31 +++++++++++++++++++++++++++---- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/world/examples/water.rs b/world/examples/water.rs index a2803dffb2..2218678456 100644 --- a/world/examples/water.rs +++ b/world/examples/water.rs @@ -49,7 +49,7 @@ fn main() { seed_elements: false, world_file: sim::FileOpts::LoadAsset(veloren_world::sim::DEFAULT_WORLD_MAP.into()), // world_file: sim::FileOpts::Load(_map_file), - // world_file: sim::FileOpts::Save, + // world_file: sim::FileOpts::Save(sim::SizeOpts::default()), ..WorldOpts::default() }, &threadpool, diff --git a/world/src/sim/mod.rs b/world/src/sim/mod.rs index 48d69accfc..f8616af117 100644 --- a/world/src/sim/mod.rs +++ b/world/src/sim/mod.rs @@ -134,14 +134,32 @@ pub(crate) struct GenCtx { pub uplift_nz: Worley, } +#[derive(Clone, Debug, Deserialize, Serialize)] +#[serde(default)] +pub struct SizeOpts { + x_lg: u32, + y_lg: u32, + scale: f64, +} + +impl Default for SizeOpts { + fn default() -> Self { + Self { + x_lg: 10, + y_lg: 10, + scale: 2.0, + } + } +} + #[derive(Clone, Debug, Deserialize, Serialize)] pub enum FileOpts { /// If set, generate the world map and do not try to save to or load from /// file (default). - Generate { x_lg: u32, y_lg: u32 }, + Generate(SizeOpts), /// If set, generate the world map and save the world file (path is created /// the same way screenshot paths are). - Save { x_lg: u32, y_lg: u32 }, + Save(SizeOpts), /// If set, load the world file from this path in legacy format (errors if /// path not found). This option may be removed at some point, since it /// only applies to maps generated before map saving was merged into @@ -158,7 +176,7 @@ pub enum FileOpts { } impl Default for FileOpts { - fn default() -> Self { Self::Generate { x_lg: 10, y_lg: 10 } } + fn default() -> Self { Self::Generate(SizeOpts::default()) } } pub struct WorldOpts { @@ -476,7 +494,8 @@ impl WorldSim { }) .unwrap_or_else(|| { let size_lg = match opts.world_file { - FileOpts::Generate { x_lg, y_lg } | FileOpts::Save { x_lg, y_lg } => { + FileOpts::Generate(SizeOpts { x_lg, y_lg, .. }) + | FileOpts::Save(SizeOpts { x_lg, y_lg, .. }) => { MapSizeLg::new(Vec2 { x: x_lg, y: y_lg }).unwrap_or_else(|e| { warn!("World size does not satisfy invariants: {:?}", e); DEFAULT_WORLD_CHUNKS_LG @@ -488,6 +507,10 @@ impl WorldSim { }); let continent_scale_hack = if let Some(map) = &parsed_world_file { map.continent_scale_hack + } else if let FileOpts::Generate(SizeOpts { scale, .. }) + | FileOpts::Save(SizeOpts { scale, .. }) = opts.world_file + { + scale } else { continent_scale_hack };