engine/EngineServerEntity.c
/*	Either finds a free edict, or allocates a new one.
	Try to avoid reusing an entity that was recently freed, because it
	can cause the client to think the entity morphed into something else
	instead of being removed and recreated, which can cause interpolated
	angles and bad trails.
*/
Either finds a free edict, or allocates a new one.
Try to avoid reusing an entity that was recently freed, because it
can cause the client to think the entity morphed into something else
instead of being removed and recreated, which can cause interpolated
angles and bad trails.
Either finds a free edict or allocates a new one . Try to avoid reusing an entity that was recently freed because it can cause the client to think the entity morphed into something else instead of being removed and recreated which can cause interpolated angles and bad trails .
ServerEntity_t *ED_Alloc (void)
{
	int i;
	ServerEntity_t *e;
	for ( i=svs.maxclients+1 ; i<sv.num_edicts ; i++)
	{
		e = EDICT_NUM(i);
		if (e->free && (e->fFreeTime < 2 || sv.time - e->fFreeTime > 0.5))
		{
			Edict_Clear(e,false);
			return e;
		}
	}
	if (i == sv.max_edicts) 
		Host_Error("ED_Alloc: no free edicts (max_edicts is %i)", sv.max_edicts); 
	sv.num_edicts++;
	e = EDICT_NUM(i);
	Edict_Clear(e,false);
	return e;
}
ServerEntity_t * ED_Alloc ( void ) { int i ; ServerEntity_t * e ; for ( i = svs . maxclients + 1 ; i < sv . num_edicts ; i ++ ) { e = EDICT_NUM ( i ) ; if ( e -> free && ( e -> fFreeTime < 2 || sv . time - e -> fFreeTime > 0.5 ) ) { Edict_Clear ( e , false ) ; return e ; } } if ( i == sv . max_edicts ) Host_Error ( " " , sv . max_edicts ) ; sv . num_edicts ++ ; e = EDICT_NUM ( i ) ; Edict_Clear ( e , false ) ; return e ; }
Either finds a free edict, or allocates a new one.
Either finds a free edict or allocates a new one .
// the first couple seconds of server time can involve a lot of // freeing and allocating, so relax the replacement policy //johnfitz -- use sv.max_edicts instead of MAX_EDICTS //johnfitz -- was Sys_Error