From 6d5e42f10bf62c7b1db9f73c86eafa9f9db33414 Mon Sep 17 00:00:00 2001 From: Joshua Yanovski Date: Sun, 26 Jan 2020 16:18:51 +0100 Subject: [PATCH] Better is_underwater() check. Takes rivers into account somewhat, and doesn't take up extra space in SimChunk. --- world/src/lib.rs | 2 +- world/src/sim/mod.rs | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/world/src/lib.rs b/world/src/lib.rs index 3745a84a1a..6954bbe4dd 100644 --- a/world/src/lib.rs +++ b/world/src/lib.rs @@ -152,7 +152,7 @@ impl World { let mut supplement = ChunkSupplement { entities: if rand::thread_rng().gen::() < SPAWN_RATE && sim_chunk.chaos < 0.5 - && !sim_chunk.is_underwater + && !sim_chunk.is_underwater() { vec![EntityInfo { pos: gen_entity_pos(), diff --git a/world/src/sim/mod.rs b/world/src/sim/mod.rs index b7be46d288..2bb51baf21 100644 --- a/world/src/sim/mod.rs +++ b/world/src/sim/mod.rs @@ -1475,7 +1475,7 @@ impl WorldSim { let new_chunk = this.get(downhill_pos)?; const SLIDE_THRESHOLD: f32 = 5.0; - if new_chunk.is_underwater || new_chunk.alt + SLIDE_THRESHOLD < chunk.alt { + if new_chunk.is_underwater() || new_chunk.alt + SLIDE_THRESHOLD < chunk.alt { break; } else { chunk = new_chunk; @@ -1720,7 +1720,6 @@ pub struct SimChunk { pub spawn_rate: f32, pub location: Option, pub river: RiverData, - pub is_underwater: bool, pub structures: Structures, pub contains_waypoint: bool, @@ -1898,7 +1897,6 @@ impl SimChunk { } else { 0.0 }, - is_underwater, is_cliffs: cliff > 0.5 && !is_underwater, near_cliffs: cliff > 0.2, tree_density, @@ -1971,6 +1969,10 @@ impl SimChunk { } } + pub fn is_underwater(&self) -> bool { + self.river.river_kind.is_some() + } + pub fn get_base_z(&self) -> f32 { self.alt - self.chaos * 50.0 - 16.0 }