diff --git a/src/p_local.h b/src/p_local.h index 7600cd00e..454368c3d 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -296,6 +296,7 @@ FUNCINLINE static ATTRINLINE boolean P_MobjWasRemoved(const mobj_t *mobj) return (!mobj || mobj->thinker.function != (actionf_p1)P_MobjThinker); } +void Reset_Zsubsecs(void); fixed_t P_MobjFloorZ(mobj_t *mobj, sector_t *sector, sector_t *boundsec, fixed_t x, fixed_t y, line_t *line, boolean lowest, boolean perfect); fixed_t P_MobjCeilingZ(mobj_t *mobj, sector_t *sector, sector_t *boundsec, fixed_t x, fixed_t y, line_t *line, boolean lowest, boolean perfect); #define P_GetFloorZ(mobj, sector, x, y, line) P_MobjFloorZ(mobj, sector, NULL, x, y, line, false, false) diff --git a/src/p_mobj.c b/src/p_mobj.c index c0d17ccad..f51731a6c 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -563,6 +563,24 @@ static fixed_t HighestOnLine(fixed_t radius, fixed_t x, fixed_t y, line_t *line, } } +// save us buncha R_PointInSubsector calls +// 0 is floor, 1 is ceiling +static subsector_t *Zsubsectors[2]; +static fixed_t Zoldx[2]; +static fixed_t Zoldy[2]; + +// make sure to reset that crap on levelload +void Reset_Zsubsecs(void) +{ + for (int i = 0; i < 2; i++) + { + Zsubsectors[i] = NULL; + // theres a super unlikely chance you spawn at x = 2147483647 and y = 2147483647 on some map + // but prob a fuckton less likely than spawning at 0 0 + Zoldx[i] = Zoldy[i] = INT32_MAX; + } +} + fixed_t P_MobjFloorZ(mobj_t *mobj, sector_t *sector, sector_t *boundsec, fixed_t x, fixed_t y, line_t *line, boolean lowest, boolean perfect) { I_Assert(mobj != NULL); @@ -593,8 +611,14 @@ fixed_t P_MobjFloorZ(mobj_t *mobj, sector_t *sector, sector_t *boundsec, fixed_t testx += x; testy += y; + if (Zsubsectors[0] == NULL || Zoldx[0] != testx || Zoldy[0] != testy) + Zsubsectors[0] = R_PointInSubsector(testx, testy); + + Zoldx[0] = testx; + Zoldy[0] = testy; + // If the highest point is in the sector, then we have it easy! Just get the Z at that point - if (R_PointInSubsector(testx, testy)->sector == (boundsec ? boundsec : sector)) + if (Zsubsectors[0]->sector == (boundsec ? boundsec : sector)) return P_GetSlopeZAt(slope, testx, testy); // If boundsec is set, we're looking for specials. In that case, iterate over every line in this sector to find the TRUE highest/lowest point @@ -680,8 +704,14 @@ fixed_t P_MobjCeilingZ(mobj_t *mobj, sector_t *sector, sector_t *boundsec, fixed testx += x; testy += y; + if (Zsubsectors[1] == NULL || Zoldx[1] != testx || Zoldy[1] != testy) + Zsubsectors[1] = R_PointInSubsector(testx, testy); + + Zoldx[1] = testx; + Zoldy[1] = testy; + // If the highest point is in the sector, then we have it easy! Just get the Z at that point - if (R_PointInSubsector(testx, testy)->sector == (boundsec ? boundsec : sector)) + if (Zsubsectors[1]->sector == (boundsec ? boundsec : sector)) return P_GetSlopeZAt(slope, testx, testy); // If boundsec is set, we're looking for specials. In that case, iterate over every line in this sector to find the TRUE highest/lowest point diff --git a/src/p_setup.c b/src/p_setup.c index 687d0e8d7..460c69775 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -2734,6 +2734,8 @@ boolean P_SetupLevel(boolean fromnetsave, boolean reloadinggamestate) lumpnum_t encoreLump = LUMPERROR; UINT8 levelfadecol; + Reset_Zsubsecs(); + // HACK: this doesent reset if you change the map from within a replay and may cause crashes or the replayhut to be non functional if (!demo.playback && demo.inreplayhut) {