From 94eebd2cd0ffd4edfed83aa04ea9ecd2b6965b62 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 12 Apr 2025 15:42:25 +0200 Subject: [PATCH] use mobjcache for savegame mobj load --- src/p_saveg.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/p_saveg.c b/src/p_saveg.c index db2c05cb9..abbe2fbfb 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -1928,6 +1928,25 @@ static inline player_t *LoadPlayer(UINT32 player) // // Loads a mobj_t from a save game // + +FUNCINLINE static ATTRINLINE mobj_t *AllocMobj(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; +} + static void LoadMobjThinker(savebuffer_t *save, actionf_p1 thinker) { thinker_t *next; @@ -1959,13 +1978,12 @@ static void LoadMobjThinker(savebuffer_t *save, actionf_p1 thinker) return; } - mobj = Z_Calloc(sizeof (*mobj), PU_LEVEL, NULL); - + mobj = AllocMobj(); mobj->spawnpoint = &mapthings[spawnpointnum]; mapthings[spawnpointnum].mobj = mobj; } else - mobj = Z_Calloc(sizeof (*mobj), PU_LEVEL, NULL); + mobj = AllocMobj(); // declare this as a valid mobj as soon as possible. mobj->thinker.function.acp1 = thinker;