From 2769abcf0f756930722388f6265f395b3d761d3f Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 11 Oct 2020 12:18:25 +0200 Subject: [PATCH] - Blood: Removed most #defines. only ThrowError and dassert left... The unused BitWriter class was also removed. --- source/blood/src/aiunicult.h | 19 ++--- source/blood/src/animatesprite.cpp | 8 +-- source/blood/src/asound.cpp | 2 +- source/blood/src/barf.cpp | 15 ++-- source/blood/src/common_game.h | 109 +++++++++-------------------- source/blood/src/db.h | 10 +-- source/blood/src/globals.cpp | 2 +- source/blood/src/globals.h | 2 +- source/blood/src/levels.h | 9 ++- source/blood/src/qav.cpp | 2 +- source/blood/src/seq.cpp | 7 +- source/blood/src/sound.cpp | 2 +- source/blood/src/view.cpp | 2 +- source/blood/src/weapon.cpp | 6 +- 14 files changed, 84 insertions(+), 111 deletions(-) diff --git a/source/blood/src/aiunicult.h b/source/blood/src/aiunicult.h index 221cb1862..7efe72aee 100644 --- a/source/blood/src/aiunicult.h +++ b/source/blood/src/aiunicult.h @@ -29,14 +29,17 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. BEGIN_BLD_NS #ifdef NOONE_EXTENSIONS -#define kGenDudeDefaultSeq 11520 -#define kGenDudeMaxSlaves 7 -#define kGenDudeTransformStatus -222 -#define kGenDudeUpdTimeRate 10 -#define kGenDudeMaxMeleeDist 2048 -#define kGenDudeMinDispesion 200 -#define kGenDudeMaxDispersion 3500 -#define kGenDudeKlabsAng 56 +enum +{ + kGenDudeDefaultSeq = 11520, + kGenDudeMaxSlaves = 7, + kGenDudeTransformStatus = -222, + kGenDudeUpdTimeRate = 10, + kGenDudeMaxMeleeDist = 2048, + kGenDudeMinDispesion = 200, + kGenDudeMaxDispersion = 3500, + kGenDudeKlabsAng = 56 +}; enum { kGenDudeSeqIdleL = 0, diff --git a/source/blood/src/animatesprite.cpp b/source/blood/src/animatesprite.cpp index cf5b65665..aeba8e6d9 100644 --- a/source/blood/src/animatesprite.cpp +++ b/source/blood/src/animatesprite.cpp @@ -135,7 +135,7 @@ static tspritetype *viewAddEffect(int nTSprite, VIEW_EFFECT nViewEffect) { dassert(nViewEffect >= 0 && nViewEffect < kViewEffectMax); auto pTSprite = &tsprite[nTSprite]; - if (gDetail < effectDetail[nViewEffect] || nTSprite >= kMaxViewSprites) return NULL; + if (gDetail < effectDetail[nViewEffect] || nTSprite >= maxspritesonscreen) return NULL; switch (nViewEffect) { case VIEW_EFFECT_18: @@ -229,7 +229,7 @@ static tspritetype *viewAddEffect(int nTSprite, VIEW_EFFECT nViewEffect) { nAng = (nAng+1024)&2047; } - for (int i = 0; i < 5 && spritesortcnt < kMaxViewSprites; i++) + for (int i = 0; i < 5 && spritesortcnt < maxspritesonscreen; i++) { int nSector = pTSprite->sectnum; auto pNSprite = viewInsertTSprite(nSector, 32767, NULL); @@ -444,7 +444,7 @@ void viewProcessSprites(int32_t cX, int32_t cY, int32_t cZ, int32_t cA, int32_t { // shift before interpolating to increase precision. int myclock = (gFrameClock<<3) + mulscale16(4<<3, smoothratio); - dassert(spritesortcnt <= kMaxViewSprites); + dassert(spritesortcnt <= maxspritesonscreen); gCameraAng = cA; int nViewSprites = spritesortcnt; for (int nTSprite = spritesortcnt-1; nTSprite >= 0; nTSprite--) @@ -648,7 +648,7 @@ void viewProcessSprites(int32_t cX, int32_t cY, int32_t cZ, int32_t cA, int32_t pTSprite->xrepeat = pTSprite->yrepeat = 0; } } - if (spritesortcnt >= kMaxViewSprites) continue; + if (spritesortcnt >= maxspritesonscreen) continue; if (pTXSprite && pTXSprite->burnTime > 0) { pTSprite->shade = ClipRange(pTSprite->shade-16-QRandom(8), -128, 127); diff --git a/source/blood/src/asound.cpp b/source/blood/src/asound.cpp index 18415020c..96b174f71 100644 --- a/source/blood/src/asound.cpp +++ b/source/blood/src/asound.cpp @@ -36,7 +36,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. BEGIN_BLD_NS -#define kMaxAmbChannel 64 +enum {kMaxAmbChannel = 64 }; struct AMB_CHANNEL { diff --git a/source/blood/src/barf.cpp b/source/blood/src/barf.cpp index 039514dea..83fedeb80 100644 --- a/source/blood/src/barf.cpp +++ b/source/blood/src/barf.cpp @@ -33,12 +33,15 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. BEGIN_BLD_NS // I don't think we still need these. -#define DICT_LOAD 0 -#define DICT_LOCK 0 - -#define kMaxCmdLineDefines 5 -#define kMaxDefines 1000 -#define kMaxParseLevels 5 +enum +{ + DICT_LOAD = 0, + DICT_LOCK = 0, + + kMaxCmdLineDefines = 5, + kMaxDefines = 1000, + kMaxParseLevels = 5 +}; static int nCmdDefines = 0; static int nDefines = 0; diff --git a/source/blood/src/common_game.h b/source/blood/src/common_game.h index c5cec7676..ced4cb1b7 100644 --- a/source/blood/src/common_game.h +++ b/source/blood/src/common_game.h @@ -38,23 +38,15 @@ BEGIN_BLD_NS void _SetErrorLoc(const char *pzFile, int nLine); void __dassert(const char *pzExpr, const char *pzFile, int nLine); void QuitGame(void); -void _consoleSysMsg(const char* pMessage, ...); +void consoleSysMsg(const char* pMessage, ...); #define ThrowError(...) \ { \ I_Error(__VA_ARGS__); \ } -// print error to console only -#define consoleSysMsg(...) \ - { \ - _consoleSysMsg(__VA_ARGS__); \ - } - #define dassert(x) assert(x) -#define kMaxViewSprites maxspritesonscreen - enum { kMaxSectors = MAXSECTORS, @@ -426,38 +418,40 @@ kAiStateRecoil = 5, kAiStateAttack = 6, }; -// sprite attributes -#define kHitagAutoAim 0x0008 -#define kHitagRespawn 0x0010 -#define kHitagFree 0x0020 -#define kHitagSmoke 0x0100 +enum +{ + // sprite attributes + kHitagAutoAim = 0x0008, + kHitagRespawn = 0x0010, + kHitagFree = 0x0020, + kHitagSmoke = 0x0100, -// sprite physics attributes -#define kPhysMove 0x0001 // affected by movement physics -#define kPhysGravity 0x0002 // affected by gravity -#define kPhysFalling 0x0004 // currently in z-motion + // sprite physics attributes + kPhysMove = 0x0001, // affected by movement physics + kPhysGravity = 0x0002, // affected by gravity + kPhysFalling = 0x0004, // currently in z-motion -// sector cstat -#define kSecCParallax 0x01 -#define kSecCSloped 0x02 -#define kSecCSwapXY 0x04 -#define kSecCExpand 0x08 -#define kSecCFlipX 0x10 -#define kSecCFlipY 0x20 -#define kSecCFlipMask 0x34 -#define kSecCRelAlign 0x40 -#define kSecCFloorShade 0x8000 - -#define kAng5 28 -#define kAng15 85 -#define kAng30 170 -#define kAng45 256 -#define kAng60 341 -#define kAng90 512 -#define kAng120 682 -#define kAng180 1024 -#define kAng360 2048 + // sector cstat + kSecCParallax = 0x01, + kSecCSloped = 0x02, + kSecCSwapXY = 0x04, + kSecCExpand = 0x08, + kSecCFlipX = 0x10, + kSecCFlipY = 0x20, + kSecCFlipMask = 0x34, + kSecCRelAlign = 0x40, + kSecCFloorShade = 0x8000, + kAng5 = 28, + kAng15 = 85, + kAng30 = 170, + kAng45 = 256, + kAng60 = 341, + kAng90 = 512, + kAng120 = 682, + kAng180 = 1024, + kAng360 = 2048, +}; // ------------------------------- @@ -747,7 +741,7 @@ public: int readBit() { if (nSize <= 0) - ThrowError("Buffer overflow"); + ThrowError("Buffer overflow in BitReader"); int bit = ((*pBuffer)>>nBitPos)&1; if (++nBitPos >= 8) { @@ -764,7 +758,7 @@ public: nSize -= nBitPos>>3; nBitPos &= 7; if ((nSize == 0 && nBitPos > 0) || nSize < 0) - ThrowError("Buffer overflow"); + ThrowError("Buffer overflow in BitReader"); } unsigned int readUnsigned(int nBits) { @@ -784,40 +778,5 @@ public: } }; -class BitWriter { -public: - int nBitPos; - int nSize; - char *pBuffer; - BitWriter(char *_pBuffer, int _nSize, int _nBitPos) { pBuffer = _pBuffer; nSize = _nSize; nBitPos = _nBitPos; memset(pBuffer, 0, nSize); nSize -= nBitPos>>3; } - BitWriter(char *_pBuffer, int _nSize) { pBuffer = _pBuffer; nSize = _nSize; nBitPos = 0; memset(pBuffer, 0, nSize); } - void writeBit(int bit) - { - if (nSize <= 0) - ThrowError("Buffer overflow"); - *pBuffer |= bit<= 8) - { - nBitPos = 0; - pBuffer++; - nSize--; - } - } - void skipBits(int nBits) - { - nBitPos += nBits; - pBuffer += nBitPos>>3; - nSize -= nBitPos>>3; - nBitPos &= 7; - if ((nSize == 0 && nBitPos > 0) || nSize < 0) - ThrowError("Buffer overflow"); - } - void write(int nValue, int nBits) - { - dassert(nBits <= 32); - for (int i = 0; i < nBits; i++) - writeBit((nValue>>i)&1); - } -}; END_BLD_NS diff --git a/source/blood/src/db.h b/source/blood/src/db.h index 6eb589183..5be2517ce 100644 --- a/source/blood/src/db.h +++ b/source/blood/src/db.h @@ -24,10 +24,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. BEGIN_BLD_NS -#define kMaxXSprites 16384 -#define kMaxXWalls 512 -#define kMaxXSectors 512 - +enum +{ + kMaxXSprites = 16384, + kMaxXWalls = 512, + kMaxXSectors = 512 +}; // by NoOne: functions to quckly check range of specifical arrays diff --git a/source/blood/src/globals.cpp b/source/blood/src/globals.cpp index 7f52a50ed..c70339b07 100644 --- a/source/blood/src/globals.cpp +++ b/source/blood/src/globals.cpp @@ -56,7 +56,7 @@ void _SetErrorLoc(const char *pzFile, int nLine) } // by NoOne: show warning msgs in game instead of throwing errors (in some cases) -void _consoleSysMsg(const char* pzFormat, ...) { +void consoleSysMsg(const char* pzFormat, ...) { va_list args; va_start(args, pzFormat); diff --git a/source/blood/src/globals.h b/source/blood/src/globals.h index c69935c1b..85ff68d0f 100644 --- a/source/blood/src/globals.h +++ b/source/blood/src/globals.h @@ -33,7 +33,7 @@ BEGIN_BLD_NS extern int gFrameClock; extern int gFrameCount; -#define MAXPLAYERNAME 16 +enum { MAXPLAYERNAME = 16 }; extern int32_t gDetail; extern bool gNoClip; diff --git a/source/blood/src/levels.h b/source/blood/src/levels.h index 03c242b79..1f069c84b 100644 --- a/source/blood/src/levels.h +++ b/source/blood/src/levels.h @@ -29,9 +29,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. BEGIN_BLD_NS -#define kMaxMessages 32 -#define kMaxEpisodes 7 -#define kMaxLevels 16 +enum +{ + kMaxMessages = 32, + kMaxEpisodes = 7, + kMaxLevels = 16 +}; #pragma pack(push, 1) diff --git a/source/blood/src/qav.cpp b/source/blood/src/qav.cpp index 0ab613c49..3227c2e9b 100644 --- a/source/blood/src/qav.cpp +++ b/source/blood/src/qav.cpp @@ -33,7 +33,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. BEGIN_BLD_NS -#define kMaxQavClients 64 +enum { kMaxQavClients = 64 }; static void (*qavClientCallback[kMaxQavClients])(int, void *); static int nQavClients; diff --git a/source/blood/src/seq.cpp b/source/blood/src/seq.cpp index eb7906454..a48e442d5 100644 --- a/source/blood/src/seq.cpp +++ b/source/blood/src/seq.cpp @@ -41,8 +41,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. BEGIN_BLD_NS -#define kMaxSeqClients 256 -#define kMaxSequences 1024 +enum +{ + kMaxSeqClients = 256, + kMaxSequences = 1024 +}; static ACTIVE activeList[kMaxSequences]; static int seqActiveCount = 0; diff --git a/source/blood/src/sound.cpp b/source/blood/src/sound.cpp index 784930880..37c6c705d 100644 --- a/source/blood/src/sound.cpp +++ b/source/blood/src/sound.cpp @@ -48,7 +48,7 @@ int soundRates[13] = { 44100, 44100, }; -#define kChannelMax 32 +enum { kChannelMax = 32 }; void ByteSwapSFX(SFX* pSFX) diff --git a/source/blood/src/view.cpp b/source/blood/src/view.cpp index a53974824..efc2ad461 100644 --- a/source/blood/src/view.cpp +++ b/source/blood/src/view.cpp @@ -69,7 +69,7 @@ char gInterpolateSprite[(kMaxSprites+7)>>3]; char gInterpolateWall[(kMaxWalls+7)>>3]; char gInterpolateSector[(kMaxSectors+7)>>3]; -#define kMaxInterpolations 16384 +enum { kMaxInterpolations = 16384 }; INTERPOLATE gInterpolation[kMaxInterpolations]; diff --git a/source/blood/src/weapon.cpp b/source/blood/src/weapon.cpp index 935728370..6edbabc54 100644 --- a/source/blood/src/weapon.cpp +++ b/source/blood/src/weapon.cpp @@ -48,7 +48,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. BEGIN_BLD_NS -#define kQAVEnd 125 +enum { kQAVEnd = 125 }; void FirePitchfork(int, PLAYER *pPlayer); void FireSpray(int, PLAYER *pPlayer); @@ -1109,7 +1109,7 @@ void FireRemote(int, PLAYER *pPlayer) evSend(0, 0, 90+(pPlayer->pSprite->type-kDudePlayer1), kCmdOn); } -#define kMaxShotgunBarrels 4 +enum { kMaxShotgunBarrels = 4 }; void FireShotgun(int nTrigger, PLAYER *pPlayer) { @@ -1193,7 +1193,7 @@ void FireTommy(int nTrigger, PLAYER *pPlayer) pPlayer->flashEffect = 1; } -#define kMaxSpread 14 +enum { kMaxSpread = 14 }; void FireSpread(int nTrigger, PLAYER *pPlayer) {