From 834a5e6b3530a5ed3cc89b3528b8f35ea8689b55 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Mon, 29 Oct 2018 12:06:22 +0000 Subject: [PATCH 1/6] V_DrawFixedPatch: Tinker with the left/top offsets code so that V_OFFSET can support V_FLIP --- src/v_video.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/v_video.c b/src/v_video.c index 802a4d38..0d80dc50 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -406,22 +406,35 @@ void V_DrawFixedPatch(fixed_t x, fixed_t y, fixed_t pscale, INT32 scrn, patch_t colfrac = FixedDiv(FRACUNIT, fdup); rowfrac = FixedDiv(FRACUNIT, fdup); - if (scrn & V_OFFSET) // Crosshair shit + // So it turns out offsets aren't scaled in V_NOSCALESTART unless V_OFFSET is applied ...poo, that's terrible + // For now let's just at least give V_OFFSET the ability to support V_FLIP + // I'll probably make a better fix for 2.2 where I don't have to worry about breaking existing support for stuff + // -- Monster Iestyn 29/10/18 { - y -= FixedMul((SHORT(patch->topoffset)*dupy)<leftoffset)*dupx)<topoffset)<width) - SHORT(patch->leftoffset))<width) - SHORT(patch->leftoffset))<leftoffset)<leftoffset)<topoffset)< Date: Mon, 29 Oct 2018 12:36:09 +0000 Subject: [PATCH 2/6] Make V_OFFSET no thing without V_NOSCALESTART, to remove any potential glitches with using it on its own --- src/v_video.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/v_video.c b/src/v_video.c index 0d80dc50..b5abd009 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -426,7 +426,7 @@ void V_DrawFixedPatch(fixed_t x, fixed_t y, fixed_t pscale, INT32 scrn, patch_t // TODO: make some kind of vertical version of V_FLIP, maybe by deprecating V_OFFSET in future?!? offsety = FixedMul(SHORT(patch->topoffset)< Date: Mon, 29 Oct 2018 13:29:16 +0000 Subject: [PATCH 3/6] HWR_DrawFixedPatch: Add V_OFFSET support for V_FLIP in hardware code as well, also add missing SHORTs for gpatch fields --- src/hardware/hw_draw.c | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/src/hardware/hw_draw.c b/src/hardware/hw_draw.c index 84081dd2..ad41c68d 100644 --- a/src/hardware/hw_draw.c +++ b/src/hardware/hw_draw.c @@ -179,18 +179,29 @@ void HWR_DrawFixedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, dupx = dupy = (dupx < dupy ? dupx : dupy); fscale = FIXED_TO_FLOAT(pscale); - if (option & V_OFFSET) + // See my comments in v_video.c's V_DrawFixedPatch + // -- Monster Iestyn 29/10/18 { - cx -= (float)gpatch->leftoffset * dupx * fscale; - cy -= (float)gpatch->topoffset * dupy * fscale; - } - else - { - cy -= (float)gpatch->topoffset * fscale; + float offsetx = 0.0f, offsety = 0.0f; + + // left offset if (option & V_FLIP) - cx -= ((float)gpatch->width - (float)gpatch->leftoffset) * fscale; + offsetx = (float)(SHORT(gpatch->width) - SHORT(gpatch->leftoffset)) * fscale; else - cx -= (float)gpatch->leftoffset * fscale; + offsetx = (float)SHORT(gpatch->leftoffset) * fscale; + + // top offset + // TODO: make some kind of vertical version of V_FLIP, maybe by deprecating V_OFFSET in future?!? + offsety = (float)SHORT(patch->topoffset) * fscale; + + if ((option & (V_NOSCALESTART|V_OFFSET)) == (V_NOSCALESTART|V_OFFSET)) // Multiply by dupx/dupy for crosshairs + { + offsetx *= dupx; + offsety *= dupy; + } + + cx -= offsetx; + cy -= offsety; } if (option & V_SPLITSCREEN) @@ -237,13 +248,13 @@ void HWR_DrawFixedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, if (pscale != FRACUNIT) { - fwidth = (float)gpatch->width * fscale * dupx; - fheight = (float)gpatch->height * fscale * dupy; + fwidth = (float)SHORT(gpatch->width) * fscale * dupx; + fheight = (float)SHORT(gpatch->height) * fscale * dupy; } else { - fwidth = (float)gpatch->width * dupx; - fheight = (float)gpatch->height * dupy; + fwidth = (float)SHORT(gpatch->width) * dupx; + fheight = (float)SHORT(gpatch->height) * dupy; } // positions of the cx, cy, are between 0 and vid.width/vid.height now, we need them to be between -1 and 1 From b022ff02a5859dd597cc67c40367085fee40ac4c Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Mon, 29 Oct 2018 13:34:54 +0000 Subject: [PATCH 4/6] add missing SHORTs in HWR_DrawPatch and HWR_DrawCroppedPatch as well --- src/hardware/hw_draw.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/hardware/hw_draw.c b/src/hardware/hw_draw.c index ad41c68d..ffd15686 100644 --- a/src/hardware/hw_draw.c +++ b/src/hardware/hw_draw.c @@ -112,10 +112,10 @@ void HWR_DrawPatch(GLPatch_t *gpatch, INT32 x, INT32 y, INT32 option) if (option & V_NOSCALESTART) sdupx = sdupy = 2.0f; - v[0].x = v[3].x = (x*sdupx-gpatch->leftoffset*pdupx)/vid.width - 1; - v[2].x = v[1].x = (x*sdupx+(gpatch->width-gpatch->leftoffset)*pdupx)/vid.width - 1; - v[0].y = v[1].y = 1-(y*sdupy-gpatch->topoffset*pdupy)/vid.height; - v[2].y = v[3].y = 1-(y*sdupy+(gpatch->height-gpatch->topoffset)*pdupy)/vid.height; + v[0].x = v[3].x = (x*sdupx-SHORT(gpatch->leftoffset)*pdupx)/vid.width - 1; + v[2].x = v[1].x = (x*sdupx+(SHORT(gpatch->width)-SHORT(gpatch->leftoffset))*pdupx)/vid.width - 1; + v[0].y = v[1].y = 1-(y*sdupy-SHORT(gpatch->topoffset)*pdupy)/vid.height; + v[2].y = v[3].y = 1-(y*sdupy+(SHORT(gpatch->height)-SHORT(gpatch->topoffset))*pdupy)/vid.height; v[0].z = v[1].z = v[2].z = v[3].z = 1.0f; @@ -352,8 +352,8 @@ void HWR_DrawCroppedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscal dupx = dupy = (dupx < dupy ? dupx : dupy); fscale = FIXED_TO_FLOAT(pscale); - cy -= (float)gpatch->topoffset * fscale; - cx -= (float)gpatch->leftoffset * fscale; + cy -= (float)SHORT(gpatch->topoffset) * fscale; + cx -= (float)SHORT(gpatch->leftoffset) * fscale; if (!(option & V_NOSCALESTART)) { @@ -403,11 +403,11 @@ void HWR_DrawCroppedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscal if (fheight > h - sy) fheight = h - sy; - if (fwidth > gpatch->width) - fwidth = gpatch->width; + if (fwidth > SHORT(gpatch->width)) + fwidth = SHORT(gpatch->width); - if (fheight > gpatch->height) - fheight = gpatch->height; + if (fheight > SHORT(gpatch->height)) + fheight = SHORT(gpatch->height); if (pscale != FRACUNIT) { @@ -437,10 +437,10 @@ void HWR_DrawCroppedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscal v[0].z = v[1].z = v[2].z = v[3].z = 1.0f; - v[0].sow = v[3].sow = ((sx)/(float)gpatch->width )*gpatch->max_s; - v[2].sow = v[1].sow = ((w )/(float)gpatch->width )*gpatch->max_s; - v[0].tow = v[1].tow = ((sy)/(float)gpatch->height)*gpatch->max_t; - v[2].tow = v[3].tow = ((h )/(float)gpatch->height)*gpatch->max_t; + v[0].sow = v[3].sow = ((sx)/(float)SHORT(gpatch->width) )*gpatch->max_s; + v[2].sow = v[1].sow = ((w )/(float)SHORT(gpatch->width) )*gpatch->max_s; + v[0].tow = v[1].tow = ((sy)/(float)SHORT(gpatch->height))*gpatch->max_t; + v[2].tow = v[3].tow = ((h )/(float)SHORT(gpatch->height))*gpatch->max_t; flags = BLENDMODE|PF_Clip|PF_NoZClip|PF_NoDepthTest; From 2fa0896fd020ef2eb83a42561344fe888df06588 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Tue, 30 Oct 2018 13:44:01 +0000 Subject: [PATCH 5/6] Fix an error I made in HWR_DrawFixedPatch --- src/hardware/hw_draw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hardware/hw_draw.c b/src/hardware/hw_draw.c index ffd15686..33f5e031 100644 --- a/src/hardware/hw_draw.c +++ b/src/hardware/hw_draw.c @@ -192,7 +192,7 @@ void HWR_DrawFixedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, // top offset // TODO: make some kind of vertical version of V_FLIP, maybe by deprecating V_OFFSET in future?!? - offsety = (float)SHORT(patch->topoffset) * fscale; + offsety = (float)SHORT(gpatch->topoffset) * fscale; if ((option & (V_NOSCALESTART|V_OFFSET)) == (V_NOSCALESTART|V_OFFSET)) // Multiply by dupx/dupy for crosshairs { From 22e8dd1f9da40d0447531f848ae4cbbdd18b869c Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Tue, 30 Oct 2018 14:22:21 +0000 Subject: [PATCH 6/6] now that V_FLIP's effects are always supported in V_DrawFixedPatch, there's no need for the "flip" variable anymore --- src/v_video.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/v_video.c b/src/v_video.c index b5abd009..933ec0f0 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -331,7 +331,6 @@ void V_DrawFixedPatch(fixed_t x, fixed_t y, fixed_t pscale, INT32 scrn, patch_t { UINT8 (*patchdrawfunc)(const UINT8*, const UINT8*, fixed_t); UINT32 alphalevel = 0; - boolean flip = false; fixed_t col, ofs, colfrac, rowfrac, fdup; INT32 dupx, dupy; @@ -415,10 +414,7 @@ void V_DrawFixedPatch(fixed_t x, fixed_t y, fixed_t pscale, INT32 scrn, patch_t // left offset if (scrn & V_FLIP) - { - flip = true; offsetx = FixedMul((SHORT(patch->width) - SHORT(patch->leftoffset))<leftoffset)<>FRACBITS) < SHORT(patch->width); col += colfrac, ++offx, desttop++) { INT32 topdelta, prevdelta = -1; - if (flip) // offx is measured from right edge instead of left + if (scrn & V_FLIP) // offx is measured from right edge instead of left { if (x+pwidth-offx < 0) // don't draw off the left of the screen (WRAP PREVENTION) break; @@ -534,7 +530,7 @@ void V_DrawFixedPatch(fixed_t x, fixed_t y, fixed_t pscale, INT32 scrn, patch_t prevdelta = topdelta; source = (const UINT8 *)(column) + 3; dest = desttop; - if (flip) + if (scrn & V_FLIP) dest = deststart + (destend - desttop); dest += FixedInt(FixedMul(topdelta<