From 2c1bb6c268cbd754d425b9eb3b2e44658692ff05 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 13 Jun 2026 13:06:37 +0200 Subject: [PATCH] smol optimize fof checks in P_CheckSight check if fof is solid before height comparisons, also split initial height comparisons to save on some height checks in some cases --- src/p_sight.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/p_sight.c b/src/p_sight.c index 7bde2d737..73c98f8f3 100644 --- a/src/p_sight.c +++ b/src/p_sight.c @@ -432,21 +432,30 @@ boolean P_CheckSight2(mobj_t *t1, mobj_t *t2, boolean fast) continue; } - topz1 = P_GetFFloorTopZAt (rover, t1->x, t1->y); - topz2 = P_GetFFloorTopZAt (rover, t2->x, t2->y); - bottomz1 = P_GetFFloorBottomZAt(rover, t1->x, t1->y); - bottomz2 = P_GetFFloorBottomZAt(rover, t2->x, t2->y); + if (rover->flags & FF_SOLID) + { + continue; // shortcut since neither mobj can be inside the 3dfloor + } // Check for blocking floors here. - if ((los.sightzstart < bottomz1 && t2->z >= topz2) - || (los.sightzstart >= topz1 && t2->z + t2->height < bottomz2)) + + topz2 = P_GetFFloorTopZAt (rover, t2->x, t2->y); + bottomz1 = P_GetFFloorBottomZAt(rover, t1->x, t1->y); + + if (los.sightzstart < bottomz1 && t2->z >= topz2) { // no way to see through that return false; } - if (rover->flags & FF_SOLID) - continue; // shortcut since neither mobj can be inside the 3dfloor + topz1 = P_GetFFloorTopZAt (rover, t1->x, t1->y); + bottomz2 = P_GetFFloorBottomZAt(rover, t2->x, t2->y); + + if (los.sightzstart >= topz1 && t2->z + t2->height < bottomz2) + { + // no way to see through that + return false; + } if (rover->flags & FF_BOTHPLANES || !(rover->flags & FF_INVERTPLANES)) {