1 //local entity management routines.
2 
3 #include "client.h"
4 
5 int	localent_count = 0;
6 
7 localent_t cl_localents[MAX_LOCAL_ENTS];
8 cvar_t	*cl_lents;
9 
10 void LE_RunEntity (localent_t *ent);
11 void V_AddEntity (entity_t *ent);
12 
Le_Alloc(void)13 localent_t *Le_Alloc (void)
14 {
15 	int i;
16 
17 	//r1: disable lents?
18 	if (!cl_lents->intvalue)
19 		return NULL;
20 
21 	for (i = 0; i < MAX_LOCAL_ENTS; i++) {
22 		if (!cl_localents[i].inuse) {
23 			if (i+1 > localent_count)
24 				localent_count = i+1;
25 			memset (&cl_localents[i], 0, sizeof(localent_t));
26 			cl_localents[i].inuse = true;
27 			return &cl_localents[i];
28 		}
29 	}
30 	Com_Printf ("Le_Alloc: no free local entities!\n", LOG_CLIENT);
31 	return NULL;
32 }
33 
Le_Free(localent_t * lent)34 void Le_Free (localent_t *lent)
35 {
36 	if (!lent->inuse) {
37 		Com_Printf ("Le_Free: freeing an unused entity.\n", LOG_CLIENT);
38 		return;
39 	}
40 
41 	memset (lent, 0, sizeof(localent_t));
42 	return;
43 }
44 
Le_Reset(void)45 void Le_Reset (void)
46 {
47 	localent_count = 0;
48 	memset (&cl_localents, 0, MAX_LOCAL_ENTS * sizeof(localent_t));
49 }
50 
LE_RunLocalEnts(void)51 void LE_RunLocalEnts (void)
52 {
53 	int i;
54 
55 	for (i = 0; i < localent_count; i++) {
56 		if (cl_localents[i].inuse)
57 			LE_RunEntity (&cl_localents[i]);
58 	}
59 }
60 
CL_AddLocalEnts(void)61 void CL_AddLocalEnts (void)
62 {
63 	int i;
64 
65 	for (i = 0; i < localent_count; i++) {
66 		if (cl_localents[i].inuse)
67 			V_AddEntity (&cl_localents[i].ent);
68 	}
69 }
70 
LE_Init(void)71 void LE_Init (void)
72 {
73 	cl_lents = Cvar_Get ("cl_lents", "0", 0);
74 }
75