v0.9.1: fixed rare cases of artifacting in the shadowcaster

This commit is contained in:
Evan Debenham 2020-11-16 19:50:31 -05:00
parent 348acd23ac
commit 0f6c06002f

View File

@ -80,9 +80,6 @@ public final class ShadowCaster {
int x, int y, double lSlope, double rSlope,
int mX, int mY, boolean mXY){
//if we have negative space to traverse, just quit.
if (rSlope < lSlope) return;
boolean inBlocking = false;
int start, end;
int col;
@ -92,6 +89,9 @@ public final class ShadowCaster {
//for each row, starting with the current one
for (; row <= distance; row++){
//if we have negative space to traverse, just quit.
if (rSlope < lSlope) return;
//we offset by slightly less than 0.5 to account for slopes just touching a cell
if (lSlope == 0) start = 0;
else start = (int)Math.floor((row - 0.5) * lSlope + 0.499);
@ -110,6 +110,13 @@ public final class ShadowCaster {
//for each column in this row, which
for (col = start; col <= end; col++){
//handles the error case of the slope value at the end of a cell being 1 farther
// along then at the beginning of the cell, and that earlier cell is vision blocking
if (col == end && inBlocking && (int)Math.ceil((row - 0.5) * rSlope - 0.499) != end){
break;
}
fov[cell] = true;
if (blocking[cell]){