rewrote memory system entirely (hunk, cache, and zone are gone, memory pools replaced...
[xonotic/darkplaces.git] / cl_light.c
1 #include "quakedef.h"
2
3 dlight_t cl_dlights[MAX_DLIGHTS];
4
5 /*
6 ===============
7 CL_AllocDlight
8
9 ===============
10 */
11 void CL_AllocDlight (entity_render_t *ent, vec3_t org, float radius, float red, float green, float blue, float decay, float lifetime)
12 {
13         int             i;
14         dlight_t        *dl;
15
16 // first look for an exact key match
17         if (ent)
18         {
19                 dl = cl_dlights;
20                 for (i = 0;i < MAX_DLIGHTS;i++, dl++)
21                         if (dl->ent == ent)
22                                 goto dlightsetup;
23         }
24
25 // then look for anything else
26         dl = cl_dlights;
27         for (i = 0;i < MAX_DLIGHTS;i++, dl++)
28                 if (!dl->radius)
29                         goto dlightsetup;
30
31         // unable to find one
32         return;
33
34 dlightsetup:
35         memset (dl, 0, sizeof(*dl));
36         dl->ent = ent;
37         VectorCopy(org, dl->origin);
38         dl->radius = radius;
39         dl->color[0] = red;
40         dl->color[1] = green;
41         dl->color[2] = blue;
42         dl->decay = decay;
43         dl->die = cl.time + lifetime;
44 }
45
46
47 /*
48 ===============
49 CL_DecayLights
50
51 ===============
52 */
53 void CL_DecayLights (void)
54 {
55         int                     i;
56         dlight_t        *dl;
57         float           time;
58
59         time = cl.time - cl.oldtime;
60
61         dl = cl_dlights;
62         for (i=0 ; i<MAX_DLIGHTS ; i++, dl++)
63         {
64                 if (!dl->radius)
65                         continue;
66                 if (dl->die < cl.time)
67                 {
68                         dl->radius = 0;
69                         continue;
70                 }
71
72                 dl->radius -= time*dl->decay;
73                 if (dl->radius < 0)
74                         dl->radius = 0;
75         }
76 }
77
78