shithub: qk1

Download patch

ref: 8a7a14f7c62afe6b89e1c1da71252aa2585eb09b
parent: 781eeead92f56bd399624c6f3edc0568935cf9b1
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Wed Dec 13 13:24:15 EST 2023

better fov refdef recalculation

--- a/r_main.c
+++ b/r_main.c
@@ -261,12 +261,16 @@
 */
 void R_ViewChanged (vrect_t *pvrect, int lineadj, float aspect)
 {
-	int		i;
+	int		i, ow, oh;
 	float	res_scale;
 
 	r_viewchanged = true;
 
+	ow = r_refdef.vrect.width;
+	oh = r_refdef.vrect.height;
 	R_SetVrect (pvrect, &r_refdef.vrect, lineadj);
+	if(ow != r_refdef.vrect.width || oh != r_refdef.vrect.height)
+		vid.recalc_refdef = true;
 
 	r_refdef.horizontalFieldOfView = 2.0 * tan (r_refdef.fov_x/360*M_PI);
 	r_refdef.fvrectx = (float)r_refdef.vrect.x;
--- a/screen.c
+++ b/screen.c
@@ -153,26 +153,15 @@
 
 //=============================================================================
 
-/*
-====================
-CalcFov
-====================
-*/
-static float CalcFov (float fov_x, float width, float height)
+static float
+CalcFov(float fov, float a, float b)
 {
-	float   a = 0;
-	float   x;
+	float v;
 
-	if (fov_x < 1 || fov_x > 179)
-		fatal ("Bad fov: %f", fov_x);
+	fov = clamp(fov, 1, 179);
+	v = a / tan(fov / 360 * M_PI);
 
-	x = width/tan(fov_x/360*M_PI);
-
-	if(x != 0)
-		a = atan (height/x);
-	a = a*360/M_PI;
-
-	return a;
+	return atan(b / v) * 360.0 / M_PI;
 }
 
 /*
@@ -189,7 +178,7 @@
 	float		size;
 
 	scr_fullupdate = 0;		// force a background redraw
-	vid.recalc_refdef = 0;
+	vid.recalc_refdef = false;
 
 	// force the status bar to redraw
 	Sbar_Changed ();
@@ -208,9 +197,11 @@
 	if (scr_fov.value > 170)
 		setcvar ("fov","170");
 
-	r_refdef.fov_x = scr_fov.value;
-	r_refdef.fov_y = CalcFov (r_refdef.fov_x, r_refdef.vrect.width, r_refdef.vrect.height);
+	r_refdef.fov_y = CalcFov(scr_fov.value, 640, 432); // 480→432 adjusted for a status bar
+	r_refdef.fov_x = CalcFov(r_refdef.fov_y, r_refdef.vrect.height, r_refdef.vrect.width);
 
+	scr_vrect = r_refdef.vrect;
+
 	// intermission is always full screen
 	if (cl.intermission)
 		size = 120;
@@ -253,7 +244,7 @@
 static void SCR_SizeUp_f (void)
 {
 	setcvarv ("viewsize",scr_viewsize.value+10);
-	vid.recalc_refdef = 1;
+	vid.recalc_refdef = true;
 }
 
 
@@ -267,7 +258,7 @@
 static void SCR_SizeDown_f (void)
 {
 	setcvarv ("viewsize",scr_viewsize.value-10);
-	vid.recalc_refdef = 1;
+	vid.recalc_refdef = true;
 }
 
 void SCR_Init (void)
@@ -612,7 +603,7 @@
 */
 void SCR_UpdateScreen (bool drawdialog)
 {
-	static float	oldlcd_x;
+	static float oldlcd_x;
 
 	if (scr_disabled_for_loading)
 	{
--- a/unix/vid.c
+++ b/unix/vid.c
@@ -81,7 +81,7 @@
 		stopfb();
 		resized = 0;
 		resetfb();
-		vid.recalc_refdef = 1;	/* force a surface cache flush */
+		vid.recalc_refdef = true;	/* force a surface cache flush */
 		Con_CheckResize();
 		Con_Clear_f();
 		return;
--- a/vid.c
+++ b/vid.c
@@ -112,7 +112,7 @@
 			sysfatal("%r");
 		resized = 0;
 		resetfb();
-		vid.recalc_refdef = 1;	/* force a surface cache flush */
+		vid.recalc_refdef = true;	/* force a surface cache flush */
 		Con_CheckResize();
 		Con_Clear_f();
 		return;
--- a/view.c
+++ b/view.c
@@ -274,7 +274,7 @@
 	oldgammavalue = v_gamma.value;
 
 	BuildGammaTable (v_gamma.value);
-	vid.recalc_refdef = 1;				// force a surface cache flush
+	vid.recalc_refdef = true;				// force a surface cache flush
 
 	return true;
 }