Skip to content

Commit

Permalink
Better check of monsters near moving sector
Browse files Browse the repository at this point in the history
Just check monsters on the periphery of a moving sector instead of all
in bounding box of the sector. Both more accurate and faster. Taken from
PrBoom+ source.
  • Loading branch information
bradharding committed Jan 29, 2014
1 parent 536293b commit ee6439e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
37 changes: 30 additions & 7 deletions src/p_map.c
Expand Up @@ -1460,20 +1460,43 @@ boolean PIT_ChangeSector(mobj_t *thing)


//
// P_ChangeSector
// P_CheckSector
// jff 3/19/98 added to just check monsters on the periphery
// of a moving sector instead of all in bounding box of the
// sector. Both more accurate and faster.
//
boolean P_ChangeSector(sector_t *sector, boolean crunch)
{
int x;
int y;
mobj_t *thing;

nofit = false;
crushchange = crunch;

// re-check heights for all things near the moving sector
for (x = sector->blockbox[BOXLEFT]; x <= sector->blockbox[BOXRIGHT]; x++)
for (y = sector->blockbox[BOXBOTTOM]; y <= sector->blockbox[BOXTOP]; y++)
P_BlockThingsIterator(x, y, PIT_ChangeSector);
// killough 4/4/98: scan list front-to-back until empty or exhausted,
// restarting from beginning after each thing is processed. Avoids
// crashes, and is sure to examine all things in the sector, and only
// the things which are in the sector, until a steady-state is reached.
// Things can arbitrarily be inserted and removed and it won't mess up.
//
// killough 4/7/98: simplified to avoid using complicated counter

// Mark all things invalid

for (thing = sector->thinglist; thing; thing = thing->snext)
thing->visited = false;

do
{
for (thing = sector->thinglist; thing; thing = thing->snext) // go through list
if (!thing->visited) // unprocessed thing found
{
thing->visited = true; // mark thing as processed
if (!(thing->flags & MF_NOBLOCKMAP)) // jff 4/7/98 don't do these
PIT_ChangeSector(thing); // process it
break; // exit and start over
}
}
while (thing); // repeat from scratch until all things left are marked valid

return nofit;
}
2 changes: 2 additions & 0 deletions src/p_mobj.h
Expand Up @@ -333,6 +333,8 @@ typedef struct mobj_s
int bobdirection;
int bobcount;

boolean visited;

} mobj_t;


Expand Down

0 comments on commit ee6439e

Please sign in to comment.