shithub: qk1

Download patch

ref: 9377317f548b91431caa9dbd26b998c141bb0a4d
parent: 8a4ebe3fc930049a7ad7699443a44412d7a16a6a
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Thu Dec 28 16:03:59 EST 2023

fog: add Nehahra-specific fog vars, but keep them bound to the same "fog" command

--- a/r_fog.c
+++ b/r_fog.c
@@ -5,7 +5,6 @@
 
 static struct {
 	float density;
-	pixel_t color;
 	byte c0, c1, c2;
 }r_fog_data;
 
@@ -12,8 +11,9 @@
 static void
 fog(void)
 {
-	int i, j, n;
+	int i, n;
 	float x;
+	char *s;
 
 	i = 1;
 	n = Cmd_Argc();
@@ -21,19 +21,29 @@
 	case 5:
 	case 2:
 		x = atof(Cmd_Argv(i++));
+		if(n == 2 && strncmp(s = Cmd_Argv(0), "gl_fog", 6) == 0 && s[6] != 'd'){ // Nehahra
+			x = 255 * clamp(x, 0.0, 1.0);
+			if(s[6] == 'r')
+				r_fog_data.c2 = x;
+			else if(s[6] == 'g')
+				r_fog_data.c1 = x;
+			else if(s[6] == 'b')
+				r_fog_data.c0 = x;
+			else if(s[6] == 'e')
+				setcvar("r_fog", Cmd_Argv(i-1));
+			break;
+		}
 		r_fog_data.density = clamp(x, 0.0, 1.0) * 0.016;
 		r_fog_data.density *= r_fog_data.density;
 		if(n == 2)
 			break;
 	case 4:
-		r_fog_data.color = 0;
-		for(j = 0; j < 3; j++, i++){
-			x = atof(Cmd_Argv(i));
-			r_fog_data.color = r_fog_data.color << 8 | (int)(0xff * clamp(x, 0.0, 1.0));
-		}
-		r_fog_data.c0 = r_fog_data.color>> 0;
-		r_fog_data.c1 = r_fog_data.color>> 8;
-		r_fog_data.c2 = r_fog_data.color>>16;
+		x = atof(Cmd_Argv(i++));
+		r_fog_data.c2 = 0xff * clamp(x, 0.0, 1.0);
+		x = atof(Cmd_Argv(i++));
+		r_fog_data.c1 = 0xff * clamp(x, 0.0, 1.0);
+		x = atof(Cmd_Argv(i++));
+		r_fog_data.c0 = 0xff * clamp(x, 0.0, 1.0);
 		break;
 	}
 }
@@ -42,7 +52,6 @@
 R_ResetFog(void)
 {
 	r_fog_data.density = 0;
-	r_fog_data.color = 0x808080;
 	r_fog_data.c0 = r_fog_data.c1 = r_fog_data.c2 = 0x80;
 	setcvar("r_skyfog", "0");
 }
@@ -102,4 +111,11 @@
 	Cmd_AddCommand("fog", fog);
 	Cvar_RegisterVariable(&r_fog);
 	Cvar_RegisterVariable(&r_skyfog);
+
+	// Nehahra
+	Cmd_AddCommand("gl_fogenable", fog);
+	Cmd_AddCommand("gl_fogdensity", fog);
+	Cmd_AddCommand("gl_fogred", fog);
+	Cmd_AddCommand("gl_foggreen", fog);
+	Cmd_AddCommand("gl_fogblue", fog);
 }