Replace usage of ThinkerIterator and BlockThingsIterator in various places where we can instead loop through sector thing lists.

While in the latter case this may result in longer loops, it also reduces GC thrashing by not needing to allocate an iterator every time.
This also simplifies the DoBlast code as there is no longer a need to manually traverse portals vertically.
This commit is contained in:
Mari the Deer 2023-07-29 13:15:34 +02:00
commit 2bd1cb0657
17 changed files with 113 additions and 220 deletions

View file

@ -523,15 +523,19 @@ Class HammerspaceEmbiggener : Inventory
// since backpacks are taller in Doom
if ( gameinfo.gametype&GAME_DoomChex )
A_SetSize(-1,26);
let bt = BlockThingsIterator.Create(self,16);
int tamount = Amount;
while ( bt.Next() )
foreach ( s:level.Sectors ) for ( Actor t=s.thinglist; t; )
{
let t = bt.Thing;
if ( !t || (t == self) || !(t is 'HammerspaceEmbiggener') || !(t.spawnpoint ~== spawnpoint) ) continue;
let next = t.snext;
if ( (t == self) || !(t is 'HammerspaceEmbiggener') || !(t.spawnpoint ~== spawnpoint) )
{
t = next;
continue;
}
tamount += HammerspaceEmbiggener(t).Amount;
t.ClearCounters();
t.Destroy();
t = next;
}
if ( tamount <= 1 ) return;
tamount -= tamount%2; // always even numbered

View file

@ -58,12 +58,10 @@ Class LampMoth : Actor
if ( !lamp )
{
// look for nearby lamps
let bi = BlockThingsIterator.Create(self,250);
double mindist = 62500.;
while ( bi.Next() )
foreach ( s:level.Sectors ) for ( Actor a=s.thinglist; a; a=a.snext )
{
if ( !bi.Thing || !(bi.Thing is 'CompanionLamp') ) continue;
Actor a = bi.Thing;
if ( !(a is 'CompanionLamp') ) continue;
double dist = Distance3DSquared(a);
if ( (a.frame == 0) || (dist > mindist) && !CheckSight(a,SF_IGNOREVISIBILITY|SF_IGNOREWATERBOUNDARY) ) continue;
mindist = dist;

View file

@ -310,11 +310,9 @@ Class GhostTarget : Actor
}
if ( isFrozen() ) return;
if ( diedie ) A_FadeOut(.05);
let bt = BlockThingsIterator.Create(self,300);
while ( bt.Next() )
foreach ( s:level.Sectors ) for ( Actor t=s.thinglist; t; t=t.snext )
{
let t = bt.Thing;
if ( !t || !t.bIsMonster || t.player || !t.IsHostile(master) || (t.target != self) ) continue;
if ( !t.bIsMonster || t.player || !t.IsHostile(master) || (t.target != self) ) continue;
if ( SWWMUtility.BoxIntersect(self,t,pad:16) || t.CheckMeleeRange() )
{
// they found out, there's no one here

View file

@ -510,9 +510,7 @@ Class Mykradvo : Inventory
{
targets.Clear();
// search all actively hostile enemies within 50m
let ti = ThinkerIterator.Create("Actor");
Actor a;
while ( a=Actor(ti.Next()) )
foreach ( s:level.Sectors ) for ( Actor a=s.thinglist; a; a=a.snext )
{
// must be an active, shootable live monster
if ( !a.bISMONSTER || !a.bSHOOTABLE || a.bDORMANT || (a.Health <= 0) ) continue;