From 2c1697fae68f030aa1912ccf41fdbbbf03a499d4 Mon Sep 17 00:00:00 2001 From: Tobias Berger Date: Sun, 4 Sep 2022 19:35:10 +0200 Subject: [PATCH] Tweak world generation 86178d7bb5bfe3733e0b3379da17811c032347e9 --- save/src/world.rs | 29 ++++++++++++++++------------- save/src/world_manager.rs | 2 ++ 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/save/src/world.rs b/save/src/world.rs index 13b648b..fc058d6 100644 --- a/save/src/world.rs +++ b/save/src/world.rs @@ -164,8 +164,6 @@ impl World { for x in 0..self.terrain[y].len() { let beta = (x as f32 / self.width as f32) * TAU; - let continent_value = self.continent_modifier(x, y); - let value_1 = self.random_noise_from_polar_coordinates(alpha, beta, RADIUS_1, offset_1)?; let value_2 = @@ -177,23 +175,28 @@ impl World { let value_5 = self.random_noise_from_polar_coordinates(alpha, beta, RADIUS_5, offset_5)?; - let value = continent_value; - let value = mix_values(value, value_3, Self::TERRAIN_NOISE_FACTOR_1); - let value = value * mix_values(1.0, value_4, Self::TERRAIN_NOISE_FACTOR_2); - let value = - value * mix_values(1.0, value_5, Self::TERRAIN_NOISE_FACTOR_3) * 0.2 + 0.4; + let continent_value = self.continent_modifier(x, y); + + let mut value_continent = continent_value; + value_continent = + mix_values(value_continent, value_3, Self::TERRAIN_NOISE_FACTOR_1); + value_continent *= mix_values(1.0, value_4, Self::TERRAIN_NOISE_FACTOR_2); + + let value_b = mix_values(1.0, value_5, Self::TERRAIN_NOISE_FACTOR_3); let mut value_mountain = mix_values(value_1, value_2, Self::MOUNTAIN_RANGE_MIX_FACTOR); value_mountain = self.mountain_range_noise_from_random_noise(value_mountain); - value_mountain = mix_values(value_mountain, value_3, Self::TERRAIN_NOISE_FACTOR_1); value_mountain = - value_mountain * mix_values(1.0, value_4, Self::TERRAIN_NOISE_FACTOR_2); - value_mountain = - value_mountain * mix_values(1.0, value_5, Self::TERRAIN_NOISE_FACTOR_3); - value_mountain = 2.0 * value_mountain * value; + mix_values(value_mountain, value_3, Self::TERRAIN_NOISE_FACTOR_1 * 1.5); + value_mountain *= mix_values(1.0, value_4, Self::TERRAIN_NOISE_FACTOR_2 * 1.5); + value_mountain *= mix_values(1.0, value_5, Self::TERRAIN_NOISE_FACTOR_3 * 1.5); - self.terrain[y][x].altitude = Self::calculate_altitude(value_mountain); + let mut raw_altitude = mix_values(value_continent, value_mountain, 0.25); + raw_altitude = mix_values(raw_altitude, value_mountain, 0.1); + raw_altitude = mix_values(raw_altitude, value_b, 0.1); + + self.terrain[y][x].altitude = Self::calculate_altitude(raw_altitude); } } Ok(()) diff --git a/save/src/world_manager.rs b/save/src/world_manager.rs index c7a805d..62b8bd6 100644 --- a/save/src/world_manager.rs +++ b/save/src/world_manager.rs @@ -10,9 +10,11 @@ impl WorldManager { pub fn new() -> WorldManager { WorldManager { world: None } } + pub fn get_world(&self) -> Option<&World> { self.world.as_ref() } + pub fn new_world(&mut self) -> Result<&World, WorldGenError> { let seed = random(); let mut new_world = World::new(400, 200, seed);