From 758fab18045a2d3e974c5f6db900951858734eed Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 14 Oct 2020 21:16:54 +0200 Subject: [PATCH] - replaced several sector iterators in Duke code. --- source/games/duke/src/bowling.cpp | 25 ++++++++-------------- source/games/duke/src/game_misc.cpp | 3 ++- source/games/duke/src/gameexec.cpp | 19 ++++++++--------- source/games/duke/src/player.cpp | 5 ++++- source/games/duke/src/player_d.cpp | 19 +++++++++-------- source/games/duke/src/player_r.cpp | 19 ++++++++--------- source/games/duke/src/premap_d.cpp | 5 ++--- source/games/duke/src/premap_r.cpp | 32 ++++++++++++++--------------- 8 files changed, 58 insertions(+), 69 deletions(-) diff --git a/source/games/duke/src/bowling.cpp b/source/games/duke/src/bowling.cpp index f8b193214..c0682c471 100644 --- a/source/games/duke/src/bowling.cpp +++ b/source/games/duke/src/bowling.cpp @@ -105,17 +105,14 @@ short checkpins(short sect) short i, pin; int x, y; short pins[10]; - short nexti, tag; + short tag; pin = 0; for(i=0;i<10;i++) pins[i] = 0; - i = headspritesect[sect]; - - while (i >= 0) + SectIterator it(sect); + while ((i = it.NextIndex()) >= 0) { - nexti = nextspritesect[i]; - if (sprite[i].picnum == RRTILE3440) { pin++; @@ -125,8 +122,6 @@ short checkpins(short sect) { tag = sprite[i].hitag; } - - i = nexti; } if (tag) @@ -190,20 +185,17 @@ short checkpins(short sect) void resetpins(short sect) { - short i, j, nexti, tag; + short i, j, tag; int x, y; - i = headspritesect[sect]; - while (i >= 0) + SectIterator it(sect); + while ((i = it.NextIndex()) >= 0) { - nexti = headspritesect[i]; if (sprite[i].picnum == 3440) deletesprite(i); - i = nexti; } - i = headspritesect[sect]; - while (i >= 0) + it.Reset(sect); + while ((i = it.NextIndex()) >= 0) { - nexti = nextspritesect[i]; if (sprite[i].picnum == 283) { j = fi.spawn(i,3440); @@ -220,7 +212,6 @@ void resetpins(short sect) } if (sprite[i].picnum == 280) tag = sprite[i].hitag; - i = nexti; } if (tag) { diff --git a/source/games/duke/src/game_misc.cpp b/source/games/duke/src/game_misc.cpp index 0fa94f55a..2a31e917e 100644 --- a/source/games/duke/src/game_misc.cpp +++ b/source/games/duke/src/game_misc.cpp @@ -417,7 +417,8 @@ bool GameInterface::DrawAutomapPlayer(int cposx, int cposy, int czoom, int cang) for (i = 0; i < numsectors; i++) { 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]; diff --git a/source/games/duke/src/gameexec.cpp b/source/games/duke/src/gameexec.cpp index 9b1a337e7..6abe63bbd 100644 --- a/source/games/duke/src/gameexec.cpp +++ b/source/games/duke/src/gameexec.cpp @@ -2507,18 +2507,17 @@ int ParseState::parse(void) 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&16384) == 0 ) - if( (sector[neartagsector].lotag&32768) == 0 ) - { - j = headspritesect[neartagsector]; - while(j >= 0) + if ((sector[neartagsector].lotag & 32768) == 0) { - if(sprite[j].picnum == ACTIVATOR) - break; - j = nextspritesect[j]; + SectIterator it(neartagsector); + while ((j = it.NextIndex()) >= 0) + { + if (sprite[j].picnum == ACTIVATOR) + break; + } + if (j == -1) + operatesectors(neartagsector, g_i); } - if(j == -1) - operatesectors(neartagsector,g_i); - } } break; case concmd_ifinspace: diff --git a/source/games/duke/src/player.cpp b/source/games/duke/src/player.cpp index e631ace85..4a2ca70fb 100644 --- a/source/games/duke/src/player.cpp +++ b/source/games/duke/src/player.cpp @@ -533,11 +533,14 @@ void footprints(int snum) if ((sector[p->cursectnum].floorstat & 2) != 2) { 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 (abs(sprite[j].x - p->posx) < 384) if (abs(sprite[j].y - p->posy) < 384) break; + } if (j < 0) { p->footprintcount--; diff --git a/source/games/duke/src/player_d.cpp b/source/games/duke/src/player_d.cpp index 66ccffd0f..c4566f226 100644 --- a/source/games/duke/src/player_d.cpp +++ b/source/games/duke/src/player_d.cpp @@ -328,8 +328,8 @@ void shoot_d(int i, int atwith) { if (wall[hitwall].nextsector >= 0) { - k = headspritesect[wall[hitwall].nextsector]; - while (k >= 0) + SectIterator it(wall[hitwall].nextsector); + while ((k = it.NextIndex()) >= 0) { if (sprite[k].statnum == 3 && sprite[k].lotag == 13) return; @@ -587,8 +587,8 @@ void shoot_d(int i, int atwith) { if (wall[hitwall].nextsector >= 0) { - l = headspritesect[wall[hitwall].nextsector]; - while (l >= 0) + SectIterator it(wall[hitwall].nextsector); + while ((l = it.NextIndex()) >= 0) { if (sprite[l].statnum == 3 && sprite[l].lotag == 13) goto SKIPBULLETHOLE; @@ -1953,13 +1953,14 @@ int operateTripbomb(int snum) if (wall[hw].overpicnum == BIGFORCE) return 0; - int j = headspritesect[sect]; - while (j >= 0) + int j; + SectIterator it(sect); + while ((j = it.NextIndex()) >= 0) { - if (sprite[j].picnum == TRIPBOMB && - 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)) + auto sj = &sprite[j]; + 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; - j = nextspritesect[j]; } if (j == -1 && hw >= 0 && (wall[hw].cstat & 16) == 0) diff --git a/source/games/duke/src/player_r.cpp b/source/games/duke/src/player_r.cpp index 504d8b985..6d4e12847 100644 --- a/source/games/duke/src/player_r.cpp +++ b/source/games/duke/src/player_r.cpp @@ -217,8 +217,8 @@ void shoot_r(int i, int atwith) { if (wall[hitwall].nextsector >= 0) { - k = headspritesect[wall[hitwall].nextsector]; - while (k >= 0) + SectIterator it(wall[hitwall].nextsector); + while ((k = it.NextIndex()) >= 0) { if (sprite[k].statnum == 3 && sprite[k].lotag == 13) return; @@ -500,8 +500,8 @@ void shoot_r(int i, int atwith) { if (wall[hitwall].nextsector >= 0) { - l = headspritesect[wall[hitwall].nextsector]; - while (l >= 0) + SectIterator it(wall[hitwall].nextsector); + while ((l = it.NextIndex()) >= 0) { if (sprite[l].statnum == 3 && sprite[l].lotag == 13) goto SKIPBULLETHOLE; @@ -3492,15 +3492,12 @@ void processinput_r(int snum) if (psectlotag == 867) { - short sj, nextsj; - sj = headspritesect[psect]; - while (sj >= 0) + SectIterator it(psect); + while ((j = it.NextIndex()) >= 0) { - nextsj = nextspritesect[sj]; - if (sprite[sj].picnum == RRTILE380) - if (sprite[sj].z - (8 << 8) < p->posz) + if (sprite[j].picnum == RRTILE380) + if (sprite[j].z - (8 << 8) < p->posz) psectlotag = 2; - sj = nextsj; } } else if (psectlotag == 7777) diff --git a/source/games/duke/src/premap_d.cpp b/source/games/duke/src/premap_d.cpp index cfcb11b2b..ab687d7af 100644 --- a/source/games/duke/src/premap_d.cpp +++ b/source/games/duke/src/premap_d.cpp @@ -252,12 +252,11 @@ void cacheit_d(void) } } - j = headspritesect[i]; - while (j >= 0) + SectIterator it(i); + while ((j = it.NextIndex()) >= 0) { if (sprite[j].xrepeat != 0 && sprite[j].yrepeat != 0 && (sprite[j].cstat & 32768) == 0) cachespritenum(j); - j = nextspritesect[j]; } precacheMarkedTiles(); diff --git a/source/games/duke/src/premap_r.cpp b/source/games/duke/src/premap_r.cpp index 188a69997..872208994 100644 --- a/source/games/duke/src/premap_r.cpp +++ b/source/games/duke/src/premap_r.cpp @@ -427,12 +427,11 @@ void cacheit_r(void) } } - j = headspritesect[i]; - while(j >= 0) + SectIterator it(i); + while ((j = it.NextIndex()) >= 0) { if(sprite[j].xrepeat != 0 && sprite[j].yrepeat != 0 && (sprite[j].cstat&32768) == 0) cachespritenum(j); - j = nextspritesect[j]; } precacheMarkedTiles(); } @@ -495,10 +494,10 @@ void prelevel_r(int g) switch (sector[i].lotag) { case 41: - k = headspritesect[i]; - while (k != -1) + { + SectIterator it(i); + while ((k = it.NextIndex()) >= 0) { - nexti = nextspritesect[k]; if (sprite[k].picnum == RRTILE11) { dist = sprite[k].lotag << 4; @@ -510,7 +509,6 @@ void prelevel_r(int g) sound = sprite[k].lotag; deletesprite(k); } - k = nexti; } for (j = 0; j < numsectors; j++) { @@ -520,22 +518,23 @@ void prelevel_r(int g) } } break; + } case 42: { short ii; int childsectnum = -1; - k = headspritesect[i]; - while (k != -1) + SectIterator it(i); + while ((k = it.NextIndex()) >= 0) { - nexti = nextspritesect[k]; - if (sprite[k].picnum == RRTILE64) + auto sj = &sprite[k]; + if (sj->picnum == RRTILE64) { - dist = sprite[k].lotag << 4; - speed = sprite[k].hitag; + dist = sj->lotag << 4; + speed = sj->hitag; for (ii = 0; ii < MAXSPRITES; ii++) { if (sprite[ii].picnum == RRTILE66) - if (sprite[ii].lotag == sprite[k].sectnum) + if (sprite[ii].lotag == sj->sectnum) { childsectnum = sprite[ii].sectnum; deletesprite(ii); @@ -543,12 +542,11 @@ void prelevel_r(int g) } deletesprite(k); } - if (sprite[k].picnum == RRTILE65) + if (sj->picnum == RRTILE65) { - sound = sprite[k].lotag; + sound = sj->lotag; deletesprite(k); } - k = nexti; } addminecart(dist, speed, i, sector[i].hitag, sound, childsectnum); break;