- converted all stat iterators outside sector*.cpp.

This commit is contained in:
Christoph Oelckers 2020-10-14 22:18:10 +02:00
parent 760a557f73
commit 3d36381752
13 changed files with 107 additions and 141 deletions

View file

@ -2571,7 +2571,7 @@ void rr_specialstats()
} }
} }
it.Reset(105); it.Reset(STAT_BOWLING);
while ((i = it.NextIndex()) >= 0) while ((i = it.NextIndex()) >= 0)
{ {
auto s = &sprite[i]; auto s = &sprite[i];

View file

@ -37,34 +37,26 @@ short pinsectorresetdown(short sect);
void ballreturn(short spr) void ballreturn(short spr)
{ {
short j, i, nexti, nextj; int j, i;
i = headspritestat[105]; StatIterator it(STAT_BOWLING);
while (i >= 0) while ((i = it.NextIndex()) >= 0)
{ {
nexti = nextspritestat[i]; auto si = &sprite[i];
if (sprite[i].picnum == RRTILE281) if (si->picnum == RRTILE281 && sprite[spr].sectnum == si->sectnum)
if (sprite[spr].sectnum == sprite[i].sectnum)
{ {
j = headspritestat[105]; StatIterator it2(STAT_BOWLING);
while (j >= 0) while ((j = it2.NextIndex()) >= 0)
{ {
nextj = nextspritestat[j]; auto sj = &sprite[j];
if (sprite[j].picnum == RRTILE282) if (sj->picnum == RRTILE282 && si->hitag == sj->hitag)
if (sprite[i].hitag == sprite[j].hitag)
fi.spawn(j, BOWLINGBALLSPRITE); fi.spawn(j, BOWLINGBALLSPRITE);
if (sprite[j].picnum == RRTILE280) if (sj->picnum == RRTILE280 && si->hitag == sj->hitag && sj->lotag == 0)
if (sprite[i].hitag == sprite[j].hitag)
if (sprite[j].lotag == 0)
{ {
sprite[j].lotag = 100; sj->lotag = 100;
sprite[j].extra++; sj->extra++;
pinsectorresetdown(sprite[j].sectnum);
} }
j = nextj;
} }
} }
i = nexti;
} }
} }

View file

@ -255,6 +255,7 @@ enum
STAT_RAROR = 15, STAT_RAROR = 15,
STAT_DESTRUCT = 100, STAT_DESTRUCT = 100,
STAT_BOWLING = 105,
STAT_NETALLOC = MAXSTATUS-1 STAT_NETALLOC = MAXSTATUS-1
}; };

View file

@ -2070,12 +2070,11 @@ int ParseState::parse(void)
updatesector(ps[g_p].posx,ps[g_p].posy,&ps[g_p].cursectnum); updatesector(ps[g_p].posx,ps[g_p].posy,&ps[g_p].cursectnum);
setpal(&ps[g_p]); setpal(&ps[g_p]);
j = headspritestat[1]; StatIterator it(STAT_ACTOR);
while (j >= 0) while ((j = it.NextIndex()) >= 0)
{ {
if (sprite[j].picnum == TILE_CAMERA1) if (sprite[j].picnum == TILE_CAMERA1)
sprite[j].yvel = 0; sprite[j].yvel = 0;
j = nextspritestat[j];
} }
} }
@ -2934,8 +2933,8 @@ int ParseState::parse(void)
lFound = -1; lFound = -1;
lDist = 32767; // big number lDist = 32767; // big number
j = headspritestat[1]; // all sprites StatIterator it(STAT_ACTOR);
while (j >= 0) while ((j = it.NextIndex()) >= 0)
{ {
if (sprite[j].picnum == lType) if (sprite[j].picnum == lType)
{ {
@ -2949,7 +2948,6 @@ int ParseState::parse(void)
} }
} }
j = nextspritestat[j];
} }
SetGameVarID(lVarID, lFound, g_i, g_p); SetGameVarID(lVarID, lFound, g_i, g_p);
@ -2980,8 +2978,8 @@ int ParseState::parse(void)
lFound = -1; lFound = -1;
lDist = 32767; // big number lDist = 32767; // big number
j = headspritestat[1]; // all sprites StatIterator it(STAT_ACTOR);
while (j >= 0) while ((j = it.NextIndex()) >= 0)
{ {
if (sprite[j].picnum == lType) if (sprite[j].picnum == lType)
{ {
@ -2995,7 +2993,6 @@ int ParseState::parse(void)
} }
} }
j = nextspritestat[j];
} }
SetGameVarID(lVarID, lFound, g_i, g_p); SetGameVarID(lVarID, lFound, g_i, g_p);

View file

@ -346,22 +346,25 @@ int aim(spritetype* s, int aang)
{ {
if (j >= 0) if (j >= 0)
break; 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) StatIterator it(aimstats[k]);
if (badguy(&sprite[i]) || k < 2) 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(sp) || sp->picnum == TILE_APLAYER)
if (badguy(&sprite[i]) || sp->picnum == TILE_APLAYER)
{ {
if (sp->picnum == TILE_APLAYER && if (sp->picnum == TILE_APLAYER &&
(isRR() && ud.ffire == 0) && (isRR() && ud.ffire == 0) &&
ud.coop == 1 && ud.coop == 1 &&
s->picnum == TILE_APLAYER && s->picnum == TILE_APLAYER &&
s != &sprite[i]) s != sp)
continue; continue;
if (gotshrinker && sprite[i].xrepeat < 30 && !(actorinfo[sp->picnum].flags & SFLAG_SHRINKAUTOAIM)) continue; if (gotshrinker && sp->xrepeat < 30 && !(actorinfo[sp->picnum].flags & SFLAG_SHRINKAUTOAIM)) continue;
if (gotfreezer && sprite[i].pal == 1) continue; if (gotfreezer && sp->pal == 1) continue;
} }
xv = (sp->x - s->x); xv = (sp->x - s->x);
@ -387,6 +390,7 @@ int aim(spritetype* s, int aang)
} }
} }
} }
}
} }
return j; return j;

View file

@ -594,13 +594,12 @@ void shoot_d(int i, int atwith)
} }
} }
l = headspritestat[5]; StatIterator it(STAT_MISC);
while (l >= 0) while ((l = it.NextIndex()) >= 0)
{ {
if (sprite[l].picnum == BULLETHOLE) if (sprite[l].picnum == BULLETHOLE)
if (dist(&sprite[l], &sprite[k]) < (12 + (krand() & 7))) if (dist(&sprite[l], &sprite[k]) < (12 + (krand() & 7)))
goto SKIPBULLETHOLE; goto SKIPBULLETHOLE;
l = nextspritestat[l];
} }
l = fi.spawn(k, BULLETHOLE); l = fi.spawn(k, BULLETHOLE);
sprite[l].xvel = -1; 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) if (j == HANDBOMB_WEAPON && p->ammo_amount[HANDBOMB_WEAPON] == 0)
{ {
k = headspritestat[1]; StatIterator it(STAT_ACTOR);
while (k >= 0) while ((k = it.NextIndex()) >= 0)
{ {
if (sprite[k].picnum == HEAVYHBOMB && sprite[k].owner == p->i) 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; j = HANDREMOTE_WEAPON;
break; break;
} }
k = nextspritestat[k];
} }
} }

View file

@ -507,13 +507,12 @@ void shoot_r(int i, int atwith)
} }
} }
l = headspritestat[5]; StatIterator it(STAT_MISC);
while (l >= 0) while ((l = it.NextIndex()) >= 0)
{ {
if (sprite[l].picnum == BULLETHOLE) if (sprite[l].picnum == BULLETHOLE)
if (dist(&sprite[l], &sprite[k]) < (12 + (krand() & 7))) if (dist(&sprite[l], &sprite[k]) < (12 + (krand() & 7)))
goto SKIPBULLETHOLE; goto SKIPBULLETHOLE;
l = nextspritestat[l];
} }
l = fi.spawn(k, BULLETHOLE); l = fi.spawn(k, BULLETHOLE);
sprite[l].xvel = -1; 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) if (j == DYNAMITE_WEAPON && p->ammo_amount[DYNAMITE_WEAPON] == 0)
{ {
k = headspritestat[1]; StatIterator it(STAT_ACTOR);
while (k >= 0) while ((k = it.NextIndex()) >= 0)
{ {
if (sprite[k].picnum == HEAVYHBOMB && sprite[k].owner == p->i) if (sprite[k].picnum == HEAVYHBOMB && sprite[k].owner == p->i)
{ {
@ -1041,7 +1040,6 @@ void selectweapon_r(int snum, int weap)
j = THROWINGDYNAMITE_WEAPON; j = THROWINGDYNAMITE_WEAPON;
break; break;
} }
k = nextspritestat[k];
} }
} }
else if (j == KNEE_WEAPON && isRRRA()) else if (j == KNEE_WEAPON && isRRRA())

View file

@ -501,7 +501,7 @@ void resetprestat(int snum,int g)
void resetpspritevars(int g) void resetpspritevars(int g)
{ {
int i, j; int i, j;
short nexti, circ; short circ;
int firstx, firsty; int firstx, firsty;
spritetype* s; spritetype* s;
int aimmode[MAXPLAYERS], autoaim[MAXPLAYERS]; int aimmode[MAXPLAYERS], autoaim[MAXPLAYERS];
@ -571,10 +571,9 @@ void resetpspritevars(int g)
which_palookup = 9; which_palookup = 9;
j = connecthead; j = connecthead;
i = headspritestat[STAT_PLAYER]; StatIterator it(STAT_PLAYER);
while (i >= 0) while ((i = it.NextIndex()) >= 0)
{ {
nexti = nextspritestat[i];
s = &sprite[i]; s = &sprite[i];
if (numplayersprites == MAXPLAYERS) if (numplayersprites == MAXPLAYERS)
@ -641,7 +640,6 @@ void resetpspritevars(int g)
} }
else deletesprite(i); else deletesprite(i);
i = nexti;
} }
} }

View file

@ -270,43 +270,42 @@ void cacheit_d(void)
void prelevel_d(int g) void prelevel_d(int g)
{ {
short i, nexti, j, startwall, endwall, lotaglist; short i, j, startwall, endwall, lotaglist;
short lotags[65]; short lotags[65];
prelevel_common(g); prelevel_common(g);
i = headspritestat[0]; StatIterator it(STAT_DEFAULT);
while (i >= 0) while ((i = it.NextIndex()) >= 0)
{ {
nexti = nextspritestat[i]; auto si = &sprite[i];
LoadActor(i, -1, -1); 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].exitx = si->x;
ps[0].exity = sprite[i].y; ps[0].exity = si->y;
} }
else switch (sprite[i].picnum) else switch (si->picnum)
{ {
case GPSPEED: case GPSPEED:
sector[sprite[i].sectnum].extra = sprite[i].lotag; sector[si->sectnum].extra = si->lotag;
deletesprite(i); deletesprite(i);
break; break;
case CYCLER: case CYCLER:
if (numcyclers >= MAXCYCLERS) if (numcyclers >= MAXCYCLERS)
I_Error("Too many cycling sectors."); I_Error("Too many cycling sectors.");
cyclers[numcyclers][0] = sprite[i].sectnum; cyclers[numcyclers][0] = si->sectnum;
cyclers[numcyclers][1] = sprite[i].lotag; cyclers[numcyclers][1] = si->lotag;
cyclers[numcyclers][2] = sprite[i].shade; cyclers[numcyclers][2] = si->shade;
cyclers[numcyclers][3] = sector[sprite[i].sectnum].floorshade; cyclers[numcyclers][3] = sector[si->sectnum].floorshade;
cyclers[numcyclers][4] = sprite[i].hitag; cyclers[numcyclers][4] = si->hitag;
cyclers[numcyclers][5] = (sprite[i].ang == 1536); cyclers[numcyclers][5] = (si->ang == 1536);
numcyclers++; numcyclers++;
deletesprite(i); deletesprite(i);
break; break;
} }
i = nexti;
} }
for (i = 0; i < MAXSPRITES; i++) for (i = 0; i < MAXSPRITES; i++)
@ -328,8 +327,8 @@ void prelevel_d(int g)
lotaglist = 0; lotaglist = 0;
i = headspritestat[0]; it.Reset(STAT_DEFAULT);
while (i >= 0) while ((i = it.NextIndex()) >= 0)
{ {
switch (sprite[i].picnum) switch (sprite[i].picnum)
{ {
@ -357,17 +356,15 @@ void prelevel_d(int g)
if (lotaglist > 64) if (lotaglist > 64)
I_Error("Too many switches (64 max)."); I_Error("Too many switches (64 max).");
j = headspritestat[3]; StatIterator it1(STAT_EFFECTOR);
while (j >= 0) while ((j = it1.NextIndex()) >= 0)
{ {
if (sprite[j].lotag == 12 && sprite[j].hitag == sprite[i].lotag) if (sprite[j].lotag == 12 && sprite[j].hitag == sprite[i].lotag)
hittype[j].temp_data[0] = 1; hittype[j].temp_data[0] = 1;
j = nextspritestat[j];
} }
} }
break; break;
} }
i = nextspritestat[i];
} }
mirrorcnt = 0; mirrorcnt = 0;

View file

@ -446,7 +446,6 @@ void prelevel_r(int g)
{ {
struct player_struct* p; struct player_struct* p;
short i; short i;
short nexti;
short j; short j;
short startwall; short startwall;
short endwall; short endwall;
@ -554,37 +553,37 @@ void prelevel_r(int g)
} }
} }
i = headspritestat[0]; StatIterator it(STAT_DEFAULT);
while (i >= 0) while ((i = it.NextIndex()) >= 0)
{ {
nexti = nextspritestat[i]; auto si = &sprite[i];
LoadActor(i, -1, -1); 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].exitx = si->x;
ps[0].exity = sprite[i].y; ps[0].exity = si->y;
} }
else switch (sprite[i].picnum) else switch (si->picnum)
{ {
case NUKEBUTTON: case NUKEBUTTON:
chickenplant = 1; chickenplant = 1;
break; break;
case GPSPEED: case GPSPEED:
sector[sprite[i].sectnum].extra = sprite[i].lotag; sector[si->sectnum].extra = si->lotag;
deletesprite(i); deletesprite(i);
break; break;
case CYCLER: case CYCLER:
if (numcyclers >= MAXCYCLERS) if (numcyclers >= MAXCYCLERS)
I_Error("Too many cycling sectors."); I_Error("Too many cycling sectors.");
cyclers[numcyclers][0] = sprite[i].sectnum; cyclers[numcyclers][0] = si->sectnum;
cyclers[numcyclers][1] = sprite[i].lotag; cyclers[numcyclers][1] = si->lotag;
cyclers[numcyclers][2] = sprite[i].shade; cyclers[numcyclers][2] = si->shade;
cyclers[numcyclers][3] = sector[sprite[i].sectnum].floorshade; cyclers[numcyclers][3] = sector[si->sectnum].floorshade;
cyclers[numcyclers][4] = sprite[i].hitag; cyclers[numcyclers][4] = si->hitag;
cyclers[numcyclers][5] = (sprite[i].ang == 1536); cyclers[numcyclers][5] = (si->ang == 1536);
numcyclers++; numcyclers++;
deletesprite(i); deletesprite(i);
break; break;
@ -600,12 +599,12 @@ void prelevel_r(int g)
break; break;
case RRTILE68: case RRTILE68:
shadedsector[sprite[i].sectnum] = 1; shadedsector[si->sectnum] = 1;
deletesprite(i); deletesprite(i);
break; break;
case RRTILE67: case RRTILE67:
sprite[i].cstat |= 32768; si->cstat |= 32768;
break; break;
case SOUNDFX: case SOUNDFX:
@ -613,16 +612,15 @@ void prelevel_r(int g)
I_Error("Too many ambient effects"); I_Error("Too many ambient effects");
else else
{ {
ambienthitag[ambientfx] = sprite[i].hitag; ambienthitag[ambientfx] = si->hitag;
ambientlotag[ambientfx] = sprite[i].lotag; ambientlotag[ambientfx] = si->lotag;
sprite[i].ang = ambientfx; si->ang = ambientfx;
ambientfx++; ambientfx++;
sprite[i].lotag = 0; si->lotag = 0;
sprite[i].hitag = 0; si->hitag = 0;
} }
break; break;
} }
i = nexti;
} }
for (i = 0; i < MAXSPRITES; i++) for (i = 0; i < MAXSPRITES; i++)
@ -687,8 +685,8 @@ void prelevel_r(int g)
lotaglist = 0; lotaglist = 0;
i = headspritestat[0]; it.Reset(STAT_DEFAULT);
while (i >= 0) while ((i = it.NextIndex()) >= 0)
{ {
switch (sprite[i].picnum) switch (sprite[i].picnum)
{ {
@ -721,17 +719,15 @@ void prelevel_r(int g)
if (lotaglist > 64) if (lotaglist > 64)
I_Error("Too many switches (64 max)."); I_Error("Too many switches (64 max).");
j = headspritestat[3]; StatIterator it1(STAT_EFFECTOR);
while (j >= 0) while ((j = it1.NextIndex()) >= 0)
{ {
if (sprite[j].lotag == 12 && sprite[j].hitag == sprite[i].lotag) if (sprite[j].lotag == 12 && sprite[j].hitag == sprite[i].lotag)
hittype[j].temp_data[0] = 1; hittype[j].temp_data[0] = 1;
j = nextspritestat[j];
} }
} }
break; break;
} }
i = nextspritestat[i];
} }
mirrorcnt = 0; mirrorcnt = 0;

View file

@ -175,8 +175,8 @@ void se40code(int x, int y, int z, binangle a, fixedhoriz h, int smoothratio)
else if (isRRRA()) tag = 150; else if (isRRRA()) tag = 150;
else return; else return;
i = headspritestat[STAT_RAROR]; StatIterator it(STAT_RAROR);
while (i >= 0) while ((i = it.NextIndex()) >= 0)
{ {
switch (sprite[i].lotag - tag + 40) 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); SE40_Draw(tag, i, x, y, z, a, h, smoothratio);
break; break;
} }
i = nextspritestat[i];
} }
} }

View file

@ -43,8 +43,9 @@ static void recreateinterpolations()
{ {
numinterpolations = 0; numinterpolations = 0;
int k = headspritestat[STAT_EFFECTOR]; int k;
while (k >= 0) StatIterator it(STAT_EFFECTOR);
while ((k = it.NextIndex()) >= 0)
{ {
switch (sprite[k].lotag) switch (sprite[k].lotag)
{ {
@ -71,8 +72,6 @@ static void recreateinterpolations()
setsectinterpolate(k); setsectinterpolate(k);
break; break;
} }
k = nextspritestat[k];
} }
for (int i = numinterpolations - 1; i >= 0; i--) bakipos[i] = *curipos[i]; for (int i = numinterpolations - 1; i >= 0; i--) bakipos[i] = *curipos[i];
@ -500,20 +499,6 @@ void GameInterface::SerializeGameState(FSerializer& arc)
show_shareware = 0; show_shareware = 0;
everyothertime = 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); FX_SetReverb(0);
} }

View file

@ -491,30 +491,31 @@ void initcrane(int j, int i, int CRANEPOLE)
msy[tempwallptr] = sp->y; msy[tempwallptr] = sp->y;
msx[tempwallptr + 2] = sp->z; msx[tempwallptr + 2] = sp->z;
int s = headspritestat[0]; int s;
while (s >= 0) 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; msy[tempwallptr + 2] = s;
t[1] = sprite[s].sectnum; t[1] = ss->sectnum;
sprite[s].xrepeat = 48; ss->xrepeat = 48;
sprite[s].yrepeat = 128; ss->yrepeat = 128;
msx[tempwallptr + 1] = sprite[s].x; msx[tempwallptr + 1] = ss->x;
msy[tempwallptr + 1] = sprite[s].y; msy[tempwallptr + 1] = ss->y;
sprite[s].x = sp->x; ss->x = sp->x;
sprite[s].y = sp->y; ss->y = sp->y;
sprite[s].z = sp->z; ss->z = sp->z;
sprite[s].shade = sp->shade; ss->shade = sp->shade;
setsprite(s, sprite[s].x, sprite[s].y, sprite[s].z); setsprite(s, ss->x, ss->y, ss->z);
break; break;
} }
s = nextspritestat[s];
} }
tempwallptr += 3; tempwallptr += 3;