summaryrefslogtreecommitdiff
path: root/src/sw_scan.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/sw_scan.c')
-rw-r--r--src/sw_scan.c245
1 files changed, 108 insertions, 137 deletions
diff --git a/src/sw_scan.c b/src/sw_scan.c
index 16754ed..1687bf9 100644
--- a/src/sw_scan.c
+++ b/src/sw_scan.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -28,7 +28,7 @@ fixed16_t r_turb_s, r_turb_t, r_turb_sstep, r_turb_tstep;
int *r_turb_turb;
int r_turb_spancount;
-void D_DrawTurbulent8Span (void);
+void D_DrawTurbulent8Span(void);
/*
@@ -39,54 +39,49 @@ this performs a slight compression of the screen at the same time as
the sine warp, to keep the edges from wrapping
=============
*/
-void D_WarpScreen (void)
+void D_WarpScreen(void)
{
int w, h;
- int u,v, u2, v2;
+ int u, v, u2, v2;
byte *dest;
int *turb;
int *col;
byte **row;
static int cached_width, cached_height;
- static byte *rowptr[MAXHEIGHT*2+AMP2*2];
- static int column[MAXWIDTH*2+AMP2*2];
+ static byte *rowptr[MAXHEIGHT * 2 + AMP2 * 2];
+ static int column[MAXWIDTH * 2 + AMP2 * 2];
//
// these are constant over resolutions, and can be saved
//
w = r_newrefdef.width;
h = r_newrefdef.height;
- if (w != cached_width || h != cached_height)
- {
+ if (w != cached_width || h != cached_height) {
cached_width = w;
cached_height = h;
- for (v=0 ; v<h+AMP2*2 ; v++)
- {
- v2 = (int)((float)v/(h + AMP2 * 2) * r_refdef.vrect.height);
+ for (v = 0; v < h + AMP2 * 2; v++) {
+ v2 = (int)((float)v / (h + AMP2 * 2) * r_refdef.vrect.height);
rowptr[v] = r_warpbuffer + (WARP_WIDTH * v2);
}
- for (u=0 ; u<w+AMP2*2 ; u++)
- {
- u2 = (int)((float)u/(w + AMP2 * 2) * r_refdef.vrect.width);
+ for (u = 0; u < w + AMP2 * 2; u++) {
+ u2 = (int)((float)u / (w + AMP2 * 2) * r_refdef.vrect.width);
column[u] = u2;
}
}
- turb = intsintable + ((int)(r_newrefdef.time*SPEED)&(CYCLE-1));
+ turb = intsintable + ((int)(r_newrefdef.time * SPEED) & (CYCLE - 1));
dest = vid.buffer + r_newrefdef.y * vid.rowbytes + r_newrefdef.x;
- for (v=0 ; v<h ; v++, dest += vid.rowbytes)
- {
- col = &column[turb[v&(CYCLE-1)]];
+ for (v = 0; v < h; v++, dest += vid.rowbytes) {
+ col = &column[turb[v & (CYCLE - 1)]];
row = &rowptr[v];
- for (u=0 ; u<w ; u+=4)
- {
- dest[u+0] = row[turb[(u+0)&(CYCLE-1)]][col[u+0]];
- dest[u+1] = row[turb[(u+1)&(CYCLE-1)]][col[u+1]];
- dest[u+2] = row[turb[(u+2)&(CYCLE-1)]][col[u+2]];
- dest[u+3] = row[turb[(u+3)&(CYCLE-1)]][col[u+3]];
+ for (u = 0; u < w; u += 4) {
+ dest[u + 0] = row[turb[(u + 0) & (CYCLE - 1)]][col[u + 0]];
+ dest[u + 1] = row[turb[(u + 1) & (CYCLE - 1)]][col[u + 1]];
+ dest[u + 2] = row[turb[(u + 2) & (CYCLE - 1)]][col[u + 2]];
+ dest[u + 3] = row[turb[(u + 3) & (CYCLE - 1)]][col[u + 3]];
}
}
}
@@ -99,15 +94,14 @@ void D_WarpScreen (void)
D_DrawTurbulent8Span
=============
*/
-void D_DrawTurbulent8Span (void)
+void D_DrawTurbulent8Span(void)
{
int sturb, tturb;
- do
- {
- sturb = ((r_turb_s + r_turb_turb[(r_turb_t>>16)&(CYCLE-1)])>>16)&63;
- tturb = ((r_turb_t + r_turb_turb[(r_turb_s>>16)&(CYCLE-1)])>>16)&63;
- *r_turb_pdest++ = *(r_turb_pbase + (tturb<<6) + sturb);
+ do {
+ sturb = ((r_turb_s + r_turb_turb[(r_turb_t >> 16) & (CYCLE - 1)]) >> 16) & 63;
+ tturb = ((r_turb_t + r_turb_turb[(r_turb_s >> 16) & (CYCLE - 1)]) >> 16) & 63;
+ *r_turb_pdest++ = *(r_turb_pbase + (tturb << 6) + sturb);
r_turb_s += r_turb_sstep;
r_turb_t += r_turb_tstep;
} while (--r_turb_spancount > 0);
@@ -121,14 +115,14 @@ void D_DrawTurbulent8Span (void)
Turbulent8
=============
*/
-void Turbulent8 (espan_t *pspan)
+void Turbulent8(espan_t *pspan)
{
int count;
fixed16_t snext, tnext;
float sdivz, tdivz, zi, z, du, dv, spancountminus1;
float sdivz16stepu, tdivz16stepu, zi16stepu;
-
- r_turb_turb = sintable + ((int)(r_newrefdef.time*SPEED)&(CYCLE-1));
+
+ r_turb_turb = sintable + ((int)(r_newrefdef.time * SPEED) & (CYCLE - 1));
r_turb_sstep = 0; // keep compiler happy
r_turb_tstep = 0; // ditto
@@ -139,20 +133,19 @@ void Turbulent8 (espan_t *pspan)
tdivz16stepu = d_tdivzstepu * 16;
zi16stepu = d_zistepu * 16;
- do
- {
+ do {
r_turb_pdest = (unsigned char *)((byte *)d_viewbuffer +
- (r_screenwidth * pspan->v) + pspan->u);
+ (r_screenwidth * pspan->v) + pspan->u);
count = pspan->count;
- // calculate the initial s/z, t/z, 1/z, s, and t and clamp
+ // calculate the initial s/z, t/z, 1/z, s, and t and clamp
du = (float)pspan->u;
dv = (float)pspan->v;
- sdivz = d_sdivzorigin + dv*d_sdivzstepv + du*d_sdivzstepu;
- tdivz = d_tdivzorigin + dv*d_tdivzstepv + du*d_tdivzstepu;
- zi = d_ziorigin + dv*d_zistepv + du*d_zistepu;
+ sdivz = d_sdivzorigin + dv * d_sdivzstepv + du * d_sdivzstepu;
+ tdivz = d_tdivzorigin + dv * d_tdivzstepv + du * d_tdivzstepu;
+ zi = d_ziorigin + dv * d_zistepv + du * d_zistepu;
z = (float)0x10000 / zi; // prescale to 16.16 fixed-point
r_turb_s = (int)(sdivz * z) + sadjust;
@@ -167,9 +160,8 @@ void Turbulent8 (espan_t *pspan)
else if (r_turb_t < 0)
r_turb_t = 0;
- do
- {
- // calculate s and t at the far end of the span
+ do {
+ // calculate s and t at the far end of the span
if (count >= 16)
r_turb_spancount = 16;
else
@@ -177,10 +169,9 @@ void Turbulent8 (espan_t *pspan)
count -= r_turb_spancount;
- if (count)
- {
- // calculate s/z, t/z, zi->fixed s and t at far end of span,
- // calculate s and t steps across span by shifting
+ if (count) {
+ // calculate s/z, t/z, zi->fixed s and t at far end of span,
+ // calculate s and t steps across span by shifting
sdivz += sdivz16stepu;
tdivz += tdivz16stepu;
zi += zi16stepu;
@@ -191,8 +182,8 @@ void Turbulent8 (espan_t *pspan)
snext = bbextents;
else if (snext < 16)
snext = 16; // prevent round-off error on <0 steps from
- // from causing overstepping & running off the
- // edge of the texture
+ // from causing overstepping & running off the
+ // edge of the texture
tnext = (int)(tdivz * z) + tadjust;
if (tnext > bbextentt)
@@ -202,13 +193,11 @@ void Turbulent8 (espan_t *pspan)
r_turb_sstep = (snext - r_turb_s) >> 4;
r_turb_tstep = (tnext - r_turb_t) >> 4;
- }
- else
- {
- // calculate s/z, t/z, zi->fixed s and t at last pixel in span (so
- // can't step off polygon), clamp, calculate s and t steps across
- // span by division, biasing steps low so we don't run off the
- // texture
+ } else {
+ // calculate s/z, t/z, zi->fixed s and t at last pixel in span (so
+ // can't step off polygon), clamp, calculate s and t steps across
+ // span by division, biasing steps low so we don't run off the
+ // texture
spancountminus1 = (float)(r_turb_spancount - 1);
sdivz += d_sdivzstepu * spancountminus1;
tdivz += d_tdivzstepu * spancountminus1;
@@ -219,8 +208,8 @@ void Turbulent8 (espan_t *pspan)
snext = bbextents;
else if (snext < 16)
snext = 16; // prevent round-off error on <0 steps from
- // from causing overstepping & running off the
- // edge of the texture
+ // from causing overstepping & running off the
+ // edge of the texture
tnext = (int)(tdivz * z) + tadjust;
if (tnext > bbextentt)
@@ -228,17 +217,16 @@ void Turbulent8 (espan_t *pspan)
else if (tnext < 16)
tnext = 16; // guard against round-off error on <0 steps
- if (r_turb_spancount > 1)
- {
+ if (r_turb_spancount > 1) {
r_turb_sstep = (snext - r_turb_s) / (r_turb_spancount - 1);
r_turb_tstep = (tnext - r_turb_t) / (r_turb_spancount - 1);
}
}
- r_turb_s = r_turb_s & ((CYCLE<<16)-1);
- r_turb_t = r_turb_t & ((CYCLE<<16)-1);
+ r_turb_s = r_turb_s & ((CYCLE << 16) - 1);
+ r_turb_t = r_turb_t & ((CYCLE << 16) - 1);
- D_DrawTurbulent8Span ();
+ D_DrawTurbulent8Span();
r_turb_s = snext;
r_turb_t = tnext;
@@ -256,13 +244,13 @@ NonTurbulent8 - this is for drawing scrolling textures. they're warping water te
but the turbulence is automatically 0.
=============
*/
-void NonTurbulent8 (espan_t *pspan)
+void NonTurbulent8(espan_t *pspan)
{
int count;
fixed16_t snext, tnext;
float sdivz, tdivz, zi, z, du, dv, spancountminus1;
float sdivz16stepu, tdivz16stepu, zi16stepu;
-
+
// r_turb_turb = sintable + ((int)(r_newrefdef.time*SPEED)&(CYCLE-1));
r_turb_turb = blanktable;
@@ -275,20 +263,19 @@ void NonTurbulent8 (espan_t *pspan)
tdivz16stepu = d_tdivzstepu * 16;
zi16stepu = d_zistepu * 16;
- do
- {
+ do {
r_turb_pdest = (unsigned char *)((byte *)d_viewbuffer +
- (r_screenwidth * pspan->v) + pspan->u);
+ (r_screenwidth * pspan->v) + pspan->u);
count = pspan->count;
- // calculate the initial s/z, t/z, 1/z, s, and t and clamp
+ // calculate the initial s/z, t/z, 1/z, s, and t and clamp
du = (float)pspan->u;
dv = (float)pspan->v;
- sdivz = d_sdivzorigin + dv*d_sdivzstepv + du*d_sdivzstepu;
- tdivz = d_tdivzorigin + dv*d_tdivzstepv + du*d_tdivzstepu;
- zi = d_ziorigin + dv*d_zistepv + du*d_zistepu;
+ sdivz = d_sdivzorigin + dv * d_sdivzstepv + du * d_sdivzstepu;
+ tdivz = d_tdivzorigin + dv * d_tdivzstepv + du * d_tdivzstepu;
+ zi = d_ziorigin + dv * d_zistepv + du * d_zistepu;
z = (float)0x10000 / zi; // prescale to 16.16 fixed-point
r_turb_s = (int)(sdivz * z) + sadjust;
@@ -303,9 +290,8 @@ void NonTurbulent8 (espan_t *pspan)
else if (r_turb_t < 0)
r_turb_t = 0;
- do
- {
- // calculate s and t at the far end of the span
+ do {
+ // calculate s and t at the far end of the span
if (count >= 16)
r_turb_spancount = 16;
else
@@ -313,10 +299,9 @@ void NonTurbulent8 (espan_t *pspan)
count -= r_turb_spancount;
- if (count)
- {
- // calculate s/z, t/z, zi->fixed s and t at far end of span,
- // calculate s and t steps across span by shifting
+ if (count) {
+ // calculate s/z, t/z, zi->fixed s and t at far end of span,
+ // calculate s and t steps across span by shifting
sdivz += sdivz16stepu;
tdivz += tdivz16stepu;
zi += zi16stepu;
@@ -327,8 +312,8 @@ void NonTurbulent8 (espan_t *pspan)
snext = bbextents;
else if (snext < 16)
snext = 16; // prevent round-off error on <0 steps from
- // from causing overstepping & running off the
- // edge of the texture
+ // from causing overstepping & running off the
+ // edge of the texture
tnext = (int)(tdivz * z) + tadjust;
if (tnext > bbextentt)
@@ -338,13 +323,11 @@ void NonTurbulent8 (espan_t *pspan)
r_turb_sstep = (snext - r_turb_s) >> 4;
r_turb_tstep = (tnext - r_turb_t) >> 4;
- }
- else
- {
- // calculate s/z, t/z, zi->fixed s and t at last pixel in span (so
- // can't step off polygon), clamp, calculate s and t steps across
- // span by division, biasing steps low so we don't run off the
- // texture
+ } else {
+ // calculate s/z, t/z, zi->fixed s and t at last pixel in span (so
+ // can't step off polygon), clamp, calculate s and t steps across
+ // span by division, biasing steps low so we don't run off the
+ // texture
spancountminus1 = (float)(r_turb_spancount - 1);
sdivz += d_sdivzstepu * spancountminus1;
tdivz += d_tdivzstepu * spancountminus1;
@@ -355,8 +338,8 @@ void NonTurbulent8 (espan_t *pspan)
snext = bbextents;
else if (snext < 16)
snext = 16; // prevent round-off error on <0 steps from
- // from causing overstepping & running off the
- // edge of the texture
+ // from causing overstepping & running off the
+ // edge of the texture
tnext = (int)(tdivz * z) + tadjust;
if (tnext > bbextentt)
@@ -364,17 +347,16 @@ void NonTurbulent8 (espan_t *pspan)
else if (tnext < 16)
tnext = 16; // guard against round-off error on <0 steps
- if (r_turb_spancount > 1)
- {
+ if (r_turb_spancount > 1) {
r_turb_sstep = (snext - r_turb_s) / (r_turb_spancount - 1);
r_turb_tstep = (tnext - r_turb_t) / (r_turb_spancount - 1);
}
}
- r_turb_s = r_turb_s & ((CYCLE<<16)-1);
- r_turb_t = r_turb_t & ((CYCLE<<16)-1);
+ r_turb_s = r_turb_s & ((CYCLE << 16) - 1);
+ r_turb_t = r_turb_t & ((CYCLE << 16) - 1);
- D_DrawTurbulent8Span ();
+ D_DrawTurbulent8Span();
r_turb_s = snext;
r_turb_t = tnext;
@@ -396,7 +378,7 @@ D_DrawSpans16
FIXME: actually make this subdivide by 16 instead of 8!!!
=============
*/
-void D_DrawSpans16 (espan_t *pspan)
+void D_DrawSpans16(espan_t *pspan)
{
int count, spancount;
unsigned char *pbase, *pdest;
@@ -413,20 +395,19 @@ void D_DrawSpans16 (espan_t *pspan)
tdivz8stepu = d_tdivzstepu * 8;
zi8stepu = d_zistepu * 8;
- do
- {
+ do {
pdest = (unsigned char *)((byte *)d_viewbuffer +
- (r_screenwidth * pspan->v) + pspan->u);
+ (r_screenwidth * pspan->v) + pspan->u);
count = pspan->count;
- // calculate the initial s/z, t/z, 1/z, s, and t and clamp
+ // calculate the initial s/z, t/z, 1/z, s, and t and clamp
du = (float)pspan->u;
dv = (float)pspan->v;
- sdivz = d_sdivzorigin + dv*d_sdivzstepv + du*d_sdivzstepu;
- tdivz = d_tdivzorigin + dv*d_tdivzstepv + du*d_tdivzstepu;
- zi = d_ziorigin + dv*d_zistepv + du*d_zistepu;
+ sdivz = d_sdivzorigin + dv * d_sdivzstepv + du * d_sdivzstepu;
+ tdivz = d_tdivzorigin + dv * d_tdivzstepv + du * d_tdivzstepu;
+ zi = d_ziorigin + dv * d_zistepv + du * d_zistepu;
z = (float)0x10000 / zi; // prescale to 16.16 fixed-point
s = (int)(sdivz * z) + sadjust;
@@ -441,9 +422,8 @@ void D_DrawSpans16 (espan_t *pspan)
else if (t < 0)
t = 0;
- do
- {
- // calculate s and t at the far end of the span
+ do {
+ // calculate s and t at the far end of the span
if (count >= 8)
spancount = 8;
else
@@ -451,10 +431,9 @@ void D_DrawSpans16 (espan_t *pspan)
count -= spancount;
- if (count)
- {
- // calculate s/z, t/z, zi->fixed s and t at far end of span,
- // calculate s and t steps across span by shifting
+ if (count) {
+ // calculate s/z, t/z, zi->fixed s and t at far end of span,
+ // calculate s and t steps across span by shifting
sdivz += sdivz8stepu;
tdivz += tdivz8stepu;
zi += zi8stepu;
@@ -465,8 +444,8 @@ void D_DrawSpans16 (espan_t *pspan)
snext = bbextents;
else if (snext < 8)
snext = 8; // prevent round-off error on <0 steps from
- // from causing overstepping & running off the
- // edge of the texture
+ // from causing overstepping & running off the
+ // edge of the texture
tnext = (int)(tdivz * z) + tadjust;
if (tnext > bbextentt)
@@ -476,13 +455,11 @@ void D_DrawSpans16 (espan_t *pspan)
sstep = (snext - s) >> 3;
tstep = (tnext - t) >> 3;
- }
- else
- {
- // calculate s/z, t/z, zi->fixed s and t at last pixel in span (so
- // can't step off polygon), clamp, calculate s and t steps across
- // span by division, biasing steps low so we don't run off the
- // texture
+ } else {
+ // calculate s/z, t/z, zi->fixed s and t at last pixel in span (so
+ // can't step off polygon), clamp, calculate s and t steps across
+ // span by division, biasing steps low so we don't run off the
+ // texture
spancountminus1 = (float)(spancount - 1);
sdivz += d_sdivzstepu * spancountminus1;
tdivz += d_tdivzstepu * spancountminus1;
@@ -493,8 +470,8 @@ void D_DrawSpans16 (espan_t *pspan)
snext = bbextents;
else if (snext < 8)
snext = 8; // prevent round-off error on <0 steps from
- // from causing overstepping & running off the
- // edge of the texture
+ // from causing overstepping & running off the
+ // edge of the texture
tnext = (int)(tdivz * z) + tadjust;
if (tnext > bbextentt)
@@ -502,15 +479,13 @@ void D_DrawSpans16 (espan_t *pspan)
else if (tnext < 8)
tnext = 8; // guard against round-off error on <0 steps
- if (spancount > 1)
- {
+ if (spancount > 1) {
sstep = (snext - s) / (spancount - 1);
tstep = (tnext - t) / (spancount - 1);
}
}
- do
- {
+ do {
*pdest++ = *(pbase + (s >> 16) + (t >> 16) * cachewidth);
s += sstep;
t += tstep;
@@ -530,7 +505,7 @@ void D_DrawSpans16 (espan_t *pspan)
D_DrawZSpans
=============
*/
-void D_DrawZSpans (espan_t *pspan)
+void D_DrawZSpans(espan_t *pspan)
{
int count, doublecount, izistep;
int izi;
@@ -543,31 +518,27 @@ void D_DrawZSpans (espan_t *pspan)
// we count on FP exceptions being turned off to avoid range problems
izistep = (int)(d_zistepu * 0x8000 * 0x10000);
- do
- {
+ do {
pdest = d_pzbuffer + (d_zwidth * pspan->v) + pspan->u;
count = pspan->count;
- // calculate the initial 1/z
+ // calculate the initial 1/z
du = (float)pspan->u;
dv = (float)pspan->v;
- zi = d_ziorigin + dv*d_zistepv + du*d_zistepu;
- // we count on FP exceptions being turned off to avoid range problems
+ zi = d_ziorigin + dv * d_zistepv + du * d_zistepu;
+ // we count on FP exceptions being turned off to avoid range problems
izi = (int)(zi * 0x8000 * 0x10000);
- if ((long)pdest & 0x02)
- {
+ if ((long)pdest & 0x02) {
*pdest++ = (short)(izi >> 16);
izi += izistep;
count--;
}
- if ((doublecount = count >> 1) > 0)
- {
- do
- {
+ if ((doublecount = count >> 1) > 0) {
+ do {
ltemp = izi >> 16;
izi += izistep;
ltemp |= izi & 0xFFFF0000;