From f02b571f7f153da5fc05b97098c73f20aea62983 Mon Sep 17 00:00:00 2001 From: jshipsey Date: Sat, 24 Aug 2019 15:32:07 -0400 Subject: [PATCH] fmt --- world/src/sim/mod.rs | 91 +++++++++++++++++++++++-------------------- world/src/sim/util.rs | 11 +++--- 2 files changed, 54 insertions(+), 48 deletions(-) diff --git a/world/src/sim/mod.rs b/world/src/sim/mod.rs index f4f66828f9..df8bfa9332 100644 --- a/world/src/sim/mod.rs +++ b/world/src/sim/mod.rs @@ -136,9 +136,11 @@ impl WorldSim { // from -0.25 * (CONFIG.mountain_scale * 1.1) to 0.25 * (CONFIG.mountain_scale * 0.9), // but value here is from -0.275 to 0.225). let alt_base = uniform_noise(|_, wposf| { - Some((gen_ctx.alt_nz.get((wposf.div(12_000.0)).into_array()) as f32) - .sub(0.1) - .mul(0.25)) + Some( + (gen_ctx.alt_nz.get((wposf.div(12_000.0)).into_array()) as f32) + .sub(0.1) + .mul(0.25), + ) }); // -1 to 1. @@ -151,10 +153,11 @@ impl WorldSim { let chaos = uniform_noise(|posi, wposf| { // From 0 to 1.6, but the distribution before the max is from -1 and 1, so there is a // 50% chance that hill will end up at 0. - let hill = (0.0 + gen_ctx - .hill_nz - .get((wposf.div(1_500.0)).into_array()) - .mul(1.0) as f32 + let hill = (0.0 + + gen_ctx + .hill_nz + .get((wposf.div(1_500.0)).into_array()) + .mul(1.0) as f32 + gen_ctx .hill_nz .get((wposf.div(400.0)).into_array()) @@ -162,36 +165,38 @@ impl WorldSim { .add(0.3) .max(0.0); - Some((gen_ctx.chaos_nz.get((wposf.div(3_000.0)).into_array()) as f32) - .add(1.0) - .mul(0.5) - // [0, 1] * [0.25, 1] = [0, 1] (but probably towards the lower end) - .mul( - (gen_ctx.chaos_nz.get((wposf.div(6_000.0)).into_array()) as f32) - .abs() - .max(0.25) - .min(1.0), - ) - // Chaos is always increased by a little when we're on a hill (but remember that - // hill is 0 about 50% of the time). - // [0, 1] + 0.15 * [0, 1.6] = [0, 1.24] - .add(0.2 * hill) - // [0, 1.24] * [0.35, 1.0] = [0, 1.24]. - // Sharply decreases (towards 0.35) when temperature is near desert_temp (from below), - // then saturates just before it actually becomes desert. Otherwise stays at 1. - // Note that this is not the *final* temperature, only the initial noise value for - // temperature. - .mul( - temp_base[posi] - .1 - .sub(0.45) - .neg() - .mul(12.0) - .max(0.35) - .min(1.0), - ) - // We can't have *no* chaos! - .max(0.1)) + Some( + (gen_ctx.chaos_nz.get((wposf.div(3_000.0)).into_array()) as f32) + .add(1.0) + .mul(0.5) + // [0, 1] * [0.25, 1] = [0, 1] (but probably towards the lower end) + .mul( + (gen_ctx.chaos_nz.get((wposf.div(6_000.0)).into_array()) as f32) + .abs() + .max(0.25) + .min(1.0), + ) + // Chaos is always increased by a little when we're on a hill (but remember that + // hill is 0 about 50% of the time). + // [0, 1] + 0.15 * [0, 1.6] = [0, 1.24] + .add(0.2 * hill) + // [0, 1.24] * [0.35, 1.0] = [0, 1.24]. + // Sharply decreases (towards 0.35) when temperature is near desert_temp (from below), + // then saturates just before it actually becomes desert. Otherwise stays at 1. + // Note that this is not the *final* temperature, only the initial noise value for + // temperature. + .mul( + temp_base[posi] + .1 + .sub(0.45) + .neg() + .mul(12.0) + .max(0.35) + .min(1.0), + ) + // We can't have *no* chaos! + .max(0.1), + ) }); // We ignore sea level because we actually want to be relative to sea level here and want @@ -219,8 +224,8 @@ impl WorldSim { + (gen_ctx.small_nz.get((wposf.div(300.0)).into_array()) as f32) .mul(alt_main.max(0.25)) .mul(0.3) - .add(1.0) - .mul(0.5)) + .add(1.0) + .mul(0.5)) }; // Now we can compute the final altitude using chaos. @@ -236,9 +241,11 @@ impl WorldSim { if alt[posi].1 <= 5.0.div(CONFIG.mountain_scale) { None } else { - Some((gen_ctx.humid_nz.get(wposf.div(1024.0).into_array()) as f32) - .add(1.0) - .mul(0.5)) + Some( + (gen_ctx.humid_nz.get(wposf.div(1024.0).into_array()) as f32) + .add(1.0) + .mul(0.5), + ) } }); diff --git a/world/src/sim/util.rs b/world/src/sim/util.rs index 5f1b3254b1..cf30ed11e3 100644 --- a/world/src/sim/util.rs +++ b/world/src/sim/util.rs @@ -133,13 +133,12 @@ pub fn uniform_idx_as_vec2(idx: usize) -> Vec2 { pub fn uniform_noise(f: impl Fn(usize, Vec2) -> Option) -> InverseCdf { let mut noise = (0..WORLD_SIZE.x * WORLD_SIZE.y) .filter_map(|i| { - ( - f( - i, - (uniform_idx_as_vec2(i) * TerrainChunkSize::SIZE.map(|e| e as i32)) - .map(|e| e as f64), - ).map(|res| (i, res)) + (f( + i, + (uniform_idx_as_vec2(i) * TerrainChunkSize::SIZE.map(|e| e as i32)) + .map(|e| e as f64), ) + .map(|res| (i, res))) }) .collect::>();