- SW: cleaned up the depth variable handling in SECT_USER which was endian dependent, including the savegame handler

This commit is contained in:
Christoph Oelckers 2021-04-19 00:24:25 +02:00
parent c17ec5fa45
commit c3e5cf322e
13 changed files with 34 additions and 65 deletions

View file

@ -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; u->WaitTics = (u->WaitTics + (ACTORMOVETICS << 3)) & 1023;
//sp->z = Z(2) + u->loz + ((Z(4) * (int) bsin(u->WaitTics)) >> 14); //sp->z = Z(2) + u->loz + ((Z(4) * (int) bsin(u->WaitTics)) >> 14);
@ -540,7 +540,7 @@ KeepActorOnFloor(short SpriteNum)
return; return;
if (u->lo_sectp && SectUser[u->lo_sectp - sector].Data()) 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 else
depth = 0; depth = 0;

View file

@ -668,8 +668,8 @@ int DoCoolgMatchPlayerZ(short SpriteNum)
hiz = u->hiz; hiz = u->hiz;
// adjust loz/hiz for water depth // adjust loz/hiz for water depth
if (u->lo_sectp && SectUser[u->lo_sectp - sector].Data() && SectUser[u->lo_sectp - sector]->depth) if (u->lo_sectp && SectUser[u->lo_sectp - sector].Data() && FixedToInt(SectUser[u->lo_sectp - sector]->depth_fixed))
loz -= Z(SectUser[u->lo_sectp - sector]->depth) - Z(8); loz -= Z(FixedToInt(SectUser[u->lo_sectp - sector]->depth_fixed)) - Z(8);
// lower bound // lower bound
if (u->lo_sp) if (u->lo_sp)

View file

@ -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)) if (SectUser[sectnum].Data() && TEST(u->lo_sectp->extra, SECTFX_SINK))
{ {
depth = SectUser[sectnum]->depth; depth = FixedToInt(SectUser[sectnum]->depth_fixed);
} }
else else
{ {

View file

@ -504,8 +504,8 @@ int DoEelMatchPlayerZ(short SpriteNum)
hiz = u->hiz; hiz = u->hiz;
// adjust loz/hiz for water depth // adjust loz/hiz for water depth
if (u->lo_sectp && SectUser[u->lo_sectp - sector].Data() && SectUser[u->lo_sectp - sector]->depth) if (u->lo_sectp && SectUser[u->lo_sectp - sector].Data() && FixedToInt(SectUser[u->lo_sectp - sector]->depth_fixed))
loz -= Z(SectUser[u->lo_sectp - sector]->depth) - Z(8); loz -= Z(FixedToInt(SectUser[u->lo_sectp - sector]->depth_fixed)) - Z(8);
// lower bound // lower bound
if (u->lo_sp && u->tgt_sp == u->hi_sp) if (u->lo_sp && u->tgt_sp == u->hi_sp)

View file

@ -1552,11 +1552,7 @@ typedef struct SECT_USER
{ {
SECT_USER() { memset(this, 0, sizeof(*this)); } SECT_USER() { memset(this, 0, sizeof(*this)); }
int dist, flags; int dist, flags;
union int depth_fixed;
{
struct { short depth_fract, depth; }; // do NOT change this, doubles as a long FIXED point number
int depth_fixed;
};
short stag, // ST? tag number - for certain things it helps to know it short stag, // ST? tag number - for certain things it helps to know it
ang, ang,
height, height,

View file

@ -380,8 +380,8 @@ int DoHornetMatchPlayerZ(short SpriteNum)
hiz = u->hiz; hiz = u->hiz;
// adjust loz/hiz for water depth // adjust loz/hiz for water depth
if (u->lo_sectp && SectUser[u->lo_sectp - sector].Data() && SectUser[u->lo_sectp - sector]->depth) if (u->lo_sectp && SectUser[u->lo_sectp - sector].Data() && FixedToInt(SectUser[u->lo_sectp - sector]->depth_fixed))
loz -= Z(SectUser[u->lo_sectp - sector]->depth) - Z(8); loz -= Z(FixedToInt(SectUser[u->lo_sectp - sector]->depth_fixed)) - Z(8);
// lower bound // lower bound
if (u->lo_sp) if (u->lo_sp)

View file

@ -515,7 +515,7 @@ DoBloodSpray(int16_t Weapon)
SET(u->Flags, SPR_BOUNCE); // no bouncing SET(u->Flags, SPR_BOUNCE); // no bouncing
// underwater // 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 SET(u->Flags, SPR_BOUNCE); // no bouncing on
// shallow water // shallow water
@ -739,7 +739,7 @@ DoPhosphorus(int16_t Weapon)
SET(u->Flags, SPR_BOUNCE); // no bouncing SET(u->Flags, SPR_BOUNCE); // no bouncing
// underwater // 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 SET(u->Flags, SPR_BOUNCE); // no bouncing on
// shallow water // shallow water
@ -976,7 +976,7 @@ DoChemBomb(int16_t Weapon)
SET(u->Flags, SPR_BOUNCE); // no bouncing SET(u->Flags, SPR_BOUNCE); // no bouncing
// underwater // 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 SET(u->Flags, SPR_BOUNCE); // no bouncing on
// shallow water // shallow water
@ -1210,7 +1210,7 @@ DoCaltrops(int16_t Weapon)
SET(u->Flags, SPR_BOUNCE); // no bouncing SET(u->Flags, SPR_BOUNCE); // no bouncing
// underwater // 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 SET(u->Flags, SPR_BOUNCE); // no bouncing on
// shallow water // shallow water

View file

@ -1462,8 +1462,8 @@ DoPlayerSetWadeDepth(PLAYERp pp)
if (TEST(sectp->extra, SECTFX_SINK)) if (TEST(sectp->extra, SECTFX_SINK))
{ {
// make sure your even in the water // make sure your even in the water
if (pp->posz + PLAYER_HEIGHT > pp->lo_sectp->floorz - Z(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 = SectUser[pp->lo_sectp - sector]->depth; pp->WadeDepth = FixedToInt(SectUser[pp->lo_sectp - sector]->depth_fixed);
} }
} }

View file

@ -492,8 +492,8 @@ void WaterAdjust(short florhit, int32_t* loz)
{ {
SECT_USERp sectu = SectUser[NORM_SECTOR(florhit)].Data(); SECT_USERp sectu = SectUser[NORM_SECTOR(florhit)].Data();
if (sectu && sectu->depth) if (sectu && FixedToInt(sectu->depth_fixed))
*loz += Z(sectu->depth); *loz += Z(FixedToInt(sectu->depth_fixed));
} }
break; break;
case HIT_SPRITE: case HIT_SPRITE:

View file

@ -801,7 +801,7 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, SECT_USER& w, SECT
{ {
arc("dist", w.dist, def->dist) arc("dist", w.dist, def->dist)
("flags", w.flags, def->flags) ("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) ("stag", w.stag, def->stag)
("ang", w.ang, def->ang) ("ang", w.ang, def->ang)
("height", w.height, def->height) ("height", w.height, def->height)

View file

@ -1984,7 +1984,7 @@ SpriteSetup(void)
if (TEST(bit, SECTFX_SINK)) if (TEST(bit, SECTFX_SINK))
{ {
sectu = GetSectUser(sp->sectnum); sectu = GetSectUser(sp->sectnum);
sectu->depth = sp->lotag; sectu->depth_fixed = IntToFixed(sp->lotag);
KillSprite(SpriteNum); KillSprite(SpriteNum);
} }
else if (TEST(bit, SECTFX_OPERATIONAL)) else if (TEST(bit, SECTFX_OPERATIONAL))
@ -7155,8 +7155,8 @@ MissileWaterAdjust(short SpriteNum)
if (u->lo_sectp) if (u->lo_sectp)
{ {
SECT_USERp sectu = SectUser[u->lo_sectp - sector].Data(); SECT_USERp sectu = SectUser[u->lo_sectp - sector].Data();
if (sectu && sectu->depth) if (sectu && FixedToInt(sectu->depth_fixed))
u->loz -= Z(sectu->depth); u->loz -= Z(FixedToInt(sectu->depth_fixed));
} }
return 0; return 0;
} }

View file

@ -834,7 +834,7 @@ SectorObjectSetupBounds(SECTOR_OBJECTp sop)
sop->zorig_ceiling[sop->num_sectors] = sector[k].ceilingz; sop->zorig_ceiling[sop->num_sectors] = sector[k].ceilingz;
if (TEST(sector[k].extra, SECTFX_SINK)) 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 // lowest and highest floorz's
if (sector[k].floorz > sop->floor_loz) if (sector[k].floorz > sop->floor_loz)
@ -2269,46 +2269,19 @@ void CallbackSOsink(ANIMp ap, void *data)
ASSERT(su != NULL); ASSERT(su != NULL);
ASSERT(GetSectUser(src_sector)); ASSERT(GetSectUser(src_sector));
tgt_depth = (GetSectUser(src_sector))->depth; tgt_depth = FixedToInt((GetSectUser(src_sector))->depth_fixed);
#if 0 short sectnum;
for (w = &Water[0]; w < &Water[MAX_WATER]; w++) 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); ndx = AnimSet(ANIM_SUdepth, dest_sector, IntToFixed(tgt_depth), (ap->vel << 8) >> 8);
AnimSetVelAdj(ndx, ap->vel_adj); 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);
AnimSetVelAdj(ndx, ap->vel_adj);
found = true; found = true;
break; 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); ASSERT(found);

View file

@ -4516,7 +4516,7 @@ WeaponMoveHit(short SpriteNum)
return true; 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); SpawnSplash(SpriteNum);
//SetSuicide(SpriteNum); //SetSuicide(SpriteNum);
@ -4798,7 +4798,7 @@ DoFireballFlames(short SpriteNum)
} }
else 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)) if (labs(sector[sp->sectnum].floorz - sp->z) <= Z(4))
{ {
@ -4871,7 +4871,7 @@ DoBreakFlames(short SpriteNum)
} }
else 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)) if (labs(sector[sp->sectnum].floorz - sp->z) <= Z(4))
{ {
@ -8077,7 +8077,7 @@ DoStar(int16_t Weapon)
if (sp->z > DIV2(u->hiz + u->loz)) 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); SpawnSplash(Weapon);
KillSprite(Weapon); KillSprite(Weapon);
@ -9078,7 +9078,7 @@ DoGrenade(int16_t Weapon)
if (TEST(u->Flags, SPR_UNDERWATER)) if (TEST(u->Flags, SPR_UNDERWATER))
SET(u->Flags, SPR_BOUNCE); // no bouncing 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 SET(u->Flags, SPR_BOUNCE); // no bouncing on shallow water
if (!TEST(u->Flags, SPR_BOUNCE)) if (!TEST(u->Flags, SPR_BOUNCE))
@ -21257,7 +21257,7 @@ DoShrapVelocity(int16_t SpriteNum)
if (TEST(u->Flags, SPR_UNDERWATER)) if (TEST(u->Flags, SPR_UNDERWATER))
SET(u->Flags, SPR_BOUNCE); // no bouncing 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 SET(u->Flags, SPR_BOUNCE); // no bouncing on shallow water
if (!TEST(u->Flags, SPR_BOUNCE)) if (!TEST(u->Flags, SPR_BOUNCE))