-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Update and fix various line finding functions #71605
Update and fix various line finding functions #71605
Conversation
this is finally moving in a direction i feel good enough about to make a draft of it
…tual/Cataclysm-DDA into lines-fixes-and-updates
alright so iv refactored all the uses of feedback on changes would be nice so that i dont wast time on stuff, and if theres any other related work or changes that would be useful please let me know ^-^ and if anyone happens to be willing to test any of this id really appreciate it <3 |
…only if end == start was required behavior
To be blunt this is a super scary area of the code to be overhauling. I'm very encouraged by how generally conservative about changing the algorithms themselves you seem to be, so that's great. It would put my mind at ease a great deal if you can get some tests of the specific things (monster-player visibility stuff) that you're specifically addressing working. It should be a relatively simple matter of enumerating a bunch of scenes where the player and monster are peeking at each other around obstacles and make assertions about whether they can see each other. |
completely understandable, these functions do seem to be used in quite a few places that get run Frequently >w> ill try and figure out some useful tests then ^-^ i was also considering making some tests to cover the additional functionality of also if it would be useful, i could throw together a visual diagram of what |
… a little todo list for new tests
…pdates (and scatter_chunks() tweaks since there was a merge conflict)
@kevingranade (hope its alright to mention for a question like this) |
That would be extremely welcome. |
i'm a bit late, but i'm pretty sure what kevin was asking for here was additions to the test suite so that we have continuous integration validating that things are behaving as they are expected to behave. |
adding to the test suite was my impression as well, i just wasnt sure what kinds of tests were desired and which parts they should be testing. my current plan that iv put some time into already but havnt pushed yet is just a whole bunch of tests in line_test.cpp that covers each piece of functionality of the line functions in a somewhat abstract mathematical way. what kevin described was a specific like, real use test case, and i wasnt sure if those were desired over a more direct set of tests |
It would be totally fine if it were abstract and didn't involve actual monsters and players, i.e. "does drawing a line from point A to point B with an intervening obstacle at point C result in the expected line" sort of thing. |
Closing as stale. If you wish to continue working on this, ping me to reopen. |
Summary
Bugfixes "Fixes to various line finding functions"
Purpose of change
Fixes #11422, fixes #61471, and probably other similar things. Also to clean up a lot of code that uses line functions since they're kinda all over the place right now and in some places the wrong functions are used there's then more code to make them work.
Describe the solution
I have a comment further down explaining how all this works, but it's a bit complicated so essentially:
bresenham()
function (and by extension everything that uses it) now gives a centered line by default, and has been given full 3d support.find_clear_path()
replacement, which I've renamed tofind_line_to()
, now correctly tries every relevant offset line, and either returns the center-most line that reached the target, or the line that got the furthest if none of them made it all the way.map.sees()
orline_to()
is used but then the line is checked Again for specific conditions at each point, so I have remade some of the functions to let you specify whatever test conditions or code you want to run at each tile so that we only iterate over the line once. This also means that when we do something likefind_line_to()
, we can find the valid line given the test we want to apply to each tile, and not just whatever the first line the default test is for that function is returns.Describe alternatives you've considered
There's a lot of different ways this could be done, and especially the way the replacement functions I'm making could be handled, which is why I'm making this draft!
Testing
Lots of throwing rocks in various situations. I also tested a few of the replacement reworks I made, such as the melee attack code that checks for a line spears can pass through if were using a spear, etc. So far everything works but given that I'm moving chunks of code to inside the interact function there could be stuff I missed.
Additional context
This is very much a work in progress, so please say what features and ideas of this sound useful and which don't! I'm also fairly new to C++ so I'm almost Certainly doing things wrong and would love to know how to do things right.