shithub: qk1

Download patch

ref: e5e155f8fb17097cbf2bee55515a3a81d839eb64
parent: 8bd89358c5cb1c25e5ed98080fe6b81db29b2c03
author: Sigrid Solveig Haflínudóttir <[email protected]>
date: Sat Dec 30 21:00:48 EST 2023

get rid of screenwidth and rowbytes

--- a/d_edge.c
+++ b/d_edge.c
@@ -34,7 +34,7 @@
 	int u, u2;
 
 	for(span = surf->spans; span; span=span->pnext){
-		pdest = dvars.viewbuffer + screenwidth*span->v;
+		pdest = dvars.viewbuffer + dvars.width*span->v;
 		u2 = span->u + span->count - 1;
 		for(u = span->u; u <= u2; u++)
 			pdest[u] = color;
--- a/d_init.c
+++ b/d_init.c
@@ -26,7 +26,7 @@
 	int i;
 
 	dvars.viewbuffer = r_dowarp ? r_warpbuffer : vid.buffer;
-	screenwidth = vid.rowbytes;
+	dvars.width = vid.width;
 
 	d_roverwrapped = false;
 	d_initial_rover = sc_rover;
--- a/d_local.h
+++ b/d_local.h
@@ -13,8 +13,8 @@
 	pixel_t *cacheblock;
 	pixel_t *viewbuffer;
 	uzint *zbuffer;
+	unsigned width;
 	unsigned cachewidth;
-	unsigned zwidth;
 	fixed16_t sadjust, tadjust;
 	fixed16_t bbextents, bbextentt;
 	float sdivzstepu, tdivzstepu, zistepu;
--- a/d_modech.c
+++ b/d_modech.c
@@ -9,10 +9,8 @@
 void
 D_ViewChanged (void)
 {
-	int rowbytes, i;
+	int i;
 
-	dvars.zwidth = vid.width;
-	rowbytes = vid.rowbytes;
 	scale_for_mip = max(xscale, yscale);
 
 	d_pix_scale = 90.0 / max(r_refdef.fov_x, r_refdef.fov_y);
@@ -26,8 +24,8 @@
 	d_vrectbottom_particle = r_refdef.vrectbottom - d_pix_max;
 
 	for(i = 0; i < vid.height; i++){
-		d_scantable[i] = i*rowbytes;
-		zspantable[i] = dvars.zbuffer + i*dvars.zwidth;
+		d_scantable[i] = i * dvars.width;
+		zspantable[i] = dvars.zbuffer + i*dvars.width;
 	}
 }
 
--- a/d_part.c
+++ b/d_part.c
@@ -35,7 +35,7 @@
 		return;
 	}
 
-	pz = dvars.zbuffer + dvars.zwidth*v + u;
+	pz = dvars.zbuffer + v*dvars.width + u;
 	pdest = dvars.viewbuffer + d_scantable[v] + u;
 	izi = zi * 0x8000 * 0x10000;
 
@@ -45,7 +45,7 @@
 		pix = 1;
 	color = pparticle->color;
 
-	for(count = pix; count; count--, pz += dvars.zwidth, pdest += screenwidth){
+	for(count = pix; count; count--, pz += dvars.width, pdest += dvars.width){
 		for(i = 0; i < pix; i++){
 			if(pz[i] <= izi){
 				pz[i] = izi;
--- a/d_polyse.c
+++ b/d_polyse.c
@@ -628,8 +628,8 @@
 	d_light[1] = plefttop->l[1];
 	d_light[2] = plefttop->l[2];
 
-	d_pdest = dvars.viewbuffer + ystart * screenwidth + plefttop->u;
-	d_pz = dvars.zbuffer + ystart * dvars.zwidth + plefttop->u;
+	d_pdest = dvars.viewbuffer + ystart * dvars.width + plefttop->u;
+	d_pz = dvars.zbuffer + ystart * dvars.width + plefttop->u;
 
 	if (initialleftheight == 1)
 	{
@@ -654,9 +654,8 @@
 		D_PolysetSetUpForLineScan(plefttop->u, plefttop->v,
 							  pleftbottom->u, pleftbottom->v);
 
-		d_pzbasestep = dvars.zwidth + ubasestep;
+		d_pdestbasestep = d_pzbasestep = dvars.width + ubasestep;
 		d_pzextrastep = d_pzbasestep + 1;
-		d_pdestbasestep = screenwidth + ubasestep;
 		d_pdestextrastep = d_pdestbasestep + 1;
 
 		// TODO: can reuse partial expressions here
@@ -720,8 +719,8 @@
 		d_light[1] = plefttop->l[1];
 		d_light[2] = plefttop->l[2];
 
-		d_pdest = dvars.viewbuffer + ystart * screenwidth + plefttop->u;
-		d_pz = dvars.zbuffer + ystart * dvars.zwidth + plefttop->u;
+		d_pdest = dvars.viewbuffer + ystart * dvars.width + plefttop->u;
+		d_pz = dvars.zbuffer + ystart * dvars.width + plefttop->u;
 
 		if (height == 1)
 		{
@@ -744,9 +743,8 @@
 			D_PolysetSetUpForLineScan(plefttop->u, plefttop->v,
 								  pleftbottom->u, pleftbottom->v);
 
-			d_pdestbasestep = screenwidth + ubasestep;
+			d_pzbasestep = d_pdestbasestep = dvars.width + ubasestep;
 			d_pdestextrastep = d_pdestbasestep + 1;
-			d_pzbasestep = dvars.zwidth + ubasestep;
 			d_pzextrastep = d_pzbasestep + 1;
 
 			if (ubasestep < 0){
--- a/d_scan.c
+++ b/d_scan.c
@@ -30,15 +30,15 @@
 	hratio = h / (float)scr_vrect.height;
 
 	for(v = 0; v < scr_vrect.height+AMP2*2; v++)
-		rowptr[v] = dvars.viewbuffer + (r_refdef.vrect.y * screenwidth) + (screenwidth * (int)((float)v * hratio * h / (h + AMP2 * 2)));
+		rowptr[v] = dvars.viewbuffer + (r_refdef.vrect.y * dvars.width) + (dvars.width * (int)((float)v * hratio * h / (h + AMP2 * 2)));
 
 	for(u = 0; u < scr_vrect.width+AMP2*2; u++)
 		column[u] = r_refdef.vrect.x + (int)((float)u * wratio * w / (w + AMP2 * 2));
 
 	turb = intsintable + ((int)(cl.time*SPEED)&(CYCLE-1));
-	dest = vid.buffer + scr_vrect.y * vid.rowbytes + scr_vrect.x;
+	dest = vid.buffer + scr_vrect.y * vid.width + scr_vrect.x;
 
-	for(v = 0; v < scr_vrect.height; v++, dest += vid.rowbytes){
+	for(v = 0; v < scr_vrect.height; v++, dest += vid.width){
 		col = &column[turb[v]];
 		row = &rowptr[v];
 
@@ -56,7 +56,8 @@
 D_DrawTurbulent8Span
 =============
 */
-void D_DrawTurbulent8Span (int izi, byte alpha)
+static inline void
+D_DrawTurbulent8Span (int izi, byte alpha)
 {
 	int sturb, tturb;
 
@@ -93,8 +94,9 @@
 	zi16stepu = dvars.zistepu * 16;
 
 	do{
-		r_turb_pdest = dvars.viewbuffer + screenwidth*pspan->v + pspan->u;
-		r_turb_z = dvars.zbuffer + dvars.zwidth*pspan->v + pspan->u;
+		r_turb_pdest = dvars.viewbuffer + pspan->v*dvars.width + pspan->u;
+		r_turb_z = dvars.zbuffer + pspan->v*dvars.width + pspan->u;
+		zi = dvars.ziorigin + pspan->v*dvars.zistepv + pspan->u*dvars.zistepu;
 
 		count = pspan->count;
 
@@ -104,7 +106,6 @@
 
 		sdivz = dvars.sdivzorigin + dv*dvars.sdivzstepv + du*dvars.sdivzstepu;
 		tdivz = dvars.tdivzorigin + dv*dvars.tdivzstepv + du*dvars.tdivzstepu;
-		zi = dvars.ziorigin + dv*dvars.zistepv + du*dvars.zistepu;
 		z = (float)0x10000 / zi;	// prescale to 16.16 fixed-point
 
 		r_turb_s = (int)(sdivz * z) + dvars.sadjust;
@@ -192,8 +193,9 @@
 	izistep = (int)(dvars.zistepu * 0x8000 * 0x10000);
 
 	do{
-		pdest = dvars.viewbuffer + screenwidth*pspan->v + pspan->u;
-		pz = dvars.zbuffer + dvars.zwidth*pspan->v + pspan->u;
+		pdest = dvars.viewbuffer + pspan->v*dvars.width + pspan->u;
+		pz = dvars.zbuffer + pspan->v*dvars.width + pspan->u;
+		zi = dvars.ziorigin + pspan->v*dvars.zistepv + pspan->u*dvars.zistepu;
 
 		count = pspan->count;
 
@@ -203,7 +205,6 @@
 
 		sdivz = dvars.sdivzorigin + dv*dvars.sdivzstepv + du*dvars.sdivzstepu;
 		tdivz = dvars.tdivzorigin + dv*dvars.tdivzstepv + du*dvars.tdivzstepu;
-		zi = dvars.ziorigin + dv*dvars.zistepv + du*dvars.zistepu;
 		z = (float)0x10000 / zi;	// prescale to 16.16 fixed-point
 
 		s = (int)(sdivz * z) + dvars.sadjust;
@@ -288,7 +289,7 @@
 	izistep = dvars.zistepu * 0x8000 * 0x10000;
 
 	do{
-		pz = dvars.zbuffer + pspan->v*dvars.zwidth + pspan->u;
+		pz = dvars.zbuffer + pspan->v*dvars.width + pspan->u;
 		zi = dvars.ziorigin + pspan->v*dvars.zistepv + pspan->u*dvars.zistepu;
 		count = pspan->count;
 
--- a/d_sky.c
+++ b/d_sky.c
@@ -52,7 +52,7 @@
 
 	do
 	{
-		pdest = dvars.viewbuffer + (screenwidth * pspan->v) + pspan->u;
+		pdest = dvars.viewbuffer + pspan->v*dvars.width + pspan->u;
 		count = pspan->count;
 
 		// calculate the initial s & t
--- a/d_sprite.c
+++ b/d_sprite.c
@@ -33,8 +33,8 @@
 
 	do
 	{
-		pdest = dvars.viewbuffer + screenwidth * pspan->v + pspan->u;
-		pz = dvars.zbuffer + dvars.zwidth * pspan->v + pspan->u;
+		pdest = dvars.viewbuffer + dvars.width * pspan->v + pspan->u;
+		pz = dvars.zbuffer + dvars.width * pspan->v + pspan->u;
 
 		count = pspan->count;
 
--- a/draw.c
+++ b/draw.c
@@ -138,7 +138,7 @@
 	}
 	else
 		drawline = 8;
-	dest = vid.conbuffer + y*vid.conrowbytes + x;
+	dest = vid.conbuffer + y*vid.conwidth + x;
 	while(drawline--){
 		if(source[0]) dest[0] = source[0];
 		if(source[1]) dest[1] = source[1];
@@ -149,7 +149,7 @@
 		if(source[6]) dest[6] = source[6];
 		if(source[7]) dest[7] = source[7];
 		source += 128;
-		dest += vid.conrowbytes;
+		dest += vid.conwidth;
 	}
 }
 
@@ -186,13 +186,13 @@
 		fatal ("Draw_Pic: bad coordinates");
 	}
 	source = pic->pixels;
-	dest = vid.buffer + y * vid.rowbytes + x;
+	dest = vid.buffer + y * vid.width + x;
 	for(py = 0; py < pic->height; py++){
 		for(px = 0; px < pic->width; px++){
 			if(opaque(source[px]))
 				dest[px] = source[px];
 		}
-		dest += vid.rowbytes;
+		dest += vid.width;
 		source += pic->width;
 	}
 }
@@ -212,13 +212,13 @@
 		fatal ("Draw_TransPic: bad coordinates");
 
 	source = pic->pixels;
-	dest = vid.buffer + y * vid.rowbytes + x;
+	dest = vid.buffer + y * vid.width + x;
 	if(pic->width & 7){	// general
 		for(v=0; v<pic->height; v++){
 			for(u=0; u<pic->width; u++)
 				if(opaque(tpix = source[u]))
 					dest[u] = tpix;
-			dest += vid.rowbytes;
+			dest += vid.width;
 			source += pic->width;
 		}
 	}else{	// unwound
@@ -241,7 +241,7 @@
 				if(opaque(tpix = source[u+7]))
 					dest[u+7] = tpix;
 			}
-			dest += vid.rowbytes;
+			dest += vid.width;
 			source += pic->width;
 		}
 	}
@@ -262,13 +262,13 @@
 		fatal ("Draw_TransPic: bad coordinates");
 
 	source = pic->pixels;
-	dest = vid.buffer + y * vid.rowbytes + x;
+	dest = vid.buffer + y * vid.width + x;
 	if (pic->width & 7){	// general
 		for(v=0; v<pic->height; v++){
 			for(u=0; u<pic->width; u++)
 				if(opaque(tpix = source[u]))
 					dest[u] = tpix;
-			dest += vid.rowbytes;
+			dest += vid.width;
 			source += pic->width;
 		}
 	}else{	// unwound
@@ -291,7 +291,7 @@
 				if(opaque(tpix = source[u+7]))
 					dest[u+7] = tpix;
 			}
-			dest += vid.rowbytes;
+			dest += vid.width;
 			source += pic->width;
 		}
 	}
@@ -344,7 +344,7 @@
 	for (x=0 ; x<n ; x++)
 		Draw_CharToConback (ver[x], dest+(x<<3));
 	dest = vid.conbuffer;
-	for(y=0; y<lines; y++, dest+=vid.conrowbytes){
+	for(y=0; y<lines; y++, dest+=vid.conwidth){
 		v = (vid.conheight - lines + y) * 200 / vid.conheight;
 		src = conback->pixels + v * 320;
 		if(vid.conwidth == 320)
@@ -373,10 +373,10 @@
 	pixel_t	t, *pdest;
 	int		i, j, srcdelta, destdelta;
 
-	pdest = vid.buffer + (prect->y * vid.rowbytes) + prect->x;
+	pdest = vid.buffer + (prect->y * vid.width) + prect->x;
 
 	srcdelta = rowbytes - prect->width;
-	destdelta = vid.rowbytes - prect->width;
+	destdelta = vid.width - prect->width;
 
 	if (transparent)
 	{
@@ -395,7 +395,7 @@
 		for (i=0 ; i<prect->height ; i++){
 			memcpy (pdest, psrc, prect->width*sizeof(pixel_t));
 			psrc += rowbytes;
-			pdest += vid.rowbytes;
+			pdest += vid.width;
 		}
 	}
 }
@@ -476,8 +476,8 @@
 	pixel_t			*dest;
 	int				u, v;
 
-	dest = vid.buffer + y*vid.rowbytes + x;
-	for(v=0; v<h; v++, dest+=vid.rowbytes)
+	dest = vid.buffer + y*vid.width + x;
+	for(v=0; v<h; v++, dest+=vid.width)
 		for(u=0; u<w; u++)
 			dest[u] = c;
 }
@@ -497,7 +497,7 @@
 	{
 		int	t;
 
-		pbuf = vid.buffer + vid.rowbytes*y;
+		pbuf = vid.buffer + vid.width*y;
 		t = (y & 1) << 1;
 
 		for (x=0 ; x<vid.width ; x++)
--- a/r_edge.c
+++ b/r_edge.c
@@ -25,8 +25,6 @@
 
 int		r_currentkey;
 
-extern	int	screenwidth;
-
 static int current_iv, edge_head_u_shift20, edge_tail_u_shift20;
 static edge_t edge_head, edge_tail, edge_aftertail, edge_sentinel;
 static float fv;
--- a/r_local.h
+++ b/r_local.h
@@ -196,8 +196,6 @@
 extern	edge_t	*newedges[MAXHEIGHT];
 extern	edge_t	*removeedges[MAXHEIGHT];
 
-extern	int	screenwidth;
-
 // FIXME: make stack vars when debugging done
 extern int		r_bmodelactive;
 
--- a/r_main.c
+++ b/r_main.c
@@ -41,8 +41,6 @@
 float		xscaleshrink, yscaleshrink;
 float		aliasxscale, aliasyscale, aliasxcenter, aliasycenter;
 
-int		screenwidth;
-
 float	pixelAspect;
 float	screenAspect;
 float	xOrigin, yOrigin;
--- a/r_shared.h
+++ b/r_shared.h
@@ -17,8 +17,6 @@
 
 //===================================================================
 
-extern int		screenwidth;
-
 extern	float	pixelAspect;
 
 extern int		r_drawnpolycount;
--- a/vid.h
+++ b/vid.h
@@ -16,7 +16,6 @@
 	pixel_t			*buffer;		// invisible buffer
 	pixel_t			*colormap;		// 256 * VID_GRADES size
 	int				fullbright;		// index of first fullbright color
-	unsigned		rowbytes;	// may be > width if displayed in a window
 	int				width;
 	int				height;
 	float			aspect;		// width / height -- < 0 is taller than wide
@@ -23,7 +22,6 @@
 	int				numpages;
 	int				recalc_refdef;	// if true, recalc vid-based stuff
 	pixel_t			*conbuffer;
-	int				conrowbytes;
 	unsigned		conwidth;
 	unsigned		conheight;
 	int				maxwarpwidth;
--- a/vid_plan9.c
+++ b/vid_plan9.c
@@ -45,9 +45,7 @@
 	surfcache = (byte*)(dvars.zbuffer + vid.width * vid.height);
 	D_InitCaches(surfcache, scachesz);
 
-	vid.rowbytes = vid.width;
 	vid.aspect = (float)vid.height / (float)vid.width * (320.0/240.0);
-	vid.conrowbytes = vid.rowbytes;
 	vid.conwidth = vid.width;
 	vid.conheight = vid.height;
 
--- a/vid_sdl.c
+++ b/vid_sdl.c
@@ -26,9 +26,7 @@
 	if(vid.height < 160)
 		vid.height = 160;
 
-	vid.rowbytes = vid.width;
 	vid.aspect = (float)vid.height / (float)vid.width * (320.0/240.0);
-	vid.conrowbytes = vid.rowbytes;
 	vid.conwidth = vid.width;
 	vid.conheight = vid.height;
 
--- a/view.c
+++ b/view.c
@@ -856,7 +856,7 @@
 		// render two interleaved views
 		int		i;
 
-		vid.rowbytes <<= 1;
+		vid.width <<= 1;
 		vid.aspect *= 0.5;
 
 		r_refdef.viewangles[YAW] -= lcd_yaw.value;
@@ -864,7 +864,7 @@
 			r_refdef.vieworg[i] -= right[i]*lcd_x.value;
 		R_RenderView ();
 
-		vid.buffer += vid.rowbytes>>1;
+		vid.buffer += vid.width>>1;
 
 		R_PushDlights ();
 
@@ -873,11 +873,11 @@
 			r_refdef.vieworg[i] += 2*right[i]*lcd_x.value;
 		R_RenderView ();
 
-		vid.buffer -= vid.rowbytes>>1;
+		vid.buffer -= vid.width>>1;
 
 		r_refdef.vrect.height <<= 1;
 
-		vid.rowbytes >>= 1;
+		vid.width >>= 1;
 		vid.aspect *= 2;
 	}
 	else