Skip to content

Conversation

@StephenCWills
Copy link
Member

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 lightblock is 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 = xoff
  • j = yoff
  • k = y
  • l = x

Subtituting 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 i and j in the equation above would swap the xoff and yoff terms in the formula. Swapping the addition and multiplication operators gives the same result, but it also matches the code in the places where lightblock is used.

See:

mult = xoff + 8 * yoff;

@StephenCWills StephenCWills force-pushed the bugfix-MakeLightTable branch from d65d08b to 32be26d Compare March 13, 2025 23:40
@StephenCWills
Copy link
Member Author

I added a brief explanation in the comment to make it clearer what the bugfix fixes.

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.
@StephenCWills StephenCWills force-pushed the bugfix-MakeLightTable branch from 32be26d to 61499a3 Compare March 13, 2025 23:43
@AJenbo AJenbo merged commit 14a9620 into diasurgical:master Mar 14, 2025
4 of 6 checks passed
@StephenCWills StephenCWills deleted the bugfix-MakeLightTable branch March 14, 2025 00:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants