From 53481fb9a300aa7ac56330a2fd8379db5f6dbb8c Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 13 Oct 2020 20:36:57 +0200 Subject: [PATCH] - Blood: simplified management of XSectors and XWalls. This does not need a free list - they get statically allocated per level, so a simple counter is enough. --- source/blood/src/db.cpp | 21 +++++++++------------ source/blood/src/db.h | 3 +-- source/blood/src/loadsave.cpp | 8 ++++---- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/source/blood/src/db.cpp b/source/blood/src/db.cpp index 4ca95c4f7..786a09aea 100644 --- a/source/blood/src/db.cpp +++ b/source/blood/src/db.cpp @@ -50,6 +50,10 @@ SPRITEHIT gSpriteHit[kMaxXSprites]; int xvel[kMaxSprites], yvel[kMaxSprites], zvel[kMaxSprites]; +unsigned short nextXSprite[kMaxXSprites]; +int XWallsUsed, XSectorsUsed; + + char qsector_filler[kMaxSectors]; @@ -257,10 +261,6 @@ int qchangespritestat(short nSprite, short nStatus) return ChangeSpriteStat(nSprite, nStatus); } -unsigned short nextXSprite[kMaxXSprites]; -unsigned short nextXWall[kMaxXWalls]; -unsigned short nextXSector[kMaxXSectors]; - void InitFreeList(unsigned short *pList, int nCount) { for (int i = 1; i < nCount; i++) @@ -302,9 +302,8 @@ void dbDeleteXSprite(int nXSprite) unsigned short dbInsertXWall(int nWall) { - int nXWall = nextXWall[0]; - nextXWall[0] = nextXWall[nXWall]; - if (nXWall == 0) + int nXWall = XWallsUsed++; + if (nXWall >= kMaxXWalls) { I_Error("Out of free XWalls"); } @@ -316,9 +315,8 @@ unsigned short dbInsertXWall(int nWall) unsigned short dbInsertXSector(int nSector) { - int nXSector = nextXSector[0]; - nextXSector[0] = nextXSector[nXSector]; - if (nXSector == 0) + int nXSector = XSectorsUsed++; + if (nXSector >= kMaxXSectors) { I_Error("Out of free XSectors"); } @@ -335,12 +333,11 @@ void dbInit(void) { xsprite[i].reference = -1; } - InitFreeList(nextXWall, kMaxXWalls); + XWallsUsed = XSectorsUsed = 0; for (int i = 1; i < kMaxXWalls; i++) { xwall[i].reference = -1; } - InitFreeList(nextXSector, kMaxXSectors); for (int i = 1; i < kMaxXSectors; i++) { xsector[i].reference = -1; diff --git a/source/blood/src/db.h b/source/blood/src/db.h index b780afdd0..6c8ec4c68 100644 --- a/source/blood/src/db.h +++ b/source/blood/src/db.h @@ -306,8 +306,7 @@ extern const char *gAmmoText[]; extern const char *gWeaponText[]; extern unsigned short nextXSprite[kMaxXSprites]; -extern unsigned short nextXWall[kMaxXWalls]; -extern unsigned short nextXSector[kMaxXSectors]; +extern int XWallsUsed, XSectorsUsed; static inline int GetWallType(int nWall) { diff --git a/source/blood/src/loadsave.cpp b/source/blood/src/loadsave.cpp index dba177efb..e0708dba7 100644 --- a/source/blood/src/loadsave.cpp +++ b/source/blood/src/loadsave.cpp @@ -602,8 +602,8 @@ void MyLoadSave::Load(void) Read(&byte_19AE44, sizeof(byte_19AE44)); Read(gStatCount, sizeof(gStatCount)); Read(nextXSprite, sizeof(nextXSprite)); - Read(nextXWall, sizeof(nextXWall)); - Read(nextXSector, sizeof(nextXSector)); + Read(&XWallsUsed, sizeof(XWallsUsed)); + Read(&XSectorsUsed, sizeof(XSectorsUsed)); memset(xsprite, 0, sizeof(xsprite)); for (int nSprite = 0; nSprite < kMaxSprites; nSprite++) { @@ -687,8 +687,8 @@ void MyLoadSave::Save(void) Write(&byte_19AE44, sizeof(byte_19AE44)); Write(gStatCount, sizeof(gStatCount)); Write(nextXSprite, sizeof(nextXSprite)); - Write(nextXWall, sizeof(nextXWall)); - Write(nextXSector, sizeof(nextXSector)); + Write(&XWallsUsed, sizeof(XWallsUsed)); + Write(&XSectorsUsed, sizeof(XSectorsUsed)); for (int nSprite = 0; nSprite < kMaxSprites; nSprite++) { if (sprite[nSprite].statnum < kMaxStatus)