-
Notifications
You must be signed in to change notification settings - Fork 566
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
get_line() refactor #5452
get_line() refactor #5452
Conversation
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
Conflicts have been resolved. A maintainer will review the pull request shortly. |
CORRECTION: the path is more consistently reversible that before, but its not always reversible. From about 70% for the original |
add small constant to each step to avoid small inaccuracies causing .99999 and rounding down
Compensated for a rounding inaccuracy, it is now consistently reversible for at least 100+ tiles. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good and haven't seen any big behaviour changes or problems from TM.
About the pull request
The codebase currently has three line-drawing algorithms:
get_line()
- never usedgetline()
- used oncegetline2()
- used many timesThey are all almost identical. There is no real use-case for one over the the other.
This PR removes
getline()
andgetline2()
and replaces those proc calls withget_line()
. Furthermore,get_line()
is replaced with a different method using linear interpolation, based on the examples here: https://www.redblobgames.com/grids/line-drawing/#optimizationThe pros of this new method are consistent, reversible projectile paths (if you can shoot them they can shoot you), and that it is possibly more performant. Bresenham's line algorithm is famously fast -- for the 1960s. This new one looks to be faster on modern computer hardware. Floats aren't scary anymore.
Explain why it's good for the game
Less duplicated code. Consistent projectile paths.
Testing Photographs and Procedure
Screenshots & Videos
The functions of interest are:
get_line()
,getline()
,getline2()
- in our codebasegetline_tgmc()
- TGMC's "Reasonably Optimized" version: https://github.com/tgstation/TerraGov-Marine-Corps/blob/2da5c237640d73e3e66ad79e34861e9682f4609c/code/__HELPERS/unsorted.dm#L816-L869get_line_testA()
- the proposed replacementThe output of
get_line_testA()
is not identical togetline2()
. A path starting at the center pillar and ending on a tiled floor has different results.The following examples are a comparison between
getline2()
andget_line_testA()
. All paths start at the wall and end at the ghost. Purple tiles are where both functions picked the same turf, red is unique togetline2()
, blue is unique toget_line_testA()
. Note thatget_line_testA()
results in the same path taken regardless of direction.Example 1a: SW to NE
Example 1b: NE to SW
Example 2a: NW to SE
Example 2b: SE to NW
Changelog
🆑
refactor: projectile paths are the same in both directions, A->B and B->A
/:cl: