]> icculus.org git repositories - divverent/darkplaces.git/blob - cl_light.c
now fetchs wgl functions
[divverent/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         if (lifetime)
44                 dl->die = cl.time + lifetime;
45         else
46                 dl->die = 0;
47 }
48
49
50 /*
51 ===============
52 CL_DecayLights
53
54 ===============
55 */
56 void CL_DecayLights (void)
57 {
58         int                     i;
59         dlight_t        *dl;
60         float           time;
61
62         time = cl.time - cl.oldtime;
63
64         dl = cl_dlights;
65         for (i=0 ; i<MAX_DLIGHTS ; i++, dl++)
66         {
67                 if (!dl->radius)
68                         continue;
69                 if (dl->die < cl.time)
70                 {
71                         dl->radius = 0;
72                         continue;
73                 }
74
75                 dl->radius -= time*dl->decay;
76                 if (dl->radius < 0)
77                         dl->radius = 0;
78         }
79 }
80
81