<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">[PATCH] Cleanup dlight colour handling

Keep all the standard colours in one place to make changes easier.
Change the dlight colour to a pointer.
Try to set the colour properly everywhere.

diff -urN b/NQ/cl_main.c head/NQ/cl_main.c
--- b/NQ/cl_main.c	2005-11-27 18:19:11.000000000 +1030
+++ head/NQ/cl_main.c	2005-11-27 18:28:28.000000000 +1030
@@ -335,6 +335,13 @@
 #endif
 }
 
+const float dl_colors[4][4] = {
+    { 0.2, 0.1, 0.05, 0.7 },	/* FLASH */
+    { 0.05, 0.05, 0.3, 0.7 },	/* BLUE */
+    { 0.5, 0.05, 0.05, 0.7 },	/* RED */
+    { 0.5, 0.05, 0.4, 0.7 }	/* PURPLE */
+};
+
 /*
 ===============
 CL_AllocDlight
@@ -353,6 +360,7 @@
 	for (i = 0; i &lt; MAX_DLIGHTS; i++, dl++) {
 	    if (dl-&gt;key == key) {
 		memset(dl, 0, sizeof(*dl));
+		dl-&gt;color = dl_colors[DLIGHT_FLASH];
 		dl-&gt;key = key;
 		return dl;
 	    }
@@ -363,6 +371,7 @@
     for (i = 0; i &lt; MAX_DLIGHTS; i++, dl++) {
 	if (dl-&gt;die &lt; cl.time) {
 	    memset(dl, 0, sizeof(*dl));
+	    dl-&gt;color = dl_colors[DLIGHT_FLASH];
 	    dl-&gt;key = key;
 	    return dl;
 	}
@@ -370,6 +379,7 @@
 
     dl = &amp;cl_dlights[0];
     memset(dl, 0, sizeof(*dl));
+    dl-&gt;color = dl_colors[DLIGHT_FLASH];
     dl-&gt;key = key;
     return dl;
 }
@@ -555,10 +565,7 @@
 	    dl-&gt;radius = 200 + (rand() &amp; 31);
 	    dl-&gt;minlight = 32;
 	    dl-&gt;die = cl.time + 0.1;
-	    dl-&gt;color[0] = 0.2;
-	    dl-&gt;color[1] = 0.1;
-	    dl-&gt;color[2] = 0.05;
-	    dl-&gt;color[3] = 0.7;
+	    dl-&gt;color = dl_colors[DLIGHT_FLASH];
 	}
 	if (ent-&gt;effects &amp; EF_BRIGHTLIGHT) {
 	    dl = CL_AllocDlight(i);
@@ -566,48 +573,33 @@
 	    dl-&gt;origin[2] += 16;
 	    dl-&gt;radius = 400 + (rand() &amp; 31);
 	    dl-&gt;die = cl.time + 0.001;
-	    dl-&gt;color[0] = 0.2;
-	    dl-&gt;color[1] = 0.1;
-	    dl-&gt;color[2] = 0.05;
-	    dl-&gt;color[3] = 0.7;
+	    dl-&gt;color = dl_colors[DLIGHT_FLASH];
 	}
 	if (ent-&gt;effects &amp; EF_DIMLIGHT) {
 	    dl = CL_AllocDlight(i);
 	    VectorCopy(ent-&gt;origin, dl-&gt;origin);
 	    dl-&gt;radius = 200 + (rand() &amp; 31);
 	    dl-&gt;die = cl.time + 0.001;
-	    dl-&gt;color[0] = 0.2;
-	    dl-&gt;color[1] = 0.1;
-	    dl-&gt;color[2] = 0.05;
-	    dl-&gt;color[3] = 0.7;
+	    dl-&gt;color = dl_colors[DLIGHT_FLASH];
 	}
 	if ((ent-&gt;effects &amp; (EF_RED | EF_BLUE)) == (EF_RED | EF_BLUE)) {
 	    dl = CL_AllocDlight(i);
 	    VectorCopy(ent-&gt;origin, dl-&gt;origin);
 	    dl-&gt;radius = 200 + (rand() &amp; 31);
 	    dl-&gt;die = cl.time + 0.001;
-	    dl-&gt;color[0] = 0.5;
-	    dl-&gt;color[1] = 0.05;
-	    dl-&gt;color[2] = 0.4;
-	    dl-&gt;color[3] = 0.7;
+	    dl-&gt;color = dl_colors[DLIGHT_PURPLE];
 	} else if (ent-&gt;effects &amp; EF_BLUE) {
 	    dl = CL_AllocDlight(i);
 	    VectorCopy(ent-&gt;origin, dl-&gt;origin);
 	    dl-&gt;radius = 200 + (rand() &amp; 31);
 	    dl-&gt;die = cl.time + 0.001;
-	    dl-&gt;color[0] = 0.05;
-	    dl-&gt;color[1] = 0.05;
-	    dl-&gt;color[2] = 0.3;
-	    dl-&gt;color[3] = 0.7;
+	    dl-&gt;color = dl_colors[DLIGHT_BLUE];
 	} else if (ent-&gt;effects &amp; EF_RED) {
 	    dl = CL_AllocDlight(i);
 	    VectorCopy(ent-&gt;origin, dl-&gt;origin);
 	    dl-&gt;radius = 200 + (rand() &amp; 31);
 	    dl-&gt;die = cl.time + 0.001;
-	    dl-&gt;color[0] = 0.5;
-	    dl-&gt;color[1] = 0.05;
-	    dl-&gt;color[2] = 0.05;
-	    dl-&gt;color[3] = 0.7;
+	    dl-&gt;color = dl_colors[DLIGHT_RED];
 	}
 
 	if (ent-&gt;model-&gt;flags &amp; EF_GIB)
diff -urN b/NQ/client.h head/NQ/client.h
--- b/NQ/client.h	2005-11-27 18:19:19.000000000 +1030
+++ head/NQ/client.h	2005-11-27 18:28:42.000000000 +1030
@@ -48,7 +48,7 @@
     float die;			// stop lighting after this time
     float decay;		// drop this each second
     float minlight;		// don't add when contributing less
-    float color[4];
+    const float *color;
 } dlight_t;
 
 typedef struct {
@@ -275,6 +275,16 @@
 // cl_main
 //
 dlight_t *CL_AllocDlight(int key);
+
+/* The standard dynamic light colors */
+enum {
+    DLIGHT_FLASH = 0,
+    DLIGHT_BLUE = 1,
+    DLIGHT_RED = 2,
+    DLIGHT_PURPLE = 3
+};
+const float dl_colors[4][4]; /* Use enums to reference the colors */
+
 void CL_DecayLights(void);
 
 void CL_Init(void);
diff -urN b/NQ/model.h head/NQ/model.h
--- b/NQ/model.h	2005-01-15 15:48:49.000000000 +1030
+++ head/NQ/model.h	2005-11-03 20:36:55.000000000 +1030
@@ -34,6 +34,16 @@
 
 */
 
+// entity effects
+
+#define	EF_BRIGHTFIELD	1
+#define	EF_MUZZLEFLASH 	2
+#define	EF_BRIGHTLIGHT 	4
+#define	EF_DIMLIGHT 	8
+
+#define EF_BLUE		64
+#define EF_RED		128
+
 /*
 ==============================================================================
 
diff -urN b/QW/client/cl_ents.c head/QW/client/cl_ents.c
--- b/QW/client/cl_ents.c	2004-07-25 15:59:56.000000000 +0930
+++ head/QW/client/cl_ents.c	2005-11-27 18:29:08.000000000 +1030
@@ -45,6 +45,13 @@
 
 //============================================================
 
+const float dl_colors[4][4] = {
+    { 0.2, 0.1, 0.05, 0.7 },	/* FLASH */
+    { 0.05, 0.05, 0.3, 0.7 },	/* BLUE */
+    { 0.5, 0.05, 0.05, 0.7 },	/* RED */
+    { 0.5, 0.05, 0.4, 0.7 }	/* PURPLE */
+};
+
 /*
 ===============
 CL_AllocDlight
@@ -62,6 +69,7 @@
 	for (i = 0; i &lt; MAX_DLIGHTS; i++, dl++) {
 	    if (dl-&gt;key == key) {
 		memset(dl, 0, sizeof(*dl));
+		dl-&gt;color = dl_colors[DLIGHT_FLASH];
 		dl-&gt;key = key;
 		return dl;
 	    }
@@ -72,6 +80,7 @@
     for (i = 0; i &lt; MAX_DLIGHTS; i++, dl++) {
 	if (dl-&gt;die &lt; cl.time) {
 	    memset(dl, 0, sizeof(*dl));
+	    dl-&gt;color = dl_colors[DLIGHT_FLASH];
 	    dl-&gt;key = key;
 	    return dl;
 	}
@@ -79,6 +88,7 @@
 
     dl = &amp;cl_dlights[0];
     memset(dl, 0, sizeof(*dl));
+    dl-&gt;color = dl_colors[DLIGHT_FLASH];
     dl-&gt;key = key;
     return dl;
 }
@@ -90,7 +100,7 @@
 */
 static void
 CL_NewDlight(int key, float x, float y, float z, float radius, float time,
-	     int type)
+	     int color)
 {
     dlight_t *dl;
 
@@ -100,27 +110,7 @@
     dl-&gt;origin[2] = z;
     dl-&gt;radius = radius;
     dl-&gt;die = cl.time + time;
-    if (type == 0) {
-	dl-&gt;color[0] = 0.2;
-	dl-&gt;color[1] = 0.1;
-	dl-&gt;color[2] = 0.05;
-	dl-&gt;color[3] = 0.7;
-    } else if (type == 1) {
-	dl-&gt;color[0] = 0.05;
-	dl-&gt;color[1] = 0.05;
-	dl-&gt;color[2] = 0.3;
-	dl-&gt;color[3] = 0.7;
-    } else if (type == 2) {
-	dl-&gt;color[0] = 0.5;
-	dl-&gt;color[1] = 0.05;
-	dl-&gt;color[2] = 0.05;
-	dl-&gt;color[3] = 0.7;
-    } else if (type == 3) {
-	dl-&gt;color[0] = 0.5;
-	dl-&gt;color[1] = 0.05;
-	dl-&gt;color[2] = 0.4;
-	dl-&gt;color[3] = 0.7;
-    }
+    dl-&gt;color = dl_colors[color];
 }
 
 
@@ -430,19 +420,19 @@
 	// spawn light flashes, even ones coming from invisible objects
 	if ((s1-&gt;effects &amp; (EF_BLUE | EF_RED)) == (EF_BLUE | EF_RED))
 	    CL_NewDlight(s1-&gt;number, s1-&gt;origin[0], s1-&gt;origin[1],
-			 s1-&gt;origin[2], 200 + (rand() &amp; 31), 0.1, 3);
+			 s1-&gt;origin[2], 200 + (rand() &amp; 31), 0.1, DLIGHT_PURPLE);
 	else if (s1-&gt;effects &amp; EF_BLUE)
 	    CL_NewDlight(s1-&gt;number, s1-&gt;origin[0], s1-&gt;origin[1],
-			 s1-&gt;origin[2], 200 + (rand() &amp; 31), 0.1, 1);
+			 s1-&gt;origin[2], 200 + (rand() &amp; 31), 0.1, DLIGHT_BLUE);
 	else if (s1-&gt;effects &amp; EF_RED)
 	    CL_NewDlight(s1-&gt;number, s1-&gt;origin[0], s1-&gt;origin[1],
-			 s1-&gt;origin[2], 200 + (rand() &amp; 31), 0.1, 2);
+			 s1-&gt;origin[2], 200 + (rand() &amp; 31), 0.1, DLIGHT_RED);
 	else if (s1-&gt;effects &amp; EF_BRIGHTLIGHT)
 	    CL_NewDlight(s1-&gt;number, s1-&gt;origin[0], s1-&gt;origin[1],
-			 s1-&gt;origin[2] + 16, 400 + (rand() &amp; 31), 0.1, 0);
+			 s1-&gt;origin[2] + 16, 400 + (rand() &amp; 31), 0.1, DLIGHT_FLASH);
 	else if (s1-&gt;effects &amp; EF_DIMLIGHT)
 	    CL_NewDlight(s1-&gt;number, s1-&gt;origin[0], s1-&gt;origin[1],
-			 s1-&gt;origin[2], 200 + (rand() &amp; 31), 0.1, 0);
+			 s1-&gt;origin[2], 200 + (rand() &amp; 31), 0.1, DLIGHT_FLASH);
 
 	// if set to invisible, skip
 	if (!s1-&gt;modelindex)
@@ -817,20 +807,20 @@
 #endif
 	    if ((state-&gt;effects &amp; (EF_BLUE | EF_RED)) == (EF_BLUE | EF_RED))
 		CL_NewDlight(j, state-&gt;origin[0], state-&gt;origin[1],
-			     state-&gt;origin[2], 200 + (rand() &amp; 31), 0.1, 3);
+			     state-&gt;origin[2], 200 + (rand() &amp; 31), 0.1, DLIGHT_PURPLE);
 	    else if (state-&gt;effects &amp; EF_BLUE)
 		CL_NewDlight(j, state-&gt;origin[0], state-&gt;origin[1],
-			     state-&gt;origin[2], 200 + (rand() &amp; 31), 0.1, 1);
+			     state-&gt;origin[2], 200 + (rand() &amp; 31), 0.1, DLIGHT_BLUE);
 	    else if (state-&gt;effects &amp; EF_RED)
 		CL_NewDlight(j, state-&gt;origin[0], state-&gt;origin[1],
-			     state-&gt;origin[2], 200 + (rand() &amp; 31), 0.1, 2);
+			     state-&gt;origin[2], 200 + (rand() &amp; 31), 0.1, DLIGHT_RED);
 	    else if (state-&gt;effects &amp; EF_BRIGHTLIGHT)
 		CL_NewDlight(j, state-&gt;origin[0], state-&gt;origin[1],
 			     state-&gt;origin[2] + 16, 400 + (rand() &amp; 31),
-			     0.1, 0);
+			     0.1, DLIGHT_FLASH);
 	    else if (state-&gt;effects &amp; EF_DIMLIGHT)
 		CL_NewDlight(j, state-&gt;origin[0], state-&gt;origin[1],
-			     state-&gt;origin[2], 200 + (rand() &amp; 31), 0.1, 0);
+			     state-&gt;origin[2], 200 + (rand() &amp; 31), 0.1, DLIGHT_FLASH);
 #ifdef GLQUAKE
 	}
 #endif
diff -urN b/QW/client/cl_parse.c head/QW/client/cl_parse.c
--- b/QW/client/cl_parse.c	2004-07-25 15:59:56.000000000 +0930
+++ head/QW/client/cl_parse.c	2005-11-27 18:29:25.000000000 +1030
@@ -1103,10 +1103,7 @@
     dl-&gt;radius = 200 + (rand() &amp; 31);
     dl-&gt;minlight = 32;
     dl-&gt;die = cl.time + 0.1;
-    dl-&gt;color[0] = 0.2;
-    dl-&gt;color[1] = 0.1;
-    dl-&gt;color[2] = 0.05;
-    dl-&gt;color[3] = 0.7;
+    dl-&gt;color = dl_colors[DLIGHT_FLASH];
 }
 
 
diff -urN b/QW/client/cl_tent.c head/QW/client/cl_tent.c
--- b/QW/client/cl_tent.c	2004-07-25 15:59:56.000000000 +0930
+++ head/QW/client/cl_tent.c	2005-11-27 18:29:40.000000000 +1030
@@ -247,10 +247,7 @@
 	dl-&gt;radius = 350;
 	dl-&gt;die = cl.time + 0.5;
 	dl-&gt;decay = 300;
-	dl-&gt;color[0] = 0.2;
-	dl-&gt;color[1] = 0.1;
-	dl-&gt;color[2] = 0.05;
-	dl-&gt;color[3] = 0.7;
+	dl-&gt;color = dl_colors[DLIGHT_FLASH];
 
 	// sound
 	S_StartSound(-1, 0, cl_sfx_r_exp3, pos, 1, 1);
diff -urN b/QW/client/client.h head/QW/client/client.h
--- b/QW/client/client.h	2005-11-27 18:19:19.000000000 +1030
+++ head/QW/client/client.h	2005-11-27 18:29:56.000000000 +1030
@@ -46,7 +46,7 @@
     float die;			// stop lighting after this time
     float decay;		// drop this each second
     float minlight;		// don't add when contributing less
-    float color[4];
+    const float *color;
 } dlight_t;
 
 typedef struct {
@@ -355,6 +355,16 @@
 // cl_main
 //
 dlight_t *CL_AllocDlight(int key);
+
+/* The standard dynamic light colors */
+enum {
+    DLIGHT_FLASH = 0,
+    DLIGHT_BLUE = 1,
+    DLIGHT_RED = 2,
+    DLIGHT_PURPLE = 3
+};
+const float dl_colors[4][4]; /* Use enums to reference the colors */
+
 void CL_DecayLights(void);
 
 void CL_Init(void);
diff -urN b/common/gl_rlight.c head/common/gl_rlight.c
--- b/common/gl_rlight.c	2005-11-27 18:19:11.000000000 +1030
+++ head/common/gl_rlight.c	2005-03-06 14:15:12.000000000 +1030
@@ -124,8 +124,7 @@
     }
 
     glBegin(GL_TRIANGLE_FAN);
-    glColor4f(light-&gt;color[0], light-&gt;color[1], light-&gt;color[2],
-	      light-&gt;color[3]);
+    glColor4fv(light-&gt;color);
 
     for (i = 0; i &lt; 3; i++)
 	v[i] = light-&gt;origin[i] - vpn[i] * rad;
</pre></body></html>