shithub: qk1

Download patch

ref: 964902ba628e0aecc635f888b4e0c09803c179cd
parent: 5c840ffec2b14ebf8ccede0f837c34b7eb159274
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Thu Jan 4 15:15:59 EST 2024

sdl: add v_fullscreen cvar

--- a/d_scan.c
+++ b/d_scan.c
@@ -103,7 +103,7 @@
 		s += sstep;
 		t += tstep;
 		if(opaque(pix) && *pz <= izi)
-			*pdest = blendalpha(blendfog(pix, *fog), *pdest, alpha);
+			*pdest = blendalpha(0xff<<24 | blendfog(pix, *fog), *pdest, alpha);
 		izi += izistep;
 		pdest++;
 		pz++;
@@ -191,7 +191,7 @@
 		if(noblend || *pz <= izi){
 			sturb = ((s + r_turb_turb[(t>>16)&(CYCLE-1)])>>16)&63;
 			tturb = ((t + r_turb_turb[(s>>16)&(CYCLE-1)])>>16)&63;
-			*pdest = blendalpha(blendfog(*(pbase + (tturb<<6) + sturb), *fog), *pdest, alpha);
+			*pdest = blendalpha(0xff<<24 | blendfog(*(pbase + (tturb<<6) + sturb), *fog), *pdest, alpha);
 			if(noblend)
 				*pz = izi;
 		}
--- a/d_sky.c
+++ b/d_sky.c
@@ -43,8 +43,8 @@
 	uzint *pz;
 	fixed16_t s[2], t[2], snext[2], tnext[2], sstep[2], tstep[2];
 	float skydist;
-	bool fog;
-	int c0, c1, c2, inva;
+	pixel_t fog;
+	int inva;
 
 	if(skyvars.source[0] == nil || skyvars.source[1] == nil)
 		return;
@@ -52,12 +52,8 @@
 	sstep[0] = sstep[1] = 0;	// keep compiler happy
 	tstep[0] = tstep[1] = 0;	// ditto
 	skydist = skyvars.time*skyvars.speed;	// TODO: add D_SetupFrame & set this there
-	if((fog = isskyfogged())){
-		c0 = fogvars.skyc0;
-		c1 = fogvars.skyc1;
-		c2 = fogvars.skyc1;
-		inva = 255 - fogvars.sky;
-	}
+	fog = fogvars.skypix;
+	inva = 255 - (fog>>24);
 
 	do
 	{
@@ -108,12 +104,8 @@
 				pix = skyvars.source[1][((t[1] & skyvars.tmask) >> skyvars.tshift) + ((s[1] & skyvars.smask) >> 16)];
 				if(!opaque(pix))
 					pix = skyvars.source[0][((t[0] & skyvars.tmask) >> skyvars.tshift) + ((s[0] & skyvars.smask) >> 16)];
-				if(fog){
-					pix =
-						((c0 + inva*((pix>> 0)&0xff)) >> 8) << 0 |
-						((c1 + inva*((pix>> 8)&0xff)) >> 8) << 8 |
-						((c2 + inva*((pix>>16)&0xff)) >> 8) << 16;
-				}
+				if(fog != 0)
+					pix = fog + mulalpha(pix, inva);
 				*pdest++ = pix;
 				s[0] += sstep[0];
 				t[0] += tstep[0];
--- a/plan9/platform.h
+++ b/plan9/platform.h
@@ -42,6 +42,6 @@
 typedef enum {false, true} bool;
 
 static double ln2c;
-#define exp2(x) (exp((x) * (ln2c ? ln2c : (ln2c = log(2.0)))))
+#define exp2f(x) (exp((x) * (ln2c ? ln2c : (ln2c = log(2.0)))))
 
 int qctz(unsigned);
--- a/r_fog.c
+++ b/r_fog.c
@@ -6,16 +6,19 @@
 fogvars_t fogvars;
 
 static void
+fogrecalc(void)
+{
+	fogvars.pix = (fogvars.allowed && fogvars.enabled)
+		? 0xff<<24 | fogvars.c2<<16 | fogvars.c1<<8 | fogvars.c0
+		: 0;
+	fogvars.skypix = mulalpha(fogvars.pix, 255 * clamp(r_skyfog.value, 0.0, 1.0));
+}
+
+static void
 r_skyfog_cb(cvar_t *var)
 {
-	if(var->value > 0.0)
-		fogvars.enabled |= Enskyfog;
-	else
-		fogvars.enabled &= ~Enskyfog;
-	fogvars.sky = 255 * clamp(var->value, 0.0, 1.0);
-	fogvars.skyc0 = fogvars.sky * fogvars.c0;
-	fogvars.skyc1 = fogvars.sky * fogvars.c1;
-	fogvars.skyc2 = fogvars.sky * fogvars.c2;
+	USED(var);
+	fogrecalc();
 }
 
 static void
@@ -40,14 +43,14 @@
 			else if(s[6] == 'b')
 				fogvars.c0 = x;
 			else if(s[6] == 'e'){
-				fogvars.enabled = x > 0 ? (Enfog | Enskyfog) : 0;
+				fogvars.enabled = x > 0;
 				setcvar("r_skyfog", x > 0 ? "1" : "0");
 			}
-			fogvars.pix = 0xff<<24 | fogvars.c2<<16 | fogvars.c1<<8 | fogvars.c0;
-			return;
+			break;
 		}
 		fogvars.density = clamp(x, 0.0, 1.0) * 0.016;
 		fogvars.density *= fogvars.density;
+		fogvars.enabled = fogvars.density > 0.0;
 		if(n == 2)
 			break;
 	case 4:
@@ -58,13 +61,9 @@
 		x = atof(Cmd_Argv(i));
 		fogvars.c0 = 0xff * clamp(x, 0.0, 1.0);
 		r_skyfog_cb(&r_skyfog); /* recalculate sky fog */
-		fogvars.pix = 0xff<<24 | fogvars.c2<<16 | fogvars.c1<<8 | fogvars.c0;
 		break;
 	}
-	if(fogvars.density > 0.0)
-		fogvars.enabled |= Enfog;
-	else
-		fogvars.enabled &= ~Enfog;
+	fogrecalc();
 }
 
 void
@@ -71,10 +70,9 @@
 R_ResetFog(void)
 {
 	memset(&fogvars, 0, sizeof(fogvars));
-	fogvars.c0 = fogvars.c1 = fogvars.c2 = 0x80;
-	fogvars.pix = 0xff808080;
+	fogvars.c2 = fogvars.c1 = fogvars.c0 = 0x80;
 	fogvars.allowed = r_fog.value > 0.0;
-	setcvar("r_skyfog", "0");
+	setcvar("r_skyfog", "0"); // calls fogrecalc
 }
 
 static void
@@ -81,6 +79,7 @@
 r_fog_cb(cvar_t *var)
 {
 	fogvars.allowed = var->value > 0.0;
+	fogrecalc();
 }
 
 void
--- a/r_fog.h
+++ b/r_fog.h
@@ -13,12 +13,13 @@
 z2foga(uzint z)
 {
 	float d;
+	unsigned x;
 
-	if(z <= 65536)
+	if(z <= 0)
 		return 0;
-	d = 65536ULL*65536ULL / (u64int)z;
-	d = 1.0 - exp2(-fogvars.density * d*d);
-	return 255*d;
+	x = 0xffffffffU / z;
+	d = exp2f(-fogvars.density * x * x);
+	return 255 - 255*d;
 }
 
 static inline pixel64_t
--- a/r_shared.h
+++ b/r_shared.h
@@ -11,18 +11,15 @@
 typedef struct fogvars_t fogvars_t;
 
 struct fogvars_t {
-	pixel_t pix;
+	pixel_t pix, skypix;
 	float density;
-	int skyc0, skyc1, skyc2;
-	int enabled;
-	byte sky, c0, c1, c2;
-	bool allowed;
+	byte c0, c1, c2;
+	bool allowed, enabled;
 };
 
 extern fogvars_t fogvars;
 
-#define isfogged() (fogvars.allowed && (fogvars.enabled & Enfog) != 0)
-#define isskyfogged() (fogvars.sky != 0 && fogvars.allowed && (fogvars.enabled & Enskyfog) != 0)
+#define isfogged() (fogvars.pix != 0)
 
 // FIXME: clean up and move into d_iface.h
 
--- a/vid_sdl.c
+++ b/vid_sdl.c
@@ -11,6 +11,7 @@
 extern pixel_t *r_warpbuffer;
 
 static cvar_t v_snail = {"v_snail", "0"};
+static cvar_t v_fullscreen = {"v_fullscreen", "0", true};
 static int oldvidbuffersz;
 
 static void
@@ -111,6 +112,24 @@
 	sys_snail(var->value != 0);
 }
 
+static void
+v_fullscreen_cb(cvar_t *var)
+{
+	static int oldmode = 0;
+	int mode;
+
+	if(var->value >= 2)
+		mode = SDL_WINDOW_FULLSCREEN_DESKTOP;
+	else if(var->value >= 1)
+		mode = SDL_WINDOW_FULLSCREEN;
+	else
+		mode = 0;
+	if(oldmode != mode && SDL_SetWindowFullscreen(win, mode) == 0){
+		vid.resized = true;
+		oldmode = mode;
+	}
+}
+
 void
 initfb(void)
 {
@@ -138,4 +157,6 @@
 
 	Cvar_RegisterVariable(&v_snail);
 	v_snail.cb = v_snail_cb;
+	Cvar_RegisterVariable(&v_fullscreen);
+	v_fullscreen.cb = v_fullscreen_cb;
 }