diff --git a/src/r_main.c b/src/r_main.c index 2f7ecfb6e..4d79fda92 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -325,29 +325,6 @@ PUREFUNC INT32 R_PointOnSide(fixed_t x, fixed_t y, const node_t *restrict node) (~mask & (FixedMul(y, node->dx>>FRACBITS) >= FixedMul(node->dy>>FRACBITS, x))); } -// killough 5/2/98: reformatted -PUREFUNC INT32 R_PointOnSegSide(fixed_t x, fixed_t y, const seg_t *line) -{ - fixed_t lx = line->v1->x; - fixed_t ly = line->v1->y; - fixed_t ldx = line->v2->x - lx; - fixed_t ldy = line->v2->y - ly; - - 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); -} - // // R_PointToAngle // To get a global angle from cartesian coordinates, diff --git a/src/r_main.h b/src/r_main.h index 2d7503ea7..0bfa8bfa5 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -73,7 +73,18 @@ extern lighttable_t *zlight[LIGHTLEVELS][MAXLIGHTZ]; // Utility functions. INT32 R_PointOnSide(fixed_t x, fixed_t y, const node_t *node); -INT32 R_PointOnSegSide(fixed_t x, fixed_t y, const seg_t *line); + +FUNCINLINE static ATTRINLINE PUREFUNC INT32 R_PointOnSegSide(fixed_t x, fixed_t y, const seg_t *line) +{ + fixed_t lx = line->v1->x; + fixed_t ly = line->v1->y; + 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; +} + angle_t R_PointToAngle(fixed_t x, fixed_t y); angle_t R_PointToAngle64(INT64 x, INT64 y); angle_t R_PointToAngle2(fixed_t px2, fixed_t py2, fixed_t px1, fixed_t py1);