CleverRaven / CleverRaven/Cataclysm-DDA
Apply Cube Assisted raymarching optimization to FoV code.
- Dominant language
- C++
- Stars
- 13.2k
- Forks
- 4.6k
- Avg merge
- 2d 1h
- Merged PRs (30d)
- 205
Description
The technique outlined at https://medium.com/@calebleak/raymarching-voxel-rendering-58018201d9d6 looks to be usable for optimization of our FoV calculation.
Specifically, if we can "stride" across a row of cells that are all transparent/opaque without checking them, it should significantly improve performance of the shadowcasting algorithm.
Some variant of https://stackoverflow.com/questions/1726632/dynamic-programming-largest-square-block/1726667#1726667 can be used to calculate the contiguous bounding box for each square, at which point encountering a square with a contiguous transparent or opaque span surrounding it can trigger a "stride" of either skipping many cells, or setting the value of a number of cells with minimal overhead.
Above "largest square block" algorithm can be used to find blocks, and a single iteration over the grid in the opposite direction can convert the "size of block starting in this corner" field to a tuple describing the block as a whole. Each cell would store the x/y[/z] offset from the current cell to the center of the square, along with the width or radius of the square. Both coordinates would be adjusted to allow tile intersections to be specified as the square center (to allow squares with sides an even number in length instead of being centered on a tile).
This approach has an additional benefit of detecting if an entire z-level has a contiguous transparency level.
Alternately, a similar approach can be used to find x/y[/z] lines instead of squares, which may be more optimal for FoV calculation. In the first pass this would accumulate largest x/y[/z] line of the same value, and the second pass would convert this to store a tuple indicating +x/-x/+y/-y[/+z/-z] of identical values.
In either case, a single signed byte is sufficient to record arbitrary distances and offsets within the extant map grid (121 < 127).
Contributor guide
Research direction
Start by locating the FoV calculation and its shadowcasting algorithm in the C++ code, then read the linked raymarching and largest-square-block references. Compare the square-block and line-based approaches against the current grid representation and map bounds. Done means a measured FoV performance improvement with equivalent visibility results.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- game-dev, performance
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100