From 2adffd32ea2c50fbbc575623a6c9a5f6d501f82b Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 5 May 2025 20:30:34 +0200 Subject: [PATCH] test: try prevent synch issues when p_setscale gets called on mobj spawn --- src/p_maputl.c | 41 +++++++++++++++++++++++------------------ src/p_maputl.h | 2 ++ src/p_mobj.c | 7 +++++++ 3 files changed, 32 insertions(+), 18 deletions(-) diff --git a/src/p_maputl.c b/src/p_maputl.c index 7b748c22e..cf7bec6c9 100644 --- a/src/p_maputl.c +++ b/src/p_maputl.c @@ -740,23 +740,7 @@ void P_UnsetThingPosition(mobj_t *thing) thing->touching_sectorlist = NULL; //to be restored by P_SetThingPosition } - if (!(thing->flags & MF_NOBLOCKMAP)) - { - /* inert things don't need to be in blockmap - * - * killough 8/11/98: simpler scheme using pointers-to-pointers for prev - * pointers, allows head node pointers to be treated like everything else - * - * Also more robust, since it doesn't depend on current position for - * unlinking. Old method required computing head node based on position - * at time of unlinking, assuming it was the same position as during - * linking. - */ - - mobj_t *bnext, **bprev = thing->bprev; - if (bprev && (*bprev = bnext = thing->bnext) != NULL) // unlink from block map - bnext->bprev = bprev; - } + P_UnlinkfromBlockMap(thing); } void P_UnsetPrecipThingPosition(precipmobj_t *thing) @@ -768,7 +752,7 @@ void P_UnsetPrecipThingPosition(precipmobj_t *thing) bnext->bprev = bprev; } -static void P_LinkToBlockMap(mobj_t *thing, mobj_t **bmap) +void P_LinkToBlockMap(mobj_t *thing, mobj_t **bmap) { const INT32 blockx = (unsigned)(thing->x - bmaporgx) >> MAPBLOCKSHIFT; const INT32 blocky = (unsigned)(thing->y - bmaporgy) >> MAPBLOCKSHIFT; @@ -797,6 +781,27 @@ static void P_LinkToBlockMap(mobj_t *thing, mobj_t **bmap) } } +void P_UnlinkfromBlockMap(mobj_t *thing) +{ + if (!(thing->flags & MF_NOBLOCKMAP)) + { + /* inert things don't need to be in blockmap + * + * killough 8/11/98: simpler scheme using pointers-to-pointers for prev + * pointers, allows head node pointers to be treated like everything else + * + * Also more robust, since it doesn't depend on current position for + * unlinking. Old method required computing head node based on position + * at time of unlinking, assuming it was the same position as during + * linking. + */ + + mobj_t *bnext, **bprev = thing->bprev; + if (bprev && (*bprev = bnext = thing->bnext) != NULL) // unlink from block map + bnext->bprev = bprev; + } +} + // // P_SetThingPosition // Links a thing into both a block and a subsector diff --git a/src/p_maputl.h b/src/p_maputl.h index d2337d007..a97fab1fa 100644 --- a/src/p_maputl.h +++ b/src/p_maputl.h @@ -51,6 +51,8 @@ fixed_t P_InterceptVector(divline_t *v2, divline_t *v1); INT32 P_BoxOnLineSide(fixed_t *tmbox, const line_t *ld); void P_UnsetPrecipThingPosition(precipmobj_t *thing); void P_SetPrecipitationThingPosition(precipmobj_t *thing); +void P_LinkToBlockMap(mobj_t *thing, mobj_t **bmap); +void P_UnlinkfromBlockMap(mobj_t *thing); void P_CreatePrecipSecNodeList(precipmobj_t *thing, fixed_t x,fixed_t y); boolean P_SceneryTryMove(mobj_t *thing, fixed_t x, fixed_t y); diff --git a/src/p_mobj.c b/src/p_mobj.c index 8f67fd03a..5ece5c99b 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -5665,6 +5665,8 @@ void P_SetScale(mobj_t *mobj, fixed_t newscale) oldscale = mobj->scale; //keep for adjusting stuff below + P_UnlinkfromBlockMap(mobj); + mobj->scale = newscale; mobj->radius = FixedMul(mobj->info->radius, newscale); @@ -5678,6 +5680,11 @@ void P_SetScale(mobj_t *mobj, fixed_t newscale) player->viewheight = FixedMul(FixedDiv(player->viewheight, oldscale), newscale); // Nonono don't calculate viewheight elsewhere, this is the best place for it! player->dashspeed = FixedMul(FixedDiv(player->dashspeed, oldscale), newscale); // Prevents the player from having to re-charge up spindash if the player grew in size } + + if (!(mobj->flags & MF_NOBLOCKMAP)) + { + P_LinkToBlockMap(mobj, blocklinks); + } } void P_Attract(mobj_t *source, mobj_t *dest, boolean nightsgrab) // Home in on your target