]> de.git.xonotic.org Git - xonotic/darkplaces.git/blob - cl_light.c
this should fix the program name in com_argv[0], so detection of which game to run...
[xonotic/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         memset (dl, 0, sizeof(*dl));
37         //dl->ent = ent;
38         VectorCopy(org, dl->origin);
39         dl->radius = radius;
40         dl->color[0] = red;
41         dl->color[1] = green;
42         dl->color[2] = blue;
43         dl->decay = decay;
44         if (lifetime)
45                 dl->die = cl.time + lifetime;
46         else
47                 dl->die = 0;
48 }
49
50
51 /*
52 ===============
53 CL_DecayLights
54
55 ===============
56 */
57 void CL_DecayLights (void)
58 {
59         int                     i;
60         dlight_t        *dl;
61         float           time;
62
63         time = cl.time - cl.oldtime;
64
65         dl = cl_dlights;
66         for (i=0 ; i<MAX_DLIGHTS ; i++, dl++)
67         {
68                 if (!dl->radius)
69                         continue;
70                 if (dl->die < cl.time)
71                 {
72                         dl->radius = 0;
73                         continue;
74                 }
75
76                 dl->radius -= time*dl->decay;
77                 if (dl->radius < 0)
78                         dl->radius = 0;
79         }
80 }
81