diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index ad52aef6b..e26406b4c 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -553,7 +553,7 @@ static void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, bool size_t len; float tempxsow, tempytow; - float scrollx = 0.0f, scrolly = 0.0f; + float scrollx = 0.0f, scrolly = 0.0f, anglef = 0.0f; angle_t angle = 0; static FOutVector *planeVerts = NULL; @@ -673,14 +673,11 @@ static void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, bool if (angle) // Only needs to be done if there's an altered angle { - angle = InvAngle(angle)>>ANGLETOFINESHIFT; - - // This needs to be done so everything aligns after rotation - // It would be done so that rotation is done, THEN the translation, but I couldn't get it to rotate AND scroll like software does - tempxsow = FloatToFixed(flatxref); - tempytow = FloatToFixed(flatyref); - flatxref = (FixedToFloat(FixedMul(tempxsow, FINECOSINE(angle)) - FixedMul(tempytow, FINESINE(angle)))); - flatyref = (FixedToFloat(FixedMul(tempxsow, FINESINE(angle)) + FixedMul(tempytow, FINECOSINE(angle)))); + tempxsow = flatxref; + tempytow = flatyref; + anglef = ANG2RAD(InvAngle(angle)); + flatxref = (tempxsow * cos(anglef)) - (tempytow * sin(anglef)); + flatyref = (tempxsow * sin(anglef)) + (tempytow * cos(anglef)); } #define SETUP3DVERT(vert, vx, vy) {\ @@ -691,10 +688,10 @@ static void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, bool /* Need to rotate before translate */\ if (angle) /* Only needs to be done if there's an altered angle */\ {\ - tempxsow = FloatToFixed(vert->s);\ - tempytow = FloatToFixed(vert->t);\ - vert->s = (FixedToFloat(FixedMul(tempxsow, FINECOSINE(angle)) - FixedMul(tempytow, FINESINE(angle))));\ - vert->t = (FixedToFloat(FixedMul(tempxsow, FINESINE(angle)) + FixedMul(tempytow, FINECOSINE(angle))));\ + tempxsow = vert->s;\ + tempytow = vert->t;\ + vert->s = (tempxsow * cos(anglef)) - (tempytow * sin(anglef));\ + vert->t = (tempxsow * sin(anglef)) + (tempytow * cos(anglef));\ }\ \ vert->x = (vx);\ diff --git a/src/r_draw.h b/src/r_draw.h index 2f5521255..946139ac1 100644 --- a/src/r_draw.h +++ b/src/r_draw.h @@ -66,6 +66,9 @@ typedef struct floatv3_t sup; floatv3_t svp; floatv3_t szp; + floatv3_t slope_origin; + floatv3_t slope_u; + floatv3_t slope_v; // Variable flat sizes UINT32 nflatxshift; diff --git a/src/r_draw_span.c b/src/r_draw_span.c index b89833aee..df4fba9fe 100644 --- a/src/r_draw_span.c +++ b/src/r_draw_span.c @@ -57,6 +57,7 @@ void R_DrawSpan(drawspandata_t* ds) { return; } + while (count >= 8) { // SoM: Why didn't I see this earlier? the spot variable is a waste now because we don't @@ -350,13 +351,17 @@ static void R_CalcTiltedLighting(INT32 *lightbuffer, INT32 x1, INT32 x2, fixed_t lightbuffer[i] = (start += step) >> FRACBITS; if (lightbuffer[i] < 0) + { lightbuffer[i] = 0; + } else if (lightbuffer[i] >= MAXLIGHTSCALE) + { lightbuffer[i] = MAXLIGHTSCALE-1; + } } } -#define PLANELIGHTFLOAT ((float)BASEVIDWIDTH * BASEVIDWIDTH / vid.width / (ds->zeroheight - FIXED_TO_FLOAT(viewz)) / 21.0f * FIXED_TO_FLOAT(fovtan)) +#define PLANELIGHTFLOAT ((float)BASEVIDWIDTH * BASEVIDWIDTH / vid.width / ds->zeroheight / 21.0f * FIXED_TO_FLOAT(fovtan)) /** \brief The R_DrawTiltedSpan function Draw slopes! Holy sheit! @@ -414,8 +419,8 @@ void R_DrawSpan_Tilted(drawspandata_t* ds) do { double z = 1.f/iz; - u = (INT64)(uz*z) + viewx; - v = (INT64)(vz*z) + viewy; + u = (INT64)(uz*z); + v = (INT64)(vz*z); bit = ((v >> ds->nflatyshift) & ds->nflatmask) | (u >> ds->nflatxshift); colormap = ds->planezlight[tiltlighting[ds->x1++]] + (ds->colormap - colormaps); @@ -447,8 +452,8 @@ void R_DrawSpan_Tilted(drawspandata_t* ds) endv = vz*endz; stepu = (INT64)((endu - startu) * INVSPAN); stepv = (INT64)((endv - startv) * INVSPAN); - u = (INT64)(startu) + viewx; - v = (INT64)(startv) + viewy; + u = (INT64)(startu); + v = (INT64)(startv); for (i = SPANSIZE-1; i >= 0; i--) { @@ -487,8 +492,8 @@ void R_DrawSpan_Tilted(drawspandata_t* ds) left = 1.f/left; stepu = (INT64)((endu - startu) * left); stepv = (INT64)((endv - startv) * left); - u = (INT64)(startu) + viewx; - v = (INT64)(startv) + viewy; + u = (INT64)(startu); + v = (INT64)(startv); for (; width != 0; width--) { @@ -561,8 +566,8 @@ void R_DrawTranslucentSpan_Tilted(drawspandata_t* ds) do { double z = 1.f/iz; - u = (INT64)(uz*z) + viewx; - v = (INT64)(vz*z) + viewy; + u = (INT64)(uz*z); + v = (INT64)(vz*z); bit = ((v >> ds->nflatyshift) & ds->nflatmask) | (u >> ds->nflatxshift); colormap = ds->planezlight[tiltlighting[ds->x1++]] + (ds->colormap - colormaps); @@ -594,8 +599,8 @@ void R_DrawTranslucentSpan_Tilted(drawspandata_t* ds) endv = vz*endz; stepu = (INT64)((endu - startu) * INVSPAN); stepv = (INT64)((endv - startv) * INVSPAN); - u = (INT64)(startu) + viewx; - v = (INT64)(startv) + viewy; + u = (INT64)(startu); + v = (INT64)(startv); for (i = SPANSIZE-1; i >= 0; i--) { @@ -634,8 +639,8 @@ void R_DrawTranslucentSpan_Tilted(drawspandata_t* ds) left = 1.f/left; stepu = (INT64)((endu - startu) * left); stepv = (INT64)((endv - startv) * left); - u = (INT64)(startu) + viewx; - v = (INT64)(startv) + viewy; + u = (INT64)(startu); + v = (INT64)(startv); for (; width != 0; width--) { @@ -710,8 +715,8 @@ void R_DrawTranslucentWaterSpan_Tilted(drawspandata_t* ds) do { double z = 1.f/iz; - u = (INT64)(uz*z) + viewx; - v = (INT64)(vz*z) + viewy; + u = (INT64)(uz*z); + v = (INT64)(vz*z); bit = ((v >> ds->nflatyshift) & ds->nflatmask) | (u >> ds->nflatxshift); colormap = ds->planezlight[tiltlighting[ds->x1++]] + (ds->colormap - colormaps); @@ -743,8 +748,8 @@ void R_DrawTranslucentWaterSpan_Tilted(drawspandata_t* ds) endv = vz*endz; stepu = (INT64)((endu - startu) * INVSPAN); stepv = (INT64)((endv - startv) * INVSPAN); - u = (INT64)(startu) + viewx; - v = (INT64)(startv) + viewy; + u = (INT64)(startu); + v = (INT64)(startv); for (i = SPANSIZE-1; i >= 0; i--) { @@ -783,8 +788,8 @@ void R_DrawTranslucentWaterSpan_Tilted(drawspandata_t* ds) left = 1.f/left; stepu = (INT64)((endu - startu) * left); stepv = (INT64)((endv - startv) * left); - u = (INT64)(startu) + viewx; - v = (INT64)(startv) + viewy; + u = (INT64)(startu); + v = (INT64)(startv); for (; width != 0; width--) { @@ -858,8 +863,8 @@ void R_DrawSplat_Tilted(drawspandata_t* ds) do { double z = 1.f/iz; - u = (INT64)(uz*z) + viewx; - v = (INT64)(vz*z) + viewy; + u = (INT64)(uz*z); + v = (INT64)(vz*z); bit = ((v >> ds->nflatyshift) & ds->nflatmask) | (u >> ds->nflatxshift); val = source[bit]; @@ -896,8 +901,8 @@ void R_DrawSplat_Tilted(drawspandata_t* ds) endv = vz*endz; stepu = (INT64)((endu - startu) * INVSPAN); stepv = (INT64)((endv - startv) * INVSPAN); - u = (INT64)(startu) + viewx; - v = (INT64)(startv) + viewy; + u = (INT64)(startu); + v = (INT64)(startv); for (i = SPANSIZE-1; i >= 0; i--) { @@ -943,8 +948,8 @@ void R_DrawSplat_Tilted(drawspandata_t* ds) left = 1.f/left; stepu = (INT64)((endu - startu) * left); stepv = (INT64)((endv - startv) * left); - u = (INT64)(startu) + viewx; - v = (INT64)(startv) + viewy; + u = (INT64)(startu); + v = (INT64)(startv); for (; width != 0; width--) { diff --git a/src/r_plane.cpp b/src/r_plane.cpp index cc3f14633..9df1af06d 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -34,9 +34,6 @@ #include "core/thread_pool.h" -static void R_SetSlopePlaneVectors(drawspandata_t* ds, visplane_t *pl, INT32 y, fixed_t xoff, fixed_t yoff, float fudge); -static void R_SetTiltedSpan(drawspandata_t* ds, INT32 span); - // // opening // @@ -94,6 +91,9 @@ fixed_t basexscale, baseyscale; static INT16 *ffloor_f_clip; static INT16 *ffloor_c_clip; +static void R_SetTiltedSpan(drawspandata_t* ds, INT32 span); +static void R_SetSlopePlaneVectors(drawspandata_t* ds, visplane_t *pl, INT32 y, fixed_t xoff, fixed_t yoff); + static void R_ReallocPlaneBounds(visplane_t *pl) { pl->top_memory = static_cast(Z_Realloc(pl->top_memory, sizeof(UINT16) * (viewwidth + 2), PU_STATIC, NULL)); @@ -166,68 +166,6 @@ static void R_UpdatePlaneRipple(drawspandata_t* ds) ds->planeripple.offset = ((leveltime-1)*140) + ((rendertimefrac*140) / FRACUNIT); } -static void R_HandleRipplePlane(drawspandata_t* ds, visplane_t *pl) -{ - INT32 top, bottom; - UINT8 *scr; - - if (!cv_ripplewater.value) - { - ds->planeripple.active = false; - return; - } - - ds->planeripple.active = true; - - if (spanfunc == R_DrawTranslucentSpan) - { - spanfunc = R_DrawTranslucentWaterSpan; - - // Copy the current scene, ugh - top = pl->high-8; - bottom = pl->low+8; - - if (top < 0) - top = 0; - if (bottom > vid.height) - bottom = vid.height; - - // Only copy the part of the screen we need - scr = (renderscreen + (top*vid.width)); - - for (UINT8 i = 1; i <= splitscreen; i++) - { - if (viewplayer != &players[displayplayers[i]]) - continue; - - switch (i) - { - case 1: - if (splitscreen == 1) - scr = (renderscreen + (top + viewheight) * vid.width); - else if (splitscreen > 1) - scr = (renderscreen + (top * vid.width) + viewwidth); - break; - case 2: - scr = (renderscreen + (top + viewheight) * vid.width); - break; - case 3: - scr = (renderscreen + (top + viewheight) * vid.width + viewwidth); - break; - default: - break; - } - - break; - } - - VID_BlitLinearScreen(scr, vid.screens[1]+((top)*vid.width), - vid.width, bottom-top, - vid.width, vid.width); - } -} - - static bool R_CheckMapPlane(const char* funcname, INT32 y, INT32 x1, INT32 x2) { if (x1 == x2) @@ -333,12 +271,8 @@ static void R_MapTiltedPlane(drawspandata_t *ds, spandrawfunc_t *localspanfunc, R_SetTiltedSpan(ds, std::clamp(y, 0, viewheight)); - float fudgecanyon = 0; - // Okay, look, don't ask me why this works, but without this setup there's a disgusting-looking misalignment with the textures. -fickle - fudgecanyon = ((1<nflatshiftup)+1.0f)/(1<nflatshiftup); - R_CalculatePlaneRipple(ds, ds->currentplane->viewangle + ds->currentplane->plangle); - R_SetSlopePlaneVectors(ds, ds->currentplane, y, (ds->xoffs + ds->planeripple.xfrac), (ds->yoffs + ds->planeripple.yfrac), fudgecanyon); + R_SetSlopePlaneVectors(ds, ds->currentplane, y, (ds->xoffs + ds->planeripple.xfrac), (ds->yoffs + ds->planeripple.yfrac)); if ((y + ds->bgofs) >= viewheight) ds->bgofs = viewheight-y-1; @@ -870,66 +804,79 @@ static void R_DrawSkyPlane(visplane_t *pl, void(*colfunc2)(drawcolumndata_t*), b } } -// Potentially override other stuff for now cus we're mean. :< But draw a slope plane! -// I copied ZDoom's code and adapted it to SRB2... -Red -static void R_CalculateSlopeVectors(drawspandata_t* ds, pslope_t *slope, fixed_t planeviewx, fixed_t planeviewy, fixed_t planeviewz, fixed_t planexscale, fixed_t planeyscale, fixed_t planexoffset, fixed_t planeyoffset, angle_t planeviewangle, angle_t planeangle, float fudge) +// Returns the height of the sloped plane at (x, y) as a 32.16 fixed_t +static INT64 R_GetSlopeZAt(const pslope_t *slope, fixed_t x, fixed_t y) { - floatv3_t p, m, n; - float ang; - float vx, vy, vz; - float xscale = FIXED_TO_FLOAT(planexscale); - float yscale = FIXED_TO_FLOAT(planeyscale); - // compiler complains when P_GetSlopeZAt is used in FLOAT_TO_FIXED directly - // use this as a temp var to store P_GetSlopeZAt's return value each time - fixed_t temp; + INT64 x64 = ((INT64)x - (INT64)slope->o.x); + INT64 y64 = ((INT64)y - (INT64)slope->o.y); - vx = FIXED_TO_FLOAT(planeviewx+planexoffset); - vy = FIXED_TO_FLOAT(planeviewy-planeyoffset); - vz = FIXED_TO_FLOAT(planeviewz); + x64 = (x64 * (INT64)slope->d.x) / FRACUNIT; + y64 = (y64 * (INT64)slope->d.y) / FRACUNIT; - temp = P_GetSlopeZAt(slope, planeviewx, planeviewy); - ds->zeroheight = FIXED_TO_FLOAT(temp); + return (INT64)slope->o.z + ((x64 + y64) * (INT64)slope->zdelta) / FRACUNIT; +} + +// Sets the texture origin vector of the sloped plane. +static void R_SetSlopePlaneOrigin(drawspandata_t *ds, pslope_t *slope, fixed_t xpos, fixed_t ypos, fixed_t zpos, fixed_t xoff, fixed_t yoff, fixed_t angle) +{ + floatv3_t *p = &ds->slope_origin; + + INT64 vx = (INT64)xpos + (INT64)xoff; + INT64 vy = (INT64)ypos - (INT64)yoff; + + float vxf = vx / (float)FRACUNIT; + float vyf = vy / (float)FRACUNIT; + float ang = ANG2RAD(ANGLE_270 - angle); // p is the texture origin in view space // Don't add in the offsets at this stage, because doing so can result in // errors if the flat is rotated. - ang = ANG2RAD(ANGLE_270 - planeviewangle); - p.x = vx * cos(ang) - vy * sin(ang); - p.z = vx * sin(ang) + vy * cos(ang); - temp = P_GetSlopeZAt(slope, -planexoffset, planeyoffset); - p.y = FIXED_TO_FLOAT(temp) - vz; + p->x = vxf * cos(ang) - vyf * sin(ang); + p->z = vxf * sin(ang) + vyf * cos(ang); + p->y = (R_GetSlopeZAt(slope, -xoff, yoff) - zpos) / (float)FRACUNIT; +} + +// This function calculates all of the vectors necessary for drawing a sloped plane. +static void R_SetSlopePlane(drawspandata_t* ds, pslope_t *slope, fixed_t xpos, fixed_t ypos, fixed_t zpos, fixed_t xoff, fixed_t yoff, angle_t angle, angle_t plangle) +{ + // Potentially override other stuff for now cus we're mean. :< But draw a slope plane! + // I copied ZDoom's code and adapted it to SRB2... -Red + floatv3_t *m = &ds->slope_v, *n = &ds->slope_u; + fixed_t height, temp; + float ang; + + R_SetSlopePlaneOrigin(ds, slope, xpos, ypos, zpos, xoff, yoff, angle); + height = P_GetSlopeZAt(slope, xpos, ypos); + ds->zeroheight = FixedToFloat(height - zpos); // m is the v direction vector in view space - ang = ANG2RAD(ANGLE_180 - (planeviewangle + planeangle)); - m.x = yscale * cos(ang); - m.z = yscale * sin(ang); + ang = ANG2RAD(ANGLE_180 - (angle + plangle)); + m->x = cos(ang); + m->z = sin(ang); // n is the u direction vector in view space - n.x = xscale * sin(ang); - n.z = -xscale * cos(ang); + n->x = sin(ang); + n->z = -cos(ang); - ang = ANG2RAD(planeangle); - temp = P_GetSlopeZAt(slope, planeviewx + FLOAT_TO_FIXED(yscale * sin(ang)), planeviewy + FLOAT_TO_FIXED(yscale * cos(ang))); - m.y = FIXED_TO_FLOAT(temp) - ds->zeroheight; - temp = P_GetSlopeZAt(slope, planeviewx + FLOAT_TO_FIXED(xscale * cos(ang)), planeviewy - FLOAT_TO_FIXED(xscale * sin(ang))); - n.y = FIXED_TO_FLOAT(temp) - ds->zeroheight; + plangle >>= ANGLETOFINESHIFT; + temp = P_GetSlopeZAt(slope, xpos + FINESINE(plangle), ypos + FINECOSINE(plangle)); + m->y = FixedToFloat(temp - height); + temp = P_GetSlopeZAt(slope, xpos + FINECOSINE(plangle), ypos - FINESINE(plangle)); + n->y = FixedToFloat(temp - height); +} - m.x /= fudge; - m.y /= fudge; - m.z /= fudge; - - n.x *= fudge; - n.y *= fudge; - n.z *= fudge; +static void R_CalculateSlopeVectors(drawspandata_t* ds) +{ + float sfmult = 65536.f; // Eh. I tried making this stuff fixed-point and it exploded on me. Here's a macro for the only floating-point vector function I recall using. #define CROSS(d, v1, v2) \ d.x = (v1.y * v2.z) - (v1.z * v2.y);\ d.y = (v1.z * v2.x) - (v1.x * v2.z);\ d.z = (v1.x * v2.y) - (v1.y * v2.x) - CROSS(ds->sup, p, m); - CROSS(ds->svp, p, n); - CROSS(ds->szp, m, n); + CROSS(ds->sup, ds->slope_origin, ds->slope_v); + CROSS(ds->svp, ds->slope_origin, ds->slope_u); + CROSS(ds->szp, ds->slope_v, ds->slope_u); #undef CROSS ds->sup.z *= focallengthf; @@ -937,17 +884,17 @@ d.z = (v1.x * v2.y) - (v1.y * v2.x) ds->szp.z *= focallengthf; // Premultiply the texture vectors with the scale factors -#define SFMULT 65536.f - ds->sup.x *= (SFMULT * (1<nflatshiftup)); - ds->sup.y *= (SFMULT * (1<nflatshiftup)); - ds->sup.z *= (SFMULT * (1<nflatshiftup)); - ds->svp.x *= (SFMULT * (1<nflatshiftup)); - ds->svp.y *= (SFMULT * (1<nflatshiftup)); - ds->svp.z *= (SFMULT * (1<nflatshiftup)); -#undef SFMULT + sfmult *= (1 << ds->nflatshiftup); + + ds->sup.x *= sfmult; + ds->sup.y *= sfmult; + ds->sup.z *= sfmult; + ds->svp.x *= sfmult; + ds->svp.y *= sfmult; + ds->svp.z *= sfmult; } -static void R_SetTiltedSpan(drawspandata_t* ds, INT32 span) +void R_SetTiltedSpan(drawspandata_t* ds, INT32 span) { if (ds_su == NULL) ds_su = static_cast(Z_Calloc(sizeof(*ds_su) * vid.height, PU_STATIC, NULL)); @@ -961,17 +908,32 @@ static void R_SetTiltedSpan(drawspandata_t* ds, INT32 span) ds->szp = ds_sz[span]; } -static void R_SetSlopePlaneVectors(drawspandata_t* ds, visplane_t *pl, INT32 y, fixed_t xoff, fixed_t yoff, float fudge) +static void R_SetSlopePlaneVectors(drawspandata_t* ds, visplane_t *pl, INT32 y, fixed_t xoff, fixed_t yoff) { R_SetTiltedSpan(ds, y); - R_CalculateSlopeVectors(ds, pl->slope, pl->viewx, pl->viewy, pl->viewz, FRACUNIT, FRACUNIT, xoff, yoff, pl->viewangle, pl->plangle, fudge); + R_SetSlopePlane(ds, pl->slope, pl->viewx, pl->viewy, pl->viewz, xoff, yoff, pl->viewangle, pl->plangle); + R_CalculateSlopeVectors(ds); +} + +static inline void R_AdjustSlopeCoordinates(drawspandata_t* ds, vector3_t *origin) +{ + const fixed_t modmask = ((1 << (32-ds->nflatshiftup)) - 1); + + fixed_t ox = (origin->x & modmask); + fixed_t oy = -(origin->y & modmask); + + ds->xoffs &= modmask; + ds->yoffs &= modmask; + + ds->xoffs -= (origin->x - ox); + ds->yoffs += (origin->y + oy); } void R_DrawSinglePlane(drawspandata_t* ds, visplane_t *pl, boolean allow_parallel) { INT32 light = 0; INT32 x; - INT32 stop, angle; + INT32 stop; size_t size; INT32 spanfunctype = BASEDRAWFUNC; ffloor_t *rover; @@ -1064,9 +1026,59 @@ void R_DrawSinglePlane(drawspandata_t* ds, visplane_t *pl, boolean allow_paralle } else light = (pl->lightlevel >> LIGHTSEGSHIFT); - if (pl->ffloor->flags & FF_RIPPLE) + if (pl->ffloor->flags & FF_RIPPLE && cv_ripplewater.value) { - R_HandleRipplePlane(ds, pl); + INT32 top, bottom; + + ds->planeripple.active = true; + + if (spanfunctype == SPANDRAWFUNC_TRANS) + { + spanfunctype = SPANDRAWFUNC_WATER; + + // Copy the current scene, ugh + top = pl->high-8; + bottom = pl->low+8; + + if (top < 0) + top = 0; + if (bottom > vid.height) + bottom = vid.height; + + // Only copy the part of the screen we need + UINT8 i = R_GetViewNumber(); + INT32 scrx = 0; + INT32 scry = top; + INT32 offset; + + if (splitscreen == 1) + { + if (i & 1) + { + scry += viewheight; + } + } + else + { + if (i & 1) + { + scrx += viewwidth; + } + + if (i / 2) + { + scry += viewheight; + } + } + + offset = (scry*vid.width) + scrx; + + // No idea if this works + VID_BlitLinearScreen(renderscreen + offset, + vid.screens[1] + (top*vid.width), // intentionally not +offset + viewwidth, bottom-top, + vid.width, vid.width); + } } } else light = (pl->lightlevel >> LIGHTSEGSHIFT); @@ -1075,9 +1087,6 @@ void R_DrawSinglePlane(drawspandata_t* ds, visplane_t *pl, boolean allow_paralle // Don't mess with angle on slopes! We'll handle this ourselves later if (!pl->slope && viewangle != pl->viewangle+pl->plangle) { - angle = (pl->viewangle+pl->plangle-ANGLE_90)>>ANGLETOFINESHIFT; - basexscale = FixedDiv(FINECOSINE(angle),centerxfrac); - baseyscale = -FixedDiv(FINESINE(angle),centerxfrac); viewangle = pl->viewangle+pl->plangle; } @@ -1143,65 +1152,12 @@ void R_DrawSinglePlane(drawspandata_t* ds, visplane_t *pl, boolean allow_paralle if (pl->slope) { - float fudgecanyon = 0; - fixed_t temp; - // Okay, look, don't ask me why this works, but without this setup there's a disgusting-looking misalignment with the textures. -fickle - fudgecanyon = ((1<nflatshiftup)+1.0f)/(1<nflatshiftup); - - angle_t hack = (pl->plangle & (ANGLE_90-1)); - mapfunc = R_MapTiltedPlane; - if (hack) + if (!pl->plangle) { - /* - Essentially: We can't & the components along the regular axes when the plane is rotated. - This is because the distance on each regular axis in order to loop is different. - We rotate them, & the components, add them together, & them again, and then rotate them back. - These three seperate & operations are done per axis in order to prevent overflows. - toast 10/04/17 - --- - ...of coooourse, this still isn't perfect. but it looks... merely kind of grody, rather than - completely wrong? idk. i'm just backporting this to kart right now. if anyone else wants to - ever try dig around: it's drifting towards 0,0, and no, multiplying by fudge doesn't fix it. - toast 27/09/18 - */ - - const fixed_t cosinecomponent = FINECOSINE(hack>>ANGLETOFINESHIFT); - const fixed_t sinecomponent = FINESINE(hack>>ANGLETOFINESHIFT); - - const fixed_t modmask = ((1 << (32-ds->nflatshiftup)) - 1); - - fixed_t ox = (FixedMul(pl->slope->o.x,cosinecomponent) & modmask) - (FixedMul(pl->slope->o.y,sinecomponent) & modmask); - fixed_t oy = (-FixedMul(pl->slope->o.x,sinecomponent) & modmask) - (FixedMul(pl->slope->o.y,cosinecomponent) & modmask); - - temp = ox & modmask; - oy &= modmask; - ox = FixedMul(temp,cosinecomponent)+FixedMul(oy,-sinecomponent); // negative sine for opposite direction - oy = -FixedMul(temp,-sinecomponent)+FixedMul(oy,cosinecomponent); - - temp = ds->xoffs; - ds->xoffs = (FixedMul(temp,cosinecomponent) & modmask) + (FixedMul(ds->yoffs, sinecomponent) & modmask); - ds->yoffs = (-FixedMul(temp,sinecomponent) & modmask) + (FixedMul(ds->yoffs, cosinecomponent) & modmask); - - temp = ds->xoffs & modmask; - ds->yoffs &= modmask; - ds->xoffs = FixedMul(temp,cosinecomponent)+FixedMul(ds->yoffs, -sinecomponent); // ditto - ds->yoffs = -FixedMul(temp,-sinecomponent)+FixedMul(ds->yoffs, cosinecomponent); - - ds->xoffs -= (pl->slope->o.x - ox); - ds->yoffs += (pl->slope->o.y + oy); + R_AdjustSlopeCoordinates(ds, &pl->slope->o); } - else - { - ds->xoffs &= ((1 << (32-ds->nflatshiftup))-1); - ds->yoffs &= ((1 << (32-ds->nflatshiftup))-1); - ds->xoffs -= (pl->slope->o.x + (1 << (31-ds->nflatshiftup))) & ~((1 << (32-ds->nflatshiftup))-1); - ds->yoffs += (pl->slope->o.y + (1 << (31-ds->nflatshiftup))) & ~((1 << (32-ds->nflatshiftup))-1); - } - - ds->xoffs = (fixed_t)(ds->xoffs*fudgecanyon); - ds->yoffs = (fixed_t)(ds->yoffs/fudgecanyon); if (ds->planeripple.active) { @@ -1213,11 +1169,11 @@ void R_DrawSinglePlane(drawspandata_t* ds, visplane_t *pl, boolean allow_paralle { ds->bgofs = R_CalculateRippleOffset(ds, x); R_CalculatePlaneRipple(ds, pl->viewangle + pl->plangle); - R_SetSlopePlaneVectors(ds, pl, x, (ds->xoffs + ds->planeripple.xfrac), (ds->yoffs + ds->planeripple.yfrac), fudgecanyon); + R_SetSlopePlaneVectors(ds, pl, x, (ds->xoffs + ds->planeripple.xfrac), (ds->yoffs + ds->planeripple.yfrac)); } } else - R_SetSlopePlaneVectors(ds, pl, 0, ds->xoffs, ds->yoffs, fudgecanyon); + R_SetSlopePlaneVectors(ds, pl, 0, ds->xoffs, ds->yoffs); switch (spanfunctype) { @@ -1253,14 +1209,6 @@ void R_DrawSinglePlane(drawspandata_t* ds, visplane_t *pl, boolean allow_paralle stop = pl->maxx + 1; - if (viewx != pl->viewx || viewy != pl->viewy) - { - viewx = pl->viewx; - viewy = pl->viewy; - } - if (viewz != pl->viewz) - viewz = pl->viewz; - for (x = pl->minx; x <= stop; x++) { R_MakeSpans(mapfunc, spanfunc, ds, x, pl->top[x-1], pl->bottom[x-1], pl->top[x], pl->bottom[x], allow_parallel);