Skip to content

Commit

Permalink
- SW: cleaned up the depth variable handling in SECT_USER which was e…
Browse files Browse the repository at this point in the history
…ndian dependent, including the savegame handler
  • Loading branch information
coelckers committed Apr 21, 2021
1 parent c17ec5f commit c3e5cf3
Show file tree
Hide file tree
Showing 13 changed files with 34 additions and 65 deletions.
4 changes: 2 additions & 2 deletions source/games/sw/src/actor.cpp
Expand Up @@ -455,7 +455,7 @@ DoActorDebris(short SpriteNum)
}
}

if (SectUser[sp->sectnum].Data() && SectUser[sp->sectnum]->depth > 10) // JBF: added null check
if (SectUser[sp->sectnum].Data() && FixedToInt(SectUser[sp->sectnum]->depth_fixed) > 10) // JBF: added null check
{
u->WaitTics = (u->WaitTics + (ACTORMOVETICS << 3)) & 1023;
//sp->z = Z(2) + u->loz + ((Z(4) * (int) bsin(u->WaitTics)) >> 14);
Expand Down Expand Up @@ -540,7 +540,7 @@ KeepActorOnFloor(short SpriteNum)
return;

if (u->lo_sectp && SectUser[u->lo_sectp - sector].Data())
depth = SectUser[u->lo_sectp - sector]->depth;
depth = FixedToInt(SectUser[u->lo_sectp - sector]->depth_fixed);
else
depth = 0;

Expand Down
4 changes: 2 additions & 2 deletions source/games/sw/src/coolg.cpp
Expand Up @@ -668,8 +668,8 @@ int DoCoolgMatchPlayerZ(short SpriteNum)
hiz = u->hiz;

// adjust loz/hiz for water depth
if (u->lo_sectp && SectUser[u->lo_sectp - sector].Data() && SectUser[u->lo_sectp - sector]->depth)
loz -= Z(SectUser[u->lo_sectp - sector]->depth) - Z(8);
if (u->lo_sectp && SectUser[u->lo_sectp - sector].Data() && FixedToInt(SectUser[u->lo_sectp - sector]->depth_fixed))
loz -= Z(FixedToInt(SectUser[u->lo_sectp - sector]->depth_fixed)) - Z(8);

// lower bound
if (u->lo_sp)
Expand Down
2 changes: 1 addition & 1 deletion source/games/sw/src/coolie.cpp
Expand Up @@ -478,7 +478,7 @@ void EnemyDefaults(short SpriteNum, ACTOR_ACTION_SETp action, PERSONALITYp perso

if (SectUser[sectnum].Data() && TEST(u->lo_sectp->extra, SECTFX_SINK))
{
depth = SectUser[sectnum]->depth;
depth = FixedToInt(SectUser[sectnum]->depth_fixed);
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions source/games/sw/src/eel.cpp
Expand Up @@ -504,8 +504,8 @@ int DoEelMatchPlayerZ(short SpriteNum)
hiz = u->hiz;

// adjust loz/hiz for water depth
if (u->lo_sectp && SectUser[u->lo_sectp - sector].Data() && SectUser[u->lo_sectp - sector]->depth)
loz -= Z(SectUser[u->lo_sectp - sector]->depth) - Z(8);
if (u->lo_sectp && SectUser[u->lo_sectp - sector].Data() && FixedToInt(SectUser[u->lo_sectp - sector]->depth_fixed))
loz -= Z(FixedToInt(SectUser[u->lo_sectp - sector]->depth_fixed)) - Z(8);

// lower bound
if (u->lo_sp && u->tgt_sp == u->hi_sp)
Expand Down
6 changes: 1 addition & 5 deletions source/games/sw/src/game.h
Expand Up @@ -1552,11 +1552,7 @@ typedef struct SECT_USER
{
SECT_USER() { memset(this, 0, sizeof(*this)); }
int dist, flags;
union
{
struct { short depth_fract, depth; }; // do NOT change this, doubles as a long FIXED point number
int depth_fixed;
};
int depth_fixed;
short stag, // ST? tag number - for certain things it helps to know it
ang,
height,
Expand Down
4 changes: 2 additions & 2 deletions source/games/sw/src/hornet.cpp
Expand Up @@ -380,8 +380,8 @@ int DoHornetMatchPlayerZ(short SpriteNum)
hiz = u->hiz;

// adjust loz/hiz for water depth
if (u->lo_sectp && SectUser[u->lo_sectp - sector].Data() && SectUser[u->lo_sectp - sector]->depth)
loz -= Z(SectUser[u->lo_sectp - sector]->depth) - Z(8);
if (u->lo_sectp && SectUser[u->lo_sectp - sector].Data() && FixedToInt(SectUser[u->lo_sectp - sector]->depth_fixed))
loz -= Z(FixedToInt(SectUser[u->lo_sectp - sector]->depth_fixed)) - Z(8);

// lower bound
if (u->lo_sp)
Expand Down
8 changes: 4 additions & 4 deletions source/games/sw/src/jweapon.cpp
Expand Up @@ -515,7 +515,7 @@ DoBloodSpray(int16_t Weapon)
SET(u->Flags, SPR_BOUNCE); // no bouncing
// underwater

if (u->lo_sectp && SectUser[sp->sectnum].Data() && SectUser[sp->sectnum]->depth)
if (u->lo_sectp && SectUser[sp->sectnum].Data() && FixedToInt(SectUser[sp->sectnum]->depth_fixed))
SET(u->Flags, SPR_BOUNCE); // no bouncing on
// shallow water

Expand Down Expand Up @@ -739,7 +739,7 @@ DoPhosphorus(int16_t Weapon)
SET(u->Flags, SPR_BOUNCE); // no bouncing
// underwater

if (u->lo_sectp && SectUser[sp->sectnum].Data() && SectUser[sp->sectnum]->depth)
if (u->lo_sectp && SectUser[sp->sectnum].Data() && FixedToInt(SectUser[sp->sectnum]->depth_fixed))
SET(u->Flags, SPR_BOUNCE); // no bouncing on
// shallow water

Expand Down Expand Up @@ -976,7 +976,7 @@ DoChemBomb(int16_t Weapon)
SET(u->Flags, SPR_BOUNCE); // no bouncing
// underwater

if (u->lo_sectp && SectUser[sp->sectnum].Data() && SectUser[sp->sectnum]->depth)
if (u->lo_sectp && SectUser[sp->sectnum].Data() && FixedToInt(SectUser[sp->sectnum]->depth_fixed))
SET(u->Flags, SPR_BOUNCE); // no bouncing on
// shallow water

Expand Down Expand Up @@ -1210,7 +1210,7 @@ DoCaltrops(int16_t Weapon)
SET(u->Flags, SPR_BOUNCE); // no bouncing
// underwater

if (u->lo_sectp && SectUser[sp->sectnum].Data() && SectUser[sp->sectnum]->depth)
if (u->lo_sectp && SectUser[sp->sectnum].Data() && FixedToInt(SectUser[sp->sectnum]->depth_fixed))
SET(u->Flags, SPR_BOUNCE); // no bouncing on
// shallow water

Expand Down
4 changes: 2 additions & 2 deletions source/games/sw/src/player.cpp
Expand Up @@ -1462,8 +1462,8 @@ DoPlayerSetWadeDepth(PLAYERp pp)
if (TEST(sectp->extra, SECTFX_SINK))
{
// make sure your even in the water
if (pp->posz + PLAYER_HEIGHT > pp->lo_sectp->floorz - Z(SectUser[pp->lo_sectp - sector]->depth))
pp->WadeDepth = SectUser[pp->lo_sectp - sector]->depth;
if (pp->posz + PLAYER_HEIGHT > pp->lo_sectp->floorz - Z(FixedToInt(SectUser[pp->lo_sectp - sector]->depth_fixed)))
pp->WadeDepth = FixedToInt(SectUser[pp->lo_sectp - sector]->depth_fixed);
}
}

Expand Down
4 changes: 2 additions & 2 deletions source/games/sw/src/rooms.cpp
Expand Up @@ -492,8 +492,8 @@ void WaterAdjust(short florhit, int32_t* loz)
{
SECT_USERp sectu = SectUser[NORM_SECTOR(florhit)].Data();

if (sectu && sectu->depth)
*loz += Z(sectu->depth);
if (sectu && FixedToInt(sectu->depth_fixed))
*loz += Z(FixedToInt(sectu->depth_fixed));
}
break;
case HIT_SPRITE:
Expand Down
2 changes: 1 addition & 1 deletion source/games/sw/src/save.cpp
Expand Up @@ -801,7 +801,7 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, SECT_USER& w, SECT
{
arc("dist", w.dist, def->dist)
("flags", w.flags, def->flags)
("depth_fract", w.depth_fract, def->depth_fract)
("depth", w.depth_fixed, def->depth_fixed)
("stag", w.stag, def->stag)
("ang", w.ang, def->ang)
("height", w.height, def->height)
Expand Down
6 changes: 3 additions & 3 deletions source/games/sw/src/sprite.cpp
Expand Up @@ -1984,7 +1984,7 @@ SpriteSetup(void)
if (TEST(bit, SECTFX_SINK))
{
sectu = GetSectUser(sp->sectnum);
sectu->depth = sp->lotag;
sectu->depth_fixed = IntToFixed(sp->lotag);
KillSprite(SpriteNum);
}
else if (TEST(bit, SECTFX_OPERATIONAL))
Expand Down Expand Up @@ -7155,8 +7155,8 @@ MissileWaterAdjust(short SpriteNum)
if (u->lo_sectp)
{
SECT_USERp sectu = SectUser[u->lo_sectp - sector].Data();
if (sectu && sectu->depth)
u->loz -= Z(sectu->depth);
if (sectu && FixedToInt(sectu->depth_fixed))
u->loz -= Z(FixedToInt(sectu->depth_fixed));
}
return 0;
}
Expand Down
39 changes: 6 additions & 33 deletions source/games/sw/src/track.cpp
Expand Up @@ -834,7 +834,7 @@ SectorObjectSetupBounds(SECTOR_OBJECTp sop)
sop->zorig_ceiling[sop->num_sectors] = sector[k].ceilingz;

if (TEST(sector[k].extra, SECTFX_SINK))
sop->zorig_floor[sop->num_sectors] += Z(SectUser[k]->depth);
sop->zorig_floor[sop->num_sectors] += Z(FixedToInt(SectUser[k]->depth_fixed));

// lowest and highest floorz's
if (sector[k].floorz > sop->floor_loz)
Expand Down Expand Up @@ -2269,46 +2269,19 @@ void CallbackSOsink(ANIMp ap, void *data)
ASSERT(su != NULL);

ASSERT(GetSectUser(src_sector));
tgt_depth = (GetSectUser(src_sector))->depth;
tgt_depth = FixedToInt((GetSectUser(src_sector))->depth_fixed);

#if 0
for (w = &Water[0]; w < &Water[MAX_WATER]; w++)
short sectnum;
for (sectnum = 0; sectnum < numsectors; sectnum++)
{
if (w->sector == dest_sector)
if (sectnum == dest_sector)
{
ndx = AnimSet(&w->depth, Z(tgt_depth), ap->vel>>8);
AnimSetVelAdj(ndx, ap->vel_adj);

// This is interesting
// Added a depth_fract to the struct so I could do a
// 16.16 Fixed point representation to change the depth
// in a more precise way
ndx = AnimSet((int *)&su->depth_fract, IntToFixed(tgt_depth), (ap->vel<<8)>>8);
ndx = AnimSet(ANIM_SUdepth, dest_sector, IntToFixed(tgt_depth), (ap->vel << 8) >> 8);
AnimSetVelAdj(ndx, ap->vel_adj);

found = true;
break;
}
}
#else
{
short sectnum;
for (sectnum = 0; sectnum < numsectors; sectnum++)
{
if (sectnum == dest_sector)
{
// This is interesting
// Added a depth_fract to the struct so I could do a
// 16.16 Fixed point representation to change the depth
// in a more precise way
ndx = AnimSet(ANIM_SUdepth, dest_sector, IntToFixed(tgt_depth), (ap->vel << 8) >> 8);
AnimSetVelAdj(ndx, ap->vel_adj);
found = true;
break;
}
}
}
#endif

ASSERT(found);

Expand Down
12 changes: 6 additions & 6 deletions source/games/sw/src/weapon.cpp
Expand Up @@ -4516,7 +4516,7 @@ WeaponMoveHit(short SpriteNum)
return true;
}

if (SectUser[hit_sect].Data() && SectUser[hit_sect]->depth > 0)
if (SectUser[hit_sect].Data() && FixedToInt(SectUser[hit_sect]->depth_fixed) > 0)
{
SpawnSplash(SpriteNum);
//SetSuicide(SpriteNum);
Expand Down Expand Up @@ -4798,7 +4798,7 @@ DoFireballFlames(short SpriteNum)
}
else
{
if (SectUser[sp->sectnum].Data() && SectUser[sp->sectnum]->depth > 0)
if (SectUser[sp->sectnum].Data() && FixedToInt(SectUser[sp->sectnum]->depth_fixed) > 0)
{
if (labs(sector[sp->sectnum].floorz - sp->z) <= Z(4))
{
Expand Down Expand Up @@ -4871,7 +4871,7 @@ DoBreakFlames(short SpriteNum)
}
else
{
if (SectUser[sp->sectnum].Data() && SectUser[sp->sectnum]->depth > 0)
if (SectUser[sp->sectnum].Data() && FixedToInt(SectUser[sp->sectnum]->depth_fixed) > 0)
{
if (labs(sector[sp->sectnum].floorz - sp->z) <= Z(4))
{
Expand Down Expand Up @@ -8077,7 +8077,7 @@ DoStar(int16_t Weapon)

if (sp->z > DIV2(u->hiz + u->loz))
{
if (SectUser[hit_sect].Data() && SectUser[hit_sect]->depth > 0)
if (SectUser[hit_sect].Data() && FixedToInt(SectUser[hit_sect]->depth_fixed) > 0)
{
SpawnSplash(Weapon);
KillSprite(Weapon);
Expand Down Expand Up @@ -9078,7 +9078,7 @@ DoGrenade(int16_t Weapon)
if (TEST(u->Flags, SPR_UNDERWATER))
SET(u->Flags, SPR_BOUNCE); // no bouncing underwater

if (u->lo_sectp && SectUser[sp->sectnum].Data() && SectUser[sp->sectnum]->depth)
if (u->lo_sectp && SectUser[sp->sectnum].Data() && FixedToInt(SectUser[sp->sectnum]->depth_fixed))
SET(u->Flags, SPR_BOUNCE); // no bouncing on shallow water

if (!TEST(u->Flags, SPR_BOUNCE))
Expand Down Expand Up @@ -21257,7 +21257,7 @@ DoShrapVelocity(int16_t SpriteNum)
if (TEST(u->Flags, SPR_UNDERWATER))
SET(u->Flags, SPR_BOUNCE); // no bouncing underwater

if (u->lo_sectp && SectUser[sp->sectnum].Data() && SectUser[sp->sectnum]->depth)
if (u->lo_sectp && SectUser[sp->sectnum].Data() && FixedToInt(SectUser[sp->sectnum]->depth_fixed))
SET(u->Flags, SPR_BOUNCE); // no bouncing on shallow water

if (!TEST(u->Flags, SPR_BOUNCE))
Expand Down

0 comments on commit c3e5cf3

Please sign in to comment.