- replaced all sector sprite iterators in Blood.

This commit is contained in:
Christoph Oelckers 2020-10-15 16:48:32 +02:00
parent b1536d8a0b
commit aa5c7c3e34
4 changed files with 69 additions and 23 deletions

View file

@ -204,7 +204,9 @@ void sub_557C4(int x, int y, int interpolation)
{ {
int nSector = mirror[i].Kills; int nSector = mirror[i].Kills;
int nSector2 = mirror[i].at14; int nSector2 = mirror[i].at14;
for (int nSprite = headspritesect[nSector]; nSprite >= 0; nSprite = nextspritesect[nSprite]) int nSprite;
SectIterator it(nSector);
while ((nSprite = it.NextIndex()) >= 0)
{ {
spritetype *pSprite = &sprite[nSprite]; spritetype *pSprite = &sprite[nSprite];
if (pSprite == gView->pSprite) if (pSprite == gView->pSprite)

View file

@ -1967,8 +1967,10 @@ void usePropertiesChanger(XSPRITE* pXSource, short objType, int objIndex) {
} }
// search for dudes in this sector and change their underwater status // search for dudes in this sector and change their underwater status
for (int nSprite = headspritesect[objIndex]; nSprite >= 0; nSprite = nextspritesect[nSprite]) { int nSprite;
SectIterator it(objIndex);
while ((nSprite = it.NextIndex()) >= 0)
{
spritetype* pSpr = &sprite[nSprite]; spritetype* pSpr = &sprite[nSprite];
if (pSpr->statnum != kStatDude || !IsDudeSprite(pSpr) || !xspriRangeIsFine(pSpr->extra)) if (pSpr->statnum != kStatDude || !IsDudeSprite(pSpr) || !xspriRangeIsFine(pSpr->extra))
continue; continue;
@ -2744,7 +2746,10 @@ bool condCheckSector(XSPRITE* pXCond, int cmpOp, bool PUSH) {
case 5: return condCmp(pSect->floorheinum, arg1, arg2, cmpOp); case 5: return condCmp(pSect->floorheinum, arg1, arg2, cmpOp);
case 6: return condCmp(pSect->ceilingheinum, arg1, arg2, cmpOp); case 6: return condCmp(pSect->ceilingheinum, arg1, arg2, cmpOp);
case 10: // required sprite type is in current sector? case 10: // required sprite type is in current sector?
for (var = headspritesect[objIndex]; var >= 0; var = nextspritesect[var]) { int nSprite;
SectIterator it(objIndex);
while ((nSprite = it.NextIndex()) >= 0)
{
if (!condCmp(sprite[var].type, arg1, arg2, cmpOp)) continue; if (!condCmp(sprite[var].type, arg1, arg2, cmpOp)) continue;
else if (PUSH) condPush(pXCond, OBJ_SPRITE, var); else if (PUSH) condPush(pXCond, OBJ_SPRITE, var);
return true; return true;

View file

@ -675,7 +675,10 @@ void playerStart(int nPlayer, int bNewLevel)
if (maxRetries != 0) { if (maxRetries != 0) {
// check if there is no spawned player in selected zone // check if there is no spawned player in selected zone
for (int i = headspritesect[pStartZone->sectnum]; i >= 0; i = nextspritesect[i]) { int i;
SectIterator it(pStartZone->sectnum);
while ((i = it.NextIndex()) >= 0)
{
spritetype* pSprite = &sprite[i]; spritetype* pSprite = &sprite[i];
if (pStartZone->x == pSprite->x && pStartZone->y == pSprite->y && IsPlayerSprite(pSprite)) { if (pStartZone->x == pSprite->x && pStartZone->y == pSprite->y && IsPlayerSprite(pSprite)) {
pStartZone = NULL; pStartZone = NULL;

View file

@ -760,7 +760,9 @@ void OperateWall(int nWall, XWALL *pXWall, EVENT event) {
void SectorStartSound(int nSector, int nState) void SectorStartSound(int nSector, int nState)
{ {
for (int nSprite = headspritesect[nSector]; nSprite >= 0; nSprite = nextspritesect[nSprite]) int nSprite;
SectIterator it(nSector);
while ((nSprite = it.NextIndex()) >= 0)
{ {
spritetype *pSprite = &sprite[nSprite]; spritetype *pSprite = &sprite[nSprite];
if (pSprite->statnum == kStatDecoration && pSprite->type == kSoundSector) if (pSprite->statnum == kStatDecoration && pSprite->type == kSoundSector)
@ -784,7 +786,9 @@ void SectorStartSound(int nSector, int nState)
void SectorEndSound(int nSector, int nState) void SectorEndSound(int nSector, int nState)
{ {
for (int nSprite = headspritesect[nSector]; nSprite >= 0; nSprite = nextspritesect[nSprite]) int nSprite;
SectIterator it(nSector);
while ((nSprite = it.NextIndex()) >= 0)
{ {
spritetype *pSprite = &sprite[nSprite]; spritetype *pSprite = &sprite[nSprite];
if (pSprite->statnum == kStatDecoration && pSprite->type == kSoundSector) if (pSprite->statnum == kStatDecoration && pSprite->type == kSoundSector)
@ -808,7 +812,9 @@ void SectorEndSound(int nSector, int nState)
void PathSound(int nSector, int nSound) void PathSound(int nSector, int nSound)
{ {
for (int nSprite = headspritesect[nSector]; nSprite >= 0; nSprite = nextspritesect[nSprite]) int nSprite;
SectIterator it(nSector);
while ((nSprite = it.NextIndex()) >= 0)
{ {
spritetype *pSprite = &sprite[nSprite]; spritetype *pSprite = &sprite[nSprite];
if (pSprite->statnum == kStatDecoration && pSprite->type == kSoundSector) if (pSprite->statnum == kStatDecoration && pSprite->type == kSoundSector)
@ -920,7 +926,9 @@ void TranslateSector(int nSector, int a2, int a3, int a4, int a5, int a6, int a7
} }
} }
} }
for (int nSprite = headspritesect[nSector]; nSprite >= 0; nSprite = nextspritesect[nSprite]) int nSprite;
SectIterator it(nSector);
while ((nSprite = it.NextIndex()) >= 0)
{ {
spritetype *pSprite = &sprite[nSprite]; spritetype *pSprite = &sprite[nSprite];
// allow to move markers by sector movements in game if flags 1 is added in editor. // allow to move markers by sector movements in game if flags 1 is added in editor.
@ -983,7 +991,9 @@ void ZTranslateSector(int nSector, XSECTOR *pXSector, int a3, int a4)
int oldZ = pSector->floorz; int oldZ = pSector->floorz;
baseFloor[nSector] = pSector->floorz = pXSector->offFloorZ + mulscale16(dz, GetWaveValue(a3, a4)); baseFloor[nSector] = pSector->floorz = pXSector->offFloorZ + mulscale16(dz, GetWaveValue(a3, a4));
velFloor[nSector] += (pSector->floorz-oldZ)<<8; velFloor[nSector] += (pSector->floorz-oldZ)<<8;
for (int nSprite = headspritesect[nSector]; nSprite >= 0; nSprite = nextspritesect[nSprite]) int nSprite;
SectIterator it(nSector);
while ((nSprite = it.NextIndex()) >= 0)
{ {
spritetype *pSprite = &sprite[nSprite]; spritetype *pSprite = &sprite[nSprite];
if (pSprite->statnum == kStatMarker || pSprite->statnum == kStatPathMarker) if (pSprite->statnum == kStatMarker || pSprite->statnum == kStatPathMarker)
@ -1010,7 +1020,9 @@ void ZTranslateSector(int nSector, XSECTOR *pXSector, int a3, int a4)
int oldZ = pSector->ceilingz; int oldZ = pSector->ceilingz;
baseCeil[nSector] = pSector->ceilingz = pXSector->offCeilZ + mulscale16(dz, GetWaveValue(a3, a4)); baseCeil[nSector] = pSector->ceilingz = pXSector->offCeilZ + mulscale16(dz, GetWaveValue(a3, a4));
velCeil[nSector] += (pSector->ceilingz-oldZ)<<8; velCeil[nSector] += (pSector->ceilingz-oldZ)<<8;
for (int nSprite = headspritesect[nSector]; nSprite >= 0; nSprite = nextspritesect[nSprite]) int nSprite;
SectIterator it(nSector);
while ((nSprite = it.NextIndex()) >= 0)
{ {
spritetype *pSprite = &sprite[nSprite]; spritetype *pSprite = &sprite[nSprite];
if (pSprite->statnum == kStatMarker || pSprite->statnum == kStatPathMarker) if (pSprite->statnum == kStatMarker || pSprite->statnum == kStatPathMarker)
@ -1028,7 +1040,9 @@ int GetHighestSprite(int nSector, int nStatus, int *a3)
{ {
*a3 = sector[nSector].floorz; *a3 = sector[nSector].floorz;
int v8 = -1; int v8 = -1;
for (int nSprite = headspritesect[nSector]; nSprite >= 0; nSprite = nextspritesect[nSprite]) int nSprite;
SectIterator it(nSector);
while ((nSprite = it.NextIndex()) >= 0)
{ {
if (sprite[nSprite].statnum == nStatus || nStatus == kStatFree) if (sprite[nSprite].statnum == nStatus || nStatus == kStatFree)
{ {
@ -1052,7 +1066,9 @@ int GetCrushedSpriteExtents(unsigned int nSector, int *pzTop, int *pzBot)
int vc = -1; int vc = -1;
sectortype *pSector = &sector[nSector]; sectortype *pSector = &sector[nSector];
int vbp = pSector->ceilingz; int vbp = pSector->ceilingz;
for (int nSprite = headspritesect[nSector]; nSprite >= 0; nSprite = nextspritesect[nSprite]) int nSprite;
SectIterator it(nSector);
while ((nSprite = it.NextIndex()) >= 0)
{ {
spritetype *pSprite = &sprite[nSprite]; spritetype *pSprite = &sprite[nSprite];
if (pSprite->statnum == kStatDude || pSprite->statnum == kStatThing) if (pSprite->statnum == kStatDude || pSprite->statnum == kStatThing)
@ -1124,7 +1140,9 @@ int VSpriteBusy(unsigned int nSector, unsigned int a2)
int dz1 = pXSector->onFloorZ - pXSector->offFloorZ; int dz1 = pXSector->onFloorZ - pXSector->offFloorZ;
if (dz1 != 0) if (dz1 != 0)
{ {
for (int nSprite = headspritesect[nSector]; nSprite >= 0; nSprite = nextspritesect[nSprite]) int nSprite;
SectIterator it(nSector);
while ((nSprite = it.NextIndex()) >= 0)
{ {
spritetype *pSprite = &sprite[nSprite]; spritetype *pSprite = &sprite[nSprite];
if (pSprite->cstat&8192) if (pSprite->cstat&8192)
@ -1137,7 +1155,9 @@ int VSpriteBusy(unsigned int nSector, unsigned int a2)
int dz2 = pXSector->onCeilZ - pXSector->offCeilZ; int dz2 = pXSector->onCeilZ - pXSector->offCeilZ;
if (dz2 != 0) if (dz2 != 0)
{ {
for (int nSprite = headspritesect[nSector]; nSprite >= 0; nSprite = nextspritesect[nSprite]) int nSprite;
SectIterator it(nSector);
while ((nSprite = it.NextIndex()) >= 0)
{ {
spritetype *pSprite = &sprite[nSprite]; spritetype *pSprite = &sprite[nSprite];
if (pSprite->cstat&16384) if (pSprite->cstat&16384)
@ -1430,7 +1450,9 @@ void OperateDoor(unsigned int nSector, XSECTOR *pXSector, EVENT event, BUSYID bu
char SectorContainsDudes(int nSector) char SectorContainsDudes(int nSector)
{ {
for (int nSprite = headspritesect[nSector]; nSprite >= 0; nSprite = nextspritesect[nSprite]) int nSprite;
SectIterator it(nSector);
while ((nSprite = it.NextIndex()) >= 0)
{ {
if (sprite[nSprite].statnum == kStatDude) if (sprite[nSprite].statnum == kStatDude)
return 1; return 1;
@ -1440,7 +1462,9 @@ char SectorContainsDudes(int nSector)
void TeleFrag(int nKiller, int nSector) void TeleFrag(int nKiller, int nSector)
{ {
for (int nSprite = headspritesect[nSector]; nSprite >= 0; nSprite = nextspritesect[nSprite]) int nSprite;
SectIterator it(nSector);
while ((nSprite = it.NextIndex()) >= 0)
{ {
spritetype *pSprite = &sprite[nSprite]; spritetype *pSprite = &sprite[nSprite];
if (pSprite->statnum == kStatDude) if (pSprite->statnum == kStatDude)
@ -1459,7 +1483,9 @@ void OperateTeleport(unsigned int nSector, XSECTOR *pXSector)
assert(pDest->statnum == kStatMarker); assert(pDest->statnum == kStatMarker);
assert(pDest->type == kMarkerWarpDest); assert(pDest->type == kMarkerWarpDest);
assert(pDest->sectnum >= 0 && pDest->sectnum < kMaxSectors); assert(pDest->sectnum >= 0 && pDest->sectnum < kMaxSectors);
for (int nSprite = headspritesect[nSector]; nSprite >= 0; nSprite = nextspritesect[nSprite]) int nSprite;
SectIterator it(nSector);
while ((nSprite = it.NextIndex()) >= 0)
{ {
spritetype *pSprite = &sprite[nSprite]; spritetype *pSprite = &sprite[nSprite];
if (pSprite->statnum == kStatDude) if (pSprite->statnum == kStatDude)
@ -1887,7 +1913,9 @@ void ProcessMotion(void)
else else
pXSector->bobTheta += mulscale16(pXSector->bobSpeed, pXSector->busy); pXSector->bobTheta += mulscale16(pXSector->bobSpeed, pXSector->busy);
int vdi = mulscale30(Sin(pXSector->bobTheta), pXSector->bobZRange<<8); int vdi = mulscale30(Sin(pXSector->bobTheta), pXSector->bobZRange<<8);
for (int nSprite = headspritesect[nSector]; nSprite >= 0; nSprite = nextspritesect[nSprite]) int nSprite;
SectIterator it(nSector);
while ((nSprite = it.NextIndex()) >= 0)
{ {
spritetype *pSprite = &sprite[nSprite]; spritetype *pSprite = &sprite[nSprite];
if (pSprite->cstat&24576) if (pSprite->cstat&24576)
@ -1901,7 +1929,9 @@ void ProcessMotion(void)
int floorZ = pSector->floorz; int floorZ = pSector->floorz;
viewInterpolateSector(nSector, pSector); viewInterpolateSector(nSector, pSector);
pSector->floorz = baseFloor[nSector]+vdi; pSector->floorz = baseFloor[nSector]+vdi;
for (int nSprite = headspritesect[nSector]; nSprite >= 0; nSprite = nextspritesect[nSprite]) int nSprite;
SectIterator it(nSector);
while ((nSprite = it.NextIndex()) >= 0)
{ {
spritetype *pSprite = &sprite[nSprite]; spritetype *pSprite = &sprite[nSprite];
if (pSprite->flags&2) if (pSprite->flags&2)
@ -1923,7 +1953,9 @@ void ProcessMotion(void)
int ceilZ = pSector->ceilingz; int ceilZ = pSector->ceilingz;
viewInterpolateSector(nSector, pSector); viewInterpolateSector(nSector, pSector);
pSector->ceilingz = baseCeil[nSector]+vdi; pSector->ceilingz = baseCeil[nSector]+vdi;
for (int nSprite = headspritesect[nSector]; nSprite >= 0; nSprite = nextspritesect[nSprite]) int nSprite;
SectIterator it(nSector);
while ((nSprite = it.NextIndex()) >= 0)
{ {
spritetype *pSprite = &sprite[nSprite]; spritetype *pSprite = &sprite[nSprite];
int top, bottom; int top, bottom;
@ -2072,7 +2104,9 @@ void trInit(void)
baseWall[pSector->wallptr+j].x = wall[pSector->wallptr+j].x; baseWall[pSector->wallptr+j].x = wall[pSector->wallptr+j].x;
baseWall[pSector->wallptr+j].y = wall[pSector->wallptr+j].y; baseWall[pSector->wallptr+j].y = wall[pSector->wallptr+j].y;
} }
for (int nSprite = headspritesect[i]; nSprite >= 0; nSprite = nextspritesect[nSprite]) int nSprite;
SectIterator it(i);
while ((nSprite = it.NextIndex()) >= 0)
{ {
baseSprite[nSprite].x = sprite[nSprite].x; baseSprite[nSprite].x = sprite[nSprite].x;
baseSprite[nSprite].y = sprite[nSprite].y; baseSprite[nSprite].y = sprite[nSprite].y;
@ -2092,7 +2126,9 @@ void trInit(void)
baseWall[pSector->wallptr+j].x = wall[pSector->wallptr+j].x; baseWall[pSector->wallptr+j].x = wall[pSector->wallptr+j].x;
baseWall[pSector->wallptr+j].y = wall[pSector->wallptr+j].y; baseWall[pSector->wallptr+j].y = wall[pSector->wallptr+j].y;
} }
for (int nSprite = headspritesect[i]; nSprite >= 0; nSprite = nextspritesect[nSprite]) int nSprite;
SectIterator it(i);
while ((nSprite = it.NextIndex()) >= 0)
{ {
baseSprite[nSprite].x = sprite[nSprite].x; baseSprite[nSprite].x = sprite[nSprite].x;
baseSprite[nSprite].y = sprite[nSprite].y; baseSprite[nSprite].y = sprite[nSprite].y;