From e1f6fb1b68e7e01054c3ecde016462371acc193a Mon Sep 17 00:00:00 2001 From: NepDisk Date: Fri, 12 Sep 2025 00:23:32 -0400 Subject: [PATCH] AllocateMobj RR port --- src/p_local.h | 2 ++ src/p_mobj.c | 29 +++++++++++++++++++---------- src/p_saveg.c | 4 ++-- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/p_local.h b/src/p_local.h index f3e565321..109d87c2f 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -303,6 +303,8 @@ mobjtype_t P_GetMobjtype(UINT16 mthingtype); void P_RespawnSpecials(void); +mobj_t *P_AllocateMobj(void); + mobj_t *P_SpawnMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype_t type); void P_CalculatePrecipFloor(precipmobj_t *mobj); diff --git a/src/p_mobj.c b/src/p_mobj.c index 6ac1ee9ff..c3dc90558 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -10926,6 +10926,24 @@ static void P_DefaultMobjShadowScale(mobj_t *thing) } } +mobj_t *P_AllocateMobj(void) +{ + mobj_t *mobj; + + if (mobjcache != NULL) + { + mobj = mobjcache; + mobjcache = mobjcache->hnext; + memset(mobj, 0, sizeof(*mobj)); + } + else + { + mobj = Z_Calloc(sizeof (*mobj), PU_LEVEL, NULL); + } + + return mobj; +} + // // P_SpawnMobj // @@ -10951,16 +10969,7 @@ mobj_t *P_SpawnMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype_t type) type = MT_RAY; } - if (mobjcache != NULL) - { - mobj = mobjcache; - mobjcache = mobjcache->hnext; - memset(mobj, 0, sizeof(*mobj)); - } - else - { - mobj = Z_Calloc(sizeof (*mobj), PU_LEVEL, NULL); - } + mobj = P_AllocateMobj(); // this is officially a mobj, declared as soon as possible. mobj->thinker.function.acp1 = (actionf_p1)P_MobjThinker; diff --git a/src/p_saveg.c b/src/p_saveg.c index ed7c98fc9..6b851a76f 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -3590,13 +3590,13 @@ static thinker_t* LoadMobjThinker(savebuffer_t *save, actionf_p1 thinker) return NULL; } - mobj = Z_Calloc(sizeof (*mobj), PU_LEVEL, NULL); + mobj = P_AllocateMobj(); mobj->spawnpoint = &mapthings[spawnpointnum]; mapthings[spawnpointnum].mobj = mobj; } else - mobj = Z_Calloc(sizeof (*mobj), PU_LEVEL, NULL); + mobj = P_AllocateMobj(); // declare this as a valid mobj as soon as possible. mobj->thinker.function.acp1 = thinker;