From 83b6a63f13f46a344ad158578feb873f595f5a67 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 9 Dec 2024 22:36:30 +0100 Subject: [PATCH 1/7] dont pass fwrapv to compiler flags this technically changes behavior of some things, even if it MAY fix some undefined behaviour --- src/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Makefile b/src/Makefile index 4df4e1fe8..ccfe7603e 100644 --- a/src/Makefile +++ b/src/Makefile @@ -298,7 +298,7 @@ else $(OBJDIR)/hw_md2load.o $(OBJDIR)/hw_md3load.o $(OBJDIR)/hw_model.o $(OBJDIR)/u_list.o $(OBJDIR)/hw_batching.o $(OBJDIR)/hw_shaders.o endif -OPTS += -DCOMPVERSION -fwrapv +OPTS += -DCOMPVERSION ifndef NONX86 ifndef GCC29 From 3b64263dc649043a2ef0853d56fdd44468cd0b52 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 10 Dec 2024 21:16:06 +0100 Subject: [PATCH 2/7] Unconditionally interpolate view even if it may NOT change but i get the feeling it may cause some issues --- src/r_fps.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/r_fps.c b/src/r_fps.c index 4d74da5a2..3dab44398 100644 --- a/src/r_fps.c +++ b/src/r_fps.c @@ -91,6 +91,15 @@ static levelinterpolator_t **levelinterpolators; static size_t levelinterpolators_len; static size_t levelinterpolators_size; +static inline fixed_t R_LerpFixedView(fixed_t from, fixed_t to, fixed_t frac) +{ + return from + FixedMul(frac, to - from); +} + +static inline angle_t R_LerpAngleView(angle_t from, angle_t to, fixed_t frac) +{ + return from + FixedMul(frac, to - from); +} static inline fixed_t R_LerpFixed(fixed_t from, fixed_t to, fixed_t frac) { @@ -153,7 +162,7 @@ static void R_SetupFreelook(void) void R_InterpolateViewRollAngle(fixed_t frac) { - viewroll = R_LerpAngle(oldview->roll, newview->roll, frac); + viewroll = R_LerpAngleView(oldview->roll, newview->roll, frac); } void R_InterpolateView(fixed_t frac, boolean forceinvalid) @@ -181,13 +190,13 @@ void R_InterpolateView(fixed_t frac, boolean forceinvalid) prevview = newview; } - viewx = R_LerpFixed(prevview->x, newview->x, frac); - viewy = R_LerpFixed(prevview->y, newview->y, frac); - viewz = R_LerpFixed(prevview->z, newview->z, frac); + viewx = R_LerpFixedView(prevview->x, newview->x, frac); + viewy = R_LerpFixedView(prevview->y, newview->y, frac); + viewz = R_LerpFixedView(prevview->z, newview->z, frac); - viewangle = R_LerpAngle(prevview->angle, newview->angle, frac); - aimingangle = R_LerpAngle(prevview->aim, newview->aim, frac); - viewroll = R_LerpAngle(prevview->roll, newview->roll, frac); + viewangle = R_LerpAngleView(prevview->angle, newview->angle, frac); + aimingangle = R_LerpAngleView(prevview->aim, newview->aim, frac); + viewroll = R_LerpAngleView(prevview->roll, newview->roll, frac); viewsin = FINESINE(viewangle>>ANGLETOFINESHIFT); viewcos = FINECOSINE(viewangle>>ANGLETOFINESHIFT); From 727a31fdb5618abdf67ca26be176719ff6c057c5 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 10 Dec 2024 21:17:50 +0100 Subject: [PATCH 3/7] one line those --- src/r_fps.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/r_fps.c b/src/r_fps.c index 3dab44398..637ce1cf4 100644 --- a/src/r_fps.c +++ b/src/r_fps.c @@ -103,16 +103,12 @@ static inline angle_t R_LerpAngleView(angle_t from, angle_t to, fixed_t frac) static inline fixed_t R_LerpFixed(fixed_t from, fixed_t to, fixed_t frac) { - if (from == to) - return to; - return from + FixedMul(frac, to - from); + return ((from == to) ? to : from + FixedMul(frac, to - from)); } static inline angle_t R_LerpAngle(angle_t from, angle_t to, fixed_t frac) { - if (from == to) - return to; - return from + FixedMul(frac, to - from); + return ((from == to) ? to : from + FixedMul(frac, to - from)); } /*static vector2_t *R_LerpVector2(const vector2_t *from, const vector2_t *to, fixed_t frac, vector2_t *out) From 0eaedd4b5efaf5a8a0ee565acbd703750447da17 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 11 Dec 2024 01:25:29 +0100 Subject: [PATCH 4/7] "extra safety" --- src/r_fps.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/r_fps.c b/src/r_fps.c index 637ce1cf4..b861dea56 100644 --- a/src/r_fps.c +++ b/src/r_fps.c @@ -103,12 +103,12 @@ static inline angle_t R_LerpAngleView(angle_t from, angle_t to, fixed_t frac) static inline fixed_t R_LerpFixed(fixed_t from, fixed_t to, fixed_t frac) { - return ((from == to) ? to : from + FixedMul(frac, to - from)); + return ((from == to) ? to : (from + FixedMul(frac, to - from))); } static inline angle_t R_LerpAngle(angle_t from, angle_t to, fixed_t frac) { - return ((from == to) ? to : from + FixedMul(frac, to - from)); + return ((from == to) ? to : (from + FixedMul(frac, to - from))); } /*static vector2_t *R_LerpVector2(const vector2_t *from, const vector2_t *to, fixed_t frac, vector2_t *out) From 91b6143f15b6efa8be44c6e9af6a3d1d79b29a9c Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 10 Dec 2024 22:15:53 +0100 Subject: [PATCH 5/7] clean up this stuff; make splitwall behave more like vanilla changes some splitwall issues slightly but gives bit better performance in some cases --- src/hardware/hw_main.c | 47 ++++++++++++++++-------------------------- 1 file changed, 18 insertions(+), 29 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 5e24e6eae..0ab84f345 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -505,7 +505,6 @@ static void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, bool if (!xsub->planepoly) return; - pv = xsub->planepoly->pts; nrPlaneVerts = xsub->planepoly->numpts; if (nrPlaneVerts < 3) //not even a triangle ? @@ -575,6 +574,8 @@ static void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, bool break; } + pv = xsub->planepoly->pts; + // reference point for flat texture coord for each vertex around the polygon flatxref = (float)(((fixed_t)pv->x & (~flatflag)) / fflatsize); flatyref = (float)(((fixed_t)pv->y & (~flatflag)) / fflatsize); @@ -1008,20 +1009,12 @@ static void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, endbheight = endrealbot; } - if (endbheight > endtop) - endbot = endtop; - - if (bheight >= top) + if (endbheight >= endtop && bheight >= top) continue; // Found a break - // The heights are clamped to ensure the polygon doesn't cross itself. - bot = bheight; - - if (bot < realbot) - bot = realbot; - - endbot = min(max(endbheight, endrealbot), endtop); + bot = max(bheight, realbot); + endbot = max(endbheight, endrealbot); Surf->PolyColor.s.alpha = alpha; @@ -1150,7 +1143,7 @@ static void HWR_DrawSkyWall(FOutVector *wallVerts, FSurfaceInfo *Surf) } // Returns true if the midtexture is visible, and false if... it isn't... -static boolean HWR_BlendMidtextureSurface(FSurfaceInfo *pSurf) +static inline boolean HWR_BlendMidtextureSurface(FSurfaceInfo *pSurf) { FUINT blendmode = PF_Masked; @@ -1188,23 +1181,16 @@ static boolean HWR_BlendMidtextureSurface(FSurfaceInfo *pSurf) case 908: blendmode = HWR_TranstableToAlpha(tr_trans90, pSurf); break; - // Translucent + // Translucent linedef types case 102: - case 121: - case 123: - case 124: - case 125: - case 141: - case 142: - case 144: - case 145: + case 121 ... 125: + case 141 ... 145: case 174: case 175: case 192: case 195: case 221: - case 253: - case 256: + case 253 ... 256: blendmode = PF_Translucent; break; default: @@ -1216,9 +1202,10 @@ static boolean HWR_BlendMidtextureSurface(FSurfaceInfo *pSurf) { // Polyobject translucency is shared between all of its lines if (gl_curline->polyseg->translucency >= NUMTRANSMAPS) // wall not drawn + { + pSurf->PolyColor.s.alpha = 0x00; // This shouldn't draw anything regardless of blendmode return false; - //Surf.PolyColor.s.alpha = 0x00; // This shouldn't draw anything regardless of blendmode - //blendmode = PF_Masked; + } else blendmode = HWR_TranstableToAlpha(gl_curline->polyseg->translucency, pSurf); } @@ -1315,7 +1302,9 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom lightnum = (HWR_ShouldUsePaletteRendering() && colormap) ? lightnum : HWR_CalcWallLight(lightnum, gl_curline); FSurfaceInfo Surf; - Surf.PolyColor.s.alpha = 255; + + if (gl_frontsector) + Surf.PolyColor.s.alpha = 255; INT32 gl_midtexture = R_GetTextureNum(gl_sidedef->midtexture); GLMapTexture_t *glTex = NULL; @@ -1711,6 +1700,8 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom // Single sided line... Deal only with the middletexture (if one exists) if (gl_midtexture && gl_linedef->special != HORIZONSPECIAL) // Ignore horizon line for OGL { + glTex = HWR_GetTexture(gl_midtexture, noencore); + fixed_t texturevpeg; // PEGGING @@ -1721,8 +1712,6 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom else texturevpeg = gl_sidedef->rowoffset; // top of texture at top - glTex = HWR_GetTexture(gl_midtexture, noencore); - wallVerts[3].t = wallVerts[2].t = texturevpeg * glTex->scaleY; wallVerts[0].t = wallVerts[1].t = (texturevpeg + gl_frontsector->ceilingheight - gl_frontsector->floorheight) * glTex->scaleY; wallVerts[0].s = wallVerts[3].s = cliplow * glTex->scaleX; From a05c38b1fe85484797a4651402a94531cbdce2ee Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 10 Dec 2024 22:20:44 +0100 Subject: [PATCH 6/7] those should better be clamped oops --- src/hardware/hw_main.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 0ab84f345..4c10a2af4 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -1013,8 +1013,9 @@ static void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, continue; // Found a break - bot = max(bheight, realbot); - endbot = max(endbheight, endrealbot); + // The heights are clamped to ensure the polygon doesn't cross itself. + bot = CLAMP(bheight,realbot , top); + endbot = CLAMP(endbheight, endrealbot, endtop); Surf->PolyColor.s.alpha = alpha; From dbe5f8a4ba716a1e62a09e683d75072db4129d56 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 10 Dec 2024 23:06:08 +0100 Subject: [PATCH 7/7] clamp splitsprite heights aswell --- src/hardware/hw_main.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 4c10a2af4..fa2f9cfb7 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -943,7 +943,7 @@ static void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, for (INT32 i = 0; i < sector->numlights; i++) { - if (endtop < endrealbot && top < realbot) + if ((endtop < endrealbot) && (top < realbot)) return; lightlist_t *list = sector->lightlist; @@ -1009,12 +1009,12 @@ static void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, endbheight = endrealbot; } - if (endbheight >= endtop && bheight >= top) + if ((endbheight >= endtop) && (bheight >= top)) continue; // Found a break // The heights are clamped to ensure the polygon doesn't cross itself. - bot = CLAMP(bheight,realbot , top); + bot = CLAMP(bheight, realbot, top); endbot = CLAMP(endbheight, endrealbot, endtop); Surf->PolyColor.s.alpha = alpha; @@ -1043,7 +1043,7 @@ static void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, bot = realbot; endbot = endrealbot; - if (endtop <= endrealbot && top <= realbot) + if ((endtop <= endrealbot) && (top <= realbot)) return; Surf->PolyColor.s.alpha = alpha; @@ -3621,7 +3621,7 @@ static void HWR_SplitSprite(gl_vissprite_t *spr, const boolean papersprite) for (i = 0; i < sector->numlights; i++) { - if (endtop < endrealbot && top < realbot) + if ((endtop < endrealbot) && (top < realbot)) return; // even if we aren't changing colormap or lightlevel, we still need to continue drawing down the sprite @@ -3645,18 +3645,13 @@ static void HWR_SplitSprite(gl_vissprite_t *spr, const boolean papersprite) endbheight = endrealbot; } - if (endbheight >= endtop && bheight >= top) + if ((endbheight >= endtop) && (bheight >= top)) continue; - bot = bheight; - - if (bot < realbot) - bot = realbot; - - endbot = endbheight; - - if (endbot < endrealbot) - endbot = endrealbot; + // Found a break + // The heights are clamped to ensure the polygon doesn't cross itself. + bot = CLAMP(bheight, realbot, top); + endbot = CLAMP(endbheight, endrealbot, endtop); wallVerts[3].t = towtop + ((realtop - top) * towmult); wallVerts[2].t = towtop + ((endrealtop - endtop) * towmult); @@ -3704,7 +3699,7 @@ static void HWR_SplitSprite(gl_vissprite_t *spr, const boolean papersprite) bot = realbot; endbot = endrealbot; - if (endtop <= endrealbot && top <= realbot) + if ((endtop <= endrealbot) && (top <= realbot)) return; // If we're ever down here, somehow the above loop hasn't draw all the light levels of sprite