From d5e9005dd0f49b66e7fa384eaaa6360e535638f1 Mon Sep 17 00:00:00 2001 From: Jaime Ita Passos Date: Wed, 14 Apr 2021 11:34:36 -0300 Subject: [PATCH] Fix NPOT flats, other minor changes. --- src/r_plane.c | 42 ++++++++++++++++-------------------------- src/r_plane.h | 2 +- src/r_splats.c | 2 +- 3 files changed, 18 insertions(+), 28 deletions(-) diff --git a/src/r_plane.c b/src/r_plane.c index a936b0911..10d87b9cc 100644 --- a/src/r_plane.c +++ b/src/r_plane.c @@ -663,7 +663,7 @@ static void R_DrawSkyPlane(visplane_t *pl) } } -// Sets the origin vector of the sloped plane. +// Sets the texture origin vector of the sloped plane. static void R_SetSlopePlaneOrigin(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; @@ -683,7 +683,7 @@ static void R_SetSlopePlaneOrigin(pslope_t *slope, fixed_t xpos, fixed_t ypos, f p->y = FixedToFloat(P_GetSlopeZAt(slope, -xoff, yoff)) - vz; } -// This function calculates all of the vectors necessary for drawing a tilted span. +// This function calculates all of the vectors necessary for drawing a sloped plane. void R_SetSlopePlane(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! @@ -710,8 +710,8 @@ void R_SetSlopePlane(pslope_t *slope, fixed_t xpos, fixed_t ypos, fixed_t zpos, n->y = FixedToFloat(temp) - zeroheight; } -// This function calculates all of the vectors necessary for drawing a scaled, tilted span. -void R_SetSlopePlaneScaled(pslope_t *slope, fixed_t xpos, fixed_t ypos, fixed_t zpos, fixed_t xs, fixed_t ys, fixed_t xoff, fixed_t yoff, angle_t angle, angle_t plangle) +// This function calculates all of the vectors necessary for drawing a sloped and scaled plane. +void R_SetScaledSlopePlane(pslope_t *slope, fixed_t xpos, fixed_t ypos, fixed_t zpos, fixed_t xs, fixed_t ys, fixed_t xoff, fixed_t yoff, angle_t angle, angle_t plangle) { floatv3_t *m = &ds_slope_v, *n = &ds_slope_u; fixed_t temp; @@ -740,6 +740,8 @@ void R_SetSlopePlaneScaled(pslope_t *slope, fixed_t xpos, fixed_t ypos, fixed_t void R_CalculateSlopeVectors(void) { + 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);\ @@ -755,27 +757,15 @@ 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 if (ds_powersoftwo) - { - ds_sup->x *= (SFMULT * (1<y *= (SFMULT * (1<z *= (SFMULT * (1<x *= (SFMULT * (1<y *= (SFMULT * (1<z *= (SFMULT * (1<x *= SFMULT; - ds_sup->y *= SFMULT; - ds_sup->z *= SFMULT; - ds_svp->x *= SFMULT; - ds_svp->y *= SFMULT; - ds_svp->z *= SFMULT; - } -#undef SFMULT + sfmult *= (1 << 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; } void R_SetTiltedSpan(INT32 span) @@ -977,8 +967,8 @@ void R_DrawSinglePlane(visplane_t *pl) if (pl->slope) { - const fixed_t modmaskw = (ds_flatwidth << FRACBITS) - 1; - const fixed_t modmaskh = (ds_flatheight << FRACBITS) - 1; + const fixed_t modmaskw = (ds_powersoftwo) ? (ds_flatwidth << FRACBITS) - 1 : (signed)(0xFFFFFFFF); + const fixed_t modmaskh = (ds_powersoftwo) ? (ds_flatheight << FRACBITS) - 1 : (signed)(0xFFFFFFFF); /* Essentially: We can't & the components along the regular axes when the plane is rotated. diff --git a/src/r_plane.h b/src/r_plane.h index 8f7574744..9b7e31e3e 100644 --- a/src/r_plane.h +++ b/src/r_plane.h @@ -95,7 +95,7 @@ void R_DrawSinglePlane(visplane_t *pl); // Calculates the slope vectors needed for tilted span drawing. void R_SetSlopePlane(pslope_t *slope, fixed_t xpos, fixed_t ypos, fixed_t zpos, fixed_t xoff, fixed_t yoff, angle_t angle, angle_t plangle); -void R_SetSlopePlaneScaled(pslope_t *slope, fixed_t xpos, fixed_t ypos, fixed_t zpos, fixed_t xs, fixed_t ys, fixed_t xoff, fixed_t yoff, angle_t angle, angle_t plangle); +void R_SetScaledSlopePlane(pslope_t *slope, fixed_t xpos, fixed_t ypos, fixed_t zpos, fixed_t xs, fixed_t ys, fixed_t xoff, fixed_t yoff, angle_t angle, angle_t plangle); void R_CalculateSlopeVectors(void); // Sets the slope vector pointers for the current tilted span. diff --git a/src/r_splats.c b/src/r_splats.c index 49b66304b..4783fb640 100644 --- a/src/r_splats.c +++ b/src/r_splats.c @@ -419,7 +419,7 @@ static void R_RasterizeFloorSplat(floorsplat_t *pSplat, vector2_t *verts, visspr if (pSplat->tilted) { R_SetTiltedSpan(0); - R_SetSlopePlaneScaled(&pSplat->slope, viewx, viewy, viewz, pSplat->xscale, pSplat->yscale, -pSplat->verts[0].x, pSplat->verts[0].y, vis->viewangle, pSplat->angle); + R_SetScaledSlopePlane(&pSplat->slope, viewx, viewy, viewz, pSplat->xscale, pSplat->yscale, -pSplat->verts[0].x, pSplat->verts[0].y, vis->viewangle, pSplat->angle); R_CalculateSlopeVectors(); spanfunctype = SPANDRAWFUNC_TILTEDSPRITE; }