foxygit / doom Log in
commit 14cf34bc65d7584984d26eea4154d58770125e60
Author:     Simon Howard <fraggle@gmail.com>
AuthorDate: Sun Aug 22 01:21:27 2010 +0000
Commit:     Simon Howard <fraggle@gmail.com>
CommitDate: Sun Aug 22 01:21:27 2010 +0000

    Change span drawing functions to work the same as Vanilla, so that in
    screenshots, floors and ceilings are pixel-perfect identical to Vanilla
    Doom (thanks Porsche Monty).

    Subversion-branch: /trunk/chocolate-doom
    Subversion-revision: 1963
---
 src/r_draw.c | 111 ++++++++++++++++++++++++++++++++---------------------------
 1 file changed, 61 insertions(+), 50 deletions(-)

diff --git a/src/r_draw.c b/src/r_draw.c
index 6813ea59..b7d847d9 100644
--- a/src/r_draw.c
+++ b/src/r_draw.c
@@ -594,48 +594,54 @@ int			dscount;
 // Draws the actual span.
 void R_DrawSpan (void)
 {
-    fixed_t		xfrac;
-    fixed_t		yfrac;
-    byte*		dest;
-    int			count;
-    int			spot;
-
-#ifdef RANGECHECK
+    unsigned int position, step;
+    byte *dest;
+    int count;
+    int spot;
+    unsigned int xtemp, ytemp;
+
+#ifdef RANGECHECK
     if (ds_x2 < ds_x1
 	|| ds_x1<0
-	|| ds_x2>=SCREENWIDTH
+	|| ds_x2>=SCREENWIDTH
 	|| (unsigned)ds_y>SCREENHEIGHT)
     {
 	I_Error( "R_DrawSpan: %i to %i at %i",
 		 ds_x1,ds_x2,ds_y);
     }
-//	dscount++;
-#endif
+//	dscount++;
+#endif
+
+    // Pack position and step variables into a single 32-bit integer,
+    // with x in the top 16 bits and y in the bottom 16 bits.  For
+    // each 16-bit part, the top 6 bits are the integer part and the
+    // bottom 10 bits are the fractional part of the pixel position.
+
+    position = ((ds_xfrac << 10) & 0xffff0000)
+             | ((ds_yfrac >> 6)  & 0x0000ffff);
+    step = ((ds_xstep << 10) & 0xffff0000)
+         | ((ds_ystep >> 6)  & 0x0000ffff);

-
-    xfrac = ds_xfrac;
-    yfrac = ds_yfrac;
-
     dest = ylookup[ds_y] + columnofs[ds_x1];

     // We do not check for zero spans here?
-    count = ds_x2 - ds_x1;
+    count = ds_x2 - ds_x1;

-    do
+    do
     {
-	// Current texture index in u,v.
-	spot = ((yfrac>>(16-6))&(63*64)) + ((xfrac>>16)&63);
+	// Calculate current texture index in u,v.
+        ytemp = (position >> 4) & 0x0fc0;
+        xtemp = (position >> 26);
+        spot = xtemp | ytemp;

 	// Lookup pixel from flat texture tile,
 	//  re-index using light/colormap.
 	*dest++ = ds_colormap[ds_source[spot]];

-	// Next step in u,v.
-	xfrac += ds_xstep;
-	yfrac += ds_ystep;
-
-    } while (count--);
-}
+        position += step;
+
+    } while (count--);
+}



@@ -715,49 +721,54 @@ void R_DrawSpan (void)
 //
 // Again..
 //
-void R_DrawSpanLow (void)
-{
-    fixed_t		xfrac;
-    fixed_t		yfrac;
-    byte*		dest;
-    int			count;
-    int			spot;
-
-#ifdef RANGECHECK
+void R_DrawSpanLow (void)
+{
+    unsigned int position, step;
+    unsigned int xtemp, ytemp;
+    byte *dest;
+    int count;
+    int spot;
+
+#ifdef RANGECHECK
     if (ds_x2 < ds_x1
 	|| ds_x1<0
-	|| ds_x2>=SCREENWIDTH
+	|| ds_x2>=SCREENWIDTH
 	|| (unsigned)ds_y>SCREENHEIGHT)
     {
 	I_Error( "R_DrawSpan: %i to %i at %i",
 		 ds_x1,ds_x2,ds_y);
     }
 //	dscount++;
-#endif
-
-    xfrac = ds_xfrac;
-    yfrac = ds_yfrac;
-
-    count = (ds_x2 - ds_x1);
+#endif
+
+    position = ((ds_xfrac << 10) & 0xffff0000)
+             | ((ds_yfrac >> 6)  & 0x0000ffff);
+    step = ((ds_xstep << 10) & 0xffff0000)
+         | ((ds_ystep >> 6)  & 0x0000ffff);
+
+    count = (ds_x2 - ds_x1);

     // Blocky mode, need to multiply by 2.
     ds_x1 <<= 1;
     ds_x2 <<= 1;
-
+
     dest = ylookup[ds_y] + columnofs[ds_x1];
-
-    do
-    {
-	spot = ((yfrac>>(16-6))&(63*64)) + ((xfrac>>16)&63);
+
+    do
+    {
+	// Calculate current texture index in u,v.
+        ytemp = (position >> 4) & 0x0fc0;
+        xtemp = (position >> 26);
+        spot = xtemp | ytemp;
+
 	// Lowres/blocky mode does it twice,
 	//  while scale is adjusted appropriately.
-	*dest++ = ds_colormap[ds_source[spot]];
 	*dest++ = ds_colormap[ds_source[spot]];
-
-	xfrac += ds_xstep;
-	yfrac += ds_ystep;
+	*dest++ = ds_colormap[ds_source[spot]];

-    } while (count--);
+	position += step;
+
+    } while (count--);
 }

 //