From 0495190a0890270cb41689474b4ed75290a2727d Mon Sep 17 00:00:00 2001 From: NepDisk Date: Thu, 13 Mar 2025 05:36:35 -0400 Subject: [PATCH] Fix Stepup issues for the most aprt. This fixes midtexture stepover and extreme stepup such as the jank line in greenhils --- src/p_map.c | 105 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 65 insertions(+), 40 deletions(-) diff --git a/src/p_map.c b/src/p_map.c index d2bf1a689..6d06a7a33 100644 --- a/src/p_map.c +++ b/src/p_map.c @@ -2520,6 +2520,20 @@ fixed_t P_GetThingStepUp(mobj_t *thing, fixed_t destX, fixed_t destY) return maxstep; } +// Used for averging height values for step up. +static fixed_t avgheight(fixed_t a, fixed_t b) +{ + if (((b > 0) && (a > (INT32_MAX - b))) || + ((b < 0) && (a < (INT32_MIN - b)))) + { + return b + (a - b) / 2; + } + else + { + return (a + b) / 2; + } +} + static boolean increment_move ( mobj_t * thing, @@ -2624,51 +2638,62 @@ increment_move thingtop = thing->z + thing->height; - // Step up - if (thing->z < g_tm.floorz) + if (maxstep > 0) { - if (g_tm.floorz - thing->z <= maxstep) - { - thing->z = thing->floorz = g_tm.floorz; - thing->eflags |= MFE_JUSTSTEPPEDDOWN; - } - else - { - return false; // mobj must raise itself to fit - } - } - else if (g_tm.ceilingz < thingtop) - { - if (thingtop - g_tm.ceilingz <= maxstep) - { - thing->z = ( thing->ceilingz = g_tm.ceilingz ) - thing->height; - thing->eflags |= MFE_JUSTSTEPPEDDOWN; - } - else - { - return false; // mobj must lower itself to fit - } - } - else if (maxstep > 0 && !( - thing->player && ( - P_MobjTouchingSectorSpecialFlag(thing, SSF_NOSTEPDOWN) - || (R_PointInSubsector(x, y)->sector->specialflags & SSF_NOSTEPDOWN)) - )) // 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. + fixed_t stepheight; - if (thingtop == thing->ceilingz && g_tm.ceilingz > thingtop && g_tm.ceilingz - thingtop <= maxstep) + // Step up + if (thing->z < g_tm.floorz) { - thing->z = (thing->ceilingz = g_tm.ceilingz) - thing->height; - thing->eflags |= MFE_JUSTSTEPPEDDOWN; - thing->ceilingdrop = 0; + stepheight = avgheight(g_tm.floorz - thing->z, g_tm.floorstep); + + if (stepheight <= maxstep) + { + thing->z = thing->floorz = g_tm.floorz; + thing->floorrover = g_tm.floorrover; + thing->eflags |= MFE_JUSTSTEPPEDDOWN; + } + else + { + return false; // mobj must raise itself to fit + } } - else if (thing->z == thing->floorz && g_tm.floorz < thing->z && thing->z - g_tm.floorz <= maxstep) + else if (g_tm.ceilingz < thingtop) { - thing->z = thing->floorz = g_tm.floorz; - thing->eflags |= MFE_JUSTSTEPPEDDOWN; - thing->floordrop = 0; + stepheight = avgheight(thingtop - g_tm.ceilingz, g_tm.ceilingstep); + + if (stepheight <= maxstep) + { + thing->z = ( thing->ceilingz = g_tm.ceilingz ) - thing->height; + thing->ceilingrover = g_tm.ceilingrover; + thing->eflags |= MFE_JUSTSTEPPEDDOWN; + } + else + { + return false; // mobj must lower itself to fit + } + } + else if (thing->momz * P_MobjFlip(thing) <= 0 // Step down requires moving down. + && !(P_MobjTouchingSectorSpecialFlag(thing, SSF_NOSTEPDOWN) + || (R_PointInSubsector(x, y)->sector->specialflags & SSF_NOSTEPDOWN))) + { + // 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. + + if (thingtop == thing->ceilingz && g_tm.ceilingz > thingtop && g_tm.ceilingz - thingtop <= maxstep) + { + thing->z = (thing->ceilingz = g_tm.ceilingz) - thing->height; + thing->ceilingrover = g_tm.ceilingrover; + thing->eflags |= MFE_JUSTSTEPPEDDOWN; + thing->ceilingdrop = 0; + } + else if (thing->z == thing->floorz && g_tm.floorz < thing->z && thing->z - g_tm.floorz <= maxstep) + { + thing->z = thing->floorz = g_tm.floorz; + thing->floorrover = g_tm.floorrover; + thing->eflags |= MFE_JUSTSTEPPEDDOWN; + thing->floordrop = 0; + } } }