- made sector ceiling/floor flags type safe.

- made sector flags type safe.
This commit is contained in:
Christoph Oelckers 2021-12-18 14:08:57 +01:00
parent b0e3c6b5ec
commit 6e32832428
14 changed files with 60 additions and 52 deletions

View file

@ -209,11 +209,11 @@ static int32_t LoadMapHack(const char *filename, SpawnSpriteDef& sprites)
sc.GetString();
if (sc.Compare("floor") && sc.CheckNumber())
{
sector[currentsector].floorstat &= ~sc.Number;
sector[currentsector].floorstat &= ESectorFlags::FromInt(~sc.Number);
}
else if (sc.Compare("ceiling") && sc.CheckNumber())
{
sector[currentsector].ceilingstat &= ~sc.Number;
sector[currentsector].ceilingstat &= ESectorFlags::FromInt(~sc.Number);
}
else sc.ScriptError("Bad token %s", sc.String);
}

View file

@ -101,8 +101,8 @@ static void ReadSectorV7(FileReader& fr, sectortype& sect)
sect.wallnum = fr.ReadInt16();
sect.ceilingz = fr.ReadInt32();
sect.floorz = fr.ReadInt32();
sect.ceilingstat = fr.ReadUInt16();
sect.floorstat = fr.ReadUInt16();
sect.ceilingstat = ESectorFlags::FromInt(fr.ReadUInt16());
sect.floorstat = ESectorFlags::FromInt(fr.ReadUInt16());
sect.ceilingpicnum = fr.ReadUInt16();
sect.ceilingheinum = fr.ReadInt16();
sect.ceilingshade = fr.ReadInt8();
@ -138,8 +138,8 @@ static void ReadSectorV6(FileReader& fr, sectortype& sect)
sect.floorxpan_ = fr.ReadUInt8();
sect.ceilingypan_ = fr.ReadUInt8();
sect.floorypan_ = fr.ReadUInt8();
sect.ceilingstat = fr.ReadUInt8();
sect.floorstat = fr.ReadUInt8();
sect.ceilingstat = ESectorFlags::FromInt(fr.ReadUInt8());
sect.floorstat = ESectorFlags::FromInt(fr.ReadUInt8());
sect.ceilingpal = fr.ReadUInt8();
sect.floorpal = fr.ReadUInt8();
sect.visibility = fr.ReadUInt8();
@ -165,16 +165,16 @@ static void ReadSectorV5(FileReader& fr, sectortype& sect)
sect.floorxpan_ = fr.ReadUInt8();
sect.ceilingypan_ = fr.ReadUInt8();
sect.floorypan_ = fr.ReadUInt8();
sect.ceilingstat = fr.ReadUInt8();
sect.floorstat = fr.ReadUInt8();
sect.ceilingstat = ESectorFlags::FromInt(fr.ReadUInt8());
sect.floorstat = ESectorFlags::FromInt(fr.ReadUInt8());
sect.ceilingpal = fr.ReadUInt8();
sect.floorpal = fr.ReadUInt8();
sect.visibility = fr.ReadUInt8();
sect.lotag = fr.ReadInt16();
sect.hitag = fr.ReadInt16();
sect.extra = fr.ReadInt16();
if ((sect.ceilingstat & 2) == 0) sect.ceilingheinum = 0;
if ((sect.floorstat & 2) == 0) sect.floorheinum = 0;
if ((sect.ceilingstat & CSTAT_SECTOR_SLOPE) == 0) sect.ceilingheinum = 0;
if ((sect.floorstat & CSTAT_SECTOR_SLOPE) == 0) sect.floorheinum = 0;
}
static void ReadWallV7(FileReader& fr, walltype& wall)

View file

@ -29,6 +29,7 @@ Prepared for public release: 03/21/2003 - Charlie Wiederhold, 3D Realms
#include <stdint.h>
#include "ns.h"
#include "tarray.h"
#include "tflags.h"
//=============================================================================
//
@ -67,8 +68,14 @@ enum ESectorBits
CSTAT_SECTOR_EXHUMED_BIT1 = 1 << 14,
CSTAT_SECTOR_EXHUMED_BIT2 = 1 << 15,
CSTAT_SECTOR_NO_CEILINGSHADE = 32768, // Blood: Force use of floorshade for sprites, even in sky sectors.
};
typedef TFlags<ESectorBits, uint16_t> ESectorFlags;
DEFINE_TFLAGS_OPERATORS(ESectorFlags)
// Extended sector bit flags.
enum ESectorExBits
{
@ -179,8 +186,8 @@ struct sectortype
float floorypan_;
int16_t wallnum;
uint16_t ceilingstat;
uint16_t floorstat;
ESectorFlags ceilingstat;
ESectorFlags floorstat;
int16_t ceilingpicnum;
int16_t ceilingheinum;
int16_t floorpicnum;

View file

@ -180,15 +180,15 @@ void setPortalFlags(int mode)
{
case 1:
if (mode)
sector[mirror[i].wallnum].ceilingstat |= 1;
sector[mirror[i].wallnum].ceilingstat |= CSTAT_SECTOR_SKY;
else
sector[mirror[i].wallnum].ceilingstat &= ~1;
sector[mirror[i].wallnum].ceilingstat &= ~CSTAT_SECTOR_SKY;
break;
case 2:
if (mode)
sector[mirror[i].wallnum].floorstat |= 1;
sector[mirror[i].wallnum].floorstat |= CSTAT_SECTOR_SKY;
else
sector[mirror[i].wallnum].floorstat &= ~1;
sector[mirror[i].wallnum].floorstat &= ~CSTAT_SECTOR_SKY;
break;
}
}
@ -273,7 +273,7 @@ void DrawMirrors(int x, int y, int z, fixed_t a, fixed_t horiz, int smooth, int
renderDrawRoomsQ16(x + mirror[i].dx, y + mirror[i].dy, z + mirror[i].dz, a, horiz, nSector, true);
viewProcessSprites(pm_tsprite, pm_spritesortcnt, x + mirror[i].dx, y + mirror[i].dy, z + mirror[i].dz, FixedToInt(a), smooth);
auto fstat = sector[nSector].floorstat;
sector[nSector].floorstat |= 1;
sector[nSector].floorstat |= CSTAT_SECTOR_SKY;
renderDrawMasks();
sector[nSector].floorstat = fstat;
for (int i = 0; i < 16; i++)
@ -305,7 +305,7 @@ void DrawMirrors(int x, int y, int z, fixed_t a, fixed_t horiz, int smooth, int
renderDrawRoomsQ16(x + mirror[i].dx, y + mirror[i].dy, z + mirror[i].dz, a, horiz, nSector, true);
viewProcessSprites(pm_tsprite, pm_spritesortcnt, x + mirror[i].dx, y + mirror[i].dy, z + mirror[i].dz, FixedToInt(a), smooth);
auto cstat = sector[nSector].ceilingstat;
sector[nSector].ceilingstat |= 1;
sector[nSector].ceilingstat |= CSTAT_SECTOR_SKY;
renderDrawMasks();
sector[nSector].ceilingstat = cstat;
for (int i = 0; i < 16; i++)

View file

@ -5781,7 +5781,7 @@ static void actCheckThings()
speed = pXSector->panVel << 9;
if (!pXSector->panAlways && pXSector->busy) speed = MulScale(speed, pXSector->busy, 16);
}
if (pSector->floorstat & 64) angle = (angle + GetWallAngle(pSector->firstWall()) + 512) & 2047;
if (pSector->floorstat & CSTAT_SECTOR_ALIGN) angle = (angle + GetWallAngle(pSector->firstWall()) + 512) & 2047;
actor->xvel += MulScale(speed, Cos(angle), 30);
actor->yvel += MulScale(speed, Sin(angle), 30);
@ -6230,7 +6230,7 @@ static void actCheckDudes()
if (!pXSector->panAlways && pXSector->busy)
speed = MulScale(speed, pXSector->busy, 16);
}
if (pSector->floorstat & 64)
if (pSector->floorstat & CSTAT_SECTOR_ALIGN)
angle = (angle + GetWallAngle(pSector->firstWall()) + 512) & 2047;
int dx = MulScale(speed, Cos(angle), 30);
int dy = MulScale(speed, Sin(angle), 30);

View file

@ -2556,9 +2556,9 @@ bool genDudePrepare(DBloodActor* actor, int propId)
// make sure dudes aren't in the floor or ceiling
int zTop, zBot; GetSpriteExtents(pSprite, &zTop, &zBot);
if (!(pSprite->sector()->ceilingstat & 0x0001))
if (!(pSprite->sector()->ceilingstat & CSTAT_SECTOR_SKY))
pSprite->z += ClipLow(pSprite->sector()->ceilingz - zTop, 0);
if (!(pSprite->sector()->floorstat & 0x0001))
if (!(pSprite->sector()->floorstat & CSTAT_SECTOR_SKY))
pSprite->z += ClipHigh(pSprite->sector()->floorz - zBot, 0);
pSprite->clipdist = ClipRange((pSprite->xrepeat + pSprite->yrepeat) >> 1, 4, 120);

View file

@ -684,7 +684,7 @@ void viewProcessSprites(tspritetype* tsprite, int& spritesortcnt, int32_t cX, in
XSECTOR const* pXSector = pSector->hasX() ? &pSector->xs() : nullptr;
int nShade = pTSprite->shade;
if ((pSector->ceilingstat & CSTAT_SECTOR_SKY) && (pSector->floorstat&32768) == 0)
if ((pSector->ceilingstat & CSTAT_SECTOR_SKY) && (pSector->floorstat & CSTAT_SECTOR_NO_CEILINGSHADE) == 0)
{
nShade += tileShade[pSector->ceilingpicnum]+pSector->ceilingshade;
}

View file

@ -310,8 +310,8 @@ void dbLoadMap(const char* pPath, int* pX, int* pY, int* pZ, short* pAngle, sect
pSector->wallnum = LittleShort(load.wallnum);
pSector->ceilingz = LittleLong(load.ceilingz);
pSector->floorz = LittleLong(load.floorz);
pSector->ceilingstat = LittleShort(load.ceilingstat);
pSector->floorstat = LittleShort(load.floorstat);
pSector->ceilingstat = ESectorFlags::FromInt(LittleShort(load.ceilingstat));
pSector->floorstat = ESectorFlags::FromInt(LittleShort(load.floorstat));
pSector->ceilingpicnum = LittleShort(load.ceilingpicnum);
pSector->ceilingheinum = LittleShort(load.ceilingheinum);
pSector->floorpicnum = LittleShort(load.floorpicnum);

View file

@ -1323,7 +1323,7 @@ void nnExtProcessSuperSprites()
if (!pXSector->panAlways && pXSector->busy)
speed = MulScale(speed, pXSector->busy, 16);
}
if (pDebris->sector()->floorstat & 64)
if (pDebris->sector()->floorstat & CSTAT_SECTOR_ALIGN)
angle = (angle + GetWallAngle(pDebris->sector()->firstWall()) + 512) & 2047;
int dx = MulScale(speed, Cos(angle), 30);
int dy = MulScale(speed, Sin(angle), 30);
@ -1383,8 +1383,8 @@ void nnExtProcessSuperSprites()
int fz = getflorzofslopeptr(pSector, pDebris->x, pDebris->y);
GetActorExtents(debrisactor, &top, &bottom);
if (fz >= bottom && pSector->lowerLink == nullptr && !(pSector->ceilingstat & 0x1)) pDebris->z += ClipLow(cz - top, 0);
if (cz <= top && pSector->upperLink == nullptr && !(pSector->floorstat & 0x1)) pDebris->z += ClipHigh(fz - bottom, 0);
if (fz >= bottom && pSector->lowerLink == nullptr && !(pSector->ceilingstat & CSTAT_SECTOR_SKY)) pDebris->z += ClipLow(cz - top, 0);
if (cz <= top && pSector->upperLink == nullptr && !(pSector->floorstat & CSTAT_SECTOR_SKY)) pDebris->z += ClipHigh(fz - bottom, 0);
}
}
}
@ -2955,14 +2955,14 @@ void usePropertiesChanger(DBloodActor* sourceactor, int objType, sectortype* pSe
// data3 = sector ceil cstat
if (valueIsBetween(pXSource->data3, -1, 32767)) {
if ((pSource->flags & kModernTypeFlag1)) pSector->ceilingstat |= pXSource->data3;
else pSector->ceilingstat = pXSource->data3;
if ((pSource->flags & kModernTypeFlag1)) pSector->ceilingstat |= ESectorFlags::FromInt(pXSource->data3);
else pSector->ceilingstat = ESectorFlags::FromInt(pXSource->data3);
}
// data4 = sector floor cstat
if (valueIsBetween(pXSource->data4, -1, 65535)) {
if ((pSource->flags & kModernTypeFlag1)) pSector->floorstat |= pXSource->data4;
else pSector->floorstat = pXSource->data4;
if ((pSource->flags & kModernTypeFlag1)) pSector->floorstat |= ESectorFlags::FromInt(pXSource->data4);
else pSector->floorstat = ESectorFlags::FromInt(pXSource->data4);
}
}
break;
@ -3848,9 +3848,10 @@ bool condCheckMixed(DBloodActor* aCond, const EVENT& event, int cmpOp, bool PUSH
case 28:
switch (arg3)
{
default: return ((pObj->floorstat & arg1) || (pObj->ceilingshade & arg1));
case 1: return (pObj->floorstat & arg1);
case 2: return (pObj->ceilingshade & arg1);
auto a = ESectorFlags::FromInt(arg1);
default: return ((pObj->floorstat & a) || (pObj->ceilingstat & a));
case 1: return (pObj->floorstat & a);
case 2: return (pObj->ceilingstat & a);
}
break;
case 29: return (pObj->hitag & arg1);

View file

@ -257,11 +257,11 @@ void DoSectorPanning(void)
if (pXSector->panFloor) // Floor
{
int nTile = pSector->floorpicnum;
if (pSector->floorstat & 64)
if (pSector->floorstat & CSTAT_SECTOR_ALIGN)
angle -= 512;
int xBits = tileWidth(nTile) >> int((pSector->floorstat & 8) != 0);
int xBits = tileWidth(nTile) >> int((pSector->floorstat & CSTAT_SECTOR_TEXHALF) != 0);
int px = MulScale(speed << 2, Cos(angle), 30) / xBits;
int yBits = tileHeight(nTile) >> int((pSector->floorstat & 8) != 0);
int yBits = tileHeight(nTile) >> int((pSector->floorstat & CSTAT_SECTOR_TEXHALF) != 0);
int py = MulScale(speed << 2, Sin(angle), 30) / yBits;
pSector->addfloorxpan(px * (1.f / 256));
pSector->addfloorypan(-py * (1.f / 256));
@ -269,11 +269,11 @@ void DoSectorPanning(void)
if (pXSector->panCeiling) // Ceiling
{
int nTile = pSector->ceilingpicnum;
if (pSector->ceilingstat & 64)
if (pSector->ceilingstat & CSTAT_SECTOR_ALIGN)
angle -= 512;
int xBits = tileWidth(nTile) >> int((pSector->ceilingstat & 8) != 0);
int xBits = tileWidth(nTile) >> int((pSector->ceilingstat & CSTAT_SECTOR_TEXHALF) != 0);
int px = MulScale(speed << 2, Cos(angle), 30) / xBits;
int yBits = tileHeight(nTile) >> int((pSector->ceilingstat & 8) != 0);
int yBits = tileHeight(nTile) >> int((pSector->ceilingstat & CSTAT_SECTOR_TEXHALF) != 0);
int py = MulScale(speed << 2, Sin(angle), 30) / yBits;
pSector->addceilingxpan(px * (1.f / 256));
pSector->addceilingypan(-py * (1.f / 256));

View file

@ -1077,11 +1077,11 @@ void DoSector(bool bSet, int lVar1, int lLabelID, int lVar2, DDukeActor* sActor,
else SetGameVarID(lVar2, sectp->floorz, sActor, sPlayer);
break;
case SECTOR_CEILINGSTAT:
if (bSet) sectp->ceilingstat = lValue;
if (bSet) sectp->ceilingstat = ESectorFlags::FromInt(lValue);
else SetGameVarID(lVar2, sectp->ceilingstat, sActor, sPlayer);
break;
case SECTOR_FLOORSTAT:
if (bSet) sectp->floorstat = lValue;
if (bSet) sectp->floorstat = ESectorFlags::FromInt(lValue);
else SetGameVarID(lVar2, sectp->floorstat, sActor, sPlayer);
break;
case SECTOR_CEILINGPICNUM:

View file

@ -103,7 +103,7 @@ void FAF_DrawRooms(int x, int y, int z, fixed_t q16ang, fixed_t q16horiz, int se
SP_TAG5(sp) = sp->sector()->ceilingpicnum;
sp->sector()->ceilingpicnum = SP_TAG2(sp);
SP_TAG4(sp) = sp->sector()->ceilingstat;
SET(sp->sector()->ceilingstat, SP_TAG6(sp));
SET(sp->sector()->ceilingstat, ESectorFlags::FromInt(SP_TAG6(sp)));
RESET(sp->sector()->ceilingstat, CSTAT_SECTOR_SKY);
}
else if (SP_TAG3(sp) == 1)
@ -111,7 +111,7 @@ void FAF_DrawRooms(int x, int y, int z, fixed_t q16ang, fixed_t q16horiz, int se
SP_TAG5(sp) = sp->sector()->floorpicnum;
sp->sector()->floorpicnum = SP_TAG2(sp);
SP_TAG4(sp) = sp->sector()->floorstat;
SET(sp->sector()->floorstat, SP_TAG6(sp));
SET(sp->sector()->floorstat, ESectorFlags::FromInt(SP_TAG6(sp)));
RESET(sp->sector()->floorstat, CSTAT_SECTOR_SKY);
}
}
@ -132,13 +132,13 @@ void FAF_DrawRooms(int x, int y, int z, fixed_t q16ang, fixed_t q16horiz, int se
{
// restore ceilingpicnum and ceilingstat
sp->sector()->ceilingpicnum = SP_TAG5(sp);
sp->sector()->ceilingstat = SP_TAG4(sp);
sp->sector()->ceilingstat = ESectorFlags::FromInt(SP_TAG4(sp));
RESET(sp->sector()->ceilingstat, CSTAT_SECTOR_SKY);
}
else if (SP_TAG3(sp) == 1)
{
sp->sector()->floorpicnum = SP_TAG5(sp);
sp->sector()->floorstat = SP_TAG4(sp);
sp->sector()->floorstat = ESectorFlags::FromInt(SP_TAG4(sp));
RESET(sp->sector()->floorstat, CSTAT_SECTOR_SKY);
}
}

View file

@ -1382,7 +1382,7 @@ void UpdateWallPortalState()
sp->sector()->ceilingpicnum = SP_TAG2(sp);
SP_TAG4(sp) = sp->sector()->ceilingstat;
//SET(sp->sector()->ceilingstat, ((int)SP_TAG7(sp))<<7);
SET(sp->sector()->ceilingstat, SP_TAG6(sp));
SET(sp->sector()->ceilingstat, ESectorFlags::FromInt(SP_TAG6(sp)));
RESET(sp->sector()->ceilingstat, CSTAT_SECTOR_SKY);
}
else if (SP_TAG3(sp) == 1)
@ -1391,7 +1391,7 @@ void UpdateWallPortalState()
sp->sector()->floorpicnum = SP_TAG2(sp);
SP_TAG4(sp) = sp->sector()->floorstat;
//SET(sp->sector()->floorstat, ((int)SP_TAG7(sp))<<7);
SET(sp->sector()->floorstat, SP_TAG6(sp));
SET(sp->sector()->floorstat, ESectorFlags::FromInt(SP_TAG6(sp)));
RESET(sp->sector()->floorstat, CSTAT_SECTOR_SKY);
}
}
@ -1408,14 +1408,14 @@ void RestorePortalState()
{
// restore ceilingpicnum and ceilingstat
sp->sector()->ceilingpicnum = SP_TAG5(sp);
sp->sector()->ceilingstat = SP_TAG4(sp);
sp->sector()->ceilingstat = ESectorFlags::FromInt(SP_TAG4(sp));
//RESET(sp->sector()->ceilingstat, CEILING_STAT_TYPE_MASK);
RESET(sp->sector()->ceilingstat, CSTAT_SECTOR_SKY);
}
else if (SP_TAG3(sp) == 1)
{
sp->sector()->floorpicnum = SP_TAG5(sp);
sp->sector()->floorstat = SP_TAG4(sp);
sp->sector()->floorstat = ESectorFlags::FromInt(SP_TAG4(sp));
//RESET(sp->sector()->floorstat, FLOOR_STAT_TYPE_MASK);
RESET(sp->sector()->floorstat, CSTAT_SECTOR_SKY);
}

View file

@ -297,7 +297,7 @@ void JS_InitMirrors(void)
wal.picnum = MIRRORLABEL + mirrorcnt;
sec->ceilingpicnum = MIRRORLABEL + mirrorcnt;
sec->floorpicnum = MIRRORLABEL + mirrorcnt;
sec->floorstat |= 1;
sec->floorstat |= CSTAT_SECTOR_SKY;
mirror[mirrorcnt].mirrorWall = &wal;
mirror[mirrorcnt].mirrorSector = sec;
mirror[mirrorcnt].numspawnspots = 0;