]> de.git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
fix entity reuse of the very last entity before the entity reuse timer expires.
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 14 Apr 2009 11:43:25 +0000 (11:43 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 14 Apr 2009 11:43:25 +0000 (11:43 +0000)
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
prvm_edict.c
sv_phys.c

index 3d9af47730cd0bd79a1576bd97ed4399ff3aaf37..c66763862807f9ab5be6d7b9cc9dda9b3c0b9cd7 100644 (file)
--- 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);
index 24eeb734a84ba692b86d8cf98026310103042e9b..c7ecc92e1dc32dbf0972124f293a9089a102597e 100644 (file)
@@ -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();
index fd1b825199d91968dd2e7c882c1140e25ecaef1c..2bcea7ff1f9dc41ab1dac6a6cd4e3100883c115e 100644 (file)
--- 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;