lighting: add BUGFIX for MakeLightTable #2302
Merged
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.
The i/j/k/l variables obfuscate the fact that the distance formula used for generating data in lightblock is using the x offset with the y component of the tile coordinate and vice-versa.
Mixing x and y this way causes light to move horizontally within a tile when the light source is moving vertically and vice-versa.
To verify, if you check the places where
lightblockis used, the code looks something like this.lightblock[xoff + 8*yoff][y][x]Compared to that, the addition and multiplication operators are swapped in
lightblock[j * 8 + i][k][l], therefore it suggests the following relationships.i = xoffj = yoffk = yl = xSubtituting these into the distance formula just a few lines up, we get:
sqrt((8 * x - yoff) * (8 * x - yoff) + (8 * y - xoff) * (8 * y - xoff))In this formula, you can clearly see that the x and y terms are being mixed up, and swapping
iandjin the equation above would swap thexoffandyoffterms in the formula. Swapping the addition and multiplication operators gives the same result, but it also matches the code in the places wherelightblockis used.See:
devilution/Source/lighting.cpp
Line 571 in 6b7135c