From 057b8a73546446a30fd7948a771f48d35ec2eda0 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 10 Apr 2021 12:54:29 +0200 Subject: [PATCH] - cleanup of bvectan family of functions. This can be greatly simplified to a single bvectangbam function using atan2 directly. --- source/build/src/polymost.cpp | 2 +- source/core/binaryangle.h | 47 +---------------------- source/core/rendering/scene/hw_portal.cpp | 5 ++- source/games/sw/src/player.cpp | 4 +- 4 files changed, 10 insertions(+), 48 deletions(-) diff --git a/source/build/src/polymost.cpp b/source/build/src/polymost.cpp index 307111c3c..118212656 100644 --- a/source/build/src/polymost.cpp +++ b/source/build/src/polymost.cpp @@ -3315,7 +3315,7 @@ void renderPrepareMirror(int32_t dax, int32_t day, int32_t daz, fixed_t daang, f *tposx = (x << 1) + Scale(dx, i, j) - dax; *tposy = (y << 1) + Scale(dy, i, j) - day; - *tang = ((bvectangq16(dx, dy) << 1) - daang) & 0x7FFFFFF; + *tang = ((bvectangbam(dx, dy).asq16() << 1) - daang) & 0x7FFFFFF; inpreparemirror = 1; diff --git a/source/core/binaryangle.h b/source/core/binaryangle.h index e4d86116a..a0690d734 100644 --- a/source/core/binaryangle.h +++ b/source/core/binaryangle.h @@ -502,54 +502,11 @@ inline FSerializer &Serialize(FSerializer &arc, const char *key, fixedhoriz &obj //--------------------------------------------------------------------------- // -// Double-precision implementation of `getangle()` with associated wrappers and helper functions. +// High precision vector angle function, mainly for the renderer. // //--------------------------------------------------------------------------- -inline double bradarangf(double vect) -{ - return atan(vect) * BRadAngScale; -} -inline double bvectangf(int32_t x, int32_t y) -{ - if ((x | y) == 0) - { - return 0; - } - else if (x == 0) - { - return 512 + ((y < 0) << 10); - } - else if (y == 0) - { - return ((x < 0) << 10); - } - else if (x == y) - { - return 256 + ((x < 0) << 10); - } - else if (x == -y) - { - return 768 + ((x > 0) << 10); - } - else if (abs(x) > abs(y)) - { - return fmod(bradarangf(double(y) / x) + ((x < 0) << 10), 2048.); - } - else - { - return fmod(bradarangf(double(x) / -y) + 512 + ((y < 0) << 10), 2048.); - } -} -inline int32_t bvectang(int32_t x, int32_t y) -{ - return xs_CRoundToInt(bvectangf(x, y)); -} -inline fixed_t bvectangq16(int32_t x, int32_t y) -{ - return FloatToFixed(bvectangf(x, y)); -} inline binangle bvectangbam(int32_t x, int32_t y) { - return bamang(xs_CRoundToUInt(bvectangf(x, y) * BAMUNIT)); + return radang(atan2(y, x)); } diff --git a/source/core/rendering/scene/hw_portal.cpp b/source/core/rendering/scene/hw_portal.cpp index db37b870f..cf35cc320 100644 --- a/source/core/rendering/scene/hw_portal.cpp +++ b/source/core/rendering/scene/hw_portal.cpp @@ -574,7 +574,10 @@ bool HWMirrorPortal::Setup(HWDrawInfo *di, FRenderState &rstate, Clipper *clippe int newx = int((x << 1) + Scale(dx, i, j) - view.x); int newy = int((y << 1) + Scale(dy, i, j) - view.y); - auto newan = bamang(int64_t((bvectangf(dx, dy) * (BAMUNIT << 1)) - vp.RotAngle) & 0xFFFFFFFF); + + auto myan = bvectangbam(dx, dy); + auto newan = myan + myan - bamang(vp.RotAngle); + vp.RotAngle = newan.asbam(); vp.SectNums = nullptr; vp.SectCount = line->sector; diff --git a/source/games/sw/src/player.cpp b/source/games/sw/src/player.cpp index 766b511f0..a8ab12403 100644 --- a/source/games/sw/src/player.cpp +++ b/source/games/sw/src/player.cpp @@ -7148,7 +7148,9 @@ domovethings(void) // auto tracking mode for single player multi-game if (numplayers <= 1 && PlayerTrackingMode && pnum == screenpeek && screenpeek != myconnectindex) { - Player[screenpeek].angle.settarget(bvectangf(Player[myconnectindex].posx - Player[screenpeek].posx, Player[myconnectindex].posy - Player[screenpeek].posy)); + int deltax = Player[myconnectindex].posx - Player[screenpeek].posx; + int deltay = Player[myconnectindex].posy - Player[screenpeek].posy; + Player[screenpeek].angle.settarget(bvectangbam(deltax, deltay)); } if (!TEST(pp->Flags, PF_DEAD))