Fix inconsistencies with margin reconciliation logic #386
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes two bugs related to #379.
Bug 1
Some of the logic assumed that world generation would never create "solid" chunks unless it was sure that the chunk was deep enough underground or high enough up in the air to not touch any surfaces. This assumption allowed us to avoid reconciling margins between a solid chunk and a dense chunk unless the dense chunk was "modified".
However, since this assumption was incorrect (for instance, due to world generation not turning solid "void" chunks into dense chunks unless a voxel is actually generated), this produced gaps in the terrain whenever a dense chunk met a solid void chunk.
Bug 2
When a voxel is modified, we assumed that only neighboring chunks' margins needs to update, since all other margins should already be correct. However, if we want to be certain, we also need to update the margins of the chunk the modified voxel is in. This is because we only guarantee that margin voxels are the correct material when they would be rendered.
Because of this, it would have been possible to dig down into a solid dirt chunk, dig across a bit, and dig up again, seeing what looks like dirt in a neighboring chunk's voxel no matter what material that voxel actually is.
Solution
The fix to bug 1 is to remove the assumption, adding logic to
fix_margins
to handle either chunk being solid.The fix to bug 2 is to change
update_margin_voxel
into a bidirectional update, updating the margins of both relevant chunks. Since this changes the public interface of the function, I also renamed it toreconcile_margin_voxels
.Bonus cleanup
The only purpose of the
modified
boolean inChunk::Populated
was to determine whether assumptions based on world generation would hold when determining whether chunks should be solid or not. Since we no longer make assumptions based on world generation, this field is now obsolete, allowing us to remove it completely.