From 32fdcc1c1c4c390dc61d9a1f16ff7a5c35659330 Mon Sep 17 00:00:00 2001 From: Joshua Yanovski Date: Tue, 5 Jul 2022 23:00:05 -0700 Subject: [PATCH] Fix iteration area. I'm pretty sure this bug already existed on master, so if the performance degradation is unacceptable, we can revert. --- world/benches/site2.rs | 8 ++++---- world/src/layer/tree.rs | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/world/benches/site2.rs b/world/benches/site2.rs index 879633227d..6425f5ce95 100644 --- a/world/benches/site2.rs +++ b/world/benches/site2.rs @@ -305,8 +305,8 @@ fn dungeon(c: &mut Criterion) { // let chunk_pos = Vec2::new(842, 839); // let chunk_pos = Vec2::new(24507/32, 20682/32); // let chunk_pos = Vec2::new(19638/32, 19621/32); - let chunk_pos = Vec2::new(21488/32, 13584/32); - // let chunk_pos = Vec2::new(21488/32 + 5, 13584/32 + 5); + // let chunk_pos = Vec2::new(21488/32, 13584/32); + let chunk_pos = Vec2::new(21488/32 + 5, 13584/32 + 5); b.iter(|| { black_box(world.generate_chunk(index.as_index_ref(), chunk_pos, || false, None)); }); @@ -319,8 +319,8 @@ fn dungeon(c: &mut Criterion) { // let chunk_pos = Vec2::new(842, 839); // let chunk_pos = Vec2::new(24507/32, 20682/32); // let chunk_pos = Vec2::new(19638/32, 19621/32); - let chunk_pos = Vec2::new(21488/32, 13584/32); - // let chunk_pos = Vec2::new(21488/32 + 5, 13584/32 + 5); + // let chunk_pos = Vec2::new(21488/32, 13584/32); + let chunk_pos = Vec2::new(21488/32 + 5, 13584/32 + 5); let chunk = world.generate_chunk(index.as_index_ref(), chunk_pos, || false, None).unwrap().0; /* println!("{:?}", chunk.sub_chunks_len()); let chunk = chunk.sub_chunks().next().unwrap(); */ diff --git a/world/src/layer/tree.rs b/world/src/layer/tree.rs index 963e472548..9a785b7127 100644 --- a/world/src/layer/tree.rs +++ b/world/src/layer/tree.rs @@ -122,17 +122,27 @@ pub fn apply_trees_to( let calendar = info.calendar(); /* let mut tree_cache = StructureGenCache::new(info.chunks().gen_ctx.structure_gen.clone()); */ + let area_size = Vec2::from(info.area().size().map(|e| e as i32)); + // Get all the trees in range. let render_area = Aabr { min: info.wpos(), - max: info.wpos() + Vec2::from(info.area().size().map(|e| e as i32)), + max: info.wpos() + area_size, + }; + + // Maximum area we have to check for tree origins. + let witness_area = Aabr { + min: info.wpos() - area_size, + max: info.wpos() + Vec2::from(info.area().size().map(|e| e as i32)) + area_size, }; let mut arena = bumpalo::Bump::new(); /*canvas.foreach_col(|canvas, wpos2d, col| {*/ info.chunks() - .get_area_trees(render_area.min + 15, render_area.max + 16) + // TODO: These should be in terms of some combination of frequency and chunk size. + .get_area_trees(render_area.min - 8, render_area.max + 16) + .filter(|attr| witness_area.contains_point(attr.pos)) .filter_map(|attr| { info.col_or_gen(attr.pos) .filter(|col| tree_valid_at(col, attr.seed))