]> icculus.org git repositories - divverent/darkplaces.git/blob - cl_light.c
mempools now have sentinel checks, for completeness
[divverent/darkplaces.git] / cl_light.c
1
2 #include "quakedef.h"
3
4 /*
5 ===============
6 CL_AllocDlight
7
8 ===============
9 */
10 void CL_AllocDlight (entity_render_t *ent, vec3_t org, float radius, float red, float green, float blue, float decay, float lifetime)
11 {
12         int             i;
13         dlight_t        *dl;
14
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
26 // then look for anything else
27         dl = cl_dlights;
28         for (i = 0;i < MAX_DLIGHTS;i++, dl++)
29                 if (!dl->radius)
30                         goto dlightsetup;
31
32         // unable to find one
33         return;
34
35 dlightsetup:
36         //Con_Printf("dlight %i : %f %f %f : %f %f %f\n", i, org[0], org[1], org[2], red * radius, green * radius, blue * radius);
37         memset (dl, 0, sizeof(*dl));
38         //dl->ent = ent;
39         VectorCopy(org, dl->origin);
40         dl->radius = radius;
41         dl->color[0] = red;
42         dl->color[1] = green;
43         dl->color[2] = blue;
44         dl->decay = decay;
45         if (lifetime)
46                 dl->die = cl.time + lifetime;
47         else
48                 dl->die = 0;
49 }
50
51
52 /*
53 ===============
54 CL_DecayLights
55
56 ===============
57 */
58 void CL_DecayLights (void)
59 {
60         int                     i;
61         dlight_t        *dl;
62         float           time;
63
64         time = cl.time - cl.oldtime;
65
66         dl = cl_dlights;
67         for (i=0 ; i<MAX_DLIGHTS ; i++, dl++)
68         {
69                 if (!dl->radius)
70                         continue;
71                 if (dl->die < cl.time)
72                 {
73                         dl->radius = 0;
74                         continue;
75                 }
76
77                 dl->radius -= time*dl->decay;
78                 if (dl->radius < 0)
79                         dl->radius = 0;
80         }
81 }
82