From bd9924b794ed5e7b89f04278d295c937a31b8afb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustaf=20Alh=C3=A4ll?= Date: Mon, 18 Aug 2025 18:24:39 +0200 Subject: [PATCH] Optimize line checks on line interception --- src/p_maputl.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/p_maputl.c b/src/p_maputl.c index bba3e9776..b6d8d1ff3 100644 --- a/src/p_maputl.c +++ b/src/p_maputl.c @@ -105,15 +105,11 @@ void P_ClosestPointOnLine3D(const vector3_t *p, const vector3_t *Line, vector3_t // P_PointOnLineSide // Returns 0 or 1 // -// killough 5/3/98: reformatted, cleaned up -// ioanch 20151228: made line const -// INT32 P_PointOnLineSide(fixed_t x, fixed_t y, const line_t *line) { - return - !line->dx ? x <= line->v1->x ? line->dy > 0 : line->dy < 0 : - !line->dy ? y <= line->v1->y ? line->dx < 0 : line->dx > 0 : - ((INT64)y - line->v1->y) * line->dx >= line->dy * ((INT64)x - line->v1->x); + // use cross product to determine side quickly + INT64 v = ((INT64)y - line->v1->y) * line->dx - ((INT64)x - line->v1->x) * line->dy; + return v > 0; } // @@ -153,15 +149,11 @@ INT32 P_BoxOnLineSide(const fixed_t *tmbox, const line_t *ld) // P_PointOnDivlineSide // Returns 0 or 1. // -// killough 5/3/98: reformatted, cleaned up -// static INT32 P_PointOnDivlineSide(fixed_t x, fixed_t y, const divline_t *line) { - return - line->dx == 0 ? x <= line->x ? line->dy > 0 : line->dy < 0 : - line->dy == 0 ? y <= line->y ? line->dx < 0 : line->dx > 0 : - (line->dy ^ line->dx ^ (x -= line->x) ^ (y -= line->y)) < 0 ? (line->dy ^ x) < 0 : - (INT64)(y) * line->dx >= (INT64)(line->dy) * x; + // use cross product to determine side quickly + INT64 v = ((INT64)y - line->y) * line->dx - ((INT64)x - line->x) * line->dy; + return v > 0; } //