Skip to content

Commit

Permalink
- deal with SW's Warp functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
coelckers committed Dec 4, 2021
1 parent d3f47b8 commit d2144aa
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 32 deletions.
19 changes: 2 additions & 17 deletions source/games/sw/src/misc.h
Expand Up @@ -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 : &sector[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 : &sector[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);
Expand Down
25 changes: 21 additions & 4 deletions source/games/sw/src/player.cpp
Expand Up @@ -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))
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
{
Expand Down
22 changes: 11 additions & 11 deletions source/games/sw/src/warp.cpp
Expand Up @@ -39,25 +39,25 @@ 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;

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);
while (auto actor = it.Next())
{
auto sp = &actor->s();

if (sp->sectnum == sectnum)
if (sp->sector() == sect)
{
// skip - don't teleport
if (SP_TAG10(sp) == 1)
Expand All @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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(&sector[*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;
Expand Down

0 comments on commit d2144aa

Please sign in to comment.