diff --git a/src/d_think.h b/src/d_think.h index 589124587..76c1bb5b8 100644 --- a/src/d_think.h +++ b/src/d_think.h @@ -51,6 +51,8 @@ typedef struct thinker_s // killough 11/98: count of how many other objects reference // this one using pointers. Used for garbage collection. INT32 references; + + boolean removing; boolean cachable; #ifdef PARANOIA diff --git a/src/f_finale.c b/src/f_finale.c index 702e29a77..0f7ef65c5 100644 --- a/src/f_finale.c +++ b/src/f_finale.c @@ -3441,7 +3441,7 @@ void F_TitleScreenTicker(boolean run) { for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (th->removing) continue; mo2 = (mobj_t *)th; diff --git a/src/g_demo.c b/src/g_demo.c index b0e16adda..8315e716b 100644 --- a/src/g_demo.c +++ b/src/g_demo.c @@ -614,7 +614,7 @@ void G_ConsGhostTic(void) mobj = NULL; for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (th->removing) continue; mobj = (mobj_t *)th; if (mobj->type == (mobjtype_t)type && mobj->x == x && mobj->y == y && mobj->z == z) @@ -2696,7 +2696,7 @@ void G_DoPlayMetal(void) // find metal sonic for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (th->removing) continue; mo = (mobj_t *)th; diff --git a/src/g_game.c b/src/g_game.c index d409bb2cf..175e757ec 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -3072,7 +3072,7 @@ void G_ChangePlayerReferences(mobj_t *oldmo, mobj_t *newmo) // scan all thinkers for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (th->removing) continue; mo2 = (mobj_t *)th; diff --git a/src/lua_blockmaplib.c b/src/lua_blockmaplib.c index c29eadecc..f570c229b 100644 --- a/src/lua_blockmaplib.c +++ b/src/lua_blockmaplib.c @@ -254,11 +254,10 @@ static int lib_searchBlockmap(lua_State *L) } else // mobj and function only - search around mobj's radius by default { - fixed_t radius = mobj->radius + MAXRADIUS; - x1 = mobj->x - radius; - x2 = mobj->x + radius; - y1 = mobj->y - radius; - y2 = mobj->y + radius; + x1 = mobj->x - mobj->radius; + x2 = mobj->x + mobj->radius; + y1 = mobj->y - mobj->radius; + y2 = mobj->y + mobj->radius; } lua_settop(L, 2); // pop everything except function, mobj diff --git a/src/lua_script.c b/src/lua_script.c index 623d88673..686555a16 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -1779,7 +1779,7 @@ void LUA_Archive(save_t *save_p) for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (th->removing) continue; // archive function will determine when to skip mobjs, @@ -1817,7 +1817,7 @@ void LUA_UnArchive(save_t *save_p) mobjnum = P_ReadUINT32(save_p); // read a mobjnum for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (th->removing) continue; if (((mobj_t *)th)->mobjnum != mobjnum) // find matching mobj continue; diff --git a/src/m_cheat.c b/src/m_cheat.c index 2b32253fa..4be071bb2 100644 --- a/src/m_cheat.c +++ b/src/m_cheat.c @@ -562,7 +562,7 @@ void Command_Teleport_f(void) for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (th->removing) continue; mo2 = (mobj_t *)th; @@ -1072,7 +1072,7 @@ static mapthing_t *OP_CreateNewMapThing(player_t *player, UINT16 type, boolean c for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (th->removing) continue; mo = (mobj_t *)th; diff --git a/src/m_perfstats.c b/src/m_perfstats.c index b9948bdc0..0a52b0125 100644 --- a/src/m_perfstats.c +++ b/src/m_perfstats.c @@ -584,7 +584,7 @@ static void PS_CountThinkers(void) for (thinker = thlist[i].next; thinker != &thlist[i]; thinker = thinker->next) { ps_thinkercount.value.i++; - if (thinker->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (thinker->removing) ps_removecount.value.i++; else if (i == THINK_POLYOBJ) ps_polythcount.value.i++; diff --git a/src/netcode/d_clisrv.c b/src/netcode/d_clisrv.c index 8807265f3..067458852 100644 --- a/src/netcode/d_clisrv.c +++ b/src/netcode/d_clisrv.c @@ -1816,7 +1816,7 @@ INT16 Consistancy(void) { for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (th->removing) continue; mo = (mobj_t *)th; diff --git a/src/p_enemy.c b/src/p_enemy.c index 59ca95409..60cffebfc 100644 --- a/src/p_enemy.c +++ b/src/p_enemy.c @@ -3744,7 +3744,7 @@ static void P_DoBossVictory(mobj_t *mo) // scan the remaining thinkers to see if all bosses are dead for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (th->removing) continue; mo2 = (mobj_t *)th; @@ -6449,7 +6449,7 @@ void A_RingExplode(mobj_t *actor) for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (th->removing) continue; mo2 = (mobj_t *)th; @@ -8756,7 +8756,7 @@ void A_FindTarget(mobj_t *actor) // scan the thinkers for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (th->removing) continue; mo2 = (mobj_t *)th; @@ -8820,7 +8820,7 @@ void A_FindTracer(mobj_t *actor) // scan the thinkers for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (th->removing) continue; mo2 = (mobj_t *)th; @@ -9498,7 +9498,7 @@ void A_RemoteAction(mobj_t *actor) // scan the thinkers for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (th->removing) continue; mo2 = (mobj_t *)th; @@ -9761,7 +9761,7 @@ void A_SetObjectTypeState(mobj_t *actor) for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (th->removing) continue; mo2 = (mobj_t *)th; @@ -10391,7 +10391,7 @@ void A_CheckThingCount(mobj_t *actor) for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (th->removing) continue; mo2 = (mobj_t *)th; diff --git a/src/p_inter.c b/src/p_inter.c index dc606a47e..0e63fea1b 100644 --- a/src/p_inter.c +++ b/src/p_inter.c @@ -101,7 +101,7 @@ void P_ClearStarPost(INT32 postnum) // scan the thinkers for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (th->removing) continue; mo2 = (mobj_t *)th; @@ -130,7 +130,7 @@ void P_ResetStarposts(void) for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (th->removing) continue; post = (mobj_t *)th; @@ -1003,7 +1003,7 @@ void P_TouchSpecialThing(mobj_t *special, mobj_t *toucher, boolean heightcheck) // scan the thinkers to find the corresponding anchorpoint for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (th->removing) continue; mo2 = (mobj_t *)th; @@ -1097,7 +1097,7 @@ void P_TouchSpecialThing(mobj_t *special, mobj_t *toucher, boolean heightcheck) // scan the remaining thinkers for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (th->removing) continue; mo2 = (mobj_t *)th; @@ -1147,7 +1147,7 @@ void P_TouchSpecialThing(mobj_t *special, mobj_t *toucher, boolean heightcheck) // in from the paraloop. Isn't this just so efficient? for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (th->removing) continue; mo2 = (mobj_t *)th; @@ -1522,7 +1522,7 @@ void P_TouchSpecialThing(mobj_t *special, mobj_t *toucher, boolean heightcheck) // scan the remaining thinkers to find koopa for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (th->removing) continue; mo2 = (mobj_t *)th; @@ -2020,7 +2020,7 @@ void P_TouchStarPost(mobj_t *post, player_t *player, boolean snaptopost) for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (th->removing) continue; mo2 = (mobj_t *)th; @@ -2870,7 +2870,7 @@ void P_KillMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source, UINT8 damaget // scan the thinkers to make sure all the old pinch dummies are gone on death for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (th->removing) continue; mo = (mobj_t *)th; diff --git a/src/p_local.h b/src/p_local.h index 3cc887b33..de519b211 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -39,11 +39,6 @@ // Convenience macro to fix issue with collision along bottom/left edges of blockmap -Red #define BMBOUNDFIX(xl, xh, yl, yh) {if (xl > xh) xl = 0; if (yl > yh) yl = 0;} -// MAXRADIUS is for precalculated sector block boxes -// the spider demon is larger, -// but we do not have any moving sectors nearby -#define MAXRADIUS (32*FRACUNIT) - // max Z move up or down without jumping // above this, a height difference is considered as a 'dropoff' #define MAXSTEPMOVE (24*FRACUNIT) diff --git a/src/p_map.c b/src/p_map.c index 1116ae06a..fce17f8c4 100644 --- a/src/p_map.c +++ b/src/p_map.c @@ -36,6 +36,9 @@ #include "m_perfstats.h" // ps_checkposition_calls +// Formerly called MAXRADIUS +#define MAXTRYMOVE (32*FRACUNIT) + fixed_t tmbbox[4]; mobj_t *tmthing; static INT32 tmflags; @@ -2165,15 +2168,10 @@ boolean P_CheckPosition(mobj_t *thing, fixed_t x, fixed_t y) } } - // The bounding box is extended by MAXRADIUS - // because mobj_ts are grouped into mapblocks - // based on their origin point, and can overlap - // into adjacent blocks by up to MAXRADIUS units. - - xl = (unsigned)(tmbbox[BOXLEFT] - bmaporgx - MAXRADIUS)>>MAPBLOCKSHIFT; - xh = (unsigned)(tmbbox[BOXRIGHT] - bmaporgx + MAXRADIUS)>>MAPBLOCKSHIFT; - yl = (unsigned)(tmbbox[BOXBOTTOM] - bmaporgy - MAXRADIUS)>>MAPBLOCKSHIFT; - yh = (unsigned)(tmbbox[BOXTOP] - bmaporgy + MAXRADIUS)>>MAPBLOCKSHIFT; + xl = (unsigned)(tmbbox[BOXLEFT] - bmaporgx)>>MAPBLOCKSHIFT; + xh = (unsigned)(tmbbox[BOXRIGHT] - bmaporgx)>>MAPBLOCKSHIFT; + yl = (unsigned)(tmbbox[BOXBOTTOM] - bmaporgy)>>MAPBLOCKSHIFT; + yh = (unsigned)(tmbbox[BOXTOP] - bmaporgy)>>MAPBLOCKSHIFT; BMBOUNDFIX(xl, xh, yl, yh); @@ -2393,11 +2391,6 @@ boolean P_CheckCameraPosition(fixed_t x, fixed_t y, camera_t *thiscam) } } - // The bounding box is extended by MAXRADIUS - // because mobj_ts are grouped into mapblocks - // based on their origin point, and can overlap - // into adjacent blocks by up to MAXRADIUS units. - xl = (unsigned)(tmbbox[BOXLEFT] - bmaporgx)>>MAPBLOCKSHIFT; xh = (unsigned)(tmbbox[BOXRIGHT] - bmaporgx)>>MAPBLOCKSHIFT; yl = (unsigned)(tmbbox[BOXBOTTOM] - bmaporgy)>>MAPBLOCKSHIFT; @@ -2528,16 +2521,16 @@ boolean P_TryCameraMove(fixed_t x, fixed_t y, camera_t *thiscam) } do { - if (x-tryx > MAXRADIUS) - tryx += MAXRADIUS; - else if (x-tryx < -MAXRADIUS) - tryx -= MAXRADIUS; + if (x-tryx > MAXTRYMOVE) + tryx += MAXTRYMOVE; + else if (x-tryx < -MAXTRYMOVE) + tryx -= MAXTRYMOVE; else tryx = x; - if (y-tryy > MAXRADIUS) - tryy += MAXRADIUS; - else if (y-tryy < -MAXRADIUS) - tryy -= MAXRADIUS; + if (y-tryy > MAXTRYMOVE) + tryy += MAXTRYMOVE; + else if (y-tryy < -MAXTRYMOVE) + tryy -= MAXTRYMOVE; else tryy = y; @@ -2683,7 +2676,7 @@ increment_move floatok = false; // This makes sure that there are no freezes from computing extremely small movements. - // Originally was MAXRADIUS/2, but that can cause some bad inconsistencies for small players. + // Originally was MAXTRYMOVE/2, but that can cause some bad inconsistencies for small players. radius = max(radius, thing->scale); // And we also have to prevent Big Large (tm) movements, as those can skip too far @@ -2872,10 +2865,10 @@ boolean P_TryMove(mobj_t *thing, fixed_t x, fixed_t y, boolean allowdropoff) { INT32 xl, xh, yl, yh; - yh = (unsigned)(thing->y + MAXRADIUS - bmaporgy)>>MAPBLOCKSHIFT; - yl = (unsigned)(thing->y - MAXRADIUS - bmaporgy)>>MAPBLOCKSHIFT; - xh = (unsigned)(thing->x + MAXRADIUS - bmaporgx)>>MAPBLOCKSHIFT; - xl = (unsigned)(thing->x - MAXRADIUS - bmaporgx)>>MAPBLOCKSHIFT; + yh = (unsigned)(thing->y + thing->radius - bmaporgy)>>MAPBLOCKSHIFT; + yl = (unsigned)(thing->y - thing->radius - bmaporgy)>>MAPBLOCKSHIFT; + xh = (unsigned)(thing->x + thing->radius - bmaporgx)>>MAPBLOCKSHIFT; + xl = (unsigned)(thing->x - thing->radius - bmaporgx)>>MAPBLOCKSHIFT; BMBOUNDFIX(xl, xh, yl, yh); @@ -2947,16 +2940,16 @@ boolean P_SceneryTryMove(mobj_t *thing, fixed_t x, fixed_t y) tryx = thing->x; tryy = thing->y; do { - if (x-tryx > MAXRADIUS) - tryx += MAXRADIUS; - else if (x-tryx < -MAXRADIUS) - tryx -= MAXRADIUS; + if (x-tryx > MAXTRYMOVE) + tryx += MAXTRYMOVE; + else if (x-tryx < -MAXTRYMOVE) + tryx -= MAXTRYMOVE; else tryx = x; - if (y-tryy > MAXRADIUS) - tryy += MAXRADIUS; - else if (y-tryy < -MAXRADIUS) - tryy -= MAXRADIUS; + if (y-tryy > MAXTRYMOVE) + tryy += MAXTRYMOVE; + else if (y-tryy < -MAXTRYMOVE) + tryy -= MAXTRYMOVE; else tryy = y; @@ -4215,7 +4208,8 @@ void P_RadiusAttack(mobj_t *spot, mobj_t *source, fixed_t damagedist, UINT8 dama INT32 xl, xh, yl, yh; fixed_t dist; - dist = FixedMul(damagedist, spot->scale) + MAXRADIUS; + dist = FixedMul(damagedist, spot->scale); + yh = (unsigned)(spot->y + dist - bmaporgy)>>MAPBLOCKSHIFT; yl = (unsigned)(spot->y - dist - bmaporgy)>>MAPBLOCKSHIFT; xh = (unsigned)(spot->x + dist - bmaporgx)>>MAPBLOCKSHIFT; @@ -4385,15 +4379,15 @@ static boolean P_CheckSectorPolyObjects(sector_t *sector, boolean realcrush, boo { mobj_t *mo; blocknode_t *block; + blocknode_t *next = NULL; if (x < 0 || y < 0 || x >= bmapwidth || y >= bmapheight) continue; - block = blocklinks[y * bmapwidth + x]; - - for (; block; block = block->mnext) + for (block = blocklinks[y * bmapwidth + x]; block != NULL; block = next) { mo = block->mobj; + next = block->mnext; // Monster Iestyn: do we need to check if a mobj has already been checked? ...probably not I suspect if (!P_MobjInsidePolyobj(po, mo)) diff --git a/src/p_maputl.c b/src/p_maputl.c index f10a396a3..5398fd7a4 100644 --- a/src/p_maputl.c +++ b/src/p_maputl.c @@ -1052,35 +1052,23 @@ boolean P_BlockLinesIterator(INT32 x, INT32 y, boolean (*func)(line_t *)) // boolean P_BlockThingsIterator(INT32 x, INT32 y, boolean (*func)(mobj_t *)) { - mobj_t *bnext = NULL; blocknode_t *block, *next = NULL; if (x < 0 || y < 0 || x >= bmapwidth || y >= bmapheight) return true; // Check interaction with the objects in the blockmap. - for (block = blocklinks[y*bmapwidth + x]; block; block = next) + for (block = blocklinks[y*bmapwidth + x]; block != NULL; block = next) { - next = block->mnext; - if (next) - P_SetTarget(&bnext, next->mobj); // We want to note our reference to bnext here in case it is MF_NOTHINK and gets removed! + next = block->mnext; // We want to note our reference to mnext here! if (!func(block->mobj)) - { - P_SetTarget(&bnext, NULL); return false; - } - if (P_MobjWasRemoved(tmthing) // func just popped our tmthing, cannot continue. - || (bnext && P_MobjWasRemoved(bnext))) // func just broke blockmap chain, cannot continue. - { - P_SetTarget(&bnext, NULL); + if (P_MobjWasRemoved(tmthing)) // func just popped our tmthing, cannot continue. return true; - } } - P_SetTarget(&bnext, NULL); - return true; } diff --git a/src/p_mobj.c b/src/p_mobj.c index aa17ddaac..0ce217e50 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -765,7 +765,7 @@ void P_EmeraldManager(void) for (think = thlist[THINK_MOBJ].next; think != &thlist[THINK_MOBJ]; think = think->next) { - if (think->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (think->removing) continue; mo = (mobj_t *)think; @@ -3455,7 +3455,7 @@ void P_DestroyRobots(void) for (think = thlist[THINK_MOBJ].next; think != &thlist[THINK_MOBJ]; think = think->next) { - if (think->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (think->removing) continue; mo = (mobj_t *)think; @@ -4254,7 +4254,7 @@ static void P_Boss3Thinker(mobj_t *mobj) // this can happen if the boss was hurt earlier than expected for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (th->removing) continue; mo2 = (mobj_t *)th; @@ -5343,7 +5343,7 @@ static void P_Boss9Thinker(mobj_t *mobj) // Build a hoop linked list of 'em! for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (th->removing) continue; mo2 = (mobj_t *)th; @@ -6045,7 +6045,7 @@ mobj_t *P_GetClosestAxis(mobj_t *source) // scan the thinkers to find the closest axis point for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (th->removing) continue; mo2 = (mobj_t *)th; @@ -9341,10 +9341,10 @@ static void P_PointPushThink(mobj_t *mobj) radius = mobj->spawnpoint->args[0] << FRACBITS; pushmobj = mobj; - xl = (unsigned)(mobj->x - radius - bmaporgx - MAXRADIUS)>>MAPBLOCKSHIFT; - xh = (unsigned)(mobj->x + radius - bmaporgx + MAXRADIUS)>>MAPBLOCKSHIFT; - yl = (unsigned)(mobj->y - radius - bmaporgy - MAXRADIUS)>>MAPBLOCKSHIFT; - yh = (unsigned)(mobj->y + radius - bmaporgy + MAXRADIUS)>>MAPBLOCKSHIFT; + xl = (unsigned)(mobj->x - radius - bmaporgx)>>MAPBLOCKSHIFT; + xh = (unsigned)(mobj->x + radius - bmaporgx)>>MAPBLOCKSHIFT; + yl = (unsigned)(mobj->y - radius - bmaporgy)>>MAPBLOCKSHIFT; + yh = (unsigned)(mobj->y + radius - bmaporgy)>>MAPBLOCKSHIFT; P_DoBlockThingsIterate(xl, yl, xh, yh, PIT_PushThing); } @@ -11187,17 +11187,16 @@ tic_t itemrespawntime[ITEMQUESIZE]; size_t iquehead, iquetail; #ifdef PARANOIA -#define SCRAMBLE_REMOVED // Force debug build to crash when Removed mobj is accessed +#define SCRAMBLE_REMOVED // Force debug build to crash when a removed mobj is accessed #endif void P_RemoveMobj(mobj_t *mobj) { I_Assert(mobj != NULL); - if (P_MobjWasRemoved(mobj)) - return; // something already removing this mobj. + if (P_MobjWasRemoved(mobj) || mobj->thinker.removing) + return; // Something already removed or is removing this mobj. - mobj->thinker.function.acp1 = (actionf_p1)P_RemoveThinkerDelayed; // shh. no recursing. + mobj->thinker.removing = true; // Set earlier to avoid recursion. LUA_HookMobj(mobj, MOBJ_HOOK(MobjRemoved)); - mobj->thinker.function.acp1 = (actionf_p1)P_MobjThinker; // needed for P_UnsetThingPosition, etc. to work. // Rings only, please! if (mobj->spawnpoint && @@ -12867,7 +12866,7 @@ static boolean P_MapAlreadyHasStarPost(mobj_t *mobj) for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (th->removing) continue; mo2 = (mobj_t *)th; diff --git a/src/p_polyobj.c b/src/p_polyobj.c index 168fca61f..3d1a38d36 100644 --- a/src/p_polyobj.c +++ b/src/p_polyobj.c @@ -878,15 +878,15 @@ static void Polyobj_carryThings(polyobj_t *po, fixed_t dx, fixed_t dy) { mobj_t *mo; blocknode_t *block; + blocknode_t *next = NULL; if (x < 0 || y < 0 || x >= bmapwidth || y >= bmapheight) continue; - block = blocklinks[y * bmapwidth + x]; - - for (; block; block = block->mnext) + for (block = blocklinks[y * bmapwidth + x]; block != NULL; block = next) { mo = block->mobj; + next = block->mnext; if (mo->lastlook == pomovecount) continue; @@ -927,11 +927,11 @@ static INT32 Polyobj_clipThings(polyobj_t *po, line_t *line) if (!(po->flags & POF_SOLID)) return hitflags; - // adjust linedef bounding box to blockmap, extend by MAXRADIUS - linebox[BOXLEFT] = (unsigned)(line->bbox[BOXLEFT] - bmaporgx - MAXRADIUS) >> MAPBLOCKSHIFT; - linebox[BOXRIGHT] = (unsigned)(line->bbox[BOXRIGHT] - bmaporgx + MAXRADIUS) >> MAPBLOCKSHIFT; - linebox[BOXBOTTOM] = (unsigned)(line->bbox[BOXBOTTOM] - bmaporgy - MAXRADIUS) >> MAPBLOCKSHIFT; - linebox[BOXTOP] = (unsigned)(line->bbox[BOXTOP] - bmaporgy + MAXRADIUS) >> MAPBLOCKSHIFT; + // adjust linedef bounding box to blockmap + linebox[BOXLEFT] = (unsigned)(line->bbox[BOXLEFT] - bmaporgx) >> MAPBLOCKSHIFT; + linebox[BOXRIGHT] = (unsigned)(line->bbox[BOXRIGHT] - bmaporgx) >> MAPBLOCKSHIFT; + linebox[BOXBOTTOM] = (unsigned)(line->bbox[BOXBOTTOM] - bmaporgy) >> MAPBLOCKSHIFT; + linebox[BOXTOP] = (unsigned)(line->bbox[BOXTOP] - bmaporgy) >> MAPBLOCKSHIFT; // check all mobj blockmap cells the line contacts for (y = linebox[BOXBOTTOM]; y <= linebox[BOXTOP]; ++y) @@ -942,9 +942,11 @@ static INT32 Polyobj_clipThings(polyobj_t *po, line_t *line) { mobj_t *mo = NULL; blocknode_t *block = blocklinks[y * bmapwidth + x]; + blocknode_t *next = NULL; - for (; block; block = block->mnext) + for (; block != NULL; block = next) { + next = block->mnext; mo = block->mobj; // Don't scroll objects that aren't affected by gravity @@ -1115,15 +1117,15 @@ static void Polyobj_rotateThings(polyobj_t *po, vector2_t origin, angle_t delta, { mobj_t *mo; blocknode_t *block; + blocknode_t *next = NULL; if (x < 0 || y < 0 || x >= bmapwidth || y >= bmapheight) continue; - block = blocklinks[y * bmapwidth + x]; - - for (; block; block = block->mnext) + for (block = blocklinks[y * bmapwidth + x]; block != NULL; block = next) { mo = block->mobj; + next = block->mnext; if (mo->lastlook == pomovecount) continue; @@ -1316,7 +1318,7 @@ void Polyobj_InitLevel(void) // the mobj_t pointers on a queue for use below. for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (th->removing) continue; mo = (mobj_t *)th; diff --git a/src/p_saveg.c b/src/p_saveg.c index e939cf8e3..650622f59 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -2972,8 +2972,7 @@ static void P_NetArchiveThinkers(save_t *save_p) // save off the current thinkers for (th = thlist[i].next; th != &thlist[i]; th = th->next) { - if (!(th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed - || th->function.acp1 == (actionf_p1)P_NullPrecipThinker)) + if (!(th->removing || th->function.acp1 == (actionf_p1)P_NullPrecipThinker)) numsaved++; if (th->function.acp1 == (actionf_p1)P_MobjThinker) @@ -3186,7 +3185,7 @@ static void P_NetArchiveThinkers(save_t *save_p) } #ifdef PARANOIA else - I_Assert(th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed); // wait garbage collection + I_Assert(th->removing); // wait garbage collection #endif } @@ -3207,7 +3206,7 @@ mobj_t *P_FindNewPosition(UINT32 oldposition) for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (th->removing) continue; mobj = (mobj_t *)th; @@ -4528,7 +4527,7 @@ static inline void P_FinishMobjs(void) for (currentthinker = thlist[THINK_MOBJ].next; currentthinker != &thlist[THINK_MOBJ]; currentthinker = currentthinker->next) { - if (currentthinker->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (currentthinker->removing) continue; mobj = (mobj_t *)currentthinker; @@ -4546,7 +4545,7 @@ static void P_RelinkPointers(void) for (currentthinker = thlist[THINK_MOBJ].next; currentthinker != &thlist[THINK_MOBJ]; currentthinker = currentthinker->next) { - if (currentthinker->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (currentthinker->removing) continue; mobj = (mobj_t *)currentthinker; @@ -5376,7 +5375,7 @@ void P_SaveNetGame(save_t *save_p, boolean resending) // Assign the mobjnumber for pointer tracking for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (th->removing) continue; mobj = (mobj_t *)th; diff --git a/src/p_setup.c b/src/p_setup.c index 906195c18..93286219d 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -692,7 +692,7 @@ void P_ReloadRings(void) // scan the thinkers to find rings/spheres/hoops to unset for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (th->removing) continue; mo = (mobj_t *)th; @@ -750,7 +750,7 @@ void P_SwitchSpheresBonusMode(boolean bonustime) // scan the thinkers to find spheres to switch for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (th->removing) continue; mo = (mobj_t *)th; @@ -7333,7 +7333,7 @@ void P_RespawnThings(void) for (think = thlist[THINK_MOBJ].next; think != &thlist[THINK_MOBJ]; think = think->next) { - if (think->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (think->removing) continue; P_RemoveMobj((mobj_t *)think); } diff --git a/src/p_spec.c b/src/p_spec.c index 9b124f9af..d375d3e2f 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -3642,7 +3642,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) if (mo2->type != MT_EGGTRAP) continue; - if (mo2->thinker.function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (mo2->thinker.removing) continue; P_KillMobj(mo2, NULL, mo, 0); @@ -3854,7 +3854,7 @@ void P_SetupSignExit(player_t *player) // spin all signposts in the level then. for (think = thlist[THINK_MOBJ].next; think != &thlist[THINK_MOBJ]; think = think->next) { - if (think->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (think->removing) continue; thing = (mobj_t *)think; @@ -3892,7 +3892,7 @@ boolean P_IsFlagAtBase(mobjtype_t flag) for (think = thlist[THINK_MOBJ].next; think != &thlist[THINK_MOBJ]; think = think->next) { - if (think->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (think->removing) continue; mo = (mobj_t *)think; @@ -4395,7 +4395,7 @@ static void P_ProcessEggCapsule(player_t *player, sector_t *sector) // The chimps are my friends.. heeheeheheehehee..... - LouisJM for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (th->removing) continue; mo2 = (mobj_t *)th; if (mo2->type != MT_EGGTRAP) diff --git a/src/p_tick.c b/src/p_tick.c index 68de09138..db8688484 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -162,7 +162,7 @@ void Command_CountMobjs_f(void) for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (th->removing) continue; if (((mobj_t *)th)->type == i) @@ -182,7 +182,7 @@ void Command_CountMobjs_f(void) for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (th->removing) continue; if (((mobj_t *)th)->type == i) @@ -348,6 +348,7 @@ void P_RemoveThinkerDelayed(thinker_t *thinker) void P_RemoveThinker(thinker_t *thinker) { LUA_InvalidateUserdata(thinker); + thinker->removing = true; thinker->function.acp1 = (actionf_p1)P_RemoveThinkerDelayed; } diff --git a/src/p_user.c b/src/p_user.c index 718a8e30f..bb5d8f44f 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -435,7 +435,7 @@ UINT8 P_FindLowestMare(void) // to find the egg capsule with the lowest mare for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (th->removing) continue; mo2 = (mobj_t *)th; @@ -488,7 +488,7 @@ boolean P_TransferToNextMare(player_t *player) // to find the closest axis point for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (th->removing) continue; mo2 = (mobj_t *)th; @@ -539,7 +539,7 @@ static mobj_t *P_FindAxis(INT32 mare, INT32 axisnum) // to find the closest axis point for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (th->removing) continue; mo2 = (mobj_t *)th; @@ -574,7 +574,7 @@ static mobj_t *P_FindAxisTransfer(INT32 mare, INT32 axisnum, mobjtype_t type) // to find the closest axis point for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (th->removing) continue; mo2 = (mobj_t *)th; @@ -615,7 +615,7 @@ void P_TransferToAxis(player_t *player, INT32 axisnum) // to find the closest axis point for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (th->removing) continue; mo2 = (mobj_t *)th; @@ -716,7 +716,7 @@ static void P_DeNightserizePlayer(player_t *player) // Check to see if the player should be killed. for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (th->removing) continue; mo2 = (mobj_t *)th; @@ -1899,7 +1899,7 @@ void P_SpawnShieldOrb(player_t *player) // blaze through the thinkers to see if an orb already exists! for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (th->removing) continue; shieldobj = (mobj_t *)th; @@ -5106,7 +5106,7 @@ void P_Telekinesis(player_t *player, fixed_t thrust, fixed_t range) for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (th->removing) continue; mo2 = (mobj_t *)th; @@ -6472,7 +6472,7 @@ static void P_NightsTransferPoints(player_t *player, fixed_t xspeed, fixed_t rad // Find next waypoint for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (th->removing) continue; mo2 = (mobj_t *)th; @@ -6508,7 +6508,7 @@ static void P_NightsTransferPoints(player_t *player, fixed_t xspeed, fixed_t rad { for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (th->removing) continue; mo2 = (mobj_t *)th; @@ -6537,7 +6537,7 @@ static void P_NightsTransferPoints(player_t *player, fixed_t xspeed, fixed_t rad { for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (th->removing) continue; mo2 = (mobj_t *)th; @@ -7269,7 +7269,7 @@ static void P_NiGHTSMovement(player_t *player) // to find the closest axis point for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (th->removing) continue; mo2 = (mobj_t *)th; @@ -8169,7 +8169,7 @@ void P_MovePlayer(player_t *player) for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (th->removing) continue; mo2 = (mobj_t *)th; @@ -9150,7 +9150,7 @@ void P_NukeEnemies(mobj_t *inflictor, mobj_t *source, fixed_t radius) for (think = thlist[THINK_MOBJ].next; think != &thlist[THINK_MOBJ]; think = think->next) { - if (think->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (think->removing) continue; mo = (mobj_t *)think; @@ -9248,7 +9248,7 @@ mobj_t *P_LookForFocusTarget(player_t *player, mobj_t *exclude, SINT8 direction, for (think = thlist[THINK_MOBJ].next; think != &thlist[THINK_MOBJ]; think = think->next) { - if (think->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (think->removing) continue; mo = (mobj_t *)think; @@ -9367,7 +9367,7 @@ mobj_t *P_LookForEnemies(player_t *player, boolean nonenemies, boolean bullet) for (think = thlist[THINK_MOBJ].next; think != &thlist[THINK_MOBJ]; think = think->next) { - if (think->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (think->removing) continue; mo = (mobj_t *)think; @@ -9513,7 +9513,7 @@ void P_FindEmerald(void) // to find all emeralds for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (th->removing) continue; mo2 = (mobj_t *)th; @@ -10914,7 +10914,7 @@ static mobj_t *P_GetAxis(INT32 num) for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (th->removing) continue; mobj = (mobj_t *)th; @@ -11996,7 +11996,7 @@ void P_PlayerThink(player_t *player) for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (th->removing) continue; mo2 = (mobj_t *)th; diff --git a/src/st_stuff.c b/src/st_stuff.c index a33f52a25..391d038a4 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -2656,7 +2656,7 @@ static boolean ST_doItemFinderIconsAndSound(void) // Scan thinkers to find emblem mobj with these ids for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) { - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + if (th->removing) continue; mo2 = (mobj_t *)th;