Fix bug where crouching affects lighting #38280
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.
Summary
SUMMARY: Bugfixes "Crouching no longer affects lighting"
Purpose of change
Crouching prevents you seeing past adjacent obstacles (like tables / windows). This was implemented by setting the transparency of such tiles to opaque. However, this had the side-effect of preventing light passing as well. Thus, crouching beside a window could make an entire room fall dark.
Describe the solution
Separate the transparency cache into two copies, one for light and one for vision. Make the crouching-related alterations only to the latter.
Describe alternatives you've considered
There are many possibilities here. We could alter the transparency cache between the light and vision casting. We could have one cache that can be interpreted in different ways. We could have some other special-case code in the shadowcasting algorithm.
I chose this solution to not affect the performance of the shadowcasting inner loop, which is what I guessed to be the most important factor. The cost of
memcpy
ing one cache to the other should be minimal.Testing
Added a new test to capture this bug, as well as the crouching-blocks-vision feature in general.
Additional context
I'm surprised no one seems to have reported this bug. It's very jarring to me (but then I have messed with the vision code more than most...).