From 7413da918b1d4a7b4b196eb74a1832657c51897c Mon Sep 17 00:00:00 2001 From: MascaraSnake Date: Wed, 13 May 2020 16:21:47 +0200 Subject: [PATCH] Store PolyObject waypoint return behavior in an enum --- src/p_polyobj.c | 17 +++++++---------- src/p_polyobj.h | 38 ++++++++++++++++++++++---------------- src/p_saveg.c | 6 ++---- src/p_spec.c | 13 ++++++++++--- 4 files changed, 41 insertions(+), 33 deletions(-) diff --git a/src/p_polyobj.c b/src/p_polyobj.c index e2c4ff519..8ba5fadac 100644 --- a/src/p_polyobj.c +++ b/src/p_polyobj.c @@ -1606,6 +1606,7 @@ void T_PolyObjWaypoint(polywaypoint_t *th) poy = po->centerPt.y; 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); if (dist < 1) @@ -1615,9 +1616,6 @@ void T_PolyObjWaypoint(polywaypoint_t *th) momy = FixedMul(FixedDiv(target->y - poy, 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 // 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) @@ -1661,22 +1659,22 @@ void T_PolyObjWaypoint(polywaypoint_t *th) CONS_Debug(DBG_POLYOBJ, "Looking for next waypoint...\n"); 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) { - th->wrap = 0; + th->returnbehavior = PWR_STOP; th->stophere = true; } 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; if (!th->continuous) - th->comeback = false; + th->returnbehavior = PWR_STOP; 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->direction = pwdata->reverse ? -1 : 1; - th->comeback = pwdata->comeback; + th->returnbehavior = pwdata->returnbehavior; th->continuous = pwdata->continuous; - th->wrap = pwdata->wrap; th->stophere = false; // 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)) { // Already at the destination point... - if (!th->wrap) + if (th->returnbehavior != PWR_WRAP) { po->thinker = NULL; P_RemoveThinker(&th->thinker); diff --git a/src/p_polyobj.h b/src/p_polyobj.h index b2331449f..6b0016195 100644 --- a/src/p_polyobj.h +++ b/src/p_polyobj.h @@ -140,19 +140,26 @@ typedef struct polymove_s UINT32 angle; // angle along which to move } 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 { thinker_t thinker; // must be first - INT32 polyObjNum; // numeric id of polyobject - INT32 speed; // resultant velocity - INT32 sequence; // waypoint sequence # - INT32 pointnum; // waypoint # - INT32 direction; // 1 for normal, -1 for backwards - UINT8 comeback; // reverses and comes back when the end is reached - UINT8 wrap; // Wrap around waypoints - UINT8 continuous; // continuously move - used with COMEBACK or WRAP - UINT8 stophere; // Will stop after it reaches the next waypoint + INT32 polyObjNum; // numeric id of polyobject + INT32 speed; // resultant velocity + INT32 sequence; // waypoint sequence # + INT32 pointnum; // waypoint # + INT32 direction; // 1 for normal, -1 for backwards + UINT8 returnbehavior; // behavior after reaching the last waypoint + UINT8 continuous; // continuously move - used with PWR_WRAP or PWR_COMEBACK + UINT8 stophere; // Will stop after it reaches the next waypoint mobj_t *target; // next waypoint mobj } polywaypoint_t; @@ -251,13 +258,12 @@ typedef struct polymovedata_s typedef struct polywaypointdata_s { - INT32 polyObjNum; // numeric id of polyobject to affect - INT32 sequence; // waypoint sequence # - fixed_t speed; // linear speed - UINT8 reverse; // if true, will go in reverse waypoint order - UINT8 comeback; // reverses and comes back when the end is reached - UINT8 wrap; // Wrap around waypoints - UINT8 continuous; // continuously move - used with COMEBACK or WRAP + INT32 polyObjNum; // numeric id of polyobject to affect + INT32 sequence; // waypoint sequence # + fixed_t speed; // linear speed + UINT8 reverse; // if true, will go in reverse waypoint order + UINT8 returnbehavior; // behavior after reaching the last waypoint + UINT8 continuous; // continuously move - used with PWR_WRAP or PWR_COMEBACK } polywaypointdata_t; // polyobject door types diff --git a/src/p_saveg.c b/src/p_saveg.c index 5e5e82453..e4393826d 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -2019,8 +2019,7 @@ static void SavePolywaypointThinker(const thinker_t *th, UINT8 type) WRITEINT32(save_p, ht->sequence); WRITEINT32(save_p, ht->pointnum); WRITEINT32(save_p, ht->direction); - WRITEUINT8(save_p, ht->comeback); - WRITEUINT8(save_p, ht->wrap); + WRITEUINT8(save_p, ht->returnbehavior); WRITEUINT8(save_p, ht->continuous); WRITEUINT8(save_p, ht->stophere); WRITEUINT32(save_p, SaveMobjnum(ht->target)); @@ -3161,8 +3160,7 @@ static inline thinker_t* LoadPolywaypointThinker(actionf_p1 thinker) ht->sequence = READINT32(save_p); ht->pointnum = READINT32(save_p); ht->direction = READINT32(save_p); - ht->comeback = READUINT8(save_p); - ht->wrap = READUINT8(save_p); + ht->returnbehavior = READUINT8(save_p); ht->continuous = READUINT8(save_p); ht->stophere = READUINT8(save_p); ht->target = LoadMobj(READUINT32(save_p)); diff --git a/src/p_spec.c b/src/p_spec.c index ae525441c..99657aab9 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -1277,9 +1277,16 @@ static boolean PolyWaypoint(line_t *line) pwd.speed = sides[line->sidenum[0]].textureoffset / 8; pwd.sequence = sides[line->sidenum[0]].rowoffset >> FRACBITS; // Sequence # 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 - pwd.continuous = (line->flags & ML_EFFECT4) == ML_EFFECT4; // Continuously move - used with COMEBACK or WRAP + + // Behavior after reaching the last waypoint? + 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); }