From 28d5478d10efe3a34dfe6af33e61041f07d8f879 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Sun, 26 Jan 2020 13:05:28 +0000 Subject: [PATCH] Use .downhill for waypoint generation --- world/src/sim/mod.rs | 28 +++++----------------------- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/world/src/sim/mod.rs b/world/src/sim/mod.rs index 7e376cc96c..5279d372fb 100644 --- a/world/src/sim/mod.rs +++ b/world/src/sim/mod.rs @@ -1461,32 +1461,14 @@ impl WorldSim { .into_par_iter() .filter_map(|(i, j)| { let mut pos = Vec2::new(i as i32, j as i32); - // Slide the waypoints down hills - for _ in 0..32 { - let last_pos = pos; - let chunk = this.get(pos)?; - - for dir in [ - Vec2::new(1, 0), - Vec2::new(-1, 0), - Vec2::new(0, 1), - Vec2::new(0, -1), - ] - .iter() - { - const MAX_HEIGHT_DIFF: f32 = 8.0; - let tgt_chunk = this.get(pos + *dir)?; - if tgt_chunk.alt + MAX_HEIGHT_DIFF < chunk.alt && !tgt_chunk.is_underwater { - pos += *dir; - } - } - - if last_pos == pos { - break; + const MAX_ITERS: usize = 64; + for _ in 0..MAX_ITERS { + match this.get(pos)?.downhill { + Some(downhill) => pos = downhill, + None => return Some(pos), } } - Some(pos) }) .collect::>();