diff options
| author | Mel <einebeere@gmail.com> | 2024-02-06 02:10:11 +0100 |
|---|---|---|
| committer | Mel <einebeere@gmail.com> | 2024-02-06 02:10:11 +0100 |
| commit | 1f89fb20d41f9597840250352b40357fc3f0e5d1 (patch) | |
| tree | 7c54e15746740f985dcc6938a64710ed3b3cea3a /src | |
| parent | c61e09ce986fa99debea040a7c0ac42749ad8052 (diff) | |
| download | meowcraft-1f89fb20d41f9597840250352b40357fc3f0e5d1.tar.zst meowcraft-1f89fb20d41f9597840250352b40357fc3f0e5d1.zip | |
Add iteration limit to voxel traversal
Diffstat (limited to 'src')
| -rw-r--r-- | src/World/VoxelTraversal.hpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/World/VoxelTraversal.hpp b/src/World/VoxelTraversal.hpp index 08a53eb..f7b67be 100644 --- a/src/World/VoxelTraversal.hpp +++ b/src/World/VoxelTraversal.hpp @@ -17,6 +17,8 @@ struct TraversalResult { Position::BlockWorldOffset normal; }; +#define MC_WORLD_VOXEL_TRAVERSAL_MAX_ITERATIONS 500 + // Amanatides, John, and Andrew Woo. 1987. // "A Fast Voxel Traversal Algorithm for Ray Tracing." // https://doi.org/10.2312/EGTP.19871000. @@ -52,7 +54,11 @@ TraversalResult traverse(Ray ray, P&& predicate, Real max_distance = 0) { // This just means we add the direction of the ray at the axis we have progressed along. Position::WorldOffset approach = {}; + UInt iterations = 0; while (!predicate(block_pos)) { + if (iterations++ > MC_WORLD_VOXEL_TRAVERSAL_MAX_ITERATIONS) + return {}; + if (max_distance > 0 && approach.magnitude() > max_distance) return {}; |
