mobjcache with explicit "true" check
just in case smth throws a garbo value and is not actually a mobj thinker
This commit is contained in:
1 parent
e1cb858d9a
commit
5aff1acea8
5 files changed
+57
-5
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);
|
||||
|
||||
+28
-3
@@ -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)
|
||||
{
|
||||
@@ -9362,7 +9363,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;
|
||||
@@ -9823,7 +9835,18 @@ mobj_t *P_SpawnShadowMobj(mobj_t * caster)
|
||||
{
|
||||
const mobjinfo_t *info = &mobjinfo[MT_SHADOW];
|
||||
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;
|
||||
@@ -10097,7 +10120,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.
|
||||
|
||||
@@ -2753,6 +2753,8 @@ boolean P_SetupLevel(boolean skipprecip, boolean reloadinggamestate)
|
||||
R_ClearLevelSplats();
|
||||
#endif
|
||||
|
||||
mobjcache = NULL;
|
||||
|
||||
R_InitializeLevelInterpolators();
|
||||
|
||||
P_InitThinkers();
|
||||
|
||||
+25
-2
@@ -196,6 +196,8 @@ 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);
|
||||
}
|
||||
|
||||
//
|
||||
@@ -235,7 +237,17 @@ void P_RemoveThinkerDelayed(thinker_t *thinker)
|
||||
* thinker->prev->next = thinker->next */
|
||||
(next->prev = currentthinker = thinker->prev)->next = next;
|
||||
R_DestroyLevelInterpolators(thinker);
|
||||
Z_Free(thinker);
|
||||
|
||||
if (thinker->cachable == true)
|
||||
{
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
@@ -250,9 +262,20 @@ void P_UnlinkThinker(thinker_t *thinker)
|
||||
I_Assert(thinker->references == 0);
|
||||
|
||||
(next->prev = thinker->prev)->next = next;
|
||||
Z_Free(thinker);
|
||||
|
||||
if (thinker->cachable == true)
|
||||
{
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// P_RemoveThinker
|
||||
//
|
||||
|
||||
Reference in new issue
Block a user