diff options
-rw-r--r-- | src/refresh/sw/edge.c | 10 | ||||
-rw-r--r-- | src/refresh/sw/poly.c | 2 | ||||
-rw-r--r-- | src/refresh/sw/scan.c | 257 | ||||
-rw-r--r-- | src/refresh/sw/sw.h | 4 |
4 files changed, 56 insertions, 217 deletions
diff --git a/src/refresh/sw/edge.c b/src/refresh/sw/edge.c index ee95cc6..529aa9a 100644 --- a/src/refresh/sw/edge.c +++ b/src/refresh/sw/edge.c @@ -854,15 +854,11 @@ void D_TurbulentSurf(surf_t *s) D_CalcGradients(pface); -//============ -//PGM - // textures that aren't warping are just flowing. Use NonTurbulent8 instead + // textures that aren't warping are just flowing. Use blanktable instead. if (!(pface->texinfo->c.flags & SURF_WARP)) - NonTurbulent8(s->spans); + D_DrawTurbulent16(s->spans, blanktable); else - Turbulent8(s->spans); -//PGM -//============ + D_DrawTurbulent16(s->spans, sintable); D_DrawZSpans(s->spans); diff --git a/src/refresh/sw/poly.c b/src/refresh/sw/poly.c index f3159b8..620d091 100644 --- a/src/refresh/sw/poly.c +++ b/src/refresh/sw/poly.c @@ -40,7 +40,7 @@ static polydesc_t r_polydesc; mface_t *r_alpha_surfaces; -extern int *r_turb_turb; +static int *r_turb_turb; static int clip_current; static vec5_t r_clip_verts[2][MAXWORKINGVERTS + 2]; diff --git a/src/refresh/sw/scan.c b/src/refresh/sw/scan.c index 9922dfe..8868ee6 100644 --- a/src/refresh/sw/scan.c +++ b/src/refresh/sw/scan.c @@ -21,14 +21,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "sw.h" -byte *r_turb_pbase, *r_turb_pdest; -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); - - /* ============= D_WarpScreen @@ -83,60 +75,34 @@ void D_WarpScreen(void) } } - -#if !USE_ASM - -/* -============= -D_DrawTurbulent8Span -============= -*/ -void D_DrawTurbulent8Span(void) -{ - int sturb, tturb; - byte *ptex; - - 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; - ptex = r_turb_pbase + (tturb * 64 * TEX_BYTES) + sturb * TEX_BYTES; - r_turb_pdest[0] = ptex[2]; - r_turb_pdest[1] = ptex[1]; - r_turb_pdest[2] = ptex[0]; - r_turb_pdest += VID_BYTES; - r_turb_s += r_turb_sstep; - r_turb_t += r_turb_tstep; - } while (--r_turb_spancount > 0); -} - -#endif // !USE_ASM - - /* ============= -Turbulent8 +D_DrawTurbulent16 ============= */ -void Turbulent8(espan_t *pspan) +void D_DrawTurbulent16(espan_t *pspan, int *warptable) { - int count; - fixed16_t snext, tnext; + int count, spancount; + byte *pbase, *pdest, *ptex; + fixed16_t s, t, snext, tnext, sstep, tstep; float sdivz, tdivz, zi, z, du, dv, spancountminus1; float sdivz16stepu, tdivz16stepu, zi16stepu; + int *turb; + int turb_s, turb_t; - r_turb_turb = sintable + ((int)(r_newrefdef.time * SPEED) & (CYCLE - 1)); + turb = warptable + ((int)(r_newrefdef.time * SPEED) & (CYCLE - 1)); - r_turb_sstep = 0; // keep compiler happy - r_turb_tstep = 0; // ditto + sstep = 0; // keep compiler happy + tstep = 0; // ditto - r_turb_pbase = (byte *)cacheblock; + pbase = (byte *)cacheblock; sdivz16stepu = d_sdivzstepu * 16; tdivz16stepu = d_tdivzstepu * 16; zi16stepu = d_zistepu * 16; do { - r_turb_pdest = (byte *)d_viewbuffer + d_scantable[pspan->v] + pspan->u * VID_BYTES; + pdest = (byte *)d_viewbuffer + d_scantable[pspan->v] + pspan->u * VID_BYTES; count = pspan->count; @@ -149,28 +115,28 @@ void Turbulent8(espan_t *pspan) 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; - if (r_turb_s > bbextents) - r_turb_s = bbextents; - else if (r_turb_s < 0) - r_turb_s = 0; + s = (int)(sdivz * z) + sadjust; + if (s > bbextents) + s = bbextents; + else if (s < 0) + s = 0; - r_turb_t = (int)(tdivz * z) + tadjust; - if (r_turb_t > bbextentt) - r_turb_t = bbextentt; - else if (r_turb_t < 0) - r_turb_t = 0; + t = (int)(tdivz * z) + tadjust; + if (t > bbextentt) + t = bbextentt; + else if (t < 0) + t = 0; do { // calculate s and t at the far end of the span if (count >= 16) - r_turb_spancount = 16; + spancount = 16; else - r_turb_spancount = count; + spancount = count; - count -= r_turb_spancount; + count -= spancount; - if (count) { + if (q_likely(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; @@ -183,8 +149,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) @@ -192,154 +158,26 @@ void Turbulent8(espan_t *pspan) else if (tnext < 16) tnext = 16; // guard against round-off error on <0 steps - r_turb_sstep = (snext - r_turb_s) >> 4; - r_turb_tstep = (tnext - r_turb_t) >> 4; + sstep = (snext - s) >> 4; + tstep = (tnext - 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 - spancountminus1 = (float)(r_turb_spancount - 1); + spancountminus1 = (float)(spancount - 1); sdivz += d_sdivzstepu * spancountminus1; tdivz += d_tdivzstepu * spancountminus1; zi += d_zistepu * spancountminus1; z = (float)0x10000 / zi; // prescale to 16.16 fixed-point - snext = (int)(sdivz * z) + sadjust; - if (snext > bbextents) - 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 - - tnext = (int)(tdivz * z) + tadjust; - if (tnext > bbextentt) - tnext = bbextentt; - else if (tnext < 16) - tnext = 16; // guard against round-off error on <0 steps - - 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); - - D_DrawTurbulent8Span(); - - r_turb_s = snext; - r_turb_t = tnext; - - } while (count > 0); - - } while ((pspan = pspan->pnext) != NULL); -} - -//==================== -//PGM -/* -============= -NonTurbulent8 - this is for drawing scrolling textures. they're warping water textures - but the turbulence is automatically 0. -============= -*/ -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; - - r_turb_sstep = 0; // keep compiler happy - r_turb_tstep = 0; // ditto - - r_turb_pbase = (byte *)cacheblock; - - sdivz16stepu = d_sdivzstepu * 16; - tdivz16stepu = d_tdivzstepu * 16; - zi16stepu = d_zistepu * 16; - - do { - r_turb_pdest = (byte *)d_viewbuffer + d_scantable[pspan->v] + pspan->u * VID_BYTES; - - count = pspan->count; - - // 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; - z = (float)0x10000 / zi; // prescale to 16.16 fixed-point - - r_turb_s = (int)(sdivz * z) + sadjust; - if (r_turb_s > bbextents) - r_turb_s = bbextents; - else if (r_turb_s < 0) - r_turb_s = 0; - - r_turb_t = (int)(tdivz * z) + tadjust; - if (r_turb_t > bbextentt) - r_turb_t = bbextentt; - else if (r_turb_t < 0) - r_turb_t = 0; - - do { - // calculate s and t at the far end of the span - if (count >= 16) - r_turb_spancount = 16; - else - r_turb_spancount = count; - - 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 - sdivz += sdivz16stepu; - tdivz += tdivz16stepu; - zi += zi16stepu; - z = (float)0x10000 / zi; // prescale to 16.16 fixed-point snext = (int)(sdivz * z) + sadjust; if (snext > bbextents) 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 - - tnext = (int)(tdivz * z) + tadjust; - if (tnext > bbextentt) - tnext = bbextentt; - else if (tnext < 16) - tnext = 16; // guard against round-off error on <0 steps - - 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 - spancountminus1 = (float)(r_turb_spancount - 1); - sdivz += d_sdivzstepu * spancountminus1; - tdivz += d_tdivzstepu * spancountminus1; - zi += d_zistepu * spancountminus1; - z = (float)0x10000 / zi; // prescale to 16.16 fixed-point - snext = (int)(sdivz * z) + sadjust; - if (snext > bbextents) - 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) @@ -347,27 +185,34 @@ void NonTurbulent8(espan_t *pspan) else if (tnext < 16) tnext = 16; // guard against round-off error on <0 steps - 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); + if (spancount > 1) { + sstep = (snext - s) / (spancount - 1); + tstep = (tnext - t) / (spancount - 1); } } - r_turb_s = r_turb_s & ((CYCLE << 16) - 1); - r_turb_t = r_turb_t & ((CYCLE << 16) - 1); + s = s & ((CYCLE << 16) - 1); + t = t & ((CYCLE << 16) - 1); - D_DrawTurbulent8Span(); + do { + turb_s = ((s + turb[(t >> 16) & (CYCLE - 1)]) >> 16) & 63; + turb_t = ((t + turb[(s >> 16) & (CYCLE - 1)]) >> 16) & 63; + ptex = pbase + (turb_t * 64 * TEX_BYTES) + turb_s * TEX_BYTES; + pdest[0] = ptex[2]; + pdest[1] = ptex[1]; + pdest[2] = ptex[0]; + pdest += VID_BYTES; + s += sstep; + t += tstep; + } while (--spancount > 0); - r_turb_s = snext; - r_turb_t = tnext; + s = snext; + t = tnext; } while (count > 0); } while ((pspan = pspan->pnext) != NULL); } -//PGM -//==================== - #if !USE_ASM diff --git a/src/refresh/sw/sw.h b/src/refresh/sw/sw.h index 3e940e5..f54a619 100644 --- a/src/refresh/sw/sw.h +++ b/src/refresh/sw/sw.h @@ -406,11 +406,9 @@ extern float d_sdivzorigin, d_tdivzorigin, d_ziorigin; extern fixed16_t sadjust, tadjust; extern fixed16_t bbextents, bbextentt; - +void D_DrawTurbulent16(espan_t *pspan, int *warptable); void D_DrawSpans16(espan_t *pspans); void D_DrawZSpans(espan_t *pspans); -void Turbulent8(espan_t *pspan); -void NonTurbulent8(espan_t *pspan); //PGM surfcache_t *D_CacheSurface(mface_t *surface, int miplevel); |