Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug where crouching affects lighting #38280

Merged

Conversation

jbytheway
Copy link
Contributor

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 memcpying 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...).

@jbytheway jbytheway force-pushed the crouching_affects_lighting branch from e5fd233 to c3cf52c Compare February 23, 2020 20:30
There are a bunch of types which are just a std::array of pointers to
two-dimensional arrays.  These are all quite verbose.

Introduce a template alias to simplify all those types.
Crouching affects your ability to see past adjacent obstacles.
Previously this was implemented by altering the transparency cache.
However, this also stops light passing the tile, and means that
crouching by a window can cause a room to fall dark.

Fix by separating the transparency cache into two, one for light and one
for vision.  The latter is a copy of the former, except with tweaks for
crouching and with the avatar's tile forced to be transparent.
This tests that the player cannot see past an adjacent obstacle when
crouching, but light can still pass it.
@jbytheway jbytheway force-pushed the crouching_affects_lighting branch from c3cf52c to 9528517 Compare February 24, 2020 00:09
@ZhilkinSerg ZhilkinSerg added <Bugfix> This is a fix for a bug (or closes open issue) [C++] Changes (can be) made in C++. Previously named `Code` labels Feb 24, 2020
@Rivet-the-Zombie Rivet-the-Zombie merged commit bd3524c into CleverRaven:master Feb 24, 2020
@jbytheway jbytheway deleted the crouching_affects_lighting branch February 24, 2020 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
<Bugfix> This is a fix for a bug (or closes open issue) [C++] Changes (can be) made in C++. Previously named `Code`
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants