added a "target" pointer to polywaypoint_t, so the polyobj waypoint thinker doesn't have to re-find the next waypoint every tic

This commit is contained in:
Monster Iestyn 2019-12-27 19:10:14 +00:00
parent 6a85e40232
commit 282fe7667c
3 changed files with 24 additions and 2 deletions

View File

@ -1815,6 +1815,7 @@ void T_PolyObjWaypoint(polywaypoint_t *th)
if (po->thinker == NULL)
po->thinker = &th->thinker;
/*
// Find out target first.
// We redo this each tic to make savegame compatibility easier.
for (wp = thlist[THINK_MOBJ].next; wp != &thlist[THINK_MOBJ]; wp = wp->next)
@ -1833,6 +1834,9 @@ void T_PolyObjWaypoint(polywaypoint_t *th)
break;
}
}
*/
target = th->target;
if (!target)
{
@ -2015,6 +2019,8 @@ void T_PolyObjWaypoint(polywaypoint_t *th)
target = waypoint;
th->pointnum = target->health;
// Set the mobj as your target! -- Monster Iestyn 27/12/19
th->target = target;
// calculate MOMX/MOMY/MOMZ for next waypoint
// change slope
@ -2641,6 +2647,8 @@ INT32 EV_DoPolyObjWaypoint(polywaypointdata_t *pwdata)
// Set pointnum
th->pointnum = target->health;
// Set the mobj as your target! -- Monster Iestyn 27/12/19
th->target = target;
// We don't deal with the mirror crap here, we'll
// handle that in the T_Thinker function.

View File

@ -161,6 +161,8 @@ typedef struct polywaypoint_s
fixed_t diffx;
fixed_t diffy;
fixed_t diffz;
mobj_t *target; // next waypoint mobj
} polywaypoint_t;
typedef struct polyslidedoor_s

View File

@ -2055,6 +2055,7 @@ static void SavePolywaypointThinker(const thinker_t *th, UINT8 type)
WRITEFIXED(save_p, ht->diffx);
WRITEFIXED(save_p, ht->diffy);
WRITEFIXED(save_p, ht->diffz);
WRITEUINT32(save_p, SaveMobjnum(ht->target));
}
//
@ -3244,6 +3245,7 @@ static inline thinker_t* LoadPolywaypointThinker(actionf_p1 thinker)
ht->diffx = READFIXED(save_p);
ht->diffy = READFIXED(save_p);
ht->diffz = READFIXED(save_p);
ht->target = LoadMobj(READUINT32(save_p));
return &ht->thinker;
}
@ -3538,6 +3540,7 @@ static void P_NetUnArchiveThinkers(void)
case tc_polywaypoint:
th = LoadPolywaypointThinker((actionf_p1)T_PolyObjWaypoint);
restoreNum = true;
break;
case tc_polyslidedoor:
@ -3599,9 +3602,9 @@ static void P_NetUnArchiveThinkers(void)
if (restoreNum)
{
executor_t *delay = NULL;
polywaypoint_t *polywp = NULL;
UINT32 mobjnum;
for (currentthinker = thlist[THINK_MAIN].next; currentthinker != &thlist[THINK_MAIN];
currentthinker = currentthinker->next)
for (currentthinker = thlist[THINK_MAIN].next; currentthinker != &thlist[THINK_MAIN]; currentthinker = currentthinker->next)
{
if (currentthinker->function.acp1 != (actionf_p1)T_ExecutorDelay)
continue;
@ -3610,6 +3613,15 @@ static void P_NetUnArchiveThinkers(void)
continue;
delay->caller = P_FindNewPosition(mobjnum);
}
for (currentthinker = thlist[THINK_POLYOBJ].next; currentthinker != &thlist[THINK_POLYOBJ]; currentthinker = currentthinker->next)
{
if (currentthinker->function.acp1 != (actionf_p1)T_PolyObjWaypoint)
continue;
polywp = (void *)currentthinker;
if (!(mobjnum = (UINT32)(size_t)polywp->target))
continue;
polywp->target = P_FindNewPosition(mobjnum);
}
}
}