Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

for_each_block{,_mut}_optimized can skip non-air blocks #168

Open
verglasz opened this issue Dec 25, 2024 · 0 comments
Open

for_each_block{,_mut}_optimized can skip non-air blocks #168

verglasz opened this issue Dec 25, 2024 · 0 comments

Comments

@verglasz
Copy link

The functions for_each_block_optimized and for_each_block_mut_optimized
in the mchprs_world crate can in some cases not invoke the given callback on
block positions which contains block (i.e., which aren't air).

This could happen because the iteration loops over batches of 16x16x16 blocks
that aren't aligned to chunk boundaries and the check for emptyness looks at the
chunk section where one of the corners of the batch is located, see:
https://github.com/MCHPR/MCHPRS/blob/76b9b8cf575ee4419eca5c2cd9dac56405a2cafe/crates/world/src/lib.rs#L156~L161
however the iteration then proceeds to all the blocks inside this batch, which can
include blocks in other chunks/section:
https://github.com/MCHPR/MCHPRS/blob/76b9b8cf575ee4419eca5c2cd9dac56405a2cafe/crates/world/src/lib.rs#L164~L166

So for example if we're looking at a region between BlockPos{x: 15, y:15, z:15}
and BlockPos{x: 40, y:40, z:40}, the previous logic would check if the chunk
section to which BlockPos{x: 15, y:15, z:15} belongs is empty (i.e., section 0
of chunk 0,0), and if it is, it would skip all the blocks between that point
and BlockPos{x: 31, y:31, z:31}, despite some of these being in other chunks/sections
not tested for emptiness yet; so e.g. if everything is air except a block
at BlockPos{x: 25, y:25, z:25}, this block would be skipped as its chunk section (section 1 of chunk 1,1)
is only checked for emptiness when deciding whether to iterate over batches that don't
include this point; the batch that would iterate over it has looked at section 0 of chunk 0,0.
(Incidentally this also reduces the effectiveness of the optimization
since some areas that are empty are still checked).

I hope this explanation makes sense, happy to clarify further if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant