From 1f49908a6f271ddfefa117cdb1cc69742d95d1aa Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sun, 28 Jul 2019 18:13:28 +0200 Subject: [PATCH] Backport https://github.com/Ferk/libretro-prboom/commit/ca2107f8a33b6dce5face9a290862d96ebf9c6e8 - wiggle fix now also fixes flats/floors --- src/r_main.c | 3 +++ src/r_main.h | 4 ++-- src/r_plane.c | 50 +++++++++++++++++++++++++++++++++++--------------- 3 files changed, 40 insertions(+), 17 deletions(-) diff --git a/src/r_main.c b/src/r_main.c index 6e41218..12169f9 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -78,6 +78,7 @@ angle_t viewangle; angle_t viewpitch; fixed_t viewcos, viewsin; player_t *viewplayer; +float viewfocratio; /*e6y: for more precise flat drawing */ fixed_t focallength; int fieldofview; fixed_t freelookviewheight; @@ -441,6 +442,8 @@ void R_ExecuteSetViewSize (void) // proff 11/06/98: Added for high-res projectiony = ((SCREENHEIGHT * centerx * 320) / 200) / SCREENWIDTH * FRACUNIT; + /* e6y: this is a precalculated value for more precise flats drawing (see R_MapPlane) */ + viewfocratio = 1.6f / ((float)SCREENWIDTH / (float)SCREENHEIGHT); R_InitBuffer (scaledviewwidth, viewheight); R_InitTextureMapping(); diff --git a/src/r_main.h b/src/r_main.h index d943299..2198041 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -52,9 +52,9 @@ extern fixed_t centeryfrac; extern fixed_t viewheightfrac; //e6y: for correct clipping of things extern fixed_t freelookviewheight; extern fixed_t projection; -// proff 11/06/98: Added for high-res -extern fixed_t projectiony; +extern fixed_t projectiony; /* proff 11/06/98: Added for high-res */ extern int validcount; +extern float viewfocratio; /* e6y: for more precise flat drawing */ extern fixed_t skyiscale; // diff --git a/src/r_plane.c b/src/r_plane.c index 72b6b47..b0dfa5c 100644 --- a/src/r_plane.c +++ b/src/r_plane.c @@ -104,6 +104,9 @@ static fixed_t xoffs,yoffs; // killough 2/28/98: flat offsets fixed_t yslope[MAX_SCREENHEIGHT], distscale[MAX_SCREENWIDTH]; +/* forward declarations */ +extern boolean r_wiggle_fix; + // // R_InitPlanes // Only at game startup. @@ -134,27 +137,44 @@ static void R_MapPlane(int y, int x1, int x2, draw_span_vars_t *dsvars) fixed_t distance, length; unsigned index; - if (planeheight != cachedheight[y]) + if (!r_wiggle_fix) { - cachedheight[y] = planeheight; - distance = cacheddistance[y] = FixedMul (planeheight, yslope[y]); - dsvars->xstep = cachedxstep[y] = FixedMul (distance,basexscale); - dsvars->ystep = cachedystep[y] = FixedMul (distance,baseyscale); + if (planeheight != cachedheight[y]) + { + cachedheight[y] = planeheight; + distance = cacheddistance[y] = FixedMul (planeheight, yslope[y]); + dsvars->xstep = cachedxstep[y] = FixedMul (distance,basexscale); + dsvars->ystep = cachedystep[y] = FixedMul (distance,baseyscale); + } + else + { + distance = cacheddistance[y]; + dsvars->xstep = cachedxstep[y]; + dsvars->ystep = cachedystep[y]; + } + + length = FixedMul (distance,distscale[x1]); + angle = (viewangle + xtoviewangle[x1])>>ANGLETOFINESHIFT; + + // killough 2/28/98: Add offsets + dsvars->xfrac = viewx + FixedMul(finecosine[angle], length) + xoffs; + dsvars->yfrac = -viewy - FixedMul(finesine[angle], length) + yoffs; } else { - distance = cacheddistance[y]; - dsvars->xstep = cachedxstep[y]; - dsvars->ystep = cachedystep[y]; + float slope, realy; + + distance = FixedMul (planeheight, yslope[y]); + slope = (float)(planeheight / 65535.0f / D_abs(centery - y)); + realy = (float)distance / 65536.0f; + + dsvars->xstep = (unsigned int)(viewsin * slope * viewfocratio); + dsvars->ystep = (unsigned int)(viewcos * slope * viewfocratio); + + dsvars->xfrac = viewx + xoffs + (int)(viewcos * realy) + (x1 - centerx) * dsvars->xstep; + dsvars->yfrac = -viewy + yoffs - (int)(viewsin * realy) + (x1 - centerx) * dsvars->ystep; } - length = FixedMul (distance,distscale[x1]); - angle = (viewangle + xtoviewangle[x1])>>ANGLETOFINESHIFT; - - // killough 2/28/98: Add offsets - dsvars->xfrac = viewx + FixedMul(finecosine[angle], length) + xoffs; - dsvars->yfrac = -viewy - FixedMul(finesine[angle], length) + yoffs; - if (drawvars.filterfloor == RDRAW_FILTER_LINEAR) { dsvars->xfrac -= (FRACUNIT>>1); dsvars->yfrac -= (FRACUNIT>>1);