- replaced several sector iterators in Duke code.

This commit is contained in:
Christoph Oelckers 2020-10-14 21:16:54 +02:00
parent 5c9b261823
commit 758fab1804
8 changed files with 58 additions and 69 deletions

View file

@ -105,17 +105,14 @@ short checkpins(short sect)
short i, pin; short i, pin;
int x, y; int x, y;
short pins[10]; short pins[10];
short nexti, tag; short tag;
pin = 0; pin = 0;
for(i=0;i<10;i++) pins[i] = 0; for(i=0;i<10;i++) pins[i] = 0;
i = headspritesect[sect]; SectIterator it(sect);
while ((i = it.NextIndex()) >= 0)
while (i >= 0)
{ {
nexti = nextspritesect[i];
if (sprite[i].picnum == RRTILE3440) if (sprite[i].picnum == RRTILE3440)
{ {
pin++; pin++;
@ -125,8 +122,6 @@ short checkpins(short sect)
{ {
tag = sprite[i].hitag; tag = sprite[i].hitag;
} }
i = nexti;
} }
if (tag) if (tag)
@ -190,20 +185,17 @@ short checkpins(short sect)
void resetpins(short sect) void resetpins(short sect)
{ {
short i, j, nexti, tag; short i, j, tag;
int x, y; int x, y;
i = headspritesect[sect]; SectIterator it(sect);
while (i >= 0) while ((i = it.NextIndex()) >= 0)
{ {
nexti = headspritesect[i];
if (sprite[i].picnum == 3440) if (sprite[i].picnum == 3440)
deletesprite(i); deletesprite(i);
i = nexti;
} }
i = headspritesect[sect]; it.Reset(sect);
while (i >= 0) while ((i = it.NextIndex()) >= 0)
{ {
nexti = nextspritesect[i];
if (sprite[i].picnum == 283) if (sprite[i].picnum == 283)
{ {
j = fi.spawn(i,3440); j = fi.spawn(i,3440);
@ -220,7 +212,6 @@ void resetpins(short sect)
} }
if (sprite[i].picnum == 280) if (sprite[i].picnum == 280)
tag = sprite[i].hitag; tag = sprite[i].hitag;
i = nexti;
} }
if (tag) if (tag)
{ {

View file

@ -417,7 +417,8 @@ bool GameInterface::DrawAutomapPlayer(int cposx, int cposy, int czoom, int cang)
for (i = 0; i < numsectors; i++) for (i = 0; i < numsectors; i++)
{ {
if (!gFullMap || !show2dsector[i]) continue; if (!gFullMap || !show2dsector[i]) continue;
for (j = headspritesect[i]; j >= 0; j = nextspritesect[j]) SectIterator it(i);
while ((j = it.NextIndex()) >= 0)
{ {
spr = &sprite[j]; spr = &sprite[j];

View file

@ -2507,18 +2507,17 @@ int ParseState::parse(void)
if( neartagsector >= 0 && isanearoperator(sector[neartagsector].lotag) ) if( neartagsector >= 0 && isanearoperator(sector[neartagsector].lotag) )
if( (sector[neartagsector].lotag&0xff) == ST_23_SWINGING_DOOR || sector[neartagsector].floorz == sector[neartagsector].ceilingz ) if( (sector[neartagsector].lotag&0xff) == ST_23_SWINGING_DOOR || sector[neartagsector].floorz == sector[neartagsector].ceilingz )
if( (sector[neartagsector].lotag&16384) == 0 ) if( (sector[neartagsector].lotag&16384) == 0 )
if( (sector[neartagsector].lotag&32768) == 0 ) if ((sector[neartagsector].lotag & 32768) == 0)
{
j = headspritesect[neartagsector];
while(j >= 0)
{ {
if(sprite[j].picnum == ACTIVATOR) SectIterator it(neartagsector);
break; while ((j = it.NextIndex()) >= 0)
j = nextspritesect[j]; {
if (sprite[j].picnum == ACTIVATOR)
break;
}
if (j == -1)
operatesectors(neartagsector, g_i);
} }
if(j == -1)
operatesectors(neartagsector,g_i);
}
} }
break; break;
case concmd_ifinspace: case concmd_ifinspace:

View file

@ -533,11 +533,14 @@ void footprints(int snum)
if ((sector[p->cursectnum].floorstat & 2) != 2) if ((sector[p->cursectnum].floorstat & 2) != 2)
{ {
int j; int j;
for (j = headspritesect[psect]; j >= 0; j = nextspritesect[j]) SectIterator it(psect);
while ((j = it.NextIndex()) >= 0)
{
if (sprite[j].picnum == TILE_FOOTPRINTS || sprite[j].picnum == TILE_FOOTPRINTS2 || sprite[j].picnum == TILE_FOOTPRINTS3 || sprite[j].picnum == TILE_FOOTPRINTS4) if (sprite[j].picnum == TILE_FOOTPRINTS || sprite[j].picnum == TILE_FOOTPRINTS2 || sprite[j].picnum == TILE_FOOTPRINTS3 || sprite[j].picnum == TILE_FOOTPRINTS4)
if (abs(sprite[j].x - p->posx) < 384) if (abs(sprite[j].x - p->posx) < 384)
if (abs(sprite[j].y - p->posy) < 384) if (abs(sprite[j].y - p->posy) < 384)
break; break;
}
if (j < 0) if (j < 0)
{ {
p->footprintcount--; p->footprintcount--;

View file

@ -328,8 +328,8 @@ void shoot_d(int i, int atwith)
{ {
if (wall[hitwall].nextsector >= 0) if (wall[hitwall].nextsector >= 0)
{ {
k = headspritesect[wall[hitwall].nextsector]; SectIterator it(wall[hitwall].nextsector);
while (k >= 0) while ((k = it.NextIndex()) >= 0)
{ {
if (sprite[k].statnum == 3 && sprite[k].lotag == 13) if (sprite[k].statnum == 3 && sprite[k].lotag == 13)
return; return;
@ -587,8 +587,8 @@ void shoot_d(int i, int atwith)
{ {
if (wall[hitwall].nextsector >= 0) if (wall[hitwall].nextsector >= 0)
{ {
l = headspritesect[wall[hitwall].nextsector]; SectIterator it(wall[hitwall].nextsector);
while (l >= 0) while ((l = it.NextIndex()) >= 0)
{ {
if (sprite[l].statnum == 3 && sprite[l].lotag == 13) if (sprite[l].statnum == 3 && sprite[l].lotag == 13)
goto SKIPBULLETHOLE; goto SKIPBULLETHOLE;
@ -1953,13 +1953,14 @@ int operateTripbomb(int snum)
if (wall[hw].overpicnum == BIGFORCE) if (wall[hw].overpicnum == BIGFORCE)
return 0; return 0;
int j = headspritesect[sect]; int j;
while (j >= 0) SectIterator it(sect);
while ((j = it.NextIndex()) >= 0)
{ {
if (sprite[j].picnum == TRIPBOMB && auto sj = &sprite[j];
abs(sprite[j].z - sz) < (12 << 8) && ((sprite[j].x - sx) * (sprite[j].x - sx) + (sprite[j].y - sy) * (sprite[j].y - sy)) < (290 * 290)) if (sj->picnum == TRIPBOMB &&
abs(sj->z - sz) < (12 << 8) && ((sj->x - sx) * (sj->x - sx) + (sj->y - sy) * (sj->y - sy)) < (290 * 290))
return 0; return 0;
j = nextspritesect[j];
} }
if (j == -1 && hw >= 0 && (wall[hw].cstat & 16) == 0) if (j == -1 && hw >= 0 && (wall[hw].cstat & 16) == 0)

View file

@ -217,8 +217,8 @@ void shoot_r(int i, int atwith)
{ {
if (wall[hitwall].nextsector >= 0) if (wall[hitwall].nextsector >= 0)
{ {
k = headspritesect[wall[hitwall].nextsector]; SectIterator it(wall[hitwall].nextsector);
while (k >= 0) while ((k = it.NextIndex()) >= 0)
{ {
if (sprite[k].statnum == 3 && sprite[k].lotag == 13) if (sprite[k].statnum == 3 && sprite[k].lotag == 13)
return; return;
@ -500,8 +500,8 @@ void shoot_r(int i, int atwith)
{ {
if (wall[hitwall].nextsector >= 0) if (wall[hitwall].nextsector >= 0)
{ {
l = headspritesect[wall[hitwall].nextsector]; SectIterator it(wall[hitwall].nextsector);
while (l >= 0) while ((l = it.NextIndex()) >= 0)
{ {
if (sprite[l].statnum == 3 && sprite[l].lotag == 13) if (sprite[l].statnum == 3 && sprite[l].lotag == 13)
goto SKIPBULLETHOLE; goto SKIPBULLETHOLE;
@ -3492,15 +3492,12 @@ void processinput_r(int snum)
if (psectlotag == 867) if (psectlotag == 867)
{ {
short sj, nextsj; SectIterator it(psect);
sj = headspritesect[psect]; while ((j = it.NextIndex()) >= 0)
while (sj >= 0)
{ {
nextsj = nextspritesect[sj]; if (sprite[j].picnum == RRTILE380)
if (sprite[sj].picnum == RRTILE380) if (sprite[j].z - (8 << 8) < p->posz)
if (sprite[sj].z - (8 << 8) < p->posz)
psectlotag = 2; psectlotag = 2;
sj = nextsj;
} }
} }
else if (psectlotag == 7777) else if (psectlotag == 7777)

View file

@ -252,12 +252,11 @@ void cacheit_d(void)
} }
} }
j = headspritesect[i]; SectIterator it(i);
while (j >= 0) while ((j = it.NextIndex()) >= 0)
{ {
if (sprite[j].xrepeat != 0 && sprite[j].yrepeat != 0 && (sprite[j].cstat & 32768) == 0) if (sprite[j].xrepeat != 0 && sprite[j].yrepeat != 0 && (sprite[j].cstat & 32768) == 0)
cachespritenum(j); cachespritenum(j);
j = nextspritesect[j];
} }
precacheMarkedTiles(); precacheMarkedTiles();

View file

@ -427,12 +427,11 @@ void cacheit_r(void)
} }
} }
j = headspritesect[i]; SectIterator it(i);
while(j >= 0) while ((j = it.NextIndex()) >= 0)
{ {
if(sprite[j].xrepeat != 0 && sprite[j].yrepeat != 0 && (sprite[j].cstat&32768) == 0) if(sprite[j].xrepeat != 0 && sprite[j].yrepeat != 0 && (sprite[j].cstat&32768) == 0)
cachespritenum(j); cachespritenum(j);
j = nextspritesect[j];
} }
precacheMarkedTiles(); precacheMarkedTiles();
} }
@ -495,10 +494,10 @@ void prelevel_r(int g)
switch (sector[i].lotag) switch (sector[i].lotag)
{ {
case 41: case 41:
k = headspritesect[i]; {
while (k != -1) SectIterator it(i);
while ((k = it.NextIndex()) >= 0)
{ {
nexti = nextspritesect[k];
if (sprite[k].picnum == RRTILE11) if (sprite[k].picnum == RRTILE11)
{ {
dist = sprite[k].lotag << 4; dist = sprite[k].lotag << 4;
@ -510,7 +509,6 @@ void prelevel_r(int g)
sound = sprite[k].lotag; sound = sprite[k].lotag;
deletesprite(k); deletesprite(k);
} }
k = nexti;
} }
for (j = 0; j < numsectors; j++) for (j = 0; j < numsectors; j++)
{ {
@ -520,22 +518,23 @@ void prelevel_r(int g)
} }
} }
break; break;
}
case 42: case 42:
{ {
short ii; short ii;
int childsectnum = -1; int childsectnum = -1;
k = headspritesect[i]; SectIterator it(i);
while (k != -1) while ((k = it.NextIndex()) >= 0)
{ {
nexti = nextspritesect[k]; auto sj = &sprite[k];
if (sprite[k].picnum == RRTILE64) if (sj->picnum == RRTILE64)
{ {
dist = sprite[k].lotag << 4; dist = sj->lotag << 4;
speed = sprite[k].hitag; speed = sj->hitag;
for (ii = 0; ii < MAXSPRITES; ii++) for (ii = 0; ii < MAXSPRITES; ii++)
{ {
if (sprite[ii].picnum == RRTILE66) if (sprite[ii].picnum == RRTILE66)
if (sprite[ii].lotag == sprite[k].sectnum) if (sprite[ii].lotag == sj->sectnum)
{ {
childsectnum = sprite[ii].sectnum; childsectnum = sprite[ii].sectnum;
deletesprite(ii); deletesprite(ii);
@ -543,12 +542,11 @@ void prelevel_r(int g)
} }
deletesprite(k); deletesprite(k);
} }
if (sprite[k].picnum == RRTILE65) if (sj->picnum == RRTILE65)
{ {
sound = sprite[k].lotag; sound = sj->lotag;
deletesprite(k); deletesprite(k);
} }
k = nexti;
} }
addminecart(dist, speed, i, sector[i].hitag, sound, childsectnum); addminecart(dist, speed, i, sector[i].hitag, sound, childsectnum);
break; break;