From 3d36381752a29b8003dc83ba79722ae7b6063b4a Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 14 Oct 2020 22:18:10 +0200 Subject: [PATCH] - converted all stat iterators outside sector*.cpp. --- source/games/duke/src/actors_r.cpp | 2 +- source/games/duke/src/bowling.cpp | 32 +++++++----------- source/games/duke/src/constants.h | 1 + source/games/duke/src/gameexec.cpp | 15 ++++----- source/games/duke/src/player.cpp | 20 ++++++----- source/games/duke/src/player_d.cpp | 10 +++--- source/games/duke/src/player_r.cpp | 10 +++--- source/games/duke/src/premap.cpp | 8 ++--- source/games/duke/src/premap_d.cpp | 41 +++++++++++------------ source/games/duke/src/premap_r.cpp | 54 ++++++++++++++---------------- source/games/duke/src/render.cpp | 5 ++- source/games/duke/src/savegame.cpp | 21 ++---------- source/games/duke/src/spawn.cpp | 29 ++++++++-------- 13 files changed, 107 insertions(+), 141 deletions(-) diff --git a/source/games/duke/src/actors_r.cpp b/source/games/duke/src/actors_r.cpp index 6d6040b5a..a4dfb3412 100644 --- a/source/games/duke/src/actors_r.cpp +++ b/source/games/duke/src/actors_r.cpp @@ -2571,7 +2571,7 @@ void rr_specialstats() } } - it.Reset(105); + it.Reset(STAT_BOWLING); while ((i = it.NextIndex()) >= 0) { auto s = &sprite[i]; diff --git a/source/games/duke/src/bowling.cpp b/source/games/duke/src/bowling.cpp index c0682c471..ef8314f32 100644 --- a/source/games/duke/src/bowling.cpp +++ b/source/games/duke/src/bowling.cpp @@ -37,34 +37,26 @@ short pinsectorresetdown(short sect); void ballreturn(short spr) { - short j, i, nexti, nextj; - i = headspritestat[105]; - while (i >= 0) + int j, i; + StatIterator it(STAT_BOWLING); + while ((i = it.NextIndex()) >= 0) { - nexti = nextspritestat[i]; - if (sprite[i].picnum == RRTILE281) - if (sprite[spr].sectnum == sprite[i].sectnum) + auto si = &sprite[i]; + if (si->picnum == RRTILE281 && sprite[spr].sectnum == si->sectnum) { - j = headspritestat[105]; - while (j >= 0) + StatIterator it2(STAT_BOWLING); + while ((j = it2.NextIndex()) >= 0) { - nextj = nextspritestat[j]; - if (sprite[j].picnum == RRTILE282) - if (sprite[i].hitag == sprite[j].hitag) + auto sj = &sprite[j]; + if (sj->picnum == RRTILE282 && si->hitag == sj->hitag) fi.spawn(j, BOWLINGBALLSPRITE); - if (sprite[j].picnum == RRTILE280) - if (sprite[i].hitag == sprite[j].hitag) - if (sprite[j].lotag == 0) + if (sj->picnum == RRTILE280 && si->hitag == sj->hitag && sj->lotag == 0) { - sprite[j].lotag = 100; - sprite[j].extra++; - pinsectorresetdown(sprite[j].sectnum); + sj->lotag = 100; + sj->extra++; } - j = nextj; } } - - i = nexti; } } diff --git a/source/games/duke/src/constants.h b/source/games/duke/src/constants.h index fc4a9eb31..b7b9f436f 100644 --- a/source/games/duke/src/constants.h +++ b/source/games/duke/src/constants.h @@ -255,6 +255,7 @@ enum STAT_RAROR = 15, STAT_DESTRUCT = 100, + STAT_BOWLING = 105, STAT_NETALLOC = MAXSTATUS-1 }; diff --git a/source/games/duke/src/gameexec.cpp b/source/games/duke/src/gameexec.cpp index 6abe63bbd..6591dbbd2 100644 --- a/source/games/duke/src/gameexec.cpp +++ b/source/games/duke/src/gameexec.cpp @@ -2070,12 +2070,11 @@ int ParseState::parse(void) updatesector(ps[g_p].posx,ps[g_p].posy,&ps[g_p].cursectnum); setpal(&ps[g_p]); - j = headspritestat[1]; - while (j >= 0) + StatIterator it(STAT_ACTOR); + while ((j = it.NextIndex()) >= 0) { if (sprite[j].picnum == TILE_CAMERA1) sprite[j].yvel = 0; - j = nextspritestat[j]; } } @@ -2934,8 +2933,8 @@ int ParseState::parse(void) lFound = -1; lDist = 32767; // big number - j = headspritestat[1]; // all sprites - while (j >= 0) + StatIterator it(STAT_ACTOR); + while ((j = it.NextIndex()) >= 0) { if (sprite[j].picnum == lType) { @@ -2949,7 +2948,6 @@ int ParseState::parse(void) } } - j = nextspritestat[j]; } SetGameVarID(lVarID, lFound, g_i, g_p); @@ -2980,8 +2978,8 @@ int ParseState::parse(void) lFound = -1; lDist = 32767; // big number - j = headspritestat[1]; // all sprites - while (j >= 0) + StatIterator it(STAT_ACTOR); + while ((j = it.NextIndex()) >= 0) { if (sprite[j].picnum == lType) { @@ -2995,7 +2993,6 @@ int ParseState::parse(void) } } - j = nextspritestat[j]; } SetGameVarID(lVarID, lFound, g_i, g_p); diff --git a/source/games/duke/src/player.cpp b/source/games/duke/src/player.cpp index 4a2ca70fb..a8c1d9b90 100644 --- a/source/games/duke/src/player.cpp +++ b/source/games/duke/src/player.cpp @@ -346,22 +346,25 @@ int aim(spritetype* s, int aang) { if (j >= 0) break; - for (i = headspritestat[aimstats[k]]; i >= 0; i = nextspritestat[i]) - if (sprite[i].xrepeat > 0 && sprite[i].extra >= 0 && (sprite[i].cstat & (257 + 32768)) == 257) - if (badguy(&sprite[i]) || k < 2) + + StatIterator it(aimstats[k]); + while ((i = it.NextIndex()) >= 0) + { + auto sp = &sprite[i]; + if (sp->xrepeat > 0 && sp->extra >= 0 && (sp->cstat & (257 + 32768)) == 257) + if (badguy(sp) || k < 2) { - auto sp = &sprite[i]; - if (badguy(&sprite[i]) || sp->picnum == TILE_APLAYER) + if (badguy(sp) || sp->picnum == TILE_APLAYER) { if (sp->picnum == TILE_APLAYER && (isRR() && ud.ffire == 0) && ud.coop == 1 && s->picnum == TILE_APLAYER && - s != &sprite[i]) + s != sp) continue; - if (gotshrinker && sprite[i].xrepeat < 30 && !(actorinfo[sp->picnum].flags & SFLAG_SHRINKAUTOAIM)) continue; - if (gotfreezer && sprite[i].pal == 1) continue; + if (gotshrinker && sp->xrepeat < 30 && !(actorinfo[sp->picnum].flags & SFLAG_SHRINKAUTOAIM)) continue; + if (gotfreezer && sp->pal == 1) continue; } xv = (sp->x - s->x); @@ -387,6 +390,7 @@ int aim(spritetype* s, int aang) } } } + } } return j; diff --git a/source/games/duke/src/player_d.cpp b/source/games/duke/src/player_d.cpp index 849d52558..9719fb646 100644 --- a/source/games/duke/src/player_d.cpp +++ b/source/games/duke/src/player_d.cpp @@ -594,13 +594,12 @@ void shoot_d(int i, int atwith) } } - l = headspritestat[5]; - while (l >= 0) + StatIterator it(STAT_MISC); + while ((l = it.NextIndex()) >= 0) { if (sprite[l].picnum == BULLETHOLE) if (dist(&sprite[l], &sprite[k]) < (12 + (krand() & 7))) goto SKIPBULLETHOLE; - l = nextspritestat[l]; } l = fi.spawn(k, BULLETHOLE); sprite[l].xvel = -1; @@ -1232,8 +1231,8 @@ void selectweapon_d(int snum, int weap) // playernum, weaponnum if (j == HANDBOMB_WEAPON && p->ammo_amount[HANDBOMB_WEAPON] == 0) { - k = headspritestat[1]; - while (k >= 0) + StatIterator it(STAT_ACTOR); + while ((k = it.NextIndex()) >= 0) { if (sprite[k].picnum == HEAVYHBOMB && sprite[k].owner == p->i) { @@ -1241,7 +1240,6 @@ void selectweapon_d(int snum, int weap) // playernum, weaponnum j = HANDREMOTE_WEAPON; break; } - k = nextspritestat[k]; } } diff --git a/source/games/duke/src/player_r.cpp b/source/games/duke/src/player_r.cpp index e7d3a4eb8..7d0d4fc00 100644 --- a/source/games/duke/src/player_r.cpp +++ b/source/games/duke/src/player_r.cpp @@ -507,13 +507,12 @@ void shoot_r(int i, int atwith) } } - l = headspritestat[5]; - while (l >= 0) + StatIterator it(STAT_MISC); + while ((l = it.NextIndex()) >= 0) { if (sprite[l].picnum == BULLETHOLE) if (dist(&sprite[l], &sprite[k]) < (12 + (krand() & 7))) goto SKIPBULLETHOLE; - l = nextspritestat[l]; } l = fi.spawn(k, BULLETHOLE); sprite[l].xvel = -1; @@ -1032,8 +1031,8 @@ void selectweapon_r(int snum, int weap) if (j == DYNAMITE_WEAPON && p->ammo_amount[DYNAMITE_WEAPON] == 0) { - k = headspritestat[1]; - while (k >= 0) + StatIterator it(STAT_ACTOR); + while ((k = it.NextIndex()) >= 0) { if (sprite[k].picnum == HEAVYHBOMB && sprite[k].owner == p->i) { @@ -1041,7 +1040,6 @@ void selectweapon_r(int snum, int weap) j = THROWINGDYNAMITE_WEAPON; break; } - k = nextspritestat[k]; } } else if (j == KNEE_WEAPON && isRRRA()) diff --git a/source/games/duke/src/premap.cpp b/source/games/duke/src/premap.cpp index bc80d1939..de7247995 100644 --- a/source/games/duke/src/premap.cpp +++ b/source/games/duke/src/premap.cpp @@ -501,7 +501,7 @@ void resetprestat(int snum,int g) void resetpspritevars(int g) { int i, j; - short nexti, circ; + short circ; int firstx, firsty; spritetype* s; int aimmode[MAXPLAYERS], autoaim[MAXPLAYERS]; @@ -571,10 +571,9 @@ void resetpspritevars(int g) which_palookup = 9; j = connecthead; - i = headspritestat[STAT_PLAYER]; - while (i >= 0) + StatIterator it(STAT_PLAYER); + while ((i = it.NextIndex()) >= 0) { - nexti = nextspritestat[i]; s = &sprite[i]; if (numplayersprites == MAXPLAYERS) @@ -641,7 +640,6 @@ void resetpspritevars(int g) } else deletesprite(i); - i = nexti; } } diff --git a/source/games/duke/src/premap_d.cpp b/source/games/duke/src/premap_d.cpp index ab687d7af..7c2d89bb6 100644 --- a/source/games/duke/src/premap_d.cpp +++ b/source/games/duke/src/premap_d.cpp @@ -270,43 +270,42 @@ void cacheit_d(void) void prelevel_d(int g) { - short i, nexti, j, startwall, endwall, lotaglist; + short i, j, startwall, endwall, lotaglist; short lotags[65]; prelevel_common(g); - i = headspritestat[0]; - while (i >= 0) + StatIterator it(STAT_DEFAULT); + while ((i = it.NextIndex()) >= 0) { - nexti = nextspritestat[i]; + auto si = &sprite[i]; LoadActor(i, -1, -1); - if (sprite[i].lotag == -1 && (sprite[i].cstat & 16)) + if (si->lotag == -1 && (si->cstat & 16)) { - ps[0].exitx = sprite[i].x; - ps[0].exity = sprite[i].y; + ps[0].exitx = si->x; + ps[0].exity = si->y; } - else switch (sprite[i].picnum) + else switch (si->picnum) { case GPSPEED: - sector[sprite[i].sectnum].extra = sprite[i].lotag; + sector[si->sectnum].extra = si->lotag; deletesprite(i); break; case CYCLER: if (numcyclers >= MAXCYCLERS) I_Error("Too many cycling sectors."); - cyclers[numcyclers][0] = sprite[i].sectnum; - cyclers[numcyclers][1] = sprite[i].lotag; - cyclers[numcyclers][2] = sprite[i].shade; - cyclers[numcyclers][3] = sector[sprite[i].sectnum].floorshade; - cyclers[numcyclers][4] = sprite[i].hitag; - cyclers[numcyclers][5] = (sprite[i].ang == 1536); + cyclers[numcyclers][0] = si->sectnum; + cyclers[numcyclers][1] = si->lotag; + cyclers[numcyclers][2] = si->shade; + cyclers[numcyclers][3] = sector[si->sectnum].floorshade; + cyclers[numcyclers][4] = si->hitag; + cyclers[numcyclers][5] = (si->ang == 1536); numcyclers++; deletesprite(i); break; } - i = nexti; } for (i = 0; i < MAXSPRITES; i++) @@ -328,8 +327,8 @@ void prelevel_d(int g) lotaglist = 0; - i = headspritestat[0]; - while (i >= 0) + it.Reset(STAT_DEFAULT); + while ((i = it.NextIndex()) >= 0) { switch (sprite[i].picnum) { @@ -357,17 +356,15 @@ void prelevel_d(int g) if (lotaglist > 64) I_Error("Too many switches (64 max)."); - j = headspritestat[3]; - while (j >= 0) + StatIterator it1(STAT_EFFECTOR); + while ((j = it1.NextIndex()) >= 0) { if (sprite[j].lotag == 12 && sprite[j].hitag == sprite[i].lotag) hittype[j].temp_data[0] = 1; - j = nextspritestat[j]; } } break; } - i = nextspritestat[i]; } mirrorcnt = 0; diff --git a/source/games/duke/src/premap_r.cpp b/source/games/duke/src/premap_r.cpp index 872208994..2844c615c 100644 --- a/source/games/duke/src/premap_r.cpp +++ b/source/games/duke/src/premap_r.cpp @@ -446,7 +446,6 @@ void prelevel_r(int g) { struct player_struct* p; short i; - short nexti; short j; short startwall; short endwall; @@ -554,37 +553,37 @@ void prelevel_r(int g) } } - i = headspritestat[0]; - while (i >= 0) + StatIterator it(STAT_DEFAULT); + while ((i = it.NextIndex()) >= 0) { - nexti = nextspritestat[i]; + auto si = &sprite[i]; LoadActor(i, -1, -1); - if (sprite[i].lotag == -1 && (sprite[i].cstat & 16)) + if (si->lotag == -1 && (si->cstat & 16)) { - ps[0].exitx = sprite[i].x; - ps[0].exity = sprite[i].y; + ps[0].exitx = si->x; + ps[0].exity = si->y; } - else switch (sprite[i].picnum) + else switch (si->picnum) { case NUKEBUTTON: chickenplant = 1; break; case GPSPEED: - sector[sprite[i].sectnum].extra = sprite[i].lotag; + sector[si->sectnum].extra = si->lotag; deletesprite(i); break; case CYCLER: if (numcyclers >= MAXCYCLERS) I_Error("Too many cycling sectors."); - cyclers[numcyclers][0] = sprite[i].sectnum; - cyclers[numcyclers][1] = sprite[i].lotag; - cyclers[numcyclers][2] = sprite[i].shade; - cyclers[numcyclers][3] = sector[sprite[i].sectnum].floorshade; - cyclers[numcyclers][4] = sprite[i].hitag; - cyclers[numcyclers][5] = (sprite[i].ang == 1536); + cyclers[numcyclers][0] = si->sectnum; + cyclers[numcyclers][1] = si->lotag; + cyclers[numcyclers][2] = si->shade; + cyclers[numcyclers][3] = sector[si->sectnum].floorshade; + cyclers[numcyclers][4] = si->hitag; + cyclers[numcyclers][5] = (si->ang == 1536); numcyclers++; deletesprite(i); break; @@ -600,12 +599,12 @@ void prelevel_r(int g) break; case RRTILE68: - shadedsector[sprite[i].sectnum] = 1; + shadedsector[si->sectnum] = 1; deletesprite(i); break; case RRTILE67: - sprite[i].cstat |= 32768; + si->cstat |= 32768; break; case SOUNDFX: @@ -613,16 +612,15 @@ void prelevel_r(int g) I_Error("Too many ambient effects"); else { - ambienthitag[ambientfx] = sprite[i].hitag; - ambientlotag[ambientfx] = sprite[i].lotag; - sprite[i].ang = ambientfx; + ambienthitag[ambientfx] = si->hitag; + ambientlotag[ambientfx] = si->lotag; + si->ang = ambientfx; ambientfx++; - sprite[i].lotag = 0; - sprite[i].hitag = 0; + si->lotag = 0; + si->hitag = 0; } break; } - i = nexti; } for (i = 0; i < MAXSPRITES; i++) @@ -687,8 +685,8 @@ void prelevel_r(int g) lotaglist = 0; - i = headspritestat[0]; - while (i >= 0) + it.Reset(STAT_DEFAULT); + while ((i = it.NextIndex()) >= 0) { switch (sprite[i].picnum) { @@ -721,17 +719,15 @@ void prelevel_r(int g) if (lotaglist > 64) I_Error("Too many switches (64 max)."); - j = headspritestat[3]; - while (j >= 0) + StatIterator it1(STAT_EFFECTOR); + while ((j = it1.NextIndex()) >= 0) { if (sprite[j].lotag == 12 && sprite[j].hitag == sprite[i].lotag) hittype[j].temp_data[0] = 1; - j = nextspritestat[j]; } } break; } - i = nextspritestat[i]; } mirrorcnt = 0; diff --git a/source/games/duke/src/render.cpp b/source/games/duke/src/render.cpp index 2a09cc92b..8ac659a6a 100644 --- a/source/games/duke/src/render.cpp +++ b/source/games/duke/src/render.cpp @@ -175,8 +175,8 @@ void se40code(int x, int y, int z, binangle a, fixedhoriz h, int smoothratio) else if (isRRRA()) tag = 150; else return; - i = headspritestat[STAT_RAROR]; - while (i >= 0) + StatIterator it(STAT_RAROR); + while ((i = it.NextIndex()) >= 0) { switch (sprite[i].lotag - tag + 40) { @@ -192,7 +192,6 @@ void se40code(int x, int y, int z, binangle a, fixedhoriz h, int smoothratio) SE40_Draw(tag, i, x, y, z, a, h, smoothratio); break; } - i = nextspritestat[i]; } } diff --git a/source/games/duke/src/savegame.cpp b/source/games/duke/src/savegame.cpp index 97b736819..5251c6ef2 100644 --- a/source/games/duke/src/savegame.cpp +++ b/source/games/duke/src/savegame.cpp @@ -43,8 +43,9 @@ static void recreateinterpolations() { numinterpolations = 0; - int k = headspritestat[STAT_EFFECTOR]; - while (k >= 0) + int k; + StatIterator it(STAT_EFFECTOR); + while ((k = it.NextIndex()) >= 0) { switch (sprite[k].lotag) { @@ -71,8 +72,6 @@ static void recreateinterpolations() setsectinterpolate(k); break; } - - k = nextspritestat[k]; } for (int i = numinterpolations - 1; i >= 0; i--) bakipos[i] = *curipos[i]; @@ -500,20 +499,6 @@ void GameInterface::SerializeGameState(FSerializer& arc) show_shareware = 0; everyothertime = 0; - // should be unnecessary with the sounds getting serialized as well. - #if 0 - if (ps[myconnectindex].jetpack_on) - spritesound(DUKE_JETPACK_IDLE, ps[myconnectindex].i); - - // Update sound state in SFX sprites. - for (int i = headspritestat[STAT_FX]; i >= 0; i = nextspritestat[i]) - if (sprite[i].picnum == MUSICANDSFX) - { - hittype[i].temp_data[1] = SoundEnabled(); - hittype[i].temp_data[0] = 0; - } - - #endif FX_SetReverb(0); } diff --git a/source/games/duke/src/spawn.cpp b/source/games/duke/src/spawn.cpp index ab057dbbd..45d5335ea 100644 --- a/source/games/duke/src/spawn.cpp +++ b/source/games/duke/src/spawn.cpp @@ -491,30 +491,31 @@ void initcrane(int j, int i, int CRANEPOLE) msy[tempwallptr] = sp->y; msx[tempwallptr + 2] = sp->z; - int s = headspritestat[0]; - while (s >= 0) + int s; + StatIterator it(STAT_DEFAULT); + while ((s = it.NextIndex()) >= 0) { - if (sprite[s].picnum == CRANEPOLE && sp->hitag == (sprite[s].hitag)) + auto ss = &sprite[s]; + if (ss->picnum == CRANEPOLE && sp->hitag == (ss->hitag)) { msy[tempwallptr + 2] = s; - t[1] = sprite[s].sectnum; + t[1] = ss->sectnum; - sprite[s].xrepeat = 48; - sprite[s].yrepeat = 128; + ss->xrepeat = 48; + ss->yrepeat = 128; - msx[tempwallptr + 1] = sprite[s].x; - msy[tempwallptr + 1] = sprite[s].y; + msx[tempwallptr + 1] = ss->x; + msy[tempwallptr + 1] = ss->y; - sprite[s].x = sp->x; - sprite[s].y = sp->y; - sprite[s].z = sp->z; - sprite[s].shade = sp->shade; + ss->x = sp->x; + ss->y = sp->y; + ss->z = sp->z; + ss->shade = sp->shade; - setsprite(s, sprite[s].x, sprite[s].y, sprite[s].z); + setsprite(s, ss->x, ss->y, ss->z); break; } - s = nextspritestat[s]; } tempwallptr += 3;