From 58bf1572de519fa6e6dc30a7de6662d6f65c7b3a Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 15 Oct 2024 23:52:17 +0200 Subject: [PATCH] Revert "optimize R_PointOnSegSide" This reverts commit 068afd7eb4d9cfed0fd2e2f9a887df2fa33e591a. --- src/r_main.h | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/r_main.h b/src/r_main.h index 1cc09a346..ef0a8c3bc 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -106,8 +106,19 @@ FUNCINLINE static ATTRINLINE PUREFUNC INT32 R_PointOnSegSide(fixed_t x, fixed_t fixed_t ldx = line->v2->x - lx; fixed_t ldy = line->v2->y - ly; - // heavily optimized version of R_PointOnSide, stolen from GZDoom. - return (INT64)(y - ly) * ldx + (INT64)(lx - x) * ldy > 0; + if (!ldx) + return x <= lx ? ldy > 0 : ldy < 0; + + if (!ldy) + return y <= ly ? ldx < 0 : ldx > 0; + + x -= lx; + y -= ly; + + // Try to quickly decide by looking at sign bits. + if ((ldy ^ ldx ^ x ^ y) < 0) + return (ldy ^ x) < 0; // (left is negative) + return FixedMul(y, ldx>>FRACBITS) >= FixedMul(ldy>>FRACBITS, x); } angle_t R_PointToAngle(fixed_t x, fixed_t y);