Cache and reuse removed mobjs when spawning mobjs
from https://git.do.srb2.org/STJr/SRB2/-/merge_requests/2200
This commit is contained in:
1 parent
52590350fa
commit
e421c1345b
5 files changed
+31
-3
No files matched your search
@@ -49,6 +49,7 @@ 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 cachable;
|
||||
} thinker_t;
|
||||
|
||||
#endif
|
||||
@@ -66,6 +66,7 @@
|
||||
|
||||
// both the head and tail of the thinker list
|
||||
extern thinker_t thinkercap;
|
||||
extern mobj_t *mobjcache;
|
||||
|
||||
void P_InitThinkers(void);
|
||||
void P_AddThinker(thinker_t *thinker);
|
||||
|
||||
+16
-2
@@ -48,6 +48,7 @@ actioncache_t actioncachehead;
|
||||
static mobj_t *overlaycap = NULL;
|
||||
static mobj_t *shadowcap = NULL;
|
||||
mobj_t *waypointcap = NULL;
|
||||
mobj_t *mobjcache = NULL;
|
||||
|
||||
void P_InitCachedActions(void)
|
||||
{
|
||||
@@ -9510,7 +9511,18 @@ mobj_t *P_SpawnMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype_t type)
|
||||
{
|
||||
const mobjinfo_t *info = &mobjinfo[type];
|
||||
state_t *st;
|
||||
mobj_t *mobj = Z_Calloc(sizeof (*mobj), PU_LEVEL, NULL);
|
||||
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);
|
||||
}
|
||||
|
||||
// this is officially a mobj, declared as soon as possible.
|
||||
mobj->thinker.function.acp1 = (actionf_p1)P_MobjThinker;
|
||||
@@ -10255,7 +10267,9 @@ void P_RemoveMobj(mobj_t *mobj)
|
||||
// Invalidate mobj_t data to cause crashes if accessed!
|
||||
memset(mobj, 0xff, sizeof(mobj_t));
|
||||
#endif
|
||||
Z_Free(mobj); // No refrences? Can be removed immediately! :D
|
||||
// no references, dump it directly in the mobj cache
|
||||
mobj->hnext = mobjcache;
|
||||
mobjcache = mobj;
|
||||
}
|
||||
else
|
||||
{ // Add thinker just to delay removing it until refrences are gone.
|
||||
|
||||
@@ -2995,6 +2995,8 @@ boolean P_SetupLevel(boolean skipprecip)
|
||||
R_FlushTranslationColormapCache();
|
||||
|
||||
Z_FreeTags(PU_LEVEL, PU_PURGELEVEL - 1);
|
||||
|
||||
mobjcache = NULL;
|
||||
|
||||
#if defined (WALLSPLATS) || defined (FLOORSPLATS)
|
||||
// clear the splats from previous level
|
||||
|
||||
+11
-1
@@ -201,6 +201,7 @@ void P_AddThinker(thinker_t *thinker)
|
||||
thinkercap.prev = thinker;
|
||||
|
||||
thinker->references = 0; // killough 11/98: init reference counter to 0
|
||||
thinker->cachable = thinker->function.acp1 == (actionf_p1)P_MobjThinker;
|
||||
}
|
||||
|
||||
//
|
||||
@@ -236,7 +237,16 @@ void P_RemoveThinkerDelayed(void *pthinker)
|
||||
(next->prev = currentthinker = thinker->prev)->next = next;
|
||||
}
|
||||
R_DestroyLevelInterpolators(thinker);
|
||||
Z_Free(thinker);
|
||||
if (thinker->cachable)
|
||||
{
|
||||
// put cachable thinkers in the mobj cache, so we can avoid allocations
|
||||
((mobj_t *)thinker)->hnext = mobjcache;
|
||||
mobjcache = (mobj_t *)thinker;
|
||||
}
|
||||
else
|
||||
{
|
||||
Z_Free(thinker);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user