Skip to content

Commit

Permalink
- use backend's collision struct in SW.
Browse files Browse the repository at this point in the history
  • Loading branch information
coelckers committed Dec 4, 2021
1 parent 5a38af6 commit 94c04ba
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 160 deletions.
2 changes: 1 addition & 1 deletion source/games/sw/src/ai.cpp
Expand Up @@ -78,7 +78,7 @@ bool ActorMoveHitReact(DSWActor* actor)
auto coll = u->coll;
if (coll.type == kHitSprite)
{
auto hitActor = coll.actor;
auto hitActor = coll.actor();
if (hitActor->hasU() && hitActor->u()->PlayerP)
{
// if you ran into a player - call close range functions
Expand Down
2 changes: 1 addition & 1 deletion source/games/sw/src/draw.cpp
Expand Up @@ -228,7 +228,7 @@ int DoShadowFindGroundPoint(tspriteptr_t sp)
{
case kHitSprite:
{
hsp = &florhit.actor->s();
hsp = &florhit.actor()->s();

if (TEST(hsp->cstat, CSTAT_SPRITE_ALIGNMENT_FLOOR))
{
Expand Down
33 changes: 2 additions & 31 deletions source/games/sw/src/game.h
Expand Up @@ -59,29 +59,10 @@ EXTERN_CVAR(Bool, sw_bunnyrockets)

BEGIN_SW_NS

// Wrapper around the insane collision info mess from Build.
class DSWActor;
struct Collision
{
int type;
int index;
int legacyVal; // should be removed later, but needed for converting back for unadjusted code.
DSWActor* actor;

Collision() = default;
explicit Collision(int legacyval) { setFromEngine(legacyval); }

void invalidate() { type = -1; } // something invalid that's not a valid hit type.
int setNone();
int setSector(int num);
int setWall(int num);
int setSprite(DSWActor* num);
int setSky();
int setFromEngine(int value);
using HitInfo = THitInfo<DSWActor>;
using Collision = TCollision<DSWActor>;

walltype* wall() const { assert(type == kHitWall); return &::wall[index]; }
sectortype* sector() const { assert(type == kHitSector); return &::sector[index]; }
};

typedef struct
{
Expand Down Expand Up @@ -1060,7 +1041,6 @@ struct ROTATOR
};

using ROTATORp = ROTATOR*;
struct Collision;

//
// User Extension record
Expand Down Expand Up @@ -1918,9 +1898,6 @@ inline bool FAF_ConnectArea(sectortype* sect)
bool PlayerCeilingHit(PLAYERp pp, int zlimit);
bool PlayerFloorHit(PLAYERp pp, int zlimit);

class DSWActor;
using HitInfo = THitInfo<DSWActor>;

void FAFhitscan(int32_t x, int32_t y, int32_t z, sectortype* sectnum,
int32_t xvect, int32_t yvect, int32_t zvect,
HitInfo& hit, int32_t clipmask);
Expand All @@ -1937,12 +1914,6 @@ void FAFgetzrangepoint(int32_t x, int32_t y, int32_t z, sectortype* sect,
int32_t* loz, Collision* florhit);


void short_setinterpolation(short *posptr);
void short_stopinterpolation(short *posptr);
void short_updateinterpolations(void);
void short_dointerpolations(int smoothratio);
void short_restoreinterpolations(void);

enum SoundType
{
SOUND_OBJECT_TYPE,
Expand Down
14 changes: 7 additions & 7 deletions source/games/sw/src/jweapon.cpp
Expand Up @@ -410,7 +410,7 @@ int DoBloodSpray(DSWActor* actor)
case kHitSprite:
{
short wall_ang;
auto hitActor = u->coll.actor;
auto hitActor = u->coll.actor();
SPRITEp hsp = &hitActor->s();

if (TEST(hsp->cstat, CSTAT_SPRITE_ALIGNMENT_WALL))
Expand Down Expand Up @@ -440,7 +440,7 @@ int DoBloodSpray(DSWActor* actor)
WALLp wph;
short wb;

wph = u->coll.wall();
wph = u->coll.hitWall;

if (wph->lotag == TAG_WALL_BREAK)
{
Expand Down Expand Up @@ -613,7 +613,7 @@ int DoPhosphorus(DSWActor* actor)
USERp hu;


auto hitActor = u->coll.actor;
auto hitActor = u->coll.actor();
hsp = &hitActor->s();
hu = hitActor->u();

Expand Down Expand Up @@ -648,7 +648,7 @@ int DoPhosphorus(DSWActor* actor)
short hit_wall, nw, wall_ang;
WALLp wph;

wph = u->coll.wall();
wph = u->coll.hitWall;

if (wph->lotag == TAG_WALL_BREAK)
{
Expand Down Expand Up @@ -858,7 +858,7 @@ int DoChemBomb(DSWActor* actor)

case kHitWall:
{
auto wph = u->coll.wall();
auto wph = u->coll.hitWall;

if (wph->lotag == TAG_WALL_BREAK)
{
Expand Down Expand Up @@ -1062,7 +1062,7 @@ int DoCaltrops(DSWActor* actor)

PlaySound(DIGI_CALTROPS, actor, v3df_dontpan);

auto hitActor = u->coll.actor;
auto hitActor = u->coll.actor();
auto hsp = &hitActor->s();

if (TEST(hsp->cstat, CSTAT_SPRITE_ALIGNMENT_WALL))
Expand All @@ -1083,7 +1083,7 @@ int DoCaltrops(DSWActor* actor)

case kHitWall:
{
auto wph = u->coll.wall();
auto wph = u->coll.hitWall;

if (wph->lotag == TAG_WALL_BREAK)
{
Expand Down
16 changes: 8 additions & 8 deletions source/games/sw/src/player.cpp
Expand Up @@ -1886,20 +1886,20 @@ void DoPlayerZrange(PLAYERp pp)

if (ceilColl.type == kHitSprite)
{
pp->highActor = ceilColl.actor;
pp->highActor = ceilColl.actor();
}
else
{
pp->hi_sectp = ceilColl.sector();
pp->hi_sectp = ceilColl.hitSector;
}

if (floorColl.type == kHitSprite)
{
pp->lowActor = floorColl.actor;
pp->lowActor = floorColl.actor();

// prevent player from standing on Zombies
auto fsp = &floorColl.actor->s();
if (fsp->statnum == STAT_ENEMY && floorColl.actor->u()->ID == ZOMBIE_RUN_R0)
auto fsp = &floorColl.actor()->s();
if (fsp->statnum == STAT_ENEMY && floorColl.actor()->u()->ID == ZOMBIE_RUN_R0)
{
pp->lo_sectp = fsp->sector();
pp->loz = fsp->z;
Expand All @@ -1908,7 +1908,7 @@ void DoPlayerZrange(PLAYERp pp)
}
else
{
pp->lo_sectp = floorColl.sector();
pp->lo_sectp = floorColl.hitSector;
}
}

Expand Down Expand Up @@ -5992,7 +5992,7 @@ void DoPlayerDeathMoveHead(PLAYERp pp)

//PlaySound(DIGI_DHCLUNK, pp, v3df_dontpan);

auto hit_sprite = u->coll.actor;
auto hit_sprite = u->coll.actor();
hsp = &hit_sprite->s();

if (!TEST(hsp->cstat, CSTAT_SPRITE_ALIGNMENT_WALL))
Expand All @@ -6008,7 +6008,7 @@ void DoPlayerDeathMoveHead(PLAYERp pp)
}
case kHitWall:
{
int wall_ang = NORM_ANGLE(getangle(u->coll.wall()->delta())-512);
int wall_ang = NORM_ANGLE(getangle(u->coll.hitWall->delta())-512);

int dang = getincangle(wall_ang, u->slide_ang);
u->slide_ang = NORM_ANGLE(wall_ang + 1024 - dang);
Expand Down
2 changes: 1 addition & 1 deletion source/games/sw/src/ripper.cpp
Expand Up @@ -1021,7 +1021,7 @@ int DoRipperMoveHang(DSWActor* actor)
u->WaitTics = 2 + ((RANDOM_P2(4 << 8) >> 8) * 120);

// hang flush with the wall
sp->ang = NORM_ANGLE(getangle(u->coll.wall()->delta()) - 512);
sp->ang = NORM_ANGLE(getangle(u->coll.hitWall->delta()) - 512);

return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion source/games/sw/src/ripper2.cpp
Expand Up @@ -1035,7 +1035,7 @@ int DoRipper2MoveHang(DSWActor* actor)
u->WaitTics = 0; // Double jump

// hang flush with the wall
sp->ang = NORM_ANGLE(getangle(u->coll.wall()->delta()) - 512);
sp->ang = NORM_ANGLE(getangle(u->coll.hitWall->delta()) - 512);

return 0;
}
Expand Down
6 changes: 3 additions & 3 deletions source/games/sw/src/rooms.cpp
Expand Up @@ -355,7 +355,7 @@ bool SectorZadjust(const Collision& ceilhit, int32_t* hiz, const Collision& flor
{
case kHitSector:
{
auto hit_sector = florhit.sector();
auto hit_sector = florhit.hitSector;

// don't jack with connect sectors
if (FAF_ConnectFloor(hit_sector))
Expand Down Expand Up @@ -409,7 +409,7 @@ bool SectorZadjust(const Collision& ceilhit, int32_t* hiz, const Collision& flor
{
case kHitSector:
{
auto hit_sector = ceilhit.sector();
auto hit_sector = ceilhit.hitSector;

// don't jack with connect sectors
if (FAF_ConnectCeiling(hit_sector))
Expand Down Expand Up @@ -460,7 +460,7 @@ void WaterAdjust(const Collision& florhit, int32_t* loz)
{
if (florhit.type == kHitSector)
{
auto sect = florhit.sector();
auto sect = florhit.hitSector;
if (!sect->hasU()) return;

if (sect->hasU() && FixedToInt(sect->depth_fixed))
Expand Down
3 changes: 1 addition & 2 deletions source/games/sw/src/save.cpp
Expand Up @@ -843,7 +843,7 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, USER& w, USER* def
("sz", w.sz, def->sz)
("sang", w.sang, def->sang)
("spal", w.spal, def->spal)
("ret", w.coll.legacyVal, def->coll.legacyVal) // is this needed?
//("ret", w.coll, def->coll) // is this needed?
("Flag1", w.Flag1, def->Flag1)
("LastWeaponNum", w.LastWeaponNum, def->LastWeaponNum)
("WeaponNum", w.WeaponNum, def->WeaponNum)
Expand All @@ -864,7 +864,6 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, USER& w, USER* def
if (arc.isReading())
{
w.oangdiff = 0;
SetCollision(&w, w.coll.legacyVal);
}
}
return arc;
Expand Down
34 changes: 17 additions & 17 deletions source/games/sw/src/sprite.cpp
Expand Up @@ -4613,10 +4613,10 @@ void DoActorZrange(DSWActor* actor)
switch (ceilhit.type)
{
case kHitSprite:
u->highActor = ceilhit.actor;
u->highActor = ceilhit.actor();
break;
case kHitSector:
u->hi_sectp = ceilhit.sector();
u->hi_sectp = ceilhit.hitSector;
break;
default:
ASSERT(true==false);
Expand All @@ -4626,10 +4626,10 @@ void DoActorZrange(DSWActor* actor)
switch (florhit.type)
{
case kHitSprite:
u->lowActor = florhit.actor;
u->lowActor = florhit.actor();
break;
case kHitSector:
u->lo_sectp = florhit.sector();
u->lo_sectp = florhit.hitSector;
break;
default:
ASSERT(true==false);
Expand All @@ -4654,20 +4654,20 @@ int DoActorGlobZ(DSWActor* actor)
switch (globhihit.type)
{
case kHitSprite:
u->highActor = globhihit.actor;
u->highActor = globhihit.actor();
break;
default:
u->hi_sectp = globhihit.sector();
u->hi_sectp = globhihit.hitSector;
break;
}

switch (globlohit.type)
{
case kHitSprite:
u->lowActor = globlohit.actor;
u->lowActor = globlohit.actor();
break;
default:
u->lo_sectp = globlohit.sector();
u->lo_sectp = globlohit.hitSector;
break;
}

Expand Down Expand Up @@ -4697,7 +4697,7 @@ bool ActorDrop(DSWActor* actor, int x, int y, int z, sectortype* new_sector, sho
{
case kHitSprite:
{
SPRITEp hsp = &florhit.actor->s();
SPRITEp hsp = &florhit.actor()->s();

// if its a floor sprite and not too far down
if (TEST(hsp->cstat, CSTAT_SPRITE_ALIGNMENT_FLOOR) &&
Expand Down Expand Up @@ -6449,7 +6449,7 @@ void SpriteControl(void)

Collision move_sprite(DSWActor* actor, int xchange, int ychange, int zchange, int ceildist, int flordist, uint32_t cliptype, int numtics)
{
Collision retval(0);
Collision retval{};
int zh;
int dasectnum;
short tempshort;
Expand Down Expand Up @@ -6660,7 +6660,7 @@ Collision move_missile(DSWActor* actor, int xchange, int ychange, int zchange, i
{
USERp u = actor->u();
SPRITEp sp = &actor->s();
Collision retval(0);
Collision retval{};
int zh;
int dasectnum, tempshort;
short lastsectnum;
Expand Down Expand Up @@ -6692,7 +6692,7 @@ Collision move_missile(DSWActor* actor, int xchange, int ychange, int zchange, i
if (dasectnum < 0)
{
// we've gone beyond a white wall - kill it
retval.setSky();
retval.setVoid();
return retval;
}
retval.setFromEngine(cmret);
Expand Down Expand Up @@ -6767,15 +6767,15 @@ Collision move_missile(DSWActor* actor, int xchange, int ychange, int zchange, i
{
if (sp->z < sp->sector()->ceilingz)
{
retval.setSky();
retval.setVoid();
}
}

if (retval.type != kHitNone && TEST(sp->sector()->floorstat, FLOOR_STAT_PLAX))
{
if (sp->z > sp->sector()->floorz)
{
retval.setSky();
retval.setVoid();
}
}

Expand All @@ -6788,7 +6788,7 @@ Collision move_ground_missile(DSWActor* actor, int xchange, int ychange, int cei
USERp u = actor->u();
SPRITEp sp = &actor->s();
int daz;
Collision retval(0);
Collision retval{};
int dasectnum;
short lastsectnum;
int ox,oy;
Expand Down Expand Up @@ -6843,7 +6843,7 @@ Collision move_ground_missile(DSWActor* actor, int xchange, int ychange, int cei
if (dasectnum < 0)
{
// we've gone beyond a white wall - kill it
retval.setSky();
retval.setVoid();
return retval;
}

Expand Down Expand Up @@ -6873,7 +6873,7 @@ Collision move_ground_missile(DSWActor* actor, int xchange, int ychange, int cei
if (labs(u->hiz - u->loz) < Z(12))
{
// we've gone into a very small place - kill it
retval.setSky();
retval.setVoid();
return retval;
}

Expand Down

0 comments on commit 94c04ba

Please sign in to comment.