Skip to content

Improve distance checking

This fixes a lot of whack with distance calculations by replacing almost all instances of R_PointToDist2(), FixedHypot() and P_AproxDist() with a new family of functions, all derived from the original R_PointToDist2(), that offer the following benefits:

  • Clearer and more unified naming scheme
  • Variants for calculating 3D distances without long, messy expressions
  • Variants for calculating mobj distances and the momentum of a mobj
  • Variants that return the distance as an integer, to allow distance checks across distance > 32k FU, essential in large maps
  • Variants for performing proximity checks without running into integer overflows in large maps
  • Much higher accuracy than P_AproxDist(). Note that some instances have been intentionally left out due to certain parts of the codebase (mostly the player movement code, player.speed and minecart jumps) apparently not liking accuracy...

This should fix most if not all issues mentioned in #1145, such as enemies detecting you from extremely far away, axis searches or explosions of various kinds affecting your from the opposite side of a large level.

Please note that there probably remain a few distance-related issues which I either overlooked or ignored because I wasn't sure what the best fix was (bosses in particular).

All the new functions are also exposed to Lua and R_PointToDist2() will be removed for 2.3 as it has become redundant and its name is unclear.

I have tested this fairly extensively in vanilla (not modded) by going through the entire singleplayer campaign, including all bosses (except Metal Sonic because he sucks real hard) and a few NiGHTs stages.

Edited by LJ Sonic

Merge request reports

Loading