Store PolyObject waypoint return behavior in an enum

This commit is contained in:
MascaraSnake 2020-05-13 16:21:47 +02:00
parent b561ee7921
commit 7413da918b
4 changed files with 41 additions and 33 deletions

View File

@ -1606,6 +1606,7 @@ void T_PolyObjWaypoint(polywaypoint_t *th)
poy = po->centerPt.y; poy = po->centerPt.y;
poz = (po->lines[0]->backsector->floorheight + po->lines[0]->backsector->ceilingheight)/2; poz = (po->lines[0]->backsector->floorheight + po->lines[0]->backsector->ceilingheight)/2;
// Calculate the distance between the polyobject and the waypoint
dist = P_AproxDistance(P_AproxDistance(target->x - pox, target->y - poy), target->z - poz); dist = P_AproxDistance(P_AproxDistance(target->x - pox, target->y - poy), target->z - poz);
if (dist < 1) if (dist < 1)
@ -1615,9 +1616,6 @@ void T_PolyObjWaypoint(polywaypoint_t *th)
momy = FixedMul(FixedDiv(target->y - poy, dist), th->speed); momy = FixedMul(FixedDiv(target->y - poy, dist), th->speed);
momz = FixedMul(FixedDiv(target->z - poz, dist), th->speed); momz = FixedMul(FixedDiv(target->z - poz, dist), th->speed);
// Calculate the distance between the polyobject and the waypoint
// 'dist' already equals this.
// Will the polyobject be FURTHER away if the momx/momy/momz is added to // Will the polyobject be FURTHER away if the momx/momy/momz is added to
// its current coordinates, or closer? (shift down to fracunits to avoid approximation errors) // its current coordinates, or closer? (shift down to fracunits to avoid approximation errors)
if (dist>>FRACBITS <= P_AproxDistance(P_AproxDistance(target->x - pox - momx, target->y - poy - momy), target->z - poz - momz)>>FRACBITS) if (dist>>FRACBITS <= P_AproxDistance(P_AproxDistance(target->x - pox - momx, target->y - poy - momy), target->z - poz - momz)>>FRACBITS)
@ -1661,22 +1659,22 @@ void T_PolyObjWaypoint(polywaypoint_t *th)
CONS_Debug(DBG_POLYOBJ, "Looking for next waypoint...\n"); CONS_Debug(DBG_POLYOBJ, "Looking for next waypoint...\n");
waypoint = (th->direction == -1) ? P_GetPreviousWaypoint(target, false) : P_GetNextWaypoint(target, false); waypoint = (th->direction == -1) ? P_GetPreviousWaypoint(target, false) : P_GetNextWaypoint(target, false);
if (!waypoint && th->wrap) // If specified, wrap waypoints if (!waypoint && th->returnbehavior == PWR_WRAP) // If specified, wrap waypoints
{ {
if (!th->continuous) if (!th->continuous)
{ {
th->wrap = 0; th->returnbehavior = PWR_STOP;
th->stophere = true; th->stophere = true;
} }
waypoint = (th->direction == -1) ? P_GetLastWaypoint(th->sequence) : P_GetFirstWaypoint(th->sequence); waypoint = (th->direction == -1) ? P_GetLastWaypoint(th->sequence) : P_GetFirstWaypoint(th->sequence);
} }
else if (!waypoint && th->comeback) // Come back to the start else if (!waypoint && th->returnbehavior == PWR_COMEBACK) // Come back to the start
{ {
th->direction = -th->direction; th->direction = -th->direction;
if (!th->continuous) if (!th->continuous)
th->comeback = false; th->returnbehavior = PWR_STOP;
waypoint = (th->direction == -1) ? P_GetPreviousWaypoint(target, false) : P_GetNextWaypoint(target, false); waypoint = (th->direction == -1) ? P_GetPreviousWaypoint(target, false) : P_GetNextWaypoint(target, false);
} }
@ -2193,9 +2191,8 @@ boolean EV_DoPolyObjWaypoint(polywaypointdata_t *pwdata)
th->sequence = pwdata->sequence; // Used to specify sequence # th->sequence = pwdata->sequence; // Used to specify sequence #
th->direction = pwdata->reverse ? -1 : 1; th->direction = pwdata->reverse ? -1 : 1;
th->comeback = pwdata->comeback; th->returnbehavior = pwdata->returnbehavior;
th->continuous = pwdata->continuous; th->continuous = pwdata->continuous;
th->wrap = pwdata->wrap;
th->stophere = false; th->stophere = false;
// Find the first waypoint we need to use // Find the first waypoint we need to use
@ -2219,7 +2216,7 @@ boolean EV_DoPolyObjWaypoint(polywaypointdata_t *pwdata)
&& last->z == (po->lines[0]->backsector->floorheight + (po->lines[0]->backsector->ceilingheight - po->lines[0]->backsector->floorheight)/2)) && last->z == (po->lines[0]->backsector->floorheight + (po->lines[0]->backsector->ceilingheight - po->lines[0]->backsector->floorheight)/2))
{ {
// Already at the destination point... // Already at the destination point...
if (!th->wrap) if (th->returnbehavior != PWR_WRAP)
{ {
po->thinker = NULL; po->thinker = NULL;
P_RemoveThinker(&th->thinker); P_RemoveThinker(&th->thinker);

View File

@ -140,19 +140,26 @@ typedef struct polymove_s
UINT32 angle; // angle along which to move UINT32 angle; // angle along which to move
} polymove_t; } polymove_t;
// PolyObject waypoint movement return behavior
typedef enum
{
PWR_STOP, // Stop after reaching last waypoint
PWR_WRAP, // Wrap back to first waypoint
PWR_COMEBACK, // Repeat sequence in reverse
} polywaypointreturn_e;
typedef struct polywaypoint_s typedef struct polywaypoint_s
{ {
thinker_t thinker; // must be first thinker_t thinker; // must be first
INT32 polyObjNum; // numeric id of polyobject INT32 polyObjNum; // numeric id of polyobject
INT32 speed; // resultant velocity INT32 speed; // resultant velocity
INT32 sequence; // waypoint sequence # INT32 sequence; // waypoint sequence #
INT32 pointnum; // waypoint # INT32 pointnum; // waypoint #
INT32 direction; // 1 for normal, -1 for backwards INT32 direction; // 1 for normal, -1 for backwards
UINT8 comeback; // reverses and comes back when the end is reached UINT8 returnbehavior; // behavior after reaching the last waypoint
UINT8 wrap; // Wrap around waypoints UINT8 continuous; // continuously move - used with PWR_WRAP or PWR_COMEBACK
UINT8 continuous; // continuously move - used with COMEBACK or WRAP UINT8 stophere; // Will stop after it reaches the next waypoint
UINT8 stophere; // Will stop after it reaches the next waypoint
mobj_t *target; // next waypoint mobj mobj_t *target; // next waypoint mobj
} polywaypoint_t; } polywaypoint_t;
@ -251,13 +258,12 @@ typedef struct polymovedata_s
typedef struct polywaypointdata_s typedef struct polywaypointdata_s
{ {
INT32 polyObjNum; // numeric id of polyobject to affect INT32 polyObjNum; // numeric id of polyobject to affect
INT32 sequence; // waypoint sequence # INT32 sequence; // waypoint sequence #
fixed_t speed; // linear speed fixed_t speed; // linear speed
UINT8 reverse; // if true, will go in reverse waypoint order UINT8 reverse; // if true, will go in reverse waypoint order
UINT8 comeback; // reverses and comes back when the end is reached UINT8 returnbehavior; // behavior after reaching the last waypoint
UINT8 wrap; // Wrap around waypoints UINT8 continuous; // continuously move - used with PWR_WRAP or PWR_COMEBACK
UINT8 continuous; // continuously move - used with COMEBACK or WRAP
} polywaypointdata_t; } polywaypointdata_t;
// polyobject door types // polyobject door types

View File

@ -2019,8 +2019,7 @@ static void SavePolywaypointThinker(const thinker_t *th, UINT8 type)
WRITEINT32(save_p, ht->sequence); WRITEINT32(save_p, ht->sequence);
WRITEINT32(save_p, ht->pointnum); WRITEINT32(save_p, ht->pointnum);
WRITEINT32(save_p, ht->direction); WRITEINT32(save_p, ht->direction);
WRITEUINT8(save_p, ht->comeback); WRITEUINT8(save_p, ht->returnbehavior);
WRITEUINT8(save_p, ht->wrap);
WRITEUINT8(save_p, ht->continuous); WRITEUINT8(save_p, ht->continuous);
WRITEUINT8(save_p, ht->stophere); WRITEUINT8(save_p, ht->stophere);
WRITEUINT32(save_p, SaveMobjnum(ht->target)); WRITEUINT32(save_p, SaveMobjnum(ht->target));
@ -3161,8 +3160,7 @@ static inline thinker_t* LoadPolywaypointThinker(actionf_p1 thinker)
ht->sequence = READINT32(save_p); ht->sequence = READINT32(save_p);
ht->pointnum = READINT32(save_p); ht->pointnum = READINT32(save_p);
ht->direction = READINT32(save_p); ht->direction = READINT32(save_p);
ht->comeback = READUINT8(save_p); ht->returnbehavior = READUINT8(save_p);
ht->wrap = READUINT8(save_p);
ht->continuous = READUINT8(save_p); ht->continuous = READUINT8(save_p);
ht->stophere = READUINT8(save_p); ht->stophere = READUINT8(save_p);
ht->target = LoadMobj(READUINT32(save_p)); ht->target = LoadMobj(READUINT32(save_p));

View File

@ -1277,9 +1277,16 @@ static boolean PolyWaypoint(line_t *line)
pwd.speed = sides[line->sidenum[0]].textureoffset / 8; pwd.speed = sides[line->sidenum[0]].textureoffset / 8;
pwd.sequence = sides[line->sidenum[0]].rowoffset >> FRACBITS; // Sequence # pwd.sequence = sides[line->sidenum[0]].rowoffset >> FRACBITS; // Sequence #
pwd.reverse = (line->flags & ML_EFFECT1) == ML_EFFECT1; // Reverse? pwd.reverse = (line->flags & ML_EFFECT1) == ML_EFFECT1; // Reverse?
pwd.comeback = (line->flags & ML_EFFECT2) == ML_EFFECT2; // Return when reaching end?
pwd.wrap = (line->flags & ML_EFFECT3) == ML_EFFECT3; // Wrap around waypoints // Behavior after reaching the last waypoint?
pwd.continuous = (line->flags & ML_EFFECT4) == ML_EFFECT4; // Continuously move - used with COMEBACK or WRAP if (line->flags & ML_EFFECT3)
pwd.returnbehavior = PWR_WRAP; // Wrap back to first waypoint
else if (line->flags & ML_EFFECT2)
pwd.returnbehavior = PWR_COMEBACK; // Go through sequence in reverse
else
pwd.returnbehavior = PWR_STOP; // Stop
pwd.continuous = (line->flags & ML_EFFECT4) == ML_EFFECT4; // Continuously move - used with PWR_WRAP or PWR_COMEBACK
return EV_DoPolyObjWaypoint(&pwd); return EV_DoPolyObjWaypoint(&pwd);
} }