From 60f845bf9ea9dfd0104404a284b3b5c8869f4d64 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 12 May 2026 15:02:44 +0200 Subject: [PATCH] P_TryMove: reduce the amount of R_PointInSubsector per call and also P_PlayerTouchingSectorSpecial since either are in a loop that often runs multiple times per call --- src/p_floor.c | 1 - src/p_map.c | 33 ++++++++++++++++++--------------- src/p_mobj.c | 2 +- src/p_spec.c | 3 ++- 4 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/p_floor.c b/src/p_floor.c index bd7a2655e..ef42b02a3 100644 --- a/src/p_floor.c +++ b/src/p_floor.c @@ -1894,7 +1894,6 @@ void T_NoEnemiesSector(levelspecthink_t *nobaddies) { if (nobaddies->sector->lines[i]->special == 223) { - upperbound = nobaddies->sector->ceilingheight; lowerbound = nobaddies->sector->floorheight; diff --git a/src/p_map.c b/src/p_map.c index 388d230f7..21bad82b9 100644 --- a/src/p_map.c +++ b/src/p_map.c @@ -2373,6 +2373,7 @@ boolean P_TryMove(mobj_t *thing, fixed_t x, fixed_t y, boolean allowdropoff) fixed_t radius = thing->radius; fixed_t thingtop ;//= thing->z + thing->height; fixed_t startingonground = P_IsObjectOnGround(thing); + INT32 special = -1; floatok = false; if (radius < MAXRADIUS/2) @@ -2406,21 +2407,31 @@ boolean P_TryMove(mobj_t *thing, fixed_t x, fixed_t y, boolean allowdropoff) if (!(thing->flags & MF_NOCLIP)) { - //All things are affected by their scale. - fixed_t maxstep = FixedMul(MAXSTEPMOVE, mapobjectscale); - INT32 special = 0; + // All things are affected by their scale. + fixed_t maxstep; + + if (tmceilingz - tmfloorz < thing->height) + { + if (tmfloorthing) + tmhitthing = tmfloorthing; + + return false; // doesn't fit + } + + maxstep = FixedMul(MAXSTEPMOVE, mapobjectscale); if (thing->player) { - special = GETSECSPECIAL(R_PointInSubsector(x, y)->sector->special, 1); + if (special == -1) + special = GETSECSPECIAL(R_PointInSubsector(x, y)->sector->special, 1); // If using type Section1:13, double the maxstep. - if (P_PlayerTouchingSectorSpecial(thing->player, 1, 13) || special == 13) + if (special == 13 || P_PlayerTouchingSectorSpecial(thing->player, 1, 13)) { maxstep <<= 1; } // If using type Section1:12, no maxstep. For ledges you don't want the player to climb! (see: Egg Zeppelin & SMK port walls) - else if (P_PlayerTouchingSectorSpecial(thing->player, 1, 12) || special == 12) + else if (special == 12 || P_PlayerTouchingSectorSpecial(thing->player, 1, 12)) { maxstep = 0; } @@ -2431,14 +2442,6 @@ boolean P_TryMove(mobj_t *thing, fixed_t x, fixed_t y, boolean allowdropoff) maxstep = 0; } - if (tmceilingz - tmfloorz < thing->height) - { - if (tmfloorthing) - tmhitthing = tmfloorthing; - - return false; // doesn't fit - } - floatok = true; thingtop = thing->z + thing->height; @@ -2469,7 +2472,7 @@ boolean P_TryMove(mobj_t *thing, fixed_t x, fixed_t y, boolean allowdropoff) } } else if (maxstep > 0 && !(thing->player && - (P_PlayerTouchingSectorSpecial(thing->player, 1, 14) || special == 14))) // Step down + (special == 14 || P_PlayerTouchingSectorSpecial(thing->player, 1, 14)))) // Step down { // If the floor difference is MAXSTEPMOVE or less, and the sector isn't Section1:14, ALWAYS // step down! Formerly required a Section1:13 sector for the full MAXSTEPMOVE, but no more. diff --git a/src/p_mobj.c b/src/p_mobj.c index 6422d924d..e44436e52 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -1859,7 +1859,7 @@ static void P_AdjustMobjFloorZ_PolyObjs(mobj_t *mo, subsector_t *subsec) while (po) { - if (!(po->flags & POF_SOLID) || !P_MobjInsidePolyobj(po, mo)) + if (!P_MobjInsidePolyobj(po, mo) || !(po->flags & POF_SOLID)) { po = (polyobj_t *)(po->link.next); continue; diff --git a/src/p_spec.c b/src/p_spec.c index 8f1121062..e37e26d54 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -4441,12 +4441,13 @@ static void P_RunSpecialSectorCheck(player_t *player, sector_t *sector) } f_affectpoint = P_GetSpecialBottomZ(player->mo, sector, sector); - c_affectpoint = P_GetSpecialTopZ(player->mo, sector, sector); // Only go further if on the ground if ((sector->flags & SF_FLIPSPECIAL_FLOOR) && !(sector->flags & SF_FLIPSPECIAL_CEILING) && player->mo->z != f_affectpoint) return; + c_affectpoint = P_GetSpecialTopZ(player->mo, sector, sector); + if ((sector->flags & SF_FLIPSPECIAL_CEILING) && !(sector->flags & SF_FLIPSPECIAL_FLOOR) && player->mo->z + player->mo->height != c_affectpoint) return;