From 760a557f73cd7ebfb6d83ed1192ad5a075466beb Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 14 Oct 2020 21:40:15 +0200 Subject: [PATCH] - converted the remaining sector iterators in Duke. --- source/build/include/build.h | 35 ----------------- source/games/duke/src/player_d.cpp | 2 - source/games/duke/src/player_r.cpp | 2 - source/games/duke/src/render.cpp | 27 +++++-------- source/games/duke/src/sectors.cpp | 60 +++++++++++++++-------------- source/games/duke/src/sectors_d.cpp | 20 ++++------ source/games/duke/src/sectors_r.cpp | 42 ++++++++------------ 7 files changed, 66 insertions(+), 122 deletions(-) diff --git a/source/build/include/build.h b/source/build/include/build.h index 0271ce2c7..199155854 100644 --- a/source/build/include/build.h +++ b/source/build/include/build.h @@ -478,41 +478,6 @@ SPRITE VARIABLES: be in some sector, and must have some kind of status that you define. -Coding example #1: - To go through all the sprites in sector 1, the code can look like this: - - sectnum = 1; - i = headspritesect[sectnum]; - while (i != -1) - { - nexti = nextspritesect[i]; - - //your code goes here - //ex: printf("Sprite %d is in sector %d\n",i,sectnum); - - i = nexti; - } - -Coding example #2: - To go through all sprites with status = 1, the code can look like this: - - statnum = 1; //status 1 - i = headspritestat[statnum]; - while (i != -1) - { - nexti = nextspritestat[i]; - - //your code goes here - //ex: printf("Sprite %d has a status of 1 (active)\n",i,statnum); - - i = nexti; - } - - insertsprite(short sectnum, short statnum); - deletesprite(short spritenum); - changespritesect(short spritenum, short newsectnum); - changespritestat(short spritenum, short newstatnum); - TILE VARIABLES: NUMTILES - the number of tiles found TILES.DAT. diff --git a/source/games/duke/src/player_d.cpp b/source/games/duke/src/player_d.cpp index c4566f226..849d52558 100644 --- a/source/games/duke/src/player_d.cpp +++ b/source/games/duke/src/player_d.cpp @@ -333,7 +333,6 @@ void shoot_d(int i, int atwith) { if (sprite[k].statnum == 3 && sprite[k].lotag == 13) return; - k = nextspritesect[k]; } } @@ -592,7 +591,6 @@ void shoot_d(int i, int atwith) { if (sprite[l].statnum == 3 && sprite[l].lotag == 13) goto SKIPBULLETHOLE; - l = nextspritesect[l]; } } diff --git a/source/games/duke/src/player_r.cpp b/source/games/duke/src/player_r.cpp index 6d4e12847..e7d3a4eb8 100644 --- a/source/games/duke/src/player_r.cpp +++ b/source/games/duke/src/player_r.cpp @@ -222,7 +222,6 @@ void shoot_r(int i, int atwith) { if (sprite[k].statnum == 3 && sprite[k].lotag == 13) return; - k = nextspritesect[k]; } } @@ -505,7 +504,6 @@ void shoot_r(int i, int atwith) { if (sprite[l].statnum == 3 && sprite[l].lotag == 13) goto SKIPBULLETHOLE; - l = nextspritesect[l]; } } diff --git a/source/games/duke/src/render.cpp b/source/games/duke/src/render.cpp index fb5ad0dd4..2a09cc92b 100644 --- a/source/games/duke/src/render.cpp +++ b/source/games/duke/src/render.cpp @@ -389,7 +389,7 @@ void setdrugmode(player_struct *p, int oyrepeat) static void geometryEffect(int cposx, int cposy, int cposz, binangle cang, fixedhoriz choriz, int sect, int smoothratio) { - short gs, tgsect, nextspr, geosect, geoid = 0; + short gs, tgsect, geosect, geoid = 0; int spr; renderDrawRoomsQ16(cposx, cposy, cposz, cang.asq16(), choriz.asq16(), sect); fi.animatesprites(cposx, cposy, cang.asbuild(), smoothratio); @@ -397,13 +397,12 @@ static void geometryEffect(int cposx, int cposy, int cposz, binangle cang, fixed for (gs = 0; gs < geocnt; gs++) { tgsect = geosector[gs]; - spr = headspritesect[tgsect]; - while (spr != -1) + + SectIterator it(tgsect); + while ((spr = it.NextIndex()) >= 0) { - nextspr = nextspritesect[spr]; changespritesect((short)spr, geosectorwarp[gs]); setsprite((short)spr, sprite[spr].x -= geox[gs], sprite[spr].y -= geoy[gs], sprite[spr].z); - spr = nextspr; } if (geosector[gs] == sect) { @@ -419,13 +418,11 @@ static void geometryEffect(int cposx, int cposy, int cposz, binangle cang, fixed for (gs = 0; gs < geocnt; gs++) { tgsect = geosectorwarp[gs]; - spr = headspritesect[tgsect]; - while (spr != -1) + SectIterator it(tgsect); + while ((spr = it.NextIndex()) >= 0) { - nextspr = nextspritesect[spr]; changespritesect((short)spr, geosector[gs]); setsprite((short)spr, sprite[spr].x += geox[gs], sprite[spr].y += geoy[gs], sprite[spr].z); - spr = nextspr; } } fi.animatesprites(cposx, cposy, cang.asbuild(), smoothratio); @@ -433,13 +430,11 @@ static void geometryEffect(int cposx, int cposy, int cposz, binangle cang, fixed for (gs = 0; gs < geocnt; gs++) { tgsect = geosector[gs]; - spr = headspritesect[tgsect]; - while (spr != -1) + SectIterator it(tgsect); + while ((spr = it.NextIndex()) >= 0) { - nextspr = nextspritesect[spr]; changespritesect((short)spr, geosectorwarp2[gs]); setsprite((short)spr, sprite[spr].x -= geox2[gs], sprite[spr].y -= geoy2[gs], sprite[spr].z); - spr = nextspr; } if (geosector[gs] == sect) { @@ -455,13 +450,11 @@ static void geometryEffect(int cposx, int cposy, int cposz, binangle cang, fixed for (gs = 0; gs < geocnt; gs++) { tgsect = geosectorwarp2[gs]; - spr = headspritesect[tgsect]; - while (spr != -1) + SectIterator it(tgsect); + while ((spr = it.NextIndex()) >= 0) { - nextspr = nextspritesect[spr]; changespritesect((short)spr, geosector[gs]); setsprite((short)spr, sprite[spr].x += geox2[gs], sprite[spr].y += geoy2[gs], sprite[spr].z); - spr = nextspr; } } fi.animatesprites(cposx, cposy, cang.asbuild(), smoothratio); diff --git a/source/games/duke/src/sectors.cpp b/source/games/duke/src/sectors.cpp index ccdd60ee2..1373e069a 100644 --- a/source/games/duke/src/sectors.cpp +++ b/source/games/duke/src/sectors.cpp @@ -57,18 +57,20 @@ int callsound(int sn, int whatsprite) return -1; } - int i = headspritesect[sn]; - while (i >= 0) + int i; + SectIterator it(sn); + while ((i = it.NextIndex()) >= 0) { - if (sprite[i].picnum == MUSICANDSFX && sprite[i].lotag < 1000) + auto si = &sprite[i]; + if (si->picnum == MUSICANDSFX && si->lotag < 1000) { if (whatsprite == -1) whatsprite = i; - int snum = sprite[i].lotag; + int snum = si->lotag; auto flags = S_GetUserFlags(snum); // Reset if the desired actor isn't playing anything. - bool hival = S_IsSoundValid(sprite[i].hitag); + bool hival = S_IsSoundValid(si->hitag); if (hittype[i].temp_data[0] == 1 && !hival) { if (!S_CheckActorSoundPlaying(hittype[i].temp_data[5], snum)) @@ -81,27 +83,26 @@ int callsound(int sn, int whatsprite) { if (snum) { - if (sprite[i].hitag && snum != sprite[i].hitag) - S_StopSound(sprite[i].hitag, hittype[i].temp_data[5]); + if (si->hitag && snum != si->hitag) + S_StopSound(si->hitag, hittype[i].temp_data[5]); S_PlayActorSound(snum, whatsprite); hittype[i].temp_data[5] = whatsprite; } - if ((sector[sprite[i].sectnum].lotag & 0xff) != ST_22_SPLITTING_DOOR) + if ((sector[si->sectnum].lotag & 0xff) != ST_22_SPLITTING_DOOR) hittype[i].temp_data[0] = 1; } } - else if (sprite[i].hitag < 1000) + else if (si->hitag < 1000) { - if ((flags & SF_LOOP) || (sprite[i].hitag && sprite[i].hitag != sprite[i].lotag)) - S_StopSound(sprite[i].lotag, hittype[i].temp_data[5]); - if (sprite[i].hitag) S_PlayActorSound(sprite[i].hitag, whatsprite); + if ((flags & SF_LOOP) || (si->hitag && si->hitag != si->lotag)) + S_StopSound(si->lotag, hittype[i].temp_data[5]); + if (si->hitag) S_PlayActorSound(si->hitag, whatsprite); hittype[i].temp_data[0] = 0; hittype[i].temp_data[5] = whatsprite; } - return sprite[i].lotag; + return si->lotag; } - i = nextspritesect[i]; } return -1; } @@ -355,13 +356,16 @@ void doanimations(void) ps[p].poszv = 0; } - for (j = headspritesect[dasect]; j >= 0; j = nextspritesect[j]) + SectIterator it(dasect); + while ((j = it.NextIndex()) >= 0) + { if (sprite[j].statnum != STAT_EFFECTOR) { hittype[j].bposz = sprite[j].z; sprite[j].z += v; hittype[j].floorz = sector[dasect].floorz + v; } + } } *animateptr(i) = a; @@ -634,15 +638,14 @@ void operatesectors(int sn, int ii) return; case ST_15_WARP_ELEVATOR://Warping elevators - + { if (sprite[ii].picnum != TILE_APLAYER) return; // if(ps[sprite[ii].yvel].select_dir == 1) return; - i = headspritesect[sn]; - while (i >= 0) + SectIterator it(sn); + while ((i = it.NextIndex()) >= 0) { if (sprite[i].picnum == SECTOREFFECTOR && sprite[i].lotag == 17) break; - i = nextspritesect[i]; } if (sprite[ii].sectnum == sn) @@ -662,7 +665,7 @@ void operatesectors(int sn, int ii) } return; - + } case ST_16_PLATFORM_DOWN: case ST_17_PLATFORM_UP: @@ -741,15 +744,14 @@ void operatesectors(int sn, int ii) if (sptr->lotag & 0x8000) { - i = headspritesect[sn]; - while (i >= 0) + SectIterator it(sn); + while ((i = it.NextIndex()) >= 0) { if (sprite[i].statnum == 3 && sprite[i].lotag == 9) { j = sprite[i].z; break; } - i = nextspritesect[i]; } if (i == -1) j = sptr->floorz; @@ -910,14 +912,14 @@ void operatesectors(int sn, int ii) case ST_28_DROP_FLOOR: + { //activate the rest of them - j = headspritesect[sn]; - while (j >= 0) + SectIterator it(sn); + while ((j = it.NextIndex()) >= 0) { if (sprite[j].statnum == 3 && (sprite[j].lotag & 0xff) == 21) break; //Found it - j = nextspritesect[j]; } j = sprite[j].hitag; @@ -934,6 +936,7 @@ void operatesectors(int sn, int ii) return; } + } } @@ -1005,8 +1008,8 @@ void operateactivators(int low, int snum) if (sector[sprite[i].sectnum].lotag < 3) { - j = headspritesect[sprite[i].sectnum]; - while (j >= 0) + SectIterator it(sprite[i].sectnum); + while ((j = it.NextIndex()) >= 0) { if (sprite[j].statnum == 3) switch (sprite[j].lotag) { @@ -1019,7 +1022,6 @@ void operateactivators(int low, int snum) callsound(sprite[i].sectnum, j); break; } - j = nextspritesect[j]; } } diff --git a/source/games/duke/src/sectors_d.cpp b/source/games/duke/src/sectors_d.cpp index 10ca07370..192e93c3b 100644 --- a/source/games/duke/src/sectors_d.cpp +++ b/source/games/duke/src/sectors_d.cpp @@ -620,8 +620,8 @@ void activatebysector_d(int sect, int j) didit = 0; - i = headspritesect[sect]; - while (i >= 0) + SectIterator it(sect); + while ((i = it.NextIndex()) >= 0) { if (sprite[i].picnum == ACTIVATOR) { @@ -629,7 +629,6 @@ void activatebysector_d(int sect, int j) didit = 1; // return; } - i = nextspritesect[i]; } if (didit == 0) @@ -986,8 +985,8 @@ bool checkhitceiling_d(int sn) if (!sector[sn].hitag) { - i = headspritesect[sn]; - while (i >= 0) + SectIterator it(sn); + while ((i = it.NextIndex()) >= 0) { if (sprite[i].picnum == SECTOREFFECTOR && sprite[i].lotag == 12) { @@ -1000,7 +999,6 @@ bool checkhitceiling_d(int sn) } break; } - i = nextspritesect[i]; } } @@ -1782,12 +1780,11 @@ void checksectors_d(int snum) if (neartagsector >= 0 && (sector[neartagsector].lotag & 16384) == 0 && isanearoperator(sector[neartagsector].lotag)) { - i = headspritesect[neartagsector]; - while (i >= 0) + SectIterator it(neartagsector); + while ((i = it.NextIndex()) >= 0) { if (sprite[i].picnum == ACTIVATOR || sprite[i].picnum == MASTERSWITCH) return; - i = nextspritesect[i]; } operatesectors(neartagsector, p->i); } @@ -1795,11 +1792,10 @@ void checksectors_d(int snum) { if (isanunderoperator(sector[sprite[p->i].sectnum].lotag)) { - i = headspritesect[sprite[p->i].sectnum]; - while (i >= 0) + SectIterator it(sprite[p->i].sectnum); + while ((i = it.NextIndex()) >= 0) { if (sprite[i].picnum == ACTIVATOR || sprite[i].picnum == MASTERSWITCH) return; - i = nextspritesect[i]; } operatesectors(sprite[p->i].sectnum, p->i); } diff --git a/source/games/duke/src/sectors_r.cpp b/source/games/duke/src/sectors_r.cpp index 1afa4c932..4ea539ac5 100644 --- a/source/games/duke/src/sectors_r.cpp +++ b/source/games/duke/src/sectors_r.cpp @@ -901,15 +901,14 @@ void activatebysector_r(int sect, int j) { short i; - i = headspritesect[sect]; - while (i >= 0) + SectIterator it(sect); + while ((i = it.NextIndex()) >= 0) { if (sprite[i].picnum == ACTIVATOR) { operateactivators(sprite[i].lotag, -1); // return; } - i = nextspritesect[i]; } if (sector[sect].lotag != 22) @@ -1072,16 +1071,14 @@ void checkhitwall_r(int spr, int dawallnum, int x, int y, int z, int atwith) case RRTILE3643 + 2: case RRTILE3643 + 3: { - short sect; - short unk = 0; - short jj; - short nextjj; - short startwall, endwall; + int sect; + int unk = 0; + int jj; + int startwall, endwall; sect = wall[wal->nextwall].nextsector; - jj = headspritesect[sect]; - while (jj != -1) + SectIterator it(sect); + while ((jj = it.NextIndex()) >= 0) { - nextjj = nextspritesect[jj]; s = &sprite[jj]; if (s->lotag == 6) { @@ -1099,7 +1096,6 @@ void checkhitwall_r(int spr, int dawallnum, int x, int y, int z, int atwith) deletesprite(jj); } } - jj = nextjj; } return; } @@ -1495,8 +1491,8 @@ bool checkhitceiling_r(int sn) if (!sector[sn].hitag) { - i = headspritesect[sn]; - while (i >= 0) + SectIterator it(sn); + while ((i = it.NextIndex()) >= 0) { if (sprite[i].picnum == SECTOREFFECTOR && (sprite[i].lotag == 12 || (isRRRA() && (sprite[i].lotag == 47 || sprite[i].lotag == 48)))) { @@ -1509,7 +1505,6 @@ bool checkhitceiling_r(int sn) } break; } - i = nextspritesect[i]; } } @@ -2732,12 +2727,11 @@ void checksectors_r(int snum) if (neartagsector >= 0 && (sector[neartagsector].lotag & 16384) == 0 && isanearoperator(sector[neartagsector].lotag)) { short unk = 0; - i = headspritesect[neartagsector]; - while (i >= 0) + SectIterator it(neartagsector); + while ((i = it.NextIndex()) >= 0) { if (sprite[i].picnum == ACTIVATOR || sprite[i].picnum == MASTERSWITCH) return; - i = nextspritesect[i]; } if (haskey(neartagsector, snum)) operatesectors(neartagsector, p->i); @@ -2754,11 +2748,10 @@ void checksectors_r(int snum) { if (isanunderoperator(sector[sprite[p->i].sectnum].lotag)) { - i = headspritesect[sprite[p->i].sectnum]; - while (i >= 0) + SectIterator it(sprite[p->i].sectnum); + while ((i = it.NextIndex()) >= 0) { if (sprite[i].picnum == ACTIVATOR || sprite[i].picnum == MASTERSWITCH) return; - i = nextspritesect[i]; } if (haskey(neartagsector, snum)) operatesectors(sprite[p->i].sectnum, p->i); @@ -2902,16 +2895,15 @@ void dofurniture(int wl, int sect, int snum) void tearitup(int sect) { - int j = headspritesect[sect]; - while (j != -1) + int j; + SectIterator it(sect); + while ((j = it.NextIndex()) >= 0) { - int nextj = nextspritesect[j]; if (sprite[j].picnum == DESTRUCTO) { hittype[j].picnum = SHOTSPARK1; hittype[j].extra = 1; } - j = nextj; } } END_DUKE_NS