Skip to content

Commit

Permalink
- Blood: simplified management of XSectors and XWalls.
Browse files Browse the repository at this point in the history
This does not need a free list - they get statically allocated per level, so a simple counter is enough.
  • Loading branch information
coelckers committed Oct 13, 2020
1 parent 2b1284e commit 53481fb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
21 changes: 9 additions & 12 deletions source/blood/src/db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down Expand Up @@ -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++)
Expand Down Expand Up @@ -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");
}
Expand All @@ -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");
}
Expand All @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions source/blood/src/db.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
8 changes: 4 additions & 4 deletions source/blood/src/loadsave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
{
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 53481fb

Please sign in to comment.