From b6ef6eb8018a383fe27189755fcc2836ea4d7df9 Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Tue, 12 Sep 2023 21:03:58 +0200 Subject: [PATCH 1/6] revert sloped midtexture fix for now huge performance regression on some maps ill look into it in the future again maybe --- src/hardware/hw_main.c | 148 +++++++++++++++++++++++++---------------- 1 file changed, 90 insertions(+), 58 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 07f74f6a5..66adf3522 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -951,9 +951,6 @@ void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfa pegb = wallVerts[0].t; pegmul = (pegb - pegt) / (top - bot); - if (fpclassify(pegmul) == FP_NAN) - pegmul = 0.0; - #ifdef ESLOPE endrealtop = endtop = wallVerts[2].y; endrealbot = endbot = wallVerts[1].y; @@ -962,8 +959,6 @@ void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfa endpegmul = (endpegb - endpegt) / (endtop - endbot); #endif - if (fpclassify(endpegmul) == FP_NAN) - endpegmul = 0.0; for (i = 0; i < sector->numlights; i++) { @@ -1074,10 +1069,24 @@ void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfa } #endif - // Found a break - bot = min(max(bheight, realbot), top); - endbot = min(max(endbheight, endrealbot), endtop); +#ifdef ESLOPE + if (endbheight >= endtop) +#endif + if (bheight >= top) + continue; + //Found a break; + bot = bheight; + + if (bot < realbot) + bot = realbot; + +#ifdef ESLOPE + endbot = endbheight; + + if (endbot < endrealbot) + endbot = endrealbot; +#endif Surf->PolyColor.s.alpha = alpha; #ifdef ESLOPE @@ -1671,7 +1680,10 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom gr_midtexture = R_GetTextureNum(gr_sidedef->midtexture); if (gr_midtexture || gr_portal == GRPORTAL_STENCIL || gr_portal == GRPORTAL_DEPTH || gl_drawing_stencil) { + FBITFIELD blendmode; sector_t *front, *back; + fixed_t popentop, popenbottom, polytop, polybottom, lowcut, highcut; + fixed_t texturevpeg = 0; INT32 repeats; if (gr_linedef->frontsector->heightsec != -1) @@ -1707,10 +1719,6 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom else repeats = 1; - fixed_t midtexheight = textureheight[gr_midtexture] * repeats; - fixed_t popentop, popenbottom, polytop, polybottom, lowcut, highcut; - fixed_t popentopslope, popenbottomslope, polytopslope, polybottomslope, lowcutslope, highcutslope; - // SoM: a little note: This code re-arranging will // fix the bug in Nimrod map02. popentop and popenbottom // record the limits the texture can be displayed in. @@ -1724,8 +1732,8 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom // From CB if (gr_curline->polyseg) { - popentop = popentopslope = back->ceilingheight; - popenbottom = popenbottomslope = back->floorheight; + popentop = back->ceilingheight; + popenbottom = back->floorheight; } else #endif @@ -1733,9 +1741,10 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom #ifdef ESLOPE popentop = min(worldtop, worldhigh); popenbottom = max(worldbottom, worldlow); - - popentopslope = min(worldtopslope, worldhighslope); - popenbottomslope = max(worldbottomslope, worldlowslope); +#else + popentop = min(front->ceilingheight, back->ceilingheight); + popenbottom = max(front->floorheight, back->floorheight); +#endif } #ifdef ESLOPE @@ -1744,16 +1753,12 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom if (!!(gr_linedef->flags & ML_DONTPEGBOTTOM) ^ !!(gr_linedef->flags & ML_EFFECT3)) { polybottom = max(front->floorheight, back->floorheight) + gr_sidedef->rowoffset; - polybottomslope = polybottom; - polytop = polybottom + midtexheight; - polytopslope = polytop; + polytop = polybottom + textureheight[gr_midtexture]*repeats; } else { polytop = min(front->ceilingheight, back->ceilingheight) + gr_sidedef->rowoffset; - polytopslope = polytop; - polybottom = polytop - midtexheight; - polybottomslope = polybottom; + polybottom = polytop - textureheight[gr_midtexture]*repeats; } } else if (!!(gr_linedef->flags & ML_DONTPEGBOTTOM) ^ !!(gr_linedef->flags & ML_EFFECT3)) @@ -1762,17 +1767,12 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom #endif { polybottom = popenbottom + gr_sidedef->rowoffset; - polytop = polybottom + midtexheight; - polybottomslope = popenbottomslope + gr_sidedef->rowoffset; - polytopslope = polybottomslope + midtexheight; + polytop = polybottom + textureheight[gr_midtexture]*repeats; } else { polytop = popentop + gr_sidedef->rowoffset; polybottom = polytop - textureheight[gr_midtexture]*repeats; - polybottom = polytop - midtexheight; - polytopslope = popentopslope + gr_sidedef->rowoffset; - polybottomslope = polytopslope - midtexheight; } // CB @@ -1783,8 +1783,6 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom { lowcut = polybottom; highcut = polytop; - lowcutslope = polybottomslope; - highcutslope = polytopslope; } #endif else @@ -1792,49 +1790,83 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom // The cut-off values of a linedef can always be constant, since every line has an absoulute front and or back sector lowcut = popenbottom; highcut = popentop; - lowcutslope = popenbottomslope; - highcutslope = popentopslope; } h = min(highcut, polytop); l = max(polybottom, lowcut); - hS = min(highcutslope, polytopslope); - lS = max(polybottomslope, lowcutslope); - // PEGGING - fixed_t texturevpeg, texturevpegslope; - - if (!!(gr_linedef->flags & ML_DONTPEGBOTTOM) ^ !!(gr_linedef->flags & ML_EFFECT3)) { - texturevpeg = midtexheight - h + polybottom; - texturevpegslope = midtexheight - hS + polybottomslope; - } - else - { - texturevpeg = polytop - h; - texturevpegslope = polytopslope - hS; - } + // PEGGING +#ifdef ESLOPE + if (!!(gr_linedef->flags & ML_DONTPEGBOTTOM) ^ !!(gr_linedef->flags & ML_EFFECT3)) +#else + if (gr_linedef->flags & ML_DONTPEGBOTTOM) +#endif + texturevpeg = textureheight[gr_sidedef->midtexture]*repeats - h + polybottom; + else + texturevpeg = polytop - h; grTex = HWR_GetTexture(gr_midtexture); - wallVerts[3].t = texturevpeg * grTex->scaleY; - wallVerts[0].t = (h - l + texturevpeg) * grTex->scaleY; - wallVerts[2].t = texturevpegslope * grTex->scaleY; - wallVerts[1].t = (hS - lS + texturevpegslope) * grTex->scaleY; - wallVerts[0].s = wallVerts[3].s = cliplow * grTex->scaleX; - wallVerts[2].s = wallVerts[1].s = cliphigh * grTex->scaleX; + wallVerts[3].t = wallVerts[2].t = texturevpeg * grTex->scaleY; + wallVerts[0].t = wallVerts[1].t = (h - l + texturevpeg) * grTex->scaleY; + wallVerts[0].s = wallVerts[3].s = cliplow * grTex->scaleX; + wallVerts[2].s = wallVerts[1].s = cliphigh * grTex->scaleX; + } // set top/bottom coords // Take the texture peg into account, rather than changing the offsets past // where the polygon might not be. - wallVerts[3].y = FIXED_TO_FLOAT(h); - wallVerts[0].y = FIXED_TO_FLOAT(l); - wallVerts[2].y = FIXED_TO_FLOAT(hS); - wallVerts[1].y = FIXED_TO_FLOAT(lS); + wallVerts[2].y = wallVerts[3].y = FIXED_TO_FLOAT(h); + wallVerts[0].y = wallVerts[1].y = FIXED_TO_FLOAT(l); + +#ifdef ESLOPE + // Correct to account for slopes + { + fixed_t midtextureslant; + + if (gr_linedef->flags & ML_EFFECT2) + midtextureslant = 0; + else if (!!(gr_linedef->flags & ML_DONTPEGBOTTOM) ^ !!(gr_linedef->flags & ML_EFFECT3)) + midtextureslant = worldlow < worldbottom + ? worldbottomslope-worldbottom + : worldlowslope-worldlow; + else + midtextureslant = worldtop < worldhigh + ? worldtopslope-worldtop + : worldhighslope-worldhigh; + + polytop += midtextureslant; + polybottom += midtextureslant; + + highcut += worldtop < worldhigh + ? worldtopslope-worldtop + : worldhighslope-worldhigh; + lowcut += worldlow < worldbottom + ? worldbottomslope-worldbottom + : worldlowslope-worldlow; + + // Texture stuff + h = min(highcut, polytop); + l = max(polybottom, lowcut); + + { + // PEGGING + if (!!(gr_linedef->flags & ML_DONTPEGBOTTOM) ^ !!(gr_linedef->flags & ML_EFFECT3)) + texturevpeg = textureheight[gr_sidedef->midtexture]*repeats - h + polybottom; + else + texturevpeg = polytop - h; + wallVerts[2].t = texturevpeg * grTex->scaleY; + wallVerts[1].t = (h - l + texturevpeg) * grTex->scaleY; + } + + wallVerts[2].y = FIXED_TO_FLOAT(h); + wallVerts[1].y = FIXED_TO_FLOAT(l); + } #endif // set alpha for transparent walls (new boom and legacy linedef types) - FBITFIELD blendmode; + // ooops ! this do not work at all because render order we should render it in backtofront order switch (gr_linedef->special) { From 64b2e2ee37a2d2fb1e1b43d4084d8f01880091db Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Wed, 13 Sep 2023 01:40:52 +0200 Subject: [PATCH 2/6] Fix bugs with HWR_SplitWall and sloped midtextures but cleaner performance still pretty bad, atleast this is cleaner than last time --- src/hardware/hw_main.c | 148 ++++++++++++++++------------------------- 1 file changed, 58 insertions(+), 90 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 66adf3522..07f74f6a5 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -951,6 +951,9 @@ void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfa pegb = wallVerts[0].t; pegmul = (pegb - pegt) / (top - bot); + if (fpclassify(pegmul) == FP_NAN) + pegmul = 0.0; + #ifdef ESLOPE endrealtop = endtop = wallVerts[2].y; endrealbot = endbot = wallVerts[1].y; @@ -959,6 +962,8 @@ void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfa endpegmul = (endpegb - endpegt) / (endtop - endbot); #endif + if (fpclassify(endpegmul) == FP_NAN) + endpegmul = 0.0; for (i = 0; i < sector->numlights; i++) { @@ -1069,24 +1074,10 @@ void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfa } #endif -#ifdef ESLOPE - if (endbheight >= endtop) -#endif - if (bheight >= top) - continue; + // Found a break + bot = min(max(bheight, realbot), top); + endbot = min(max(endbheight, endrealbot), endtop); - //Found a break; - bot = bheight; - - if (bot < realbot) - bot = realbot; - -#ifdef ESLOPE - endbot = endbheight; - - if (endbot < endrealbot) - endbot = endrealbot; -#endif Surf->PolyColor.s.alpha = alpha; #ifdef ESLOPE @@ -1680,10 +1671,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom gr_midtexture = R_GetTextureNum(gr_sidedef->midtexture); if (gr_midtexture || gr_portal == GRPORTAL_STENCIL || gr_portal == GRPORTAL_DEPTH || gl_drawing_stencil) { - FBITFIELD blendmode; sector_t *front, *back; - fixed_t popentop, popenbottom, polytop, polybottom, lowcut, highcut; - fixed_t texturevpeg = 0; INT32 repeats; if (gr_linedef->frontsector->heightsec != -1) @@ -1719,6 +1707,10 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom else repeats = 1; + fixed_t midtexheight = textureheight[gr_midtexture] * repeats; + fixed_t popentop, popenbottom, polytop, polybottom, lowcut, highcut; + fixed_t popentopslope, popenbottomslope, polytopslope, polybottomslope, lowcutslope, highcutslope; + // SoM: a little note: This code re-arranging will // fix the bug in Nimrod map02. popentop and popenbottom // record the limits the texture can be displayed in. @@ -1732,8 +1724,8 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom // From CB if (gr_curline->polyseg) { - popentop = back->ceilingheight; - popenbottom = back->floorheight; + popentop = popentopslope = back->ceilingheight; + popenbottom = popenbottomslope = back->floorheight; } else #endif @@ -1741,10 +1733,9 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom #ifdef ESLOPE popentop = min(worldtop, worldhigh); popenbottom = max(worldbottom, worldlow); -#else - popentop = min(front->ceilingheight, back->ceilingheight); - popenbottom = max(front->floorheight, back->floorheight); -#endif + + popentopslope = min(worldtopslope, worldhighslope); + popenbottomslope = max(worldbottomslope, worldlowslope); } #ifdef ESLOPE @@ -1753,12 +1744,16 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom if (!!(gr_linedef->flags & ML_DONTPEGBOTTOM) ^ !!(gr_linedef->flags & ML_EFFECT3)) { polybottom = max(front->floorheight, back->floorheight) + gr_sidedef->rowoffset; - polytop = polybottom + textureheight[gr_midtexture]*repeats; + polybottomslope = polybottom; + polytop = polybottom + midtexheight; + polytopslope = polytop; } else { polytop = min(front->ceilingheight, back->ceilingheight) + gr_sidedef->rowoffset; - polybottom = polytop - textureheight[gr_midtexture]*repeats; + polytopslope = polytop; + polybottom = polytop - midtexheight; + polybottomslope = polybottom; } } else if (!!(gr_linedef->flags & ML_DONTPEGBOTTOM) ^ !!(gr_linedef->flags & ML_EFFECT3)) @@ -1767,12 +1762,17 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom #endif { polybottom = popenbottom + gr_sidedef->rowoffset; - polytop = polybottom + textureheight[gr_midtexture]*repeats; + polytop = polybottom + midtexheight; + polybottomslope = popenbottomslope + gr_sidedef->rowoffset; + polytopslope = polybottomslope + midtexheight; } else { polytop = popentop + gr_sidedef->rowoffset; polybottom = polytop - textureheight[gr_midtexture]*repeats; + polybottom = polytop - midtexheight; + polytopslope = popentopslope + gr_sidedef->rowoffset; + polybottomslope = polytopslope - midtexheight; } // CB @@ -1783,6 +1783,8 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom { lowcut = polybottom; highcut = polytop; + lowcutslope = polybottomslope; + highcutslope = polytopslope; } #endif else @@ -1790,83 +1792,49 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom // The cut-off values of a linedef can always be constant, since every line has an absoulute front and or back sector lowcut = popenbottom; highcut = popentop; + lowcutslope = popenbottomslope; + highcutslope = popentopslope; } h = min(highcut, polytop); l = max(polybottom, lowcut); + hS = min(highcutslope, polytopslope); + lS = max(polybottomslope, lowcutslope); + // PEGGING + fixed_t texturevpeg, texturevpegslope; + + if (!!(gr_linedef->flags & ML_DONTPEGBOTTOM) ^ !!(gr_linedef->flags & ML_EFFECT3)) { - // PEGGING -#ifdef ESLOPE - if (!!(gr_linedef->flags & ML_DONTPEGBOTTOM) ^ !!(gr_linedef->flags & ML_EFFECT3)) -#else - if (gr_linedef->flags & ML_DONTPEGBOTTOM) -#endif - texturevpeg = textureheight[gr_sidedef->midtexture]*repeats - h + polybottom; - else - texturevpeg = polytop - h; + texturevpeg = midtexheight - h + polybottom; + texturevpegslope = midtexheight - hS + polybottomslope; + } + else + { + texturevpeg = polytop - h; + texturevpegslope = polytopslope - hS; + } grTex = HWR_GetTexture(gr_midtexture); - wallVerts[3].t = wallVerts[2].t = texturevpeg * grTex->scaleY; - wallVerts[0].t = wallVerts[1].t = (h - l + texturevpeg) * grTex->scaleY; - wallVerts[0].s = wallVerts[3].s = cliplow * grTex->scaleX; - wallVerts[2].s = wallVerts[1].s = cliphigh * grTex->scaleX; - } + wallVerts[3].t = texturevpeg * grTex->scaleY; + wallVerts[0].t = (h - l + texturevpeg) * grTex->scaleY; + wallVerts[2].t = texturevpegslope * grTex->scaleY; + wallVerts[1].t = (hS - lS + texturevpegslope) * grTex->scaleY; + wallVerts[0].s = wallVerts[3].s = cliplow * grTex->scaleX; + wallVerts[2].s = wallVerts[1].s = cliphigh * grTex->scaleX; // set top/bottom coords // Take the texture peg into account, rather than changing the offsets past // where the polygon might not be. - wallVerts[2].y = wallVerts[3].y = FIXED_TO_FLOAT(h); - wallVerts[0].y = wallVerts[1].y = FIXED_TO_FLOAT(l); - -#ifdef ESLOPE - // Correct to account for slopes - { - fixed_t midtextureslant; - - if (gr_linedef->flags & ML_EFFECT2) - midtextureslant = 0; - else if (!!(gr_linedef->flags & ML_DONTPEGBOTTOM) ^ !!(gr_linedef->flags & ML_EFFECT3)) - midtextureslant = worldlow < worldbottom - ? worldbottomslope-worldbottom - : worldlowslope-worldlow; - else - midtextureslant = worldtop < worldhigh - ? worldtopslope-worldtop - : worldhighslope-worldhigh; - - polytop += midtextureslant; - polybottom += midtextureslant; - - highcut += worldtop < worldhigh - ? worldtopslope-worldtop - : worldhighslope-worldhigh; - lowcut += worldlow < worldbottom - ? worldbottomslope-worldbottom - : worldlowslope-worldlow; - - // Texture stuff - h = min(highcut, polytop); - l = max(polybottom, lowcut); - - { - // PEGGING - if (!!(gr_linedef->flags & ML_DONTPEGBOTTOM) ^ !!(gr_linedef->flags & ML_EFFECT3)) - texturevpeg = textureheight[gr_sidedef->midtexture]*repeats - h + polybottom; - else - texturevpeg = polytop - h; - wallVerts[2].t = texturevpeg * grTex->scaleY; - wallVerts[1].t = (h - l + texturevpeg) * grTex->scaleY; - } - - wallVerts[2].y = FIXED_TO_FLOAT(h); - wallVerts[1].y = FIXED_TO_FLOAT(l); - } + wallVerts[3].y = FIXED_TO_FLOAT(h); + wallVerts[0].y = FIXED_TO_FLOAT(l); + wallVerts[2].y = FIXED_TO_FLOAT(hS); + wallVerts[1].y = FIXED_TO_FLOAT(lS); #endif // set alpha for transparent walls (new boom and legacy linedef types) - // ooops ! this do not work at all because render order we should render it in backtofront order + FBITFIELD blendmode; switch (gr_linedef->special) { From 06a2508a9cbb2ccc1dd018d06507b1b710d346d9 Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Wed, 13 Sep 2023 01:52:25 +0200 Subject: [PATCH 3/6] cleanup HWR_SplitWall e --- src/hardware/hw_main.c | 83 ++++++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 39 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 07f74f6a5..7fe8f9be8 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -915,11 +915,10 @@ void HWR_ProjectWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, FBITFIELD blend // // HWR_SplitWall // +// SoM: split up and light walls according to the lightlist. +// This may also include leaving out parts of the wall that can't be seen void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfaceInfo* Surf, INT32 cutflag, ffloor_t *pfloor, FBITFIELD polyflags) { - /* SoM: split up and light walls according to the - lightlist. This may also include leaving out parts - of the wall that can't be seen */ float realtop, realbot, top, bot; float pegt, pegb, pegmul; @@ -930,48 +929,55 @@ void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfa float endpegt, endpegb, endpegmul; float endheight = 0.0f, endbheight = 0.0f; - fixed_t v1x = FLOAT_TO_FIXED(wallVerts[0].x); - fixed_t v1y = FLOAT_TO_FIXED(wallVerts[0].z); // not a typo - fixed_t v2x = FLOAT_TO_FIXED(wallVerts[1].x); - fixed_t v2y = FLOAT_TO_FIXED(wallVerts[1].z); // not a typo - // compiler complains when P_GetZAt is used in FLOAT_TO_FIXED directly - // use this as a temp var to store P_GetZAt's return value each time - fixed_t temp; + fixed_t v1x = FloatToFixed(wallVerts[0].x); + fixed_t v1y = FloatToFixed(wallVerts[0].z); + fixed_t v2x = FloatToFixed(wallVerts[1].x); + fixed_t v2y = FloatToFixed(wallVerts[1].z); + float diff; #endif - INT32 solid, i; - lightlist_t * list = sector->lightlist; const UINT8 alpha = Surf->PolyColor.s.alpha; FUINT lightnum = HWR_CalcWallLight(sector->lightlevel, v1x, v1y, v2x, v2y); extracolormap_t *colormap = NULL; realtop = top = wallVerts[3].y; realbot = bot = wallVerts[0].y; + diff = top - bot; pegt = wallVerts[3].t; pegb = wallVerts[0].t; - pegmul = (pegb - pegt) / (top - bot); - - if (fpclassify(pegmul) == FP_NAN) + + // Lactozilla: If both heights of a side lay on the same position, then this wall is a triangle. + // To avoid division by zero, which would result in a NaN, we check if the vertical difference + // between the two vertices is not zero. + if (fpclassify(diff) == FP_ZERO) pegmul = 0.0; + else + pegmul = (pegb - pegt) / diff; #ifdef ESLOPE endrealtop = endtop = wallVerts[2].y; endrealbot = endbot = wallVerts[1].y; + diff = endtop - endbot; + endpegt = wallVerts[2].t; endpegb = wallVerts[1].t; - endpegmul = (endpegb - endpegt) / (endtop - endbot); + + if (fpclassify(diff) == FP_ZERO) + endpegmul = 0.0; + else + endpegmul = (endpegb - endpegt) / diff; #endif - if (fpclassify(endpegmul) == FP_NAN) - endpegmul = 0.0; - for (i = 0; i < sector->numlights; i++) + for (INT32 i = 0; i < sector->numlights; i++) { #ifdef ESLOPE if (endtop < endrealbot) #endif if (top < realbot) return; + + lightlist_t *list = sector->lightlist; if (!(list[i].flags & FF_NOSHADE)) { @@ -987,7 +993,7 @@ void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfa } } - solid = false; + boolean solid = false; if ((sector->lightlist[i].flags & FF_CUTSOLIDS) && !(cutflag & FF_EXTRA)) solid = true; @@ -1007,10 +1013,8 @@ void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfa #ifdef ESLOPE if (list[i].slope) { - temp = P_GetZAt(list[i].slope, v1x, v1y); - height = FIXED_TO_FLOAT(temp); - temp = P_GetZAt(list[i].slope, v2x, v2y); - endheight = FIXED_TO_FLOAT(temp); + height = FixedToFloat(P_GetZAt(&list[i], v1x, v1y)); + endheight = FixedToFloat(P_GetZAt(&list[i], v2x, v2y)); } else height = endheight = FIXED_TO_FLOAT(list[i].height); @@ -1018,10 +1022,8 @@ void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfa { if (*list[i].caster->b_slope) { - temp = P_GetZAt(*list[i].caster->b_slope, v1x, v1y); - bheight = FIXED_TO_FLOAT(temp); - temp = P_GetZAt(*list[i].caster->b_slope, v2x, v2y); - endbheight = FIXED_TO_FLOAT(temp); + bheight = FixedToFloat(P_GetZAt(list[i].caster, v1x, v1y)); + endbheight = FixedToFloat(P_GetZAt(list[i].caster, v2x, v2y)); } else bheight = endbheight = FIXED_TO_FLOAT(*list[i].caster->bottomheight); @@ -1050,10 +1052,8 @@ void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfa { if (list[i+1].slope) { - temp = P_GetZAt(list[i+1].slope, v1x, v1y); - bheight = FIXED_TO_FLOAT(temp); - temp = P_GetZAt(list[i+1].slope, v2x, v2y); - endbheight = FIXED_TO_FLOAT(temp); + bheight = FixedToFloat(P_GetZAt(&list[i+1], v1x, v1y)); + endbheight = FixedToFloat(P_GetZAt(&list[i+1], v2x, v2y)); } else bheight = endbheight = FIXED_TO_FLOAT(list[i+1].height); @@ -1074,10 +1074,11 @@ void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfa } #endif +#ifdef ESLOPE // Found a break bot = min(max(bheight, realbot), top); endbot = min(max(endbheight, endrealbot), endtop); - +#endif Surf->PolyColor.s.alpha = alpha; #ifdef ESLOPE @@ -1706,7 +1707,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom } else repeats = 1; - + fixed_t midtexheight = textureheight[gr_midtexture] * repeats; fixed_t popentop, popenbottom, polytop, polybottom, lowcut, highcut; fixed_t popentopslope, popenbottomslope, polytopslope, polybottomslope, lowcutslope, highcutslope; @@ -1733,9 +1734,12 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom #ifdef ESLOPE popentop = min(worldtop, worldhigh); popenbottom = max(worldbottom, worldlow); - popentopslope = min(worldtopslope, worldhighslope); popenbottomslope = max(worldbottomslope, worldlowslope); +#else + popentop = min(front->ceilingheight, back->ceilingheight); + popenbottom = max(front->floorheight, back->floorheight); +#endif } #ifdef ESLOPE @@ -1769,7 +1773,6 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom else { polytop = popentop + gr_sidedef->rowoffset; - polybottom = polytop - textureheight[gr_midtexture]*repeats; polybottom = polytop - midtexheight; polytopslope = popentopslope + gr_sidedef->rowoffset; polybottomslope = polytopslope - midtexheight; @@ -1800,11 +1803,14 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom l = max(polybottom, lowcut); hS = min(highcutslope, polytopslope); lS = max(polybottomslope, lowcutslope); - + // PEGGING fixed_t texturevpeg, texturevpegslope; - +#ifdef ESLOPE if (!!(gr_linedef->flags & ML_DONTPEGBOTTOM) ^ !!(gr_linedef->flags & ML_EFFECT3)) +#else + if (gr_linedef->flags & ML_DONTPEGBOTTOM) +#endif { texturevpeg = midtexheight - h + polybottom; texturevpegslope = midtexheight - hS + polybottomslope; @@ -1831,7 +1837,6 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom wallVerts[0].y = FIXED_TO_FLOAT(l); wallVerts[2].y = FIXED_TO_FLOAT(hS); wallVerts[1].y = FIXED_TO_FLOAT(lS); -#endif // set alpha for transparent walls (new boom and legacy linedef types) FBITFIELD blendmode; From a929636a289f10b8fafdc2c53a5da47e3f04acdc Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Wed, 13 Sep 2023 01:52:25 +0200 Subject: [PATCH 4/6] Revert "cleanup HWR_SplitWall" This reverts commit 06a2508a9cbb2ccc1dd018d06507b1b710d346d9. --- src/hardware/hw_main.c | 83 ++++++++++++++++++++---------------------- 1 file changed, 39 insertions(+), 44 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 7fe8f9be8..07f74f6a5 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -915,10 +915,11 @@ void HWR_ProjectWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, FBITFIELD blend // // HWR_SplitWall // -// SoM: split up and light walls according to the lightlist. -// This may also include leaving out parts of the wall that can't be seen void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfaceInfo* Surf, INT32 cutflag, ffloor_t *pfloor, FBITFIELD polyflags) { + /* SoM: split up and light walls according to the + lightlist. This may also include leaving out parts + of the wall that can't be seen */ float realtop, realbot, top, bot; float pegt, pegb, pegmul; @@ -929,55 +930,48 @@ void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfa float endpegt, endpegb, endpegmul; float endheight = 0.0f, endbheight = 0.0f; - fixed_t v1x = FloatToFixed(wallVerts[0].x); - fixed_t v1y = FloatToFixed(wallVerts[0].z); - fixed_t v2x = FloatToFixed(wallVerts[1].x); - fixed_t v2y = FloatToFixed(wallVerts[1].z); - float diff; + fixed_t v1x = FLOAT_TO_FIXED(wallVerts[0].x); + fixed_t v1y = FLOAT_TO_FIXED(wallVerts[0].z); // not a typo + fixed_t v2x = FLOAT_TO_FIXED(wallVerts[1].x); + fixed_t v2y = FLOAT_TO_FIXED(wallVerts[1].z); // not a typo + // compiler complains when P_GetZAt is used in FLOAT_TO_FIXED directly + // use this as a temp var to store P_GetZAt's return value each time + fixed_t temp; #endif + INT32 solid, i; + lightlist_t * list = sector->lightlist; const UINT8 alpha = Surf->PolyColor.s.alpha; FUINT lightnum = HWR_CalcWallLight(sector->lightlevel, v1x, v1y, v2x, v2y); extracolormap_t *colormap = NULL; realtop = top = wallVerts[3].y; realbot = bot = wallVerts[0].y; - diff = top - bot; pegt = wallVerts[3].t; pegb = wallVerts[0].t; - - // Lactozilla: If both heights of a side lay on the same position, then this wall is a triangle. - // To avoid division by zero, which would result in a NaN, we check if the vertical difference - // between the two vertices is not zero. - if (fpclassify(diff) == FP_ZERO) + pegmul = (pegb - pegt) / (top - bot); + + if (fpclassify(pegmul) == FP_NAN) pegmul = 0.0; - else - pegmul = (pegb - pegt) / diff; #ifdef ESLOPE endrealtop = endtop = wallVerts[2].y; endrealbot = endbot = wallVerts[1].y; - diff = endtop - endbot; - endpegt = wallVerts[2].t; endpegb = wallVerts[1].t; - - if (fpclassify(diff) == FP_ZERO) - endpegmul = 0.0; - else - endpegmul = (endpegb - endpegt) / diff; + endpegmul = (endpegb - endpegt) / (endtop - endbot); #endif + if (fpclassify(endpegmul) == FP_NAN) + endpegmul = 0.0; - for (INT32 i = 0; i < sector->numlights; i++) + for (i = 0; i < sector->numlights; i++) { #ifdef ESLOPE if (endtop < endrealbot) #endif if (top < realbot) return; - - lightlist_t *list = sector->lightlist; if (!(list[i].flags & FF_NOSHADE)) { @@ -993,7 +987,7 @@ void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfa } } - boolean solid = false; + solid = false; if ((sector->lightlist[i].flags & FF_CUTSOLIDS) && !(cutflag & FF_EXTRA)) solid = true; @@ -1013,8 +1007,10 @@ void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfa #ifdef ESLOPE if (list[i].slope) { - height = FixedToFloat(P_GetZAt(&list[i], v1x, v1y)); - endheight = FixedToFloat(P_GetZAt(&list[i], v2x, v2y)); + temp = P_GetZAt(list[i].slope, v1x, v1y); + height = FIXED_TO_FLOAT(temp); + temp = P_GetZAt(list[i].slope, v2x, v2y); + endheight = FIXED_TO_FLOAT(temp); } else height = endheight = FIXED_TO_FLOAT(list[i].height); @@ -1022,8 +1018,10 @@ void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfa { if (*list[i].caster->b_slope) { - bheight = FixedToFloat(P_GetZAt(list[i].caster, v1x, v1y)); - endbheight = FixedToFloat(P_GetZAt(list[i].caster, v2x, v2y)); + temp = P_GetZAt(*list[i].caster->b_slope, v1x, v1y); + bheight = FIXED_TO_FLOAT(temp); + temp = P_GetZAt(*list[i].caster->b_slope, v2x, v2y); + endbheight = FIXED_TO_FLOAT(temp); } else bheight = endbheight = FIXED_TO_FLOAT(*list[i].caster->bottomheight); @@ -1052,8 +1050,10 @@ void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfa { if (list[i+1].slope) { - bheight = FixedToFloat(P_GetZAt(&list[i+1], v1x, v1y)); - endbheight = FixedToFloat(P_GetZAt(&list[i+1], v2x, v2y)); + temp = P_GetZAt(list[i+1].slope, v1x, v1y); + bheight = FIXED_TO_FLOAT(temp); + temp = P_GetZAt(list[i+1].slope, v2x, v2y); + endbheight = FIXED_TO_FLOAT(temp); } else bheight = endbheight = FIXED_TO_FLOAT(list[i+1].height); @@ -1074,11 +1074,10 @@ void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfa } #endif -#ifdef ESLOPE // Found a break bot = min(max(bheight, realbot), top); endbot = min(max(endbheight, endrealbot), endtop); -#endif + Surf->PolyColor.s.alpha = alpha; #ifdef ESLOPE @@ -1707,7 +1706,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom } else repeats = 1; - + fixed_t midtexheight = textureheight[gr_midtexture] * repeats; fixed_t popentop, popenbottom, polytop, polybottom, lowcut, highcut; fixed_t popentopslope, popenbottomslope, polytopslope, polybottomslope, lowcutslope, highcutslope; @@ -1734,12 +1733,9 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom #ifdef ESLOPE popentop = min(worldtop, worldhigh); popenbottom = max(worldbottom, worldlow); + popentopslope = min(worldtopslope, worldhighslope); popenbottomslope = max(worldbottomslope, worldlowslope); -#else - popentop = min(front->ceilingheight, back->ceilingheight); - popenbottom = max(front->floorheight, back->floorheight); -#endif } #ifdef ESLOPE @@ -1773,6 +1769,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom else { polytop = popentop + gr_sidedef->rowoffset; + polybottom = polytop - textureheight[gr_midtexture]*repeats; polybottom = polytop - midtexheight; polytopslope = popentopslope + gr_sidedef->rowoffset; polybottomslope = polytopslope - midtexheight; @@ -1803,14 +1800,11 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom l = max(polybottom, lowcut); hS = min(highcutslope, polytopslope); lS = max(polybottomslope, lowcutslope); - + // PEGGING fixed_t texturevpeg, texturevpegslope; -#ifdef ESLOPE + if (!!(gr_linedef->flags & ML_DONTPEGBOTTOM) ^ !!(gr_linedef->flags & ML_EFFECT3)) -#else - if (gr_linedef->flags & ML_DONTPEGBOTTOM) -#endif { texturevpeg = midtexheight - h + polybottom; texturevpegslope = midtexheight - hS + polybottomslope; @@ -1837,6 +1831,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom wallVerts[0].y = FIXED_TO_FLOAT(l); wallVerts[2].y = FIXED_TO_FLOAT(hS); wallVerts[1].y = FIXED_TO_FLOAT(lS); +#endif // set alpha for transparent walls (new boom and legacy linedef types) FBITFIELD blendmode; From ad4d587a526eb62114931a3eca2b760148c4e456 Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Wed, 13 Sep 2023 02:58:20 +0200 Subject: [PATCH 5/6] screw you bleh, pegging midtextures to slopes now works correctly, but cutting them is broken again atleast this fixes the performance issues no idea tho why it screws up things so much --- src/hardware/hw_main.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 07f74f6a5..40ec21cbe 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -1074,9 +1074,24 @@ void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfa } #endif - // Found a break - bot = min(max(bheight, realbot), top); - endbot = min(max(endbheight, endrealbot), endtop); +#ifdef ESLOPE + if (endbheight >= endtop) +#endif + if (bheight >= top) + continue; + + //Found a break; + bot = bheight; + + if (bot < realbot) + bot = realbot; + +#ifdef ESLOPE + endbot = endbheight; + + if (endbot < endrealbot) + endbot = endrealbot; +#endif Surf->PolyColor.s.alpha = alpha; From 2cba586d9c3bd244e6aa52507895491eb32a3316 Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Wed, 13 Sep 2023 03:54:12 +0200 Subject: [PATCH 6/6] im good at coding absolute bruh thing, but it somehow works, fixes the midtextures, and doesent kill performance lmao --- src/hardware/hw_main.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 40ec21cbe..6a254a285 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -1075,7 +1075,8 @@ void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfa #endif #ifdef ESLOPE - if (endbheight >= endtop) + if (endbheight > endtop) + endbot = endtop; #endif if (bheight >= top) continue; @@ -1085,12 +1086,9 @@ void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfa if (bot < realbot) bot = realbot; - + #ifdef ESLOPE - endbot = endbheight; - - if (endbot < endrealbot) - endbot = endrealbot; + endbot = min(max(endbheight, endrealbot), endtop); #endif Surf->PolyColor.s.alpha = alpha;