]> icculus.org git repositories - divverent/darkplaces.git/blob - cl_light.c
e4b9d4bb0108019fdbc45cbcce5e02efcb8d5bd6
[divverent/darkplaces.git] / cl_light.c
1 #include "quakedef.h"
2
3 dlight_t cl_dlights[MAX_DLIGHTS];
4
5 void cl_light_start(void)
6 {
7 }
8
9 void cl_light_shutdown(void)
10 {
11 }
12
13 void cl_light_newmap(void)
14 {
15         memset (cl_dlights, 0, sizeof(cl_dlights));
16 }
17
18 void CL_Light_Init(void)
19 {
20         R_RegisterModule("CL_Light", cl_light_start, cl_light_shutdown, cl_light_newmap);
21 }
22
23 /*
24 ===============
25 CL_AllocDlight
26
27 ===============
28 */
29 void CL_AllocDlight (entity_render_t *ent, vec3_t org, float radius, float red, float green, float blue, float decay, float lifetime)
30 {
31         int             i;
32         dlight_t        *dl;
33
34 // first look for an exact key match
35         if (ent)
36         {
37                 dl = cl_dlights;
38                 for (i = 0;i < MAX_DLIGHTS;i++, dl++)
39                         if (dl->ent == ent)
40                                 goto dlightsetup;
41         }
42
43 // then look for anything else
44         dl = cl_dlights;
45         for (i = 0;i < MAX_DLIGHTS;i++, dl++)
46                 if (!dl->radius)
47                         goto dlightsetup;
48
49         // unable to find one
50         return;
51
52 dlightsetup:
53         memset (dl, 0, sizeof(*dl));
54         dl->ent = ent;
55         VectorCopy(org, dl->origin);
56         dl->radius = radius;
57         dl->color[0] = red;
58         dl->color[1] = green;
59         dl->color[2] = blue;
60         dl->decay = decay;
61         dl->die = cl.time + lifetime;
62 }
63
64
65 /*
66 ===============
67 CL_DecayLights
68
69 ===============
70 */
71 void CL_DecayLights (void)
72 {
73         int                     i;
74         dlight_t        *dl;
75         float           time;
76
77         time = cl.time - cl.oldtime;
78
79         c_dlights = 0;
80         dl = cl_dlights;
81         for (i=0 ; i<MAX_DLIGHTS ; i++, dl++)
82         {
83                 if (!dl->radius)
84                         continue;
85                 if (dl->die < cl.time)
86                 {
87                         dl->radius = 0;
88                         continue;
89                 }
90
91                 c_dlights++; // count every dlight in use
92
93                 dl->radius -= time*dl->decay;
94                 if (dl->radius < 0)
95                         dl->radius = 0;
96         }
97 }
98
99