- warp.cpp

This commit is contained in:
Christoph Oelckers 2021-11-03 16:51:38 +01:00
parent 21af63dfcc
commit e98e1a6fea
5 changed files with 68 additions and 80 deletions

View file

@ -18,14 +18,12 @@ void InitCheats();
void MapColors(short num,COLOR_MAP cm,short create);
int32_t CONFIG_ReadSetup(void);
bool WarpPlaneSectorInfo(short sectnum, SPRITEp* sp_ceiling, SPRITEp* sp_floor);
SPRITEp WarpPlane(int32_t* x, int32_t* y, int32_t* z, int* sectnum);
SPRITEp WarpToArea(SPRITEp sp_from, int32_t* x, int32_t* y, int32_t* z, int* sectnum);
bool WarpSectorInfo(short sectnum, SPRITEp* sp_warp);
SPRITEp Warp(int32_t* x, int32_t* y, int32_t* z, int* sectnum);
DSWActor* WarpPlane(int32_t* x, int32_t* y, int32_t* z, int* sectnum);
bool WarpSectorInfo(short sectnum, DSWActor** sp_warp);
DSWActor* Warp(int32_t* x, int32_t* y, int32_t* z, int* sectnum);
[[deprecated]]
SPRITEp Warp(int32_t* x, int32_t* y, int32_t* z, int16_t* sectnum)
DSWActor* Warp(int32_t* x, int32_t* y, int32_t* z, int16_t* sectnum)
{
int sect16 = *sectnum;
auto p= Warp(x, y, z, &sect16);
@ -34,7 +32,7 @@ SPRITEp Warp(int32_t* x, int32_t* y, int32_t* z, int16_t* sectnum)
}
[[deprecated]]
SPRITEp WarpPlane(int32_t* x, int32_t* y, int32_t* z, int16_t* sectnum)
DSWActor* WarpPlane(int32_t* x, int32_t* y, int32_t* z, int16_t* sectnum)
{
int sect16 = *sectnum;
auto p= WarpPlane(x, y, z, &sect16);

View file

@ -1364,6 +1364,7 @@ void DoPlayerWarpTeleporter(PLAYERp pp)
USERp u = ppActor->u();
SPRITEp sp = &ppActor->s();
short pnum;
DSWActor* act_warp;
SPRITEp sp_warp;
#if 0
@ -1376,9 +1377,10 @@ void DoPlayerWarpTeleporter(PLAYERp pp)
#endif
if ((sp_warp = Warp(&pp->posx, &pp->posy, &pp->posz, &pp->cursectnum)) == nullptr)
if ((act_warp = Warp(&pp->posx, &pp->posy, &pp->posz, &pp->cursectnum)) == nullptr)
return;
sp_warp = &act_warp->s();
switch (SP_TAG3(sp_warp))
{
case 1:

View file

@ -107,7 +107,7 @@ bool FAF_Sector(short sectnum)
void SetWallWarpHitscan(short sectnum)
{
short start_wall, wall_num;
SPRITEp sp_warp;
DSWActor* sp_warp;
if (!WarpSectorInfo(sectnum, &sp_warp))
return;

View file

@ -105,7 +105,7 @@ int PlaxCeilGlobZadjust, PlaxFloorGlobZadjust;
void SetSectorWallBits(short sectnum, int bit_mask, bool set_sectwall, bool set_nextwall);
int DoActorDebris(DSWActor* actor);
void ActorWarpUpdatePos(short SpriteNum,short sectnum);
void ActorWarpType(SPRITEp sp, SPRITEp sp_warp);
void ActorWarpType(DSWActor* sp, DSWActor* act_warp);
int MissileZrange(short SpriteNum);
#define ACTIVE_CHECK_TIME (3*120)
@ -6869,16 +6869,15 @@ SpriteControl(void)
int
move_sprite(int spritenum, int xchange, int ychange, int zchange, int ceildist, int flordist, uint32_t cliptype, int numtics)
{
auto actor = &swActors[spritenum];
int retval=0, zh;
int dasectnum;
short tempshort;
SPRITEp spr;
USERp u = User[spritenum].Data();
SPRITEp spr = &actor->s();
USERp u = actor->u();
short lastsectnum;
spr = &sprite[spritenum];
ASSERT(u);
ASSERT(actor->hasU());
vec3_t clippos = spr->pos;
@ -6972,11 +6971,11 @@ move_sprite(int spritenum, int xchange, int ychange, int zchange, int ceildist,
if (TEST(sector[spr->sectnum].extra, SECTFX_WARP_SECTOR))
{
SPRITEp sp_warp;
DSWActor* sp_warp;
if ((sp_warp = WarpPlane(&spr->x, &spr->y, &spr->z, &dasectnum)))
{
ActorWarpUpdatePos(spritenum, dasectnum);
ActorWarpType(spr, sp_warp);
ActorWarpType(actor, sp_warp);
}
if (spr->sectnum != lastsectnum)
@ -6984,7 +6983,7 @@ move_sprite(int spritenum, int xchange, int ychange, int zchange, int ceildist,
if ((sp_warp = Warp(&spr->x, &spr->y, &spr->z, &dasectnum)))
{
ActorWarpUpdatePos(spritenum, dasectnum);
ActorWarpType(spr, sp_warp);
ActorWarpType(actor, sp_warp);
}
}
}
@ -7041,8 +7040,9 @@ void ActorWarpUpdatePos(short SpriteNum, short sectnum)
DoActorZrange(SpriteNum);
}
void MissileWarpType(SPRITEp sp, SPRITEp sp_warp)
void MissileWarpType(DSWActor* sp, DSWActor* act_warp)
{
auto sp_warp = &act_warp->s();
switch (SP_TAG1(sp_warp))
{
case WARP_CEILING_PLANE:
@ -7056,20 +7056,21 @@ void MissileWarpType(SPRITEp sp, SPRITEp sp_warp)
break;
default:
PlaySound(DIGI_ITEM_SPAWN, sp, v3df_none);
DoSpawnItemTeleporterEffect(sp);
DoSpawnItemTeleporterEffect(&sp->s());
break;
}
}
void ActorWarpType(SPRITEp sp, SPRITEp sp_warp)
void ActorWarpType(DSWActor* sp, DSWActor* act_warp)
{
auto sp_warp = &act_warp->s();
switch (SP_TAG3(sp_warp))
{
case 1:
break;
default:
PlaySound(DIGI_ITEM_SPAWN, sp, v3df_none);
DoSpawnTeleporterEffectPlace(&swActors[sp - sprite]);
DoSpawnTeleporterEffectPlace(sp);
break;
}
}
@ -7117,15 +7118,14 @@ MissileZrange(short SpriteNum)
int
move_missile(int spritenum, int xchange, int ychange, int zchange, int ceildist, int flordist, uint32_t cliptype, int numtics)
{
DSWActor* actor = &swActors[spritenum];
USERp u = actor->u();
SPRITEp sp = &actor->s();
int retval, zh;
int dasectnum, tempshort;
SPRITEp sp;
USERp u = User[spritenum].Data();
short lastsectnum;
sp = &sprite[spritenum];
ASSERT(u);
ASSERT(actor->hasU());
vec3_t clippos = sp->pos;
@ -7209,12 +7209,12 @@ move_missile(int spritenum, int xchange, int ychange, int zchange, int ceildist,
if (TEST(sector[sp->sectnum].extra, SECTFX_WARP_SECTOR))
{
SPRITEp sp_warp;
DSWActor* sp_warp;
if ((sp_warp = WarpPlane(&sp->x, &sp->y, &sp->z, &dasectnum)))
{
MissileWarpUpdatePos(spritenum, dasectnum);
MissileWarpType(sp, sp_warp);
MissileWarpType(actor, sp_warp);
}
if (sp->sectnum != lastsectnum)
@ -7222,7 +7222,7 @@ move_missile(int spritenum, int xchange, int ychange, int zchange, int ceildist,
if ((sp_warp = Warp(&sp->x, &sp->y, &sp->z, &dasectnum)))
{
MissileWarpUpdatePos(spritenum, dasectnum);
MissileWarpType(sp, sp_warp);
MissileWarpType(actor, sp_warp);
}
}
}
@ -7252,17 +7252,16 @@ move_missile(int spritenum, int xchange, int ychange, int zchange, int ceildist,
int
move_ground_missile(short spritenum, int xchange, int ychange, int ceildist, int flordist, uint32_t cliptype, int numtics)
{
DSWActor* actor = &swActors[spritenum];
USERp u = actor->u();
SPRITEp sp = &actor->s();
int daz;
int retval=0;
int dasectnum;
SPRITEp sp;
USERp u = User[spritenum].Data();
short lastsectnum;
int ox,oy;
sp = &sprite[spritenum];
ASSERT(u);
ASSERT(actor->hasU());
// Can't modify sprite sectors
// directly becuase of linked lists
@ -7407,12 +7406,12 @@ move_ground_missile(short spritenum, int xchange, int ychange, int ceildist, int
if (TEST(sector[sp->sectnum].extra, SECTFX_WARP_SECTOR))
{
SPRITEp sp_warp;
DSWActor* sp_warp;
if ((sp_warp = WarpPlane(&sp->x, &sp->y, &sp->z, &dasectnum)))
{
MissileWarpUpdatePos(spritenum, dasectnum);
MissileWarpType(sp, sp_warp);
MissileWarpType(actor, sp_warp);
}
if (sp->sectnum != lastsectnum)
@ -7420,7 +7419,7 @@ move_ground_missile(short spritenum, int xchange, int ychange, int ceildist, int
if ((sp_warp = Warp(&sp->x, &sp->y, &sp->z, &dasectnum)))
{
MissileWarpUpdatePos(spritenum, dasectnum);
MissileWarpType(sp, sp_warp);
MissileWarpType(actor, sp_warp);
}
}
}

View file

@ -39,13 +39,10 @@ BEGIN_SW_NS
////////////////////////////////////////////////////////////////////////////////
extern bool Prediction;
DSWActor* WarpToArea(DSWActor* sp_from, int32_t* x, int32_t* y, int32_t* z, int* sectnum);
bool
WarpPlaneSectorInfo(short sectnum, SPRITEp *sp_ceiling, SPRITEp *sp_floor)
bool WarpPlaneSectorInfo(short sectnum, DSWActor** sp_ceiling, DSWActor** sp_floor)
{
int i;
SPRITEp sp;
*sp_floor = nullptr;
*sp_ceiling = nullptr;
@ -55,10 +52,10 @@ WarpPlaneSectorInfo(short sectnum, SPRITEp *sp_ceiling, SPRITEp *sp_floor)
if (sectnum < 0 || !TEST(sector[sectnum].extra, SECTFX_WARP_SECTOR))
return false;
StatIterator it(STAT_WARP);
while ((i = it.NextIndex()) >= 0)
SWStatIterator it(STAT_WARP);
while (auto actor = it.Next())
{
sp = &sprite[i];
auto sp = &actor->s();
if (sp->sectnum == sectnum)
{
@ -68,11 +65,11 @@ WarpPlaneSectorInfo(short sectnum, SPRITEp *sp_ceiling, SPRITEp *sp_floor)
if (sp->hitag == WARP_CEILING_PLANE)
{
*sp_ceiling = sp;
*sp_ceiling = actor;
}
else if (sp->hitag == WARP_FLOOR_PLANE)
{
*sp_floor = sp;
*sp_floor = actor;
}
}
}
@ -80,10 +77,9 @@ WarpPlaneSectorInfo(short sectnum, SPRITEp *sp_ceiling, SPRITEp *sp_floor)
return true;
}
SPRITEp
WarpPlane(int32_t* x, int32_t* y, int32_t* z, int* sectnum)
DSWActor* WarpPlane(int32_t* x, int32_t* y, int32_t* z, int* sectnum)
{
SPRITEp sp_floor, sp_ceiling;
DSWActor* sp_floor,* sp_ceiling;
if (Prediction)
return nullptr;
@ -93,7 +89,7 @@ WarpPlane(int32_t* x, int32_t* y, int32_t* z, int* sectnum)
if (sp_ceiling)
{
if (*z <= sp_ceiling->z)
if (*z <= sp_ceiling->s().z)
{
return WarpToArea(sp_ceiling, x, y, z, sectnum);
}
@ -101,7 +97,7 @@ WarpPlane(int32_t* x, int32_t* y, int32_t* z, int* sectnum)
if (sp_floor)
{
if (*z >= sp_floor->z)
if (*z >= sp_floor->s().z)
{
return WarpToArea(sp_floor, x, y, z, sectnum);
}
@ -110,14 +106,12 @@ WarpPlane(int32_t* x, int32_t* y, int32_t* z, int* sectnum)
return nullptr;
}
SPRITEp
WarpToArea(SPRITEp 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, int* sectnum)
{
int xoff;
int yoff;
int zoff;
int i;
SPRITEp sp = sp_from;
SPRITEp const sp = &sp_from->s();
short match;
short to_tag = 0;
short match_rand[16];
@ -173,32 +167,32 @@ WarpToArea(SPRITEp sp_from, int32_t* x, int32_t* y, int32_t* z, int* sectnum)
break;
}
StatIterator it(STAT_WARP);
while ((i = it.NextIndex()) >= 0)
SWStatIterator it(STAT_WARP);
while (auto actor = it.Next())
{
SPRITEp sp = &sprite[i];
auto spi = &actor->s();
if (sp->lotag == match && sp != sp_from)
if (spi->lotag == match && actor != sp_from)
{
// exp: WARP_CEILING or WARP_CEILING_PLANE
if (sp->hitag == to_tag)
if (spi->hitag == to_tag)
{
if (!validSectorIndex(sp->sectnum))
if (!validSectorIndex(spi->sectnum))
return nullptr;
// determine new x,y,z position
*x = sp->x + xoff;
*y = sp->y + yoff;
*z = sp->z + zoff;
*x = spi->x + xoff;
*y = spi->y + yoff;
*z = spi->z + zoff;
// make sure you warp outside of warp plane
*z += z_adj;
// get new sector
*sectnum = sp->sectnum;
*sectnum = spi->sectnum;
updatesector(*x, *y, sectnum);
return sp;
return actor;
}
}
}
@ -212,21 +206,17 @@ WarpToArea(SPRITEp sp_from, int32_t* x, int32_t* y, int32_t* z, int* sectnum)
//
////////////////////////////////////////////////////////////////////////////////
bool
WarpSectorInfo(short sectnum, SPRITEp *sp_warp)
bool WarpSectorInfo(short sectnum, DSWActor** sp_warp)
{
int i;
SPRITEp sp;
*sp_warp = nullptr;
if (!TEST(sector[sectnum].extra, SECTFX_WARP_SECTOR))
return false;
StatIterator it(STAT_WARP);
while ((i = it.NextIndex()) >= 0)
SWStatIterator it(STAT_WARP);
while (auto actor = it.Next())
{
sp = &sprite[i];
auto sp = &actor->s();
if (sp->sectnum == sectnum)
{
@ -236,7 +226,7 @@ WarpSectorInfo(short sectnum, SPRITEp *sp_warp)
if (sp->hitag == WARP_TELEPORTER)
{
*sp_warp = sp;
*sp_warp = actor;
}
}
}
@ -244,10 +234,9 @@ WarpSectorInfo(short sectnum, SPRITEp *sp_warp)
return true;
}
SPRITEp
Warp(int32_t* x, int32_t* y, int32_t* z, int* sectnum)
DSWActor* Warp(int32_t* x, int32_t* y, int32_t* z, int* sectnum)
{
SPRITEp sp_warp;
DSWActor* sp_warp;
if (Prediction)
return nullptr;