Fix and simplify world::for_each_block_optimized#169
Conversation
implement iterators over chunk/section indices intersecting a bounding box delimited by two corners (block positions) and over block positions belonging to a chunk that are within a bounding box
new tests for the new iterators and the `for_each_block_optimized` function in the `world` crate. Note that the function has a bug and some of the tests fail.
use common iterator abstraction to simplify the implementation of `for_each_block_optimized` and `for_each_block_mut_optimized`, also solving a bug they had.
|
Good catch, I initally wrote this code to only work for entire plots, but I seems like I somehow forgot that invariant when making it more generic, thank you very much! |
|
Yeah, I think it’d need benchmarking to see what’s the best performant approach for that, couldn’t think of anything particularly clever to do around it but it may be worth seeing if checking whether we’re in one of the chunk sections on the edge or maybe iterating over those separately from the interior to perform better. |
StackDoubleFlow
left a comment
There was a problem hiding this comment.
Sorry for the late reply, and thanks for taking the time to fix this issue. Just left a small comment, but overall LGTM
First time contributor, so please let me know if I'm doing anything wrong.
I was looking at the source for no particular reason at all and decided to take a stab at this:
MCHPRS/crates/world/src/lib.rs
Line 84 in 76b9b8c
finding a bug in the process.
This PR replaces the duplicated implementation of
for_each_block_optimizedandfor_each_block_mut_optimizedin themchprs_worldcrate with a simpler implementationthat abstracts the iteration logic.
Also this adds tests for the iteration logic and for the
for_each_block_optimizedfunction(which is how I realised that the current implementation had a bug that could lead
to some non-air block being skipped, see #168 for more details); let me know if
they're too verbose or if there should be other cases covered.
With the new implementation #168 should be fixed, since the new iteration special-cases
the bounding box boundaries and otherwise checks the block in batches corresponding
to chunk sections.