From c63b01e4f1df68bf43f88accfd385c88170a657c Mon Sep 17 00:00:00 2001 From: "Dr. Dystopia" Date: Tue, 1 Jun 2021 18:14:02 +0200 Subject: [PATCH] Extract 'new_method' from 'apply_paths_to' --- world/src/layer/mod.rs | 46 ++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/world/src/layer/mod.rs b/world/src/layer/mod.rs index 9785b7b01a..659a77afb2 100644 --- a/world/src/layer/mod.rs +++ b/world/src/layer/mod.rs @@ -7,7 +7,7 @@ pub use self::{scatter::apply_scatter_to, tree::apply_trees_to}; use crate::{ column::ColumnSample, util::{FastNoise, RandomField, Sampler}, - Canvas, IndexRef, + Canvas, CanvasInfo, IndexRef, }; use common::{ assets::AssetExt, @@ -53,25 +53,7 @@ pub fn apply_paths_to(canvas: &mut Canvas) { { let inset = 0; - // Try to use the column at the centre of the path for sampling to make them - // flatter - let col_pos = -info.wpos().map(|e| e as f32) + path_nearest; - let col00 = info.col(info.wpos() + col_pos.map(|e| e.floor() as i32) + Vec2::new(0, 0)); - let col10 = info.col(info.wpos() + col_pos.map(|e| e.floor() as i32) + Vec2::new(1, 0)); - let col01 = info.col(info.wpos() + col_pos.map(|e| e.floor() as i32) + Vec2::new(0, 1)); - let col11 = info.col(info.wpos() + col_pos.map(|e| e.floor() as i32) + Vec2::new(1, 1)); - let col_attr = |col: &ColumnSample| { - Vec3::new(col.riverless_alt, col.alt, col.water_dist.unwrap_or(1000.0)) - }; - let [riverless_alt, alt, water_dist] = match (col00, col10, col01, col11) { - (Some(col00), Some(col10), Some(col01), Some(col11)) => Lerp::lerp( - Lerp::lerp(col_attr(col00), col_attr(col10), path_nearest.x.fract()), - Lerp::lerp(col_attr(col01), col_attr(col11), path_nearest.x.fract()), - path_nearest.y.fract(), - ), - _ => col_attr(col), - } - .into_array(); + let (riverless_alt, alt, water_dist) = new_method(info, col, path_nearest); let (bridge_offset, depth) = ( ((water_dist.max(0.0) * 0.2).min(f32::consts::PI).cos() + 1.0) * 5.0, ((1.0 - ((water_dist + 2.0) * 0.3).min(0.0).cos().abs()) @@ -107,6 +89,30 @@ pub fn apply_paths_to(canvas: &mut Canvas) { }); } +//TODO: Rename +fn new_method(info: CanvasInfo, col: &ColumnSample, path_nearest: Vec2) -> (f32, f32, f32) { + // Try to use the column at the centre of the path for sampling to make them + // flatter + let col_pos = -info.wpos().map(|e| e as f32) + path_nearest; + let col00 = info.col(info.wpos() + col_pos.map(|e| e.floor() as i32) + Vec2::new(0, 0)); + let col10 = info.col(info.wpos() + col_pos.map(|e| e.floor() as i32) + Vec2::new(1, 0)); + let col01 = info.col(info.wpos() + col_pos.map(|e| e.floor() as i32) + Vec2::new(0, 1)); + let col11 = info.col(info.wpos() + col_pos.map(|e| e.floor() as i32) + Vec2::new(1, 1)); + let col_attr = |col: &ColumnSample| { + Vec3::new(col.riverless_alt, col.alt, col.water_dist.unwrap_or(1000.0)) + }; + let [riverless_alt, alt, water_dist] = match (col00, col10, col01, col11) { + (Some(col00), Some(col10), Some(col01), Some(col11)) => Lerp::lerp( + Lerp::lerp(col_attr(col00), col_attr(col10), path_nearest.x.fract()), + Lerp::lerp(col_attr(col01), col_attr(col11), path_nearest.x.fract()), + path_nearest.y.fract(), + ), + _ => col_attr(col), + } + .into_array(); + (riverless_alt, alt, water_dist) +} + pub fn apply_caves_to(canvas: &mut Canvas, rng: &mut impl Rng) { let info = canvas.info(); canvas.foreach_col(|canvas, wpos2d, col| {