super ugly and wonky P_MobjCeiling/FloorZ optimization
cache the subsector if the test points didnt change between calls
This commit is contained in:
1 parent
d8b2b8394a
commit
b16db76f1e
3 files changed
+35
-2
No files matched your search
@@ -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)
|
||||
|
||||
+32
-2
@@ -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
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user