diff --git a/src/p_map.c b/src/p_map.c index 7cfd649a98..2fe2a0924d 100644 --- a/src/p_map.c +++ b/src/p_map.c @@ -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; } \ No newline at end of file diff --git a/src/p_mobj.h b/src/p_mobj.h index 7f7f9258d4..55ec1a3a43 100644 --- a/src/p_mobj.h +++ b/src/p_mobj.h @@ -333,6 +333,8 @@ typedef struct mobj_s int bobdirection; int bobcount; + boolean visited; + } mobj_t;