From abd07aea09bef8e783e1ed6852975bb44ca604ed Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Fri, 5 Jul 2019 21:37:38 +0100 Subject: [PATCH] Improved z caching --- world/src/block/mod.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/world/src/block/mod.rs b/world/src/block/mod.rs index 301a79b221..be6a98a5fc 100644 --- a/world/src/block/mod.rs +++ b/world/src/block/mod.rs @@ -82,10 +82,11 @@ impl<'a> BlockGen<'a> { column_gen, } = self; + // Main sample let sample = Self::sample_column(column_gen, column_cache, wpos)?; + // Tree samples let mut tree_samples = [None, None, None, None, None, None, None, None, None]; - for i in 0..tree_samples.len() { tree_samples[i] = Self::sample_column( column_gen, @@ -129,6 +130,7 @@ impl<'a> BlockGen<'a> { let tree_samples = &z_cache?.tree_samples; + let wpos2d = Vec2::from(wpos); let wposf = wpos.map(|e| e as f64); let (definitely_underground, height, water_height) = @@ -318,7 +320,8 @@ impl<'a> BlockGen<'a> { if tree_sample.tree_density > 0.5 + (*tree_seed as f32 / 1000.0).fract() * 0.2 && tree_sample.alt > tree_sample.water_level - && tree_sample.spawn_rate > 0.5 => + && tree_sample.spawn_rate > 0.5 + && wpos2d.distance_squared(*tree_pos) < 20 * 20 => { let cliff_height = Self::get_cliff_height( column_gen,