- 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.
This commit is contained in:
Christoph Oelckers 2020-10-13 20:36:57 +02:00
parent 2b1284e8fa
commit 53481fb9a3
3 changed files with 14 additions and 18 deletions

View file

@ -50,6 +50,10 @@ SPRITEHIT gSpriteHit[kMaxXSprites];
int xvel[kMaxSprites], yvel[kMaxSprites], zvel[kMaxSprites]; int xvel[kMaxSprites], yvel[kMaxSprites], zvel[kMaxSprites];
unsigned short nextXSprite[kMaxXSprites];
int XWallsUsed, XSectorsUsed;
char qsector_filler[kMaxSectors]; char qsector_filler[kMaxSectors];
@ -257,10 +261,6 @@ int qchangespritestat(short nSprite, short nStatus)
return ChangeSpriteStat(nSprite, nStatus); return ChangeSpriteStat(nSprite, nStatus);
} }
unsigned short nextXSprite[kMaxXSprites];
unsigned short nextXWall[kMaxXWalls];
unsigned short nextXSector[kMaxXSectors];
void InitFreeList(unsigned short *pList, int nCount) void InitFreeList(unsigned short *pList, int nCount)
{ {
for (int i = 1; i < nCount; i++) for (int i = 1; i < nCount; i++)
@ -302,9 +302,8 @@ void dbDeleteXSprite(int nXSprite)
unsigned short dbInsertXWall(int nWall) unsigned short dbInsertXWall(int nWall)
{ {
int nXWall = nextXWall[0]; int nXWall = XWallsUsed++;
nextXWall[0] = nextXWall[nXWall]; if (nXWall >= kMaxXWalls)
if (nXWall == 0)
{ {
I_Error("Out of free XWalls"); I_Error("Out of free XWalls");
} }
@ -316,9 +315,8 @@ unsigned short dbInsertXWall(int nWall)
unsigned short dbInsertXSector(int nSector) unsigned short dbInsertXSector(int nSector)
{ {
int nXSector = nextXSector[0]; int nXSector = XSectorsUsed++;
nextXSector[0] = nextXSector[nXSector]; if (nXSector >= kMaxXSectors)
if (nXSector == 0)
{ {
I_Error("Out of free XSectors"); I_Error("Out of free XSectors");
} }
@ -335,12 +333,11 @@ void dbInit(void)
{ {
xsprite[i].reference = -1; xsprite[i].reference = -1;
} }
InitFreeList(nextXWall, kMaxXWalls); XWallsUsed = XSectorsUsed = 0;
for (int i = 1; i < kMaxXWalls; i++) for (int i = 1; i < kMaxXWalls; i++)
{ {
xwall[i].reference = -1; xwall[i].reference = -1;
} }
InitFreeList(nextXSector, kMaxXSectors);
for (int i = 1; i < kMaxXSectors; i++) for (int i = 1; i < kMaxXSectors; i++)
{ {
xsector[i].reference = -1; xsector[i].reference = -1;

View file

@ -306,8 +306,7 @@ extern const char *gAmmoText[];
extern const char *gWeaponText[]; extern const char *gWeaponText[];
extern unsigned short nextXSprite[kMaxXSprites]; extern unsigned short nextXSprite[kMaxXSprites];
extern unsigned short nextXWall[kMaxXWalls]; extern int XWallsUsed, XSectorsUsed;
extern unsigned short nextXSector[kMaxXSectors];
static inline int GetWallType(int nWall) static inline int GetWallType(int nWall)
{ {

View file

@ -602,8 +602,8 @@ void MyLoadSave::Load(void)
Read(&byte_19AE44, sizeof(byte_19AE44)); Read(&byte_19AE44, sizeof(byte_19AE44));
Read(gStatCount, sizeof(gStatCount)); Read(gStatCount, sizeof(gStatCount));
Read(nextXSprite, sizeof(nextXSprite)); Read(nextXSprite, sizeof(nextXSprite));
Read(nextXWall, sizeof(nextXWall)); Read(&XWallsUsed, sizeof(XWallsUsed));
Read(nextXSector, sizeof(nextXSector)); Read(&XSectorsUsed, sizeof(XSectorsUsed));
memset(xsprite, 0, sizeof(xsprite)); memset(xsprite, 0, sizeof(xsprite));
for (int nSprite = 0; nSprite < kMaxSprites; nSprite++) for (int nSprite = 0; nSprite < kMaxSprites; nSprite++)
{ {
@ -687,8 +687,8 @@ void MyLoadSave::Save(void)
Write(&byte_19AE44, sizeof(byte_19AE44)); Write(&byte_19AE44, sizeof(byte_19AE44));
Write(gStatCount, sizeof(gStatCount)); Write(gStatCount, sizeof(gStatCount));
Write(nextXSprite, sizeof(nextXSprite)); Write(nextXSprite, sizeof(nextXSprite));
Write(nextXWall, sizeof(nextXWall)); Write(&XWallsUsed, sizeof(XWallsUsed));
Write(nextXSector, sizeof(nextXSector)); Write(&XSectorsUsed, sizeof(XSectorsUsed));
for (int nSprite = 0; nSprite < kMaxSprites; nSprite++) for (int nSprite = 0; nSprite < kMaxSprites; nSprite++)
{ {
if (sprite[nSprite].statnum < kMaxStatus) if (sprite[nSprite].statnum < kMaxStatus)