From 8f012d1beb8c98de0587d15d2b0117eb6f2ebb59 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 18 Dec 2021 15:36:50 +0100 Subject: [PATCH] - made wall flags type safe --- source/build/src/clip.cpp | 10 +++++----- source/core/maphack.cpp | 4 ++-- source/core/maploader.cpp | 6 +++--- source/core/maptypes.h | 5 ++++- source/games/blood/src/actor.cpp | 5 ++--- source/games/blood/src/db.cpp | 4 ++-- source/games/blood/src/nnexts.cpp | 2 +- source/games/duke/src/gameexec.cpp | 2 +- 8 files changed, 20 insertions(+), 18 deletions(-) diff --git a/source/build/src/clip.cpp b/source/build/src/clip.cpp index bc6255cf6..837ece2eb 100644 --- a/source/build/src/clip.cpp +++ b/source/build/src/clip.cpp @@ -451,7 +451,7 @@ CollisionBase clipmove_(vec3_t * const pos, int * const sectnum, int32_t xvect, int const initialsectnum = *sectnum; - int32_t const dawalclipmask = (cliptype & 65535); // CLIPMASK0 = 0x00010001 + int32_t const dawalclipmask = (cliptype & 65535); // CLIPMASK0 = 0x00010001 (in desperate need of getting fixed!) int32_t const dasprclipmask = (cliptype >> 16); // CLIPMASK1 = 0x01000040 vec2_t const move = { xvect, yvect }; @@ -514,7 +514,7 @@ CollisionBase clipmove_(vec3_t * const pos, int * const sectnum, int32_t xvect, int clipyou = 0; - if (wal->nextsector < 0 || (wal->cstat&dawalclipmask)) + if (wal->nextsector < 0 || (wal->cstat & EWallFlags::FromInt(dawalclipmask))) { clipyou = 1; } @@ -879,7 +879,7 @@ int pushmove_(vec3_t *const vect, int *const sectnum, if (clipinsidebox(&vect->vec2, i, walldist-4) == 1) { int j = 0; - if (wal->nextsector < 0 || wal->cstat&dawalclipmask) j = 1; + if (wal->nextsector < 0 || wal->cstat & EWallFlags::FromInt(dawalclipmask)) j = 1; else { int32_t daz2; @@ -1005,7 +1005,7 @@ void getzrange(const vec3_t& pos, sectortype* sect, int32_t* ceilz, CollisionBas if (da.x >= da.y) continue; - if (wal.cstat&dawalclipmask) continue; // XXX? + if (wal.cstat & EWallFlags::FromInt(dawalclipmask)) continue; // XXX? if (((nextsect->ceilingstat & CSTAT_SECTOR_SKY) == 0) && (pos.z <= nextsect->ceilingz+(3<<8))) continue; if (((nextsect->floorstat & CSTAT_SECTOR_SKY) == 0) && (pos.z >= nextsect->floorz-(3<<8))) continue; @@ -1297,7 +1297,7 @@ int hitscan(const vec3_t& start, const sectortype* startsect, const vec3_t& dire if (!curspr) { - if ((!wal->twoSided()) || (wal->cstat&dawalclipmask)) + if ((!wal->twoSided()) || (wal->cstat & EWallFlags::FromInt(dawalclipmask))) { hit_set(&hitinfo, sec, wal, nullptr, intx, inty, intz); continue; diff --git a/source/core/maphack.cpp b/source/core/maphack.cpp index 0d4a8d331..98313cd7c 100644 --- a/source/core/maphack.cpp +++ b/source/core/maphack.cpp @@ -221,7 +221,7 @@ static int32_t LoadMapHack(const char *filename, SpawnSpriteDef& sprites) { if (currentwall != -1 && validateWall()) { - wall[currentwall].cstat &= ~sc.Number; + wall[currentwall].cstat &= EWallFlags::FromInt(~sc.Number); } else if (currentsprite != -1 && validateSprite()) { @@ -235,7 +235,7 @@ static int32_t LoadMapHack(const char *filename, SpawnSpriteDef& sprites) { if (currentwall != -1 && validateWall()) { - wall[currentwall].cstat |= sc.Number; + wall[currentwall].cstat |= EWallFlags::FromInt(sc.Number); } else if (currentsprite != -1 && validateSprite()) { diff --git a/source/core/maploader.cpp b/source/core/maploader.cpp index 4756cfb7d..2a15ca94d 100644 --- a/source/core/maploader.cpp +++ b/source/core/maploader.cpp @@ -184,7 +184,7 @@ static void ReadWallV7(FileReader& fr, walltype& wall) wall.point2 = fr.ReadInt16(); wall.nextwall = fr.ReadInt16(); wall.nextsector = fr.ReadInt16(); - wall.cstat = fr.ReadUInt16(); + wall.cstat = EWallFlags::FromInt(fr.ReadUInt16()); wall.picnum = fr.ReadInt16(); wall.overpicnum = fr.ReadInt16(); wall.shade = fr.ReadInt8(); @@ -209,7 +209,7 @@ static void ReadWallV6(FileReader& fr, walltype& wall) wall.overpicnum = fr.ReadInt16(); wall.shade = fr.ReadInt8(); wall.pal = fr.ReadUInt8(); - wall.cstat = fr.ReadUInt16(); + wall.cstat = EWallFlags::FromInt(fr.ReadUInt16()); wall.xrepeat = fr.ReadUInt8(); wall.yrepeat = fr.ReadUInt8(); wall.xpan_ = fr.ReadUInt8(); @@ -227,7 +227,7 @@ static void ReadWallV5(FileReader& fr, walltype& wall) wall.picnum = fr.ReadInt16(); wall.overpicnum = fr.ReadInt16(); wall.shade = fr.ReadInt8(); - wall.cstat = fr.ReadUInt16(); + wall.cstat = EWallFlags::FromInt(fr.ReadUInt16()); wall.xrepeat = fr.ReadUInt8(); wall.yrepeat = fr.ReadUInt8(); wall.xpan_ = fr.ReadUInt8(); diff --git a/source/core/maptypes.h b/source/core/maptypes.h index 6da3b0892..bc53bc4a4 100644 --- a/source/core/maptypes.h +++ b/source/core/maptypes.h @@ -116,6 +116,9 @@ enum EWallBits // names are from Shadow Warrior }; +typedef TFlags EWallFlags; +DEFINE_TFLAGS_OPERATORS(EWallFlags) + enum ESpriteBits // names mostly from SW. { CSTAT_SPRITE_BLOCK = 1, // bit 0: 1 = Blocking sprite (use with clipmove, getzrange) "B" @@ -312,7 +315,7 @@ struct walltype float xpan_; float ypan_; - uint16_t cstat; + EWallFlags cstat; int16_t picnum; int16_t overpicnum; union { int16_t lotag, type; }; // type is for Blood diff --git a/source/games/blood/src/actor.cpp b/source/games/blood/src/actor.cpp index a9b6a4467..e280f23df 100644 --- a/source/games/blood/src/actor.cpp +++ b/source/games/blood/src/actor.cpp @@ -5384,7 +5384,7 @@ int MoveMissile(DBloodActor* actor) if (pXWall->triggerVector) { trTriggerWall(pWall, kCmdWallImpact); - if (!(pWall->cstat & 64)) + if (!(pWall->cstat & CSTAT_WALL_BLOCK_HITSCAN)) { cliptype = -1; if (i-- > 0) @@ -6814,8 +6814,7 @@ bool actCheckRespawn(DBloodActor* actor) bool actCanSplatWall(walltype* pWall) { - if (pWall->cstat & 16384) return 0; - if (pWall->cstat & 32768) return 0; + if (pWall->cstat & (CSTAT_WALL_MOVE_MASK)) return 0; int nType = pWall->type; if (nType >= kWallBase && nType < kWallMax) return 0; diff --git a/source/games/blood/src/db.cpp b/source/games/blood/src/db.cpp index e2266c022..d3b47edbf 100644 --- a/source/games/blood/src/db.cpp +++ b/source/games/blood/src/db.cpp @@ -445,8 +445,8 @@ void dbLoadMap(const char* pPath, int* pX, int* pY, int* pZ, short* pAngle, sect pWall->point2 = LittleShort(load.point2); pWall->nextwall = LittleShort(load.nextwall); pWall->nextsector = LittleShort(load.nextsector); - pWall->cstat = LittleShort(load.cstat); - pWall->picnum = LittleShort(load.picnum); + pWall->cstat = EWallFlags::FromInt(LittleShort(load.cstat)); + pWall->picnum = EWallFlags::FromInt(LittleShort(load.picnum)); pWall->overpicnum = LittleShort(load.overpicnum); pWall->type = LittleShort(load.type); pWall->hitag = LittleShort(load.hitag); diff --git a/source/games/blood/src/nnexts.cpp b/source/games/blood/src/nnexts.cpp index 94be5b570..621c07c7b 100644 --- a/source/games/blood/src/nnexts.cpp +++ b/source/games/blood/src/nnexts.cpp @@ -3782,7 +3782,7 @@ bool condCheckMixed(DBloodActor* aCond, const EVENT& event, int cmpOp, bool PUSH case 25: return condCmp(pObj->picnum, arg1, arg2, cmpOp); case 26: return condCmp(pObj->pal, arg1, arg2, cmpOp); case 27: return condCmp(pObj->shade, arg1, arg2, cmpOp); - case 28: return (pObj->cstat & arg1); + case 28: return (pObj->cstat & EWallFlags::FromInt(arg1)); case 29: return (pObj->hitag & arg1); case 30: return condCmp(pObj->xrepeat, arg1, arg2, cmpOp); case 31: return condCmp(pObj->xpan(), arg1, arg2, cmpOp); diff --git a/source/games/duke/src/gameexec.cpp b/source/games/duke/src/gameexec.cpp index cbc5dadbd..b112c7b2b 100644 --- a/source/games/duke/src/gameexec.cpp +++ b/source/games/duke/src/gameexec.cpp @@ -979,7 +979,7 @@ void DoWall(bool bSet, int lVar1, int lLabelID, int lVar2, DDukeActor* sActor, i if (!bSet) SetGameVarID(lVar2, wallp->nextsector, sActor, sPlayer); break; case WALL_CSTAT: - if (bSet) wallp->cstat = lValue; + if (bSet) wallp->cstat = EWallFlags::FromInt(lValue); else SetGameVarID(lVar2, wallp->cstat, sActor, sPlayer); break; case WALL_PICNUM: