From f19f656dd9f71a863bf2af75e9b0bb169b24592a Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 26 Nov 2021 17:03:00 +0100 Subject: [PATCH] - deal with SW's Warp functions. --- source/games/sw/src/misc.h | 19 ++----------------- source/games/sw/src/player.cpp | 25 +++++++++++++++++++++---- source/games/sw/src/warp.cpp | 22 +++++++++++----------- 3 files changed, 34 insertions(+), 32 deletions(-) diff --git a/source/games/sw/src/misc.h b/source/games/sw/src/misc.h index 0e471b91a..d8f296b84 100644 --- a/source/games/sw/src/misc.h +++ b/source/games/sw/src/misc.h @@ -18,24 +18,9 @@ void InitCheats(); void MapColors(short num,COLOR_MAP cm,short create); int32_t CONFIG_ReadSetup(void); -DSWActor* WarpPlane(int32_t* x, int32_t* y, int32_t* z, int* sect); bool WarpSectorInfo(sectortype* sect, DSWActor** sp_warp); -DSWActor* Warp(int32_t* x, int32_t* y, int32_t* z, int* sect); -inline DSWActor* Warp(int32_t* x, int32_t* y, int32_t* z, sectortype** sect) -{ - int sn = sectnum(*sect); - auto res = Warp(x, y, z, &sn); - *sect = sn == -1? nullptr : §or[sn]; - return res; -} - -inline DSWActor* WarpPlane(int32_t* x, int32_t* y, int32_t* z, sectortype** sect) -{ - int sn = sectnum(*sect); - auto res = WarpPlane(x, y, z, &sn); - *sect = sn == -1 ? nullptr : §or[sn]; - return res; -} +DSWActor* Warp(int32_t* x, int32_t* y, int32_t* z, sectortype** sect); +DSWActor* WarpPlane(int32_t* x, int32_t* y, int32_t* z, sectortype** sect); void ProcessVisOn(void); diff --git a/source/games/sw/src/player.cpp b/source/games/sw/src/player.cpp index 73b0d2145..734bdb724 100644 --- a/source/games/sw/src/player.cpp +++ b/source/games/sw/src/player.cpp @@ -1370,9 +1370,14 @@ void DoPlayerWarpTeleporter(PLAYERp pp) TAG 5 to 8 = random match locations #endif - - if ((act_warp = Warp(&pp->posx, &pp->posy, &pp->posz, &pp->cursectnum)) == nullptr) +#pragma message(__FILE__ "remove workaround"); + auto cursect = pp->cursector(); + if ((act_warp = Warp(&pp->posx, &pp->posy, &pp->posz, &cursect)) == nullptr) + { + pp->setcursector(cursect); return; + } + pp->setcursector(cursect); sp_warp = &act_warp->s(); switch (SP_TAG3(sp_warp)) @@ -2152,8 +2157,14 @@ void DoPlayerMove(PLAYERp pp) } // check for warp - probably can remove from CeilingHit - if (WarpPlane(&pp->posx, &pp->posy, &pp->posz, &pp->cursectnum)) +#pragma message(__FILE__ "remove workaround"); + sectortype* cursect = pp->cursector(); + if (WarpPlane(&pp->posx, &pp->posy, &pp->posz, &cursect)) + { + pp->setcursector(cursect); PlayerWarpUpdatePos(pp); + } + pp->setcursector(cursect); DoPlayerZrange(pp); @@ -2729,6 +2740,8 @@ void DoPlayerMoveVehicle(PLAYERp pp) #pragma message(__FILE__ "remove workaround"); sectortype* cursect = pp->cursector(); clipmove(clippos, &cursect, pp->xvect, pp->yvect, (int)pp->sop->clipdist, Z(4), floor_dist, CLIPMASK_PLAYER, u->coll); + pp->setcursector(cursect); + pp->pos.vec2 = clippos.vec2; } else @@ -3384,11 +3397,15 @@ void DoPlayerClimb(PLAYERp pp) LadderUpdate = true; } - if (WarpPlane(&pp->posx, &pp->posy, &pp->posz, &pp->cursectnum)) +#pragma message(__FILE__ "remove workaround"); + sectortype* cursect = pp->cursector(); + if (WarpPlane(&pp->posx, &pp->posy, &pp->posz, &cursect)) { + pp->setcursector(cursect); PlayerWarpUpdatePos(pp); LadderUpdate = true; } + pp->setcursector(cursect); if (LadderUpdate) { diff --git a/source/games/sw/src/warp.cpp b/source/games/sw/src/warp.cpp index ceffdaff2..362295b86 100644 --- a/source/games/sw/src/warp.cpp +++ b/source/games/sw/src/warp.cpp @@ -39,9 +39,9 @@ BEGIN_SW_NS //////////////////////////////////////////////////////////////////////////////// extern bool Prediction; -DSWActor* WarpToArea(DSWActor* sp_from, int32_t* x, int32_t* y, int32_t* z, int* sect); +DSWActor* WarpToArea(DSWActor* sp_from, int32_t* x, int32_t* y, int32_t* z, sectortype** sect); -bool WarpPlaneSectorInfo(short sectnum, DSWActor** sp_ceiling, DSWActor** sp_floor) +bool WarpPlaneSectorInfo(sectortype* sect, DSWActor** sp_ceiling, DSWActor** sp_floor) { *sp_floor = nullptr; *sp_ceiling = nullptr; @@ -49,7 +49,7 @@ bool WarpPlaneSectorInfo(short sectnum, DSWActor** sp_ceiling, DSWActor** sp_flo if (Prediction) return false; - if (sectnum < 0 || !TEST(sector[sectnum].extra, SECTFX_WARP_SECTOR)) + if (sect== nullptr || !TEST(sect->extra, SECTFX_WARP_SECTOR)) return false; SWStatIterator it(STAT_WARP); @@ -57,7 +57,7 @@ bool WarpPlaneSectorInfo(short sectnum, DSWActor** sp_ceiling, DSWActor** sp_flo { auto sp = &actor->s(); - if (sp->sectnum == sectnum) + if (sp->sector() == sect) { // skip - don't teleport if (SP_TAG10(sp) == 1) @@ -77,7 +77,7 @@ bool WarpPlaneSectorInfo(short sectnum, DSWActor** sp_ceiling, DSWActor** sp_flo return true; } -DSWActor* WarpPlane(int32_t* x, int32_t* y, int32_t* z, int* sect) +DSWActor* WarpPlane(int32_t* x, int32_t* y, int32_t* z, sectortype** sect) { DSWActor* sp_floor,* sp_ceiling; @@ -106,7 +106,7 @@ DSWActor* WarpPlane(int32_t* x, int32_t* y, int32_t* z, int* sect) return nullptr; } -DSWActor* WarpToArea(DSWActor* sp_from, int32_t* x, int32_t* y, int32_t* z, int* sectnum) +DSWActor* WarpToArea(DSWActor* sp_from, int32_t* x, int32_t* y, int32_t* z, sectortype** sect) { int xoff; int yoff; @@ -189,8 +189,8 @@ DSWActor* WarpToArea(DSWActor* sp_from, int32_t* x, int32_t* y, int32_t* z, int* *z += z_adj; // get new sector - *sectnum = spi->sectnum; - updatesector(*x, *y, sectnum); + *sect = spi->sector(); + updatesector(*x, *y, sect); return actor; } @@ -234,19 +234,19 @@ bool WarpSectorInfo(sectortype* sect, DSWActor** sp_warp) return true; } -DSWActor* Warp(int32_t* x, int32_t* y, int32_t* z, int* sectnum) +DSWActor* Warp(int32_t* x, int32_t* y, int32_t* z, sectortype** sect) { DSWActor* sp_warp; if (Prediction) return nullptr; - if (!WarpSectorInfo(§or[*sectnum], &sp_warp)) + if (!WarpSectorInfo(*sect, &sp_warp)) return nullptr; if (sp_warp) { - return WarpToArea(sp_warp, x, y, z, sectnum); + return WarpToArea(sp_warp, x, y, z, sect); } return nullptr;