From db4f0d041ee671e2b562a86af77e609a9d7b5eb4 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 15 Oct 2020 19:10:51 +0200 Subject: [PATCH] - all iterators in Exhumed handled. --- source/exhumed/src/exhumed.cpp | 11 +++++++---- source/exhumed/src/lighting.cpp | 4 +++- source/exhumed/src/move.cpp | 9 ++++++--- source/exhumed/src/object.cpp | 24 +++++++++++------------ source/exhumed/src/player.cpp | 34 +++------------------------------ source/exhumed/src/player.h | 1 - source/exhumed/src/snake.cpp | 4 +++- 7 files changed, 34 insertions(+), 53 deletions(-) diff --git a/source/exhumed/src/exhumed.cpp b/source/exhumed/src/exhumed.cpp index 14bace9b3..8bdbe32f8 100644 --- a/source/exhumed/src/exhumed.cpp +++ b/source/exhumed/src/exhumed.cpp @@ -194,7 +194,10 @@ void ShutDown(void) void DoClockBeep() { - for (int i = headspritestat[407]; i != -1; i = nextspritestat[i]) { + int i; + StatIterator it(407); + while ((i = it.NextIndex()) >= 0) + { PlayFX2(StaticSound[kSound74], i); } } @@ -207,7 +210,9 @@ void DoRedAlert(int nVal) nRedTicks = 30; } - for (int i = headspritestat[405]; i != -1; i = nextspritestat[i]) + int i; + StatIterator it(405); + while ((i = it.NextIndex()) >= 0) { if (nVal) { @@ -533,9 +538,7 @@ void GameInterface::app_init() void mychangespritesect(int nSprite, int nSector) { - DoKenTest(); changespritesect(nSprite, nSector); - DoKenTest(); } void mydeletesprite(int nSprite) diff --git a/source/exhumed/src/lighting.cpp b/source/exhumed/src/lighting.cpp index aafc239df..0cf681507 100644 --- a/source/exhumed/src/lighting.cpp +++ b/source/exhumed/src/lighting.cpp @@ -298,7 +298,9 @@ void AddFlash(short nSector, int x, int y, int z, int val) } } - for (short nSprite = headspritesect[nSector]; nSprite >= 0; nSprite = nextspritesect[nSprite]) + int nSprite; + SectIterator it(nSector); + while ((nSprite = it.NextIndex()) >= 0) { if (sprite[nSprite].pal < 4) { diff --git a/source/exhumed/src/move.cpp b/source/exhumed/src/move.cpp index 62236b25a..f21fc1005 100644 --- a/source/exhumed/src/move.cpp +++ b/source/exhumed/src/move.cpp @@ -1001,7 +1001,8 @@ void MoveSector(short nSector, int nAngle, int *nXVel, int *nYVel) // GREEN if (yvect || xvect) { - for (i = headspritesect[nSector]; i != -1; i = nextspritesect[i]) + SectIterator it(nSector); + while ((i = it.NextIndex()) >= 0) { if (sprite[i].statnum < 99) { @@ -1027,7 +1028,8 @@ void MoveSector(short nSector, int nAngle, int *nXVel, int *nYVel) } } - for (i = headspritesect[nNextSector]; i != -1; i = nextspritesect[i]) + it.Reset(nNextSector); + while ((i = it.NextIndex()) >= 0) { if (sprite[i].statnum >= 99) { @@ -1078,7 +1080,8 @@ void MoveSector(short nSector, int nAngle, int *nXVel, int *nYVel) if (!(nSectFlag & kSectUnderwater)) { - for (i = headspritesect[nSector]; i != -1; i = nextspritesect[i]) + SectIterator it(nSector); + while ((i = it.NextIndex()) >= 0) { if (sprite[i].statnum >= 99 && nZVal == sprite[i].z && !(sprite[i].cstat & 0x8000)) { diff --git a/source/exhumed/src/object.cpp b/source/exhumed/src/object.cpp index 733a898dd..4beda230f 100644 --- a/source/exhumed/src/object.cpp +++ b/source/exhumed/src/object.cpp @@ -490,11 +490,11 @@ int CheckSectorSprites(short nSector, int nVal) if (nVal) { - short nSprite = headspritesect[nSector]; - int nZDiff = sector[nSector].floorz - sector[nSector].ceilingz; - while (nSprite != -1) + int nSprite; + SectIterator it(nSector); + while ((nSprite = it.NextIndex()) >= 0) { if ((sprite[nSprite].cstat & 0x101) && (nZDiff < GetSpriteHeight(nSprite))) { @@ -515,12 +515,13 @@ int CheckSectorSprites(short nSector, int nVal) sprite[nSprite].sectnum | 0x4000); } } - nSprite = nextspritesect[nSprite]; } } else { - for (int i = headspritesect[nSector]; i != -1; i = nextspritesect[i]) + int i; + SectIterator it(nSector); + while ((i = it.NextIndex()) >= 0) { if (sprite[i].cstat & 0x101) { return 1; @@ -535,15 +536,13 @@ int CheckSectorSprites(short nSector, int nVal) // done void MoveSectorSprites(int nSector, int z) { - int nSprite = headspritesect[nSector]; - - while (nSprite != -1) + int nSprite; + SectIterator it(nSector); + while ((nSprite = it.NextIndex()) >= 0) { if (sprite[nSprite].statnum != 200) { sprite[nSprite].z += z; } - - nSprite = nextspritesect[nSprite]; } } @@ -1621,7 +1620,6 @@ void KillCreatures() { signed int v0; signed int v1; - int i; v0 = 99; v1 = 99; @@ -1630,7 +1628,9 @@ void KillCreatures() { if (v0 != 100) { - for (i = headspritestat[v1]; i != -1; i = nextspritestat[i]) + int i; + StatIterator it(v1); + while ((i = it.NextIndex()) >= 0) { runlist_DamageEnemy(i, -1, 1600); } diff --git a/source/exhumed/src/player.cpp b/source/exhumed/src/player.cpp index ceb581bba..632d46a59 100644 --- a/source/exhumed/src/player.cpp +++ b/source/exhumed/src/player.cpp @@ -161,11 +161,10 @@ void feebtag(int x, int y, int z, int nSector, short *nSprite, int nVal2, int nV { if (nSector != -1) { - short i = headspritesect[nSector]; - - while (i != -1) + int i; + SectIterator it(nSector); + while ((i = it.NextIndex()) >= 0) { - short nNextSprite = nextspritesect[i]; short nStat = sprite[i].statnum; if (nStat >= 900 && !(sprite[i].cstat & 0x8000)) @@ -193,8 +192,6 @@ void feebtag(int x, int y, int z, int nSector, short *nSprite, int nVal2, int nV } } } - - i = nNextSprite; } } @@ -666,31 +663,6 @@ void PlayAlert(const char *str) PlayLocalSound(StaticSound[kSound63], 0); } -void DoKenTest() -{ - int nPlayerSprite = PlayerList[0].nSprite; - if ((unsigned int)nPlayerSprite >= kMaxSprites) - { - return; - } - int nSector = sprite[nPlayerSprite].sectnum; - if ((unsigned int)nSector >= kMaxSectors) - { - Printf("DoKenTest: (unsigned int)nSector >= kMaxSectors\n"); - return; - } - - for (int i = headspritesect[nSector]; ; i = nextspritesect[i]) - { - if (i == -1) { - return; - } - - if (nextspritesect[i] == i) { - I_Error("ERROR in Ken's linked list!\n"); - } - } -} static void pickupMessage(int no) { diff --git a/source/exhumed/src/player.h b/source/exhumed/src/player.h index bde734f9a..254796ae0 100644 --- a/source/exhumed/src/player.h +++ b/source/exhumed/src/player.h @@ -28,7 +28,6 @@ void RestoreSavePoint(int nPlayer, int *x, int *y, int *z, short *nSector, short void SetSavePoint(int nPlayer, int x, int y, int z, short nSector, short nAngle); void InitPlayer(); void InitPlayerKeys(short nPlayer); -void DoKenTest(); int GrabPlayer(); void InitPlayerInventory(short nPlayer); void RestartPlayer(short nPlayer); diff --git a/source/exhumed/src/snake.cpp b/source/exhumed/src/snake.cpp index 57e0c019f..7b6bf9937 100644 --- a/source/exhumed/src/snake.cpp +++ b/source/exhumed/src/snake.cpp @@ -274,7 +274,9 @@ int FindSnakeEnemy(short nSnake) int nEnemy = -1; - for (int i = headspritesect[nSector]; i >= 0; i = nextspritesect[i]) + int i; + SectIterator it(nSector); + while ((i = it.NextIndex()) >= 0) { if (sprite[i].statnum >= 90 && sprite[i].statnum < 150 && (sprite[i].cstat & 0x101)) {