From c360f95fc145cb80b56a06230d68459f591e4cef Mon Sep 17 00:00:00 2001 From: divverent Date: Tue, 14 Apr 2009 11:43:25 +0000 Subject: [PATCH] fix entity reuse of the very last entity before the entity reuse timer expires. Fixes bug with Nexuiz muzzle flashes sticking to the gun, and some other "PL-like" bugs too. git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@8926 d7cf8633-e32d-0410-b094-e92efae38249 --- progsvm.h | 1 + prvm_edict.c | 22 +++++++++++++++++++--- sv_phys.c | 2 +- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/progsvm.h b/progsvm.h index 3d9af477..c6676386 100644 --- a/progsvm.h +++ b/progsvm.h @@ -539,6 +539,7 @@ func_t PRVM_ED_FindFunctionOffset(const char *name); void PRVM_MEM_IncreaseEdicts(void); +qboolean PRVM_ED_CanAlloc(prvm_edict_t *e); prvm_edict_t *PRVM_ED_Alloc (void); void PRVM_ED_Free (prvm_edict_t *ed); void PRVM_ED_ClearEdict (prvm_edict_t *e); diff --git a/prvm_edict.c b/prvm_edict.c index 24eeb734..c7ecc92e 100644 --- a/prvm_edict.c +++ b/prvm_edict.c @@ -236,6 +236,24 @@ const char *PRVM_AllocationOrigin() return buf; } +/* +================= +PRVM_ED_CanAlloc + +Returns if this particular edict could get allocated by PRVM_ED_Alloc +================= +*/ +qboolean PRVM_ED_CanAlloc(prvm_edict_t *e) +{ + if(!e->priv.required->free) + return false; + if(e->priv.required->freetime < prog->starttime + 2) + return true; + if(realtime > e->priv.required->freetime + 1) + return true; + return false; // entity slot still blocked because the entity was freed less than one second ago +} + /* ================= PRVM_ED_Alloc @@ -260,9 +278,7 @@ prvm_edict_t *PRVM_ED_Alloc (void) for (i = prog->reserved_edicts + 1;i < prog->num_edicts;i++) { e = PRVM_EDICT_NUM(i); - // the first couple seconds of server time can involve a lot of - // freeing and allocating, so relax the replacement policy - if (e->priv.required->free && ( e->priv.required->freetime < prog->starttime + 2 || (realtime - e->priv.required->freetime) > 1 ) ) + if(PRVM_ED_CanAlloc(e)) { PRVM_ED_ClearEdict (e); e->priv.required->allocation_origin = PRVM_AllocationOrigin(); diff --git a/sv_phys.c b/sv_phys.c index fd1b8251..2bcea7ff 100644 --- a/sv_phys.c +++ b/sv_phys.c @@ -2387,7 +2387,7 @@ void SV_Physics (void) } // decrement prog->num_edicts if the highest number entities died - for (;PRVM_EDICT_NUM(prog->num_edicts - 1)->priv.server->free;prog->num_edicts--); + for (;PRVM_ED_CanAlloc(PRVM_EDICT_NUM(prog->num_edicts - 1));prog->num_edicts--); if (!sv_freezenonclients.integer) sv.time += sv.frametime; -- 2.39.2