From c25641c631664318678c7bdd74f6122ea3eda33f Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 29 Dec 2021 20:33:09 +0100 Subject: [PATCH] - db.cpp cleanup. There were too many pointless global variables here and quite a bit of code doing nothing useful. --- source/games/blood/src/db.cpp | 88 +++++++++++++++-------------- source/games/blood/src/db.h | 5 +- source/games/blood/src/fx.cpp | 11 +--- source/games/blood/src/loadsave.cpp | 1 - 4 files changed, 49 insertions(+), 56 deletions(-) diff --git a/source/games/blood/src/db.cpp b/source/games/blood/src/db.cpp index dee84f8ca..c734cb56e 100644 --- a/source/games/blood/src/db.cpp +++ b/source/games/blood/src/db.cpp @@ -38,6 +38,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. BEGIN_BLD_NS +int gSkyCount; +//--------------------------------------------------------------------------- +// +// +// +//--------------------------------------------------------------------------- + DBloodActor* InsertSprite(sectortype* pSector, int nStat) { auto act = static_cast(::InsertActor(RUNTIME_CLASS(DBloodActor), pSector, nStat)); @@ -59,10 +66,14 @@ int DeleteSprite(DBloodActor* actor) bool gModernMap = false; -unsigned int gStatCount[kMaxStatus + 1]; - int gVisibility; +//--------------------------------------------------------------------------- +// +// +// +//--------------------------------------------------------------------------- + void dbCrypt(char *pPtr, int nLength, int nKey) { for (int i = 0; i < nLength; i++) @@ -72,14 +83,15 @@ void dbCrypt(char *pPtr, int nLength, int nKey) } } -bool drawtile2048, encrypted; -MAPHEADER2 byte_19AE44; +//--------------------------------------------------------------------------- +// +// +// +//--------------------------------------------------------------------------- unsigned int dbReadMapCRC(const char *pPath) { - encrypted = 0; - FString mapname = pPath; DefaultExtension(mapname, ".map"); auto fr = fileSystem.OpenFileReader(mapname); @@ -102,7 +114,6 @@ unsigned int dbReadMapCRC(const char *pPath) } else if ((ver & 0xff00) == 0x700) { - encrypted = 1; } else { @@ -112,15 +123,21 @@ unsigned int dbReadMapCRC(const char *pPath) return fr.ReadInt32(); } -int gMapRev, gMattId, gSkyCount; -//char byte_19AE44[128]; -const int nXSectorSize = 60; -const int nXSpriteSize = 56; -const int nXWallSize = 24; - +//--------------------------------------------------------------------------- +// +// +// +//--------------------------------------------------------------------------- void dbLoadMap(const char* pPath, int* pX, int* pY, int* pZ, short* pAngle, sectortype** ppSector, unsigned int* pCRC, BloodSpawnSpriteDef& sprites) { + const int nXSectorSize = 60; + const int nXSpriteSize = 56; + const int nXWallSize = 24; + + MAPHEADER2 xheader; + int gMapRev, gMattId; + int16_t tpskyoff[256]; ClearAutomap(); #ifdef NOONE_EXTENSIONS @@ -146,7 +163,7 @@ void dbLoadMap(const char* pPath, int* pX, int* pY, int* pZ, short* pAngle, sect { I_Error("%s: Map file corrupted", mapname.GetChars()); } - encrypted = 0; + bool encrypted = 0; if ((LittleShort(header.version) & 0xff00) == 0x700) { encrypted = 1; @@ -189,15 +206,7 @@ void dbLoadMap(const char* pPath, int* pX, int* pY, int* pZ, short* pAngle, sect gMattId = mapHeader.mattid; if (encrypted) { - if (mapHeader.mattid == 0x7474614d || mapHeader.mattid == 0x4d617474) - { - drawtile2048 = 1; - } - else if (!mapHeader.mattid) - { - drawtile2048 = 0; - } - else + if (!(mapHeader.mattid == 0x7474614d || mapHeader.mattid == 0x4d617474 || !mapHeader.mattid)) { I_Error("%s: Corrupted Map file", mapname.GetChars()); } @@ -216,16 +225,16 @@ void dbLoadMap(const char* pPath, int* pX, int* pY, int* pZ, short* pAngle, sect if (encrypted) { - fr.Read(&byte_19AE44, 128); - dbCrypt((char*)&byte_19AE44, 128, wall.Size()); + fr.Read(&xheader, 128); + dbCrypt((char*)&xheader, 128, wall.Size()); - byte_19AE44.numxsprites = LittleLong(byte_19AE44.numxsprites); - byte_19AE44.numxwalls = LittleLong(byte_19AE44.numxwalls); - byte_19AE44.numxsectors = LittleLong(byte_19AE44.numxsectors); + xheader.numxsprites = LittleLong(xheader.numxsprites); + xheader.numxwalls = LittleLong(xheader.numxwalls); + xheader.numxsectors = LittleLong(xheader.numxsectors); } else { - memset(&byte_19AE44, 0, 128); + memset(&xheader, 0, 128); } gSkyCount = 1 << mapHeader.pskybits; fr.Read(tpskyoff, gSkyCount * sizeof(tpskyoff[0])); @@ -290,7 +299,7 @@ void dbLoadMap(const char* pPath, int* pX, int* pY, int* pZ, short* pAngle, sect } else { - nCount = byte_19AE44.numxsectors; + nCount = xheader.numxsectors; } assert(nCount <= nXSectorSize); fr.Read(pBuffer, nCount); @@ -415,7 +424,7 @@ void dbLoadMap(const char* pPath, int* pX, int* pY, int* pZ, short* pAngle, sect } else { - nCount = byte_19AE44.numxwalls; + nCount = xheader.numxwalls; } assert(nCount <= nXWallSize); fr.Read(pBuffer, nCount); @@ -507,7 +516,7 @@ void dbLoadMap(const char* pPath, int* pX, int* pY, int* pZ, short* pAngle, sect } else { - nCount = byte_19AE44.numxsprites; + nCount = xheader.numxsprites; } assert(nCount <= nXSpriteSize); fr.Read(pBuffer, nCount); @@ -604,15 +613,7 @@ void dbLoadMap(const char* pPath, int* pX, int* pY, int* pZ, short* pAngle, sect *pCRC = nCRC; if (encrypted) { - if (gMattId == 0x7474614d || gMattId == 0x4d617474) - { - drawtile2048 = 1; - } - else if (!gMattId) - { - drawtile2048 = 0; - } - else + if (!(gMattId == 0x7474614d || gMattId == 0x4d617474 || !gMattId)) { I_Error("%s: Corrupted Map file", mapname.GetChars()); } @@ -677,7 +678,12 @@ void dbLoadMap(const char* pPath, int* pX, int* pY, int* pZ, short* pAngle, sect END_BLD_NS +//--------------------------------------------------------------------------- +// // only used by the backup loader. +// +//--------------------------------------------------------------------------- + void qloadboard(const char* filename, char flags, vec3_t* dapos, int16_t* daang) { Blood::BloodSpawnSpriteDef sprites; diff --git a/source/games/blood/src/db.h b/source/games/blood/src/db.h index ebad32250..6db212857 100644 --- a/source/games/blood/src/db.h +++ b/source/games/blood/src/db.h @@ -74,14 +74,11 @@ struct MAPHEADER2 { #pragma pack(pop) -extern bool drawtile2048, encrypted; -extern MAPHEADER2 byte_19AE44; - extern int gVisibility; -extern int gMapRev, gMattId, gSkyCount; extern const char *gItemText[]; extern const char *gAmmoText[]; extern const char *gWeaponText[]; +extern int gSkyCount; void GetSpriteExtents(spritetypebase const * const pSprite, int *top, int *bottom) { diff --git a/source/games/blood/src/fx.cpp b/source/games/blood/src/fx.cpp index 776b4c0bf..c17ca4d60 100644 --- a/source/games/blood/src/fx.cpp +++ b/source/games/blood/src/fx.cpp @@ -150,16 +150,7 @@ DBloodActor* CFX::fxSpawnActor(FX_ID nFx, sectortype* pSector, int x, int y, int if (nFx < 0 || nFx >= kFXMax) return nullptr; FXDATA *pFX = &gFXData[nFx]; - if (gStatCount[1] == 512) - { - BloodStatIterator it(kStatFX); - auto iactor = it.Next(); - while (iactor && (iactor->spr.flags & 32)) - iactor = it.Next(); - if (!iactor) - return nullptr; - destroy(iactor); - } + auto actor = actSpawnSprite(pSector, x, y, z, 1, 0); actor->spr.type = nFx; diff --git a/source/games/blood/src/loadsave.cpp b/source/games/blood/src/loadsave.cpp index 86882685b..c456b89bc 100644 --- a/source/games/blood/src/loadsave.cpp +++ b/source/games/blood/src/loadsave.cpp @@ -661,7 +661,6 @@ void SerializeState(FSerializer& arc) ("frameclock", PlayClock) ("framecount", gFrameCount) ("hitinfo", gHitInfo) - .Array("statcount", gStatCount, kMaxStatus + 1) ("fogmode", gFogMode) #ifdef NOONE_EXTENSIONS ("modern", gModernMap)