From 465fea8bb3415a9fb9265064dd81e565faef3a3c Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 30 Jun 2025 12:18:21 +0200 Subject: [PATCH 01/13] "restrict" macro for c++ since it does not have it, use __restrict instead --- src/doomdef.h | 8 ++++++++ src/r_draw_column.cpp | 16 ++++++++-------- src/r_draw_span.cpp | 20 ++++++++++---------- src/r_main.h | 2 +- src/r_plane.cpp | 10 +++++----- 5 files changed, 32 insertions(+), 24 deletions(-) diff --git a/src/doomdef.h b/src/doomdef.h index dbeabce63..ce846ee27 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -566,6 +566,14 @@ UINT32 quickncasehash (const char *p, size_t n) #define UNLIKELY(x) (x) #endif +#ifdef __cplusplus +#if defined(__GNUC__) || defined(__clang__) || defined(_MSC_VER) + #define restrict __restrict +#else + #define restrict +#endif +#endif + // An assert-type mechanism. #ifdef PARANOIA #define I_Assert(e) ((e) ? (void)0 : I_Error("assert failed: %s, file %s, line %d", #e, __FILE__, __LINE__)) diff --git a/src/r_draw_column.cpp b/src/r_draw_column.cpp index bc91ef0d3..dcc1a5b90 100644 --- a/src/r_draw_column.cpp +++ b/src/r_draw_column.cpp @@ -31,7 +31,7 @@ enum DrawColumnType }; template -static constexpr UINT8 R_GetColumnTranslated(drawcolumndata_t* dc, UINT8 col, const UINT8 * __restrict colormap) +static constexpr UINT8 R_GetColumnTranslated(drawcolumndata_t* dc, UINT8 col, const UINT8 * restrict colormap) { if constexpr (Type & DrawColumnType::DC_COLORMAP) { @@ -42,7 +42,7 @@ static constexpr UINT8 R_GetColumnTranslated(drawcolumndata_t* dc, UINT8 col, co } template -static constexpr UINT8 R_GetColumnTranslucent(drawcolumndata_t* dc, UINT8 * __restrict dest, UINT8 col, const UINT8 * __restrict colormap) +static constexpr UINT8 R_GetColumnTranslucent(drawcolumndata_t* dc, UINT8 * restrict dest, UINT8 col, const UINT8 * restrict colormap) { col = R_GetColumnTranslated(dc, col, colormap); @@ -57,7 +57,7 @@ static constexpr UINT8 R_GetColumnTranslucent(drawcolumndata_t* dc, UINT8 * __re } template -static constexpr UINT8 R_DrawColumnPixel(drawcolumndata_t* dc, UINT8 * __restrict dest, UINT32 bit, const __restrict UINT8 *source, const __restrict UINT8 *colormap) +static constexpr UINT8 R_DrawColumnPixel(drawcolumndata_t* dc, UINT8 * restrict dest, UINT32 bit, const restrict UINT8 *source, const restrict UINT8 *colormap) { UINT8 col = source[bit]; @@ -189,11 +189,11 @@ static void R_DrawColumnTemplate(drawcolumndata_t *dc) const INT32 npow2max = dc->sourcelength; const INT32 stride = vid.width; - const UINT8 * __restrict source = dc->source; - const lighttable_t * __restrict colormap = dc->colormap; + const UINT8 * restrict source = dc->source; + const lighttable_t * restrict colormap = dc->colormap; // Framebuffer destination address. - UINT8 * __restrict dest = R_Address(dc->x, dc->yl); + UINT8 * restrict dest = R_Address(dc->x, dc->yl); count++; @@ -325,7 +325,7 @@ DEFINE_COLUMN_FUNC(R_Draw2sMultiPatchTranslucentColumn, DC_HOLES|DC_TRANSMAP) void R_DrawFogColumn(drawcolumndata_t* dc) { INT32 count; - UINT8 * __restrict dest; + UINT8 * restrict dest; count = dc->yh - dc->yl; @@ -344,7 +344,7 @@ void R_DrawFogColumn(drawcolumndata_t* dc) dest = R_Address(dc->x, dc->yl); const INT32 stride = vid.width; - const lighttable_t * __restrict colormap = dc->colormap; + const lighttable_t * restrict colormap = dc->colormap; // Determine scaling, which is the only mapping to be done. do diff --git a/src/r_draw_span.cpp b/src/r_draw_span.cpp index 7ead430c4..cf7878184 100644 --- a/src/r_draw_span.cpp +++ b/src/r_draw_span.cpp @@ -88,10 +88,10 @@ static void R_DrawSpanTemplate(drawspandata_t* ds) UINT32 xstep, ystep; UINT32 bit; - UINT8 * __restrict dest = R_Address(ds->x1, ds->y); - UINT8 * __restrict dsrc; + UINT8 * restrict dest = R_Address(ds->x1, ds->y); + UINT8 * restrict dsrc; - const UINT8 * __restrict deststop = vid.screens[0] + vid.rowbytes * vid.height; + const UINT8 * restrict deststop = vid.screens[0] + vid.rowbytes * vid.height; if (dest+8 > deststop) { @@ -104,8 +104,8 @@ static void R_DrawSpanTemplate(drawspandata_t* ds) xposition = ds->xfrac; yposition = ds->yfrac; xstep = ds->xstep; ystep = ds->ystep; - const UINT8 * __restrict source = ds->source; - const UINT8 * __restrict colormap = ds->colormap; + const UINT8 * restrict source = ds->source; + const UINT8 * restrict colormap = ds->colormap; if constexpr (Type & DS_RIPPLE) { @@ -202,8 +202,8 @@ static void R_DrawTiltedSpanTemplate(drawspandata_t* ds) UINT32 u, v; int i; - UINT8 * __restrict dest = R_Address(ds->x1, ds->y); - UINT8 * __restrict dsrc; + UINT8 * restrict dest = R_Address(ds->x1, ds->y); + UINT8 * restrict dsrc; float startz, startu, startv; float izstep, uzstep, vzstep; @@ -382,8 +382,8 @@ DEFINE_SPAN_COMBO(R_DrawTranslucentWaterSpan, DS_TRANSMAP|DS_RIPPLE) */ void R_DrawFogSpan(drawspandata_t* ds) { - const UINT8 * __restrict colormap = ds->colormap; - UINT8 * __restrict dest = R_Address(ds->x1, ds->y); + const UINT8 * restrict colormap = ds->colormap; + UINT8 * restrict dest = R_Address(ds->x1, ds->y); intptr_t count = ds->x2 - ds->x1 + 1; @@ -409,7 +409,7 @@ void R_DrawFogSpan_Tilted(drawspandata_t* ds) { int width = ds->x2 - ds->x1; float iz = ds->szp.z + ds->szp.y*(centery-ds->y) + ds->szp.x*(ds->x1-centerx); - UINT8 * __restrict dest; + UINT8 * restrict dest; local_for_thread INT32 *tiltlighting = NULL; local_for_thread INT32 oldviewwidth = 0; diff --git a/src/r_main.h b/src/r_main.h index e95862c57..29a6b308e 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -88,7 +88,7 @@ extern lighttable_t *zlight[LIGHTLEVELS][MAXLIGHTZ]; // // killough 5/2/98: reformatted // -FUNCINLINE static ATTRINLINE PUREFUNC INT32 R_PointOnSide(fixed_t x, fixed_t y, const node_t * __restrict node) +FUNCINLINE static ATTRINLINE PUREFUNC INT32 R_PointOnSide(fixed_t x, fixed_t y, const node_t * restrict node) { if (!node->dx) return x <= node->x ? node->dy > 0 : node->dy < 0; diff --git a/src/r_plane.cpp b/src/r_plane.cpp index 54a0f04da..c52771bc4 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -100,7 +100,7 @@ static void R_ReallocPlaneBounds(visplane_t *pl) { pl->top_memory = static_cast(Z_Realloc(pl->top_memory, sizeof(UINT16) * (viewwidth + 2), PU_STATIC, NULL)); pl->bottom_memory = static_cast(Z_Realloc(pl->bottom_memory, sizeof(UINT16) * (viewwidth + 2), PU_STATIC, NULL)); - pl->top = pl->top_memory + 1; + pl->top = pl->top_memory + 1; pl->bottom = pl->bottom_memory + 1; } @@ -203,14 +203,14 @@ static void R_MapPlane(drawspandata_t *ds, spandrawfunc_t *localspanfunc, INT32 if (!R_CheckMapPlane(__func__, y, x1, x2)) return; - angle = (ds->currentplane->viewangle + ds->currentplane->plangle)>>ANGLETOFINESHIFT; + angle = (ds->currentplane->viewangle + ds->currentplane->plangle)>>ANGLETOFINESHIFT; planecos = FINECOSINE(angle); planesin = FINESINE(angle); // [RH] Notice that I dumped the caching scheme used by Doom. // It did not offer any appreciable speedup. distance = FixedMul(ds->planeheight, yslope[y]); - span = abs(centery - y); + span = abs(centery - y); if (span) // don't divide by zero { @@ -259,7 +259,7 @@ static void R_MapPlane(drawspandata_t *ds, spandrawfunc_t *localspanfunc, INT32 if (ds->currentplane->extra_colormap) ds->colormap = ds->currentplane->extra_colormap->colormap + (ds->colormap - colormaps); - ds->y = y; + ds->y = y; ds->x1 = x1; ds->x2 = x2; @@ -301,7 +301,7 @@ static void R_MapTiltedPlane(drawspandata_t *ds, spandrawfunc_t *localspanfunc, ds->colormap += COLORMAP_REMAPOFFSET; } - ds->y = y; + ds->y = y; ds->x1 = x1; ds->x2 = x2; From 612431c1f13e3baa2ffcf6261d40f28a039d1f19 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 1 Jul 2025 14:22:49 +0200 Subject: [PATCH 02/13] dont define min and max with c++ --- src/doomdef.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/doomdef.h b/src/doomdef.h index f9467199b..ba606cac0 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -524,12 +524,15 @@ UINT32 quickncasehash (const char *p, size_t n) return x; } +#ifndef __cplusplus #ifndef min // Double-Check with WATTCP-32's cdefs.h #define min(x, y) (((x) < (y)) ? (x) : (y)) #endif #ifndef max // Double-Check with WATTCP-32's cdefs.h #define max(x, y) (((x) > (y)) ? (x) : (y)) #endif +#endif + #ifndef CLAMP #define CLAMP(x, y, z) ((x) < (y) ? (y) : ((x) > (z) ? (z) : (x))) #endif From f4d40bd55f790175b78e04b4385c0c515a5c129a Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 1 Jul 2025 14:38:32 +0200 Subject: [PATCH 03/13] "-Wno-aggregate-return" for c++ --- src/Makefile.d/versions.mk | 3 +++ src/r_plane.cpp | 6 ------ src/r_things.cpp | 3 --- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/Makefile.d/versions.mk b/src/Makefile.d/versions.mk index a3cdbbd4b..ce23c3e4e 100644 --- a/src/Makefile.d/versions.mk +++ b/src/Makefile.d/versions.mk @@ -16,6 +16,9 @@ $(foreach v,$(join $(wordlist 2,$(_n),- $(gcc_versions)),\ $(and $(findstring =,$(v)),\ $(eval $(call _predecessor,$(subst =, ,$(v)))))) +# aggregate returns seem to happen alot in c++ so just supress em lel +CXXFLAGS+= -Wno-aggregate-return + # -W -Wno-unused ifdef GCC150 diff --git a/src/r_plane.cpp b/src/r_plane.cpp index c52771bc4..4d6244468 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -740,12 +740,9 @@ void R_DrawPlanes(void) } } #ifdef HAVE_THREADS -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Waggregate-return" tp_sema = srb2::g_main_threadpool->end_sema(); srb2::g_main_threadpool->notify_sema(tp_sema); srb2::g_main_threadpool->wait_sema(tp_sema); -#pragma GCC diagnostic pop #endif } @@ -771,12 +768,9 @@ void R_DrawSkyPlanes(void) } } #ifdef HAVE_THREADS -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Waggregate-return" tp_sema = srb2::g_main_threadpool->end_sema(); srb2::g_main_threadpool->notify_sema(tp_sema); srb2::g_main_threadpool->wait_sema(tp_sema); -#pragma GCC diagnostic pop #endif } diff --git a/src/r_things.cpp b/src/r_things.cpp index bf33fb97c..06c346645 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -2977,12 +2977,9 @@ static void R_DrawMaskedList(drawnode_t* head) #endif R_DrawSinglePlane(&ds, r2->plane, cv_parallelsoftware.value); #ifdef HAVE_THREADS -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Waggregate-return" tp_sema = srb2::g_main_threadpool->end_sema(); srb2::g_main_threadpool->notify_sema(tp_sema); srb2::g_main_threadpool->wait_sema(tp_sema); -#pragma GCC diagnostic pop #endif R_DoneWithNode(r2); r2 = next; From 3c282b5022d85e0667ea4a92f4568fd832ff69af Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 1 Jul 2025 14:42:17 +0200 Subject: [PATCH 04/13] this can use min/max --- src/r_plane.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/r_plane.cpp b/src/r_plane.cpp index 4d6244468..653353a2b 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -1096,6 +1096,7 @@ void R_DrawSinglePlane(drawspandata_t* ds, visplane_t *pl, boolean allow_paralle // and mercilessly shoved into saturn by chearii 02-02-2025 { INT32 trans = (10*((256+12) - pl->ffloor->alpha))/255; + if (trans >= 10) return; // Don't even draw it @@ -1132,13 +1133,8 @@ void R_DrawSinglePlane(drawspandata_t* ds, visplane_t *pl, boolean allow_paralle 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; + top = std::max(0, pl->high - 8); + bottom = std::min(viewheight, pl->low + 8); // Only copy the part of the screen we need UINT8 i = R_GetViewNumber(); From 5a44afcd9fdee9be513bfca839a2483941331391 Mon Sep 17 00:00:00 2001 From: Indev Date: Tue, 1 Jul 2025 16:07:51 +0300 Subject: [PATCH 05/13] Disable multithreading in R_DrawMaskedList --- src/r_things.cpp | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/r_things.cpp b/src/r_things.cpp index 06c346645..683904ccb 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -2971,16 +2971,8 @@ static void R_DrawMaskedList(drawnode_t* head) { drawspandata_t ds = {}; next = r2->prev; -#ifdef HAVE_THREADS - srb2::ThreadPool::Sema tp_sema; - srb2::g_main_threadpool->begin_sema(); -#endif - R_DrawSinglePlane(&ds, r2->plane, cv_parallelsoftware.value); -#ifdef HAVE_THREADS - tp_sema = srb2::g_main_threadpool->end_sema(); - srb2::g_main_threadpool->notify_sema(tp_sema); - srb2::g_main_threadpool->wait_sema(tp_sema); -#endif + // Force disable multithreading since it is usually slower because of waiting for each plane to render + R_DrawSinglePlane(&ds, r2->plane, false); R_DoneWithNode(r2); r2 = next; } From d275db9bb41a9f9963b8eea97c063a6dbab9076b Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 1 Jul 2025 15:25:14 +0200 Subject: [PATCH 06/13] turn TC_ stuff into enum --- src/r_draw.h | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/r_draw.h b/src/r_draw.h index a28a09e79..763375709 100644 --- a/src/r_draw.h +++ b/src/r_draw.h @@ -179,12 +179,15 @@ extern lumpnum_t viewborderlump[8]; #define GTC_MENUCACHE GTC_CACHE //@TODO Add a separate caching mechanism for menu colormaps distinct from in-level GTC_CACHE. For now this is still preferable to memory leaks... -#define TC_DEFAULT -1 -#define TC_BOSS -2 -#define TC_METALSONIC -3 // For Metal Sonic battle -#define TC_ALLWHITE -4 // For Cy-Brak-demon -#define TC_RAINBOW -5 // For invincibility power -#define TC_BLINK -6 // For item blinking +enum +{ + TC_BLINK = -6, // For item blinking, according to kart + TC_RAINBOW, // For single colour + TC_ALLWHITE, // For Cy-Brak-demon + TC_METALSONIC, // For Metal Sonic battle + TC_BOSS, + TC_DEFAULT +}; // Initialize color translation tables, for player rendering etc. UINT8* R_GetTranslationColormap(INT32 skinnum, skincolors_t color, UINT8 flags); From 1b418caf6b7f33a2b52d58bacb4e00ed8f8fa109 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 29 Jun 2025 11:49:36 +0200 Subject: [PATCH 07/13] ceepeepeefy hw_main, abuse templates for portal stuff no idea if this is faster at all lmao --- src/hardware/Sourcefile | 2 +- src/hardware/hw_batching.h | 8 + src/hardware/hw_clip.h | 8 + src/hardware/hw_gl.h | 8 + src/hardware/hw_glob.h | 8 + src/hardware/{hw_main.c => hw_main.cpp} | 633 +++++++++++++----------- src/hardware/hw_main.h | 9 +- src/hardware/hw_portal.c | 2 +- src/hardware/hw_portal.h | 8 + src/hardware/r_opengl/r_opengl.h | 8 + src/m_fixed.h | 8 + src/st_stuff.h | 8 + 12 files changed, 426 insertions(+), 284 deletions(-) rename src/hardware/{hw_main.c => hw_main.cpp} (93%) diff --git a/src/hardware/Sourcefile b/src/hardware/Sourcefile index 3114c975c..e66482c3d 100644 --- a/src/hardware/Sourcefile +++ b/src/hardware/Sourcefile @@ -1,6 +1,6 @@ hw_bsp.c hw_draw.c -hw_main.c +hw_main.cpp hw_clip.c hw_md2.c hw_cache.c diff --git a/src/hardware/hw_batching.h b/src/hardware/hw_batching.h index 7f418fc77..d1808ce43 100644 --- a/src/hardware/hw_batching.h +++ b/src/hardware/hw_batching.h @@ -13,6 +13,10 @@ #ifndef __HWR_BATCHING_H__ #define __HWR_BATCHING_H__ +#ifdef __cplusplus +extern "C" { +#endif + #include "hw_defs.h" #include "hw_data.h" #include "hw_gl.h" @@ -36,4 +40,8 @@ void HWR_SetCurrentTexture(GLMipmap_t *texture); void HWR_ProcessPolygon(FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags, int shader, boolean horizonSpecial); void HWR_RenderBatches(void); +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/hardware/hw_clip.h b/src/hardware/hw_clip.h index dfaa87f81..4299fbaea 100644 --- a/src/hardware/hw_clip.h +++ b/src/hardware/hw_clip.h @@ -7,6 +7,10 @@ * */ +#ifdef __cplusplus +extern "C" { +#endif + // OpenGL BSP clipping #include "../doomdef.h" #include "../tables.h" @@ -22,3 +26,7 @@ angle_t gld_FrustumAngle(angle_t tiltangle); void gld_FrustumSetup(void); boolean gld_SphereInFrustum(float x, float y, float z, float radius); #endif + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/src/hardware/hw_gl.h b/src/hardware/hw_gl.h index a21fd0a3a..8780fc57b 100644 --- a/src/hardware/hw_gl.h +++ b/src/hardware/hw_gl.h @@ -13,6 +13,10 @@ #ifndef __HWR_GL_H__ #define __HWR_GL_H__ +#ifdef __cplusplus +extern "C" { +#endif + #include "../screen.h" #include "hw_data.h" @@ -76,4 +80,8 @@ UINT32 GL_CreateLightTable(RGBA_t *hw_lighttable); void GL_ClearLightTables(void); void GL_SetScreenPalette(RGBA_t *palette); +#ifdef __cplusplus +} // extern "C" +#endif + #endif // __HWR_GL_H__ diff --git a/src/hardware/hw_glob.h b/src/hardware/hw_glob.h index 0589ba1d2..09956b99d 100644 --- a/src/hardware/hw_glob.h +++ b/src/hardware/hw_glob.h @@ -14,6 +14,10 @@ #ifndef _HWR_GLOB_H_ #define _HWR_GLOB_H_ +#ifdef __cplusplus +extern "C" { +#endif + #include "hw_defs.h" #include "../m_misc.h" #include "../r_defs.h" @@ -109,4 +113,8 @@ const char *HWR_GetShaderName(INT32 shader); extern customshaderxlat_t shaderxlat[]; +#ifdef __cplusplus +} // extern "C" +#endif + #endif //_HW_GLOB_ diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.cpp similarity index 93% rename from src/hardware/hw_main.c rename to src/hardware/hw_main.cpp index c3cd01ad7..0667c9806 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.cpp @@ -11,6 +11,7 @@ /// \file /// \brief hardware renderer, using the standard HardWareRender driver DLL for SRB2 +#include #include #include "../doomstat.h" @@ -107,21 +108,21 @@ static INT32 bsp_culling_distances[] = {(1024+512)*FRACUNIT, (2048+512)*FRACUNIT (6144+512)*FRACUNIT, (8192+512)*FRACUNIT, (12288+512)*FRACUNIT, (16384+512)*FRACUNIT}; // Performance stats -ps_metric_t ps_hw_nodesorttime = {0}; -ps_metric_t ps_hw_nodedrawtime = {0}; -ps_metric_t ps_hw_spritesorttime = {0}; -ps_metric_t ps_hw_spritedrawtime = {0}; +ps_metric_t ps_hw_nodesorttime = {}; +ps_metric_t ps_hw_nodedrawtime = {}; +ps_metric_t ps_hw_spritesorttime = {}; +ps_metric_t ps_hw_spritedrawtime = {}; // Performance stats for batching -ps_metric_t ps_hw_numpolys = {0}; -ps_metric_t ps_hw_numverts = {0}; -ps_metric_t ps_hw_numcalls = {0}; -ps_metric_t ps_hw_numshaders = {0}; -ps_metric_t ps_hw_numtextures = {0}; -ps_metric_t ps_hw_numpolyflags = {0}; -ps_metric_t ps_hw_numcolors = {0}; -ps_metric_t ps_hw_batchsorttime = {0}; -ps_metric_t ps_hw_batchdrawtime = {0}; +ps_metric_t ps_hw_numpolys = {}; +ps_metric_t ps_hw_numverts = {}; +ps_metric_t ps_hw_numcalls = {}; +ps_metric_t ps_hw_numshaders = {}; +ps_metric_t ps_hw_numtextures = {}; +ps_metric_t ps_hw_numpolyflags = {}; +ps_metric_t ps_hw_numcolors = {}; +ps_metric_t ps_hw_batchsorttime = {}; +ps_metric_t ps_hw_batchdrawtime = {}; static void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, boolean noencore, FSurfaceInfo* Surf, INT32 cutflag, ffloor_t *pfloor, FBITFIELD polyflags); static void HWR_RenderWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, FBITFIELD blend, boolean fogwall, INT32 lightlevel, extracolormap_t *wallcolormap); @@ -372,7 +373,7 @@ void HWR_ObjectLightLevelPost(gl_vissprite_t *spr, const sector_t *sector, INT32 fixed_t extralight = R_GetSpriteDirectionalLighting(R_PointToAngle(spr->mobj->x, spr->mobj->y)); // Less change in contrast in dark sectors - extralight = FixedMul(extralight, min(max(0, *lightlevel), 255) * FRACUNIT / 255); + extralight = FixedMul(extralight, CLAMP(*lightlevel, 0, 255) * FRACUNIT / 255); // simple OGL approximation fixed_t tr = R_PointToDist(spr->mobj->x, spr->mobj->y); @@ -380,7 +381,7 @@ void HWR_ObjectLightLevelPost(gl_vissprite_t *spr, const sector_t *sector, INT32 // Less change in contrast at further distances, to counteract DOOM diminished light fixed_t n = FixedDiv(FixedMul(xscale, LIGHTRESOLUTIONFIX), ((MAXLIGHTSCALE-1) << LIGHTSCALESHIFT)); - extralight = FixedMul(extralight, min(n, FRACUNIT)); + extralight = FixedMul(extralight, std::min(n, FRACUNIT)); // Contrast is stronger for normal sprites, stronger than wall lighting is at the same distance *lightlevel += FixedFloor((extralight * 2) + (FRACUNIT / 2)) / FRACUNIT; @@ -414,9 +415,9 @@ void HWR_Lighting(FSurfaceInfo *Surface, INT32 light_level, extracolormap_t *col float tint_alpha, fade_alpha; float red, green, blue; - red = (float)poly_color.s.red; + red = (float)poly_color.s.red; green = (float)poly_color.s.green; - blue = (float)poly_color.s.blue; + blue = (float)poly_color.s.blue; // 48 is just an arbritrary value that looked relatively okay. tint_alpha = (float)(sqrt(tint_color.s.alpha) * 48) / 255.0f; @@ -428,20 +429,20 @@ void HWR_Lighting(FSurfaceInfo *Surface, INT32 light_level, extracolormap_t *col fade_alpha = (float)(sqrt(255-light_level) * 12) / 255.0f; // Clamp the alpha values - tint_alpha = min(max(tint_alpha, 0.0f), 1.0f); - fade_alpha = min(max(fade_alpha, 0.0f), 1.0f); + tint_alpha = CLAMP(tint_alpha, 0.0f, 1.0f); + fade_alpha = CLAMP(fade_alpha, 0.0f, 1.0f); - red = (tint_color.s.red * tint_alpha) + (red * (1.0f - tint_alpha)); + red = (tint_color.s.red * tint_alpha) + (red * (1.0f - tint_alpha)); green = (tint_color.s.green * tint_alpha) + (green * (1.0f - tint_alpha)); - blue = (tint_color.s.blue * tint_alpha) + (blue * (1.0f - tint_alpha)); + blue = (tint_color.s.blue * tint_alpha) + (blue * (1.0f - tint_alpha)); - red = (fade_color.s.red * fade_alpha) + (red * (1.0f - fade_alpha)); + red = (fade_color.s.red * fade_alpha) + (red * (1.0f - fade_alpha)); green = (fade_color.s.green * fade_alpha) + (green * (1.0f - fade_alpha)); - blue = (fade_color.s.blue * fade_alpha) + (blue * (1.0f - fade_alpha)); + blue = (fade_color.s.blue * fade_alpha) + (blue * (1.0f - fade_alpha)); - poly_color.s.red = (UINT8)red; + poly_color.s.red = (UINT8)red; poly_color.s.green = (UINT8)green; - poly_color.s.blue = (UINT8)blue; + poly_color.s.blue = (UINT8)blue; } // Clamp the light level, since it can sometimes go out of the 0-255 range from animations @@ -1192,14 +1193,14 @@ static void HWR_SkyWallList_Add(FOutVector *wallVerts) if (!skyWallVertexArray) { // array has not been allocated yet. allocate it now - skyWallVertexArray = Z_Malloc(sizeof(FOutVector) * 4 * skyWallVertexArrayAllocSize, PU_STATIC, NULL); + skyWallVertexArray = static_cast(Z_Malloc(sizeof(FOutVector) * 4 * skyWallVertexArrayAllocSize, PU_STATIC, NULL)); } if (skyWallVertexArraySize == skyWallVertexArrayAllocSize) { // allocated array got full, allocate more space skyWallVertexArrayAllocSize *= 2; - skyWallVertexArray = Z_Realloc(skyWallVertexArray, sizeof(FOutVector) * 4 * skyWallVertexArrayAllocSize, PU_STATIC, NULL); + skyWallVertexArray = static_cast(Z_Realloc(skyWallVertexArray, sizeof(FOutVector) * 4 * skyWallVertexArrayAllocSize, PU_STATIC, NULL)); } memcpy(skyWallVertexArray + skyWallVertexArraySize * 4, wallVerts, sizeof(FOutVector) * 4); @@ -1417,6 +1418,13 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom // Sky Ceilings wallVerts[3].y = wallVerts[2].y = FixedToFloat(INT32_MAX); + auto draw_sky_walls = [&](int vert1, int vert2, fixed_t world, fixed_t worldslope) + { + wallVerts[vert1].y = FixedToFloat(world); + wallVerts[vert2].y = FixedToFloat(worldslope); + HWR_DrawSkyWall(wallVerts, &Surf); + }; + if (gl_frontsector->ceilingpic == skyflatnum) { if (gl_backsector->ceilingpic == skyflatnum) @@ -1427,25 +1435,19 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom && (worldhigh != worldtop || worldhighslope != worldtopslope)) // Removing the second line above will render more rarely visible skywalls. Example: Cave garden ceiling in Dark race { - wallVerts[0].y = FixedToFloat(worldhigh); - wallVerts[1].y = FixedToFloat(worldhighslope); - HWR_DrawSkyWall(wallVerts, &Surf); + draw_sky_walls(0, 1, worldhigh, worldhighslope); } } else { // Only the frontsector is sky, just draw a skywall from the front ceiling - wallVerts[0].y = FixedToFloat(worldtop); - wallVerts[1].y = FixedToFloat(worldtopslope); - HWR_DrawSkyWall(wallVerts, &Surf); + draw_sky_walls(0, 1, worldtop, worldtopslope); } } else if (gl_backsector->ceilingpic == skyflatnum) { // Only the backsector is sky, just draw a skywall from the front ceiling - wallVerts[0].y = FixedToFloat(worldtop); - wallVerts[1].y = FixedToFloat(worldtopslope); - HWR_DrawSkyWall(wallVerts, &Surf); + draw_sky_walls(0, 1, worldtop, worldtopslope); } // Sky Floors @@ -1463,25 +1465,19 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom // Removing the second line above will render more rarely visible skywalls. Example: Cave garden ceiling in Dark race && !(gl_sidedef->bottomtexture)) { - wallVerts[3].y = FixedToFloat(worldlow); - wallVerts[2].y = FixedToFloat(worldlowslope); - HWR_DrawSkyWall(wallVerts, &Surf); + draw_sky_walls(3, 2, worldlow, worldlowslope); } } else { // Only the backsector has sky, just draw a skywall from the back floor - wallVerts[3].y = FixedToFloat(worldbottom); - wallVerts[2].y = FixedToFloat(worldbottomslope); - HWR_DrawSkyWall(wallVerts, &Surf); + draw_sky_walls(3, 2, worldbottom, worldbottomslope); } } else if ((gl_backsector->floorpic == skyflatnum) && !(gl_sidedef->bottomtexture)) { // Only the backsector has sky, just draw a skywall from the back floor if there's no bottomtexture - wallVerts[3].y = FixedToFloat(worldlow); - wallVerts[2].y = FixedToFloat(worldlowslope); - HWR_DrawSkyWall(wallVerts, &Surf); + draw_sky_walls(3, 2, worldlow, worldlowslope); } } @@ -1674,10 +1670,10 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom } else { - popentop = min(worldtop, worldhigh); - popenbottom = max(worldbottom, worldlow); - popentopslope = min(worldtopslope, worldhighslope); - popenbottomslope = max(worldbottomslope, worldlowslope); + popentop = std::min(worldtop, worldhigh); + popenbottom = std::max(worldbottom, worldlow); + popentopslope = std::min(worldtopslope, worldhighslope); + popenbottomslope = std::max(worldbottomslope, worldlowslope); } // Find the wall's coordinates @@ -1687,12 +1683,12 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom { if (!!(gl_linedef->flags & ML_DONTPEGBOTTOM) ^ !!(gl_linedef->flags & ML_EFFECT3)) // Peg it to the floor { - polybottom = max(front->floorheight, back->floorheight) + gl_sidedef->rowoffset; - polytop = polybottom + midtexheight; + polybottom = std::max(front->floorheight, back->floorheight) + gl_sidedef->rowoffset; + polytop = polybottom + midtexheight; } else // Peg it to the ceiling { - polytop = min(front->ceilingheight, back->ceilingheight) + gl_sidedef->rowoffset; + polytop = std::min(front->ceilingheight, back->ceilingheight) + gl_sidedef->rowoffset; polybottom = polytop - midtexheight; } @@ -1709,9 +1705,9 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom } else // Skew it according to the ceiling's slope { - polytop = popentop + gl_sidedef->rowoffset; - polybottom = polytop - midtexheight; - polytopslope = popentopslope + gl_sidedef->rowoffset; + polytop = popentop + gl_sidedef->rowoffset; + polybottom = polytop - midtexheight; + polytopslope = popentopslope + gl_sidedef->rowoffset; polybottomslope = polytopslope - midtexheight; } @@ -1720,24 +1716,24 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom // you must use the linedef's backsector to be correct if (gl_curline->polyseg) { - lowcut = polybottom; - highcut = polytop; - lowcutslope = polybottomslope; + lowcut = polybottom; + highcut = polytop; + lowcutslope = polybottomslope; highcutslope = polytopslope; } else { // 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; + lowcut = popenbottom; + highcut = popentop; + lowcutslope = popenbottomslope; highcutslope = popentopslope; } - h = min(highcut, polytop); - l = max(polybottom, lowcut); - hS = min(highcutslope, polytopslope); - lS = max(polybottomslope, lowcutslope); + h = std::min(highcut, polytop); + l = std::max(polybottom, lowcut); + hS = std::min(highcutslope, polytopslope); + lS = std::max(polybottomslope, lowcutslope); // PEGGING fixed_t texturevpegslope; @@ -1893,10 +1889,10 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom INT32 texnum; line_t * newline = NULL; // Multi-Property FOF - lowcut = max(worldbottom, worldlow); - highcut = min(worldtop, worldhigh); - lowcutslope = max(worldbottomslope, worldlowslope); - highcutslope = min(worldtopslope, worldhighslope); + lowcut = std::max(worldbottom, worldlow); + highcut = std::min(worldtop, worldhigh); + lowcutslope = std::max(worldbottomslope, worldlowslope); + highcutslope = std::min(worldtopslope, worldhighslope); if (gl_backsector->ffloors) { @@ -1917,7 +1913,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom if (rover->master->flags & ML_TFERLINE) { - size_t linenum = min((size_t)(gl_curline->linedef-gl_backsector->lines[0]), rover->master->frontsector->linecount); + size_t linenum = std::min((size_t)(gl_curline->linedef-gl_backsector->lines[0]), rover->master->frontsector->linecount); newline = rover->master->frontsector->lines[0] + linenum; texnum = R_GetTextureNum(sides[newline->sidenum[0]].midtexture); } @@ -2067,7 +2063,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom if (rover->master->flags & ML_TFERLINE) { - size_t linenum = min((size_t)(gl_curline->linedef-gl_backsector->lines[0]), rover->master->frontsector->linecount); + size_t linenum = std::min((size_t)(gl_curline->linedef-gl_backsector->lines[0]), rover->master->frontsector->linecount); newline = rover->master->frontsector->lines[0] + linenum; texnum = R_GetTextureNum(sides[newline->sidenum[0]].midtexture); } @@ -2182,6 +2178,7 @@ static inline boolean HWR_UsePortals(void) boolean checkforemptylines = true; // Don't modify anything here, just check // Kalaron: Modified for sloped linedefs + static boolean CheckClip(sector_t * afrontsector, sector_t * abacksector) { fixed_t frontf1,frontf2, frontc1, frontc2; // front floor/ceiling ends @@ -2315,17 +2312,121 @@ static boolean CheckClip(sector_t * afrontsector, sector_t * abacksector) // HWR_AddLine // Clips the given segment and adds any visible pieces to the line list. +namespace +{ + enum class AddLineType + { + kPortal, + kNormal, + }; + +template +static inline void DoAddLine(seg_t* line, angle_t angle1, angle_t angle2) +{ + // SoM: Backsector needs to be run through R_FakeFlat + static sector_t tempsec; + + if constexpr (Type == AddLineType::kPortal) + { + boolean dont_draw = false; + + // do extra checks on the seg when rendering portals: + // don't render segs that are behind the portal destination line + if (portalclipline && + !HWR_PortalCheckPointSide(line->v1->x, line->v1->y) && + !HWR_PortalCheckPointSide(line->v2->x, line->v2->y)) + { + return; + } + + if (gl_portal_state == GLPORTAL_STENCIL || gl_portal_state == GLPORTAL_DEPTH) + goto doaddline; + + if (line->linedef->special == 40) + { + if (line->side == 0) + { + // Find the other side! + INT32 line2 = P_FindSpecialLineFromTag(40, line->linedef->tag, -1); + + if (line->linedef == &lines[line2]) + line2 = P_FindSpecialLineFromTag(40, line->linedef->tag, line2); + + if (line2 >= 0) // found it! + { + if (gl_portal_state == GLPORTAL_SEARCH) + HWR_Portal_Add2Lines(line->linedef-lines, line2, line); + else if (gl_portal_state == GLPORTAL_INSIDE) + dont_draw = true; + } + } + else + return;// dont do anything with the other side i guess? + } + + doaddline: + if (!line->backsector) + { + gld_clipper_SafeAddClipRange(angle2, angle1); + } + else + { + gl_backsector = R_FakeFlat(gl_backsector, &tempsec, NULL, NULL, true); + + if (CheckClip(gl_frontsector, gl_backsector)) + { + gld_clipper_SafeAddClipRange(angle2, angle1); + checkforemptylines = false; + } + + // Reject empty lines used for triggers and special events. + // Identical floor and ceiling on both sides, + // identical light levels on both sides, + // and no middle texture. + if (checkforemptylines && R_IsEmptyLine(line, gl_frontsector, gl_backsector)) + return; + } + + if (LIKELY(gl_portal_state != GLPORTAL_SEARCH && !dont_draw))// no need to do this during the portal check + HWR_ProcessSeg(); // Doesn't need arguments because they're defined globally :D + return; + } + + if constexpr (Type == AddLineType::kNormal) + { + if (!line->backsector) + { + gld_clipper_SafeAddClipRange(angle2, angle1); + } + else + { + gl_backsector = R_FakeFlat(gl_backsector, &tempsec, NULL, NULL, true); + + if (CheckClip(gl_frontsector, gl_backsector)) + { + gld_clipper_SafeAddClipRange(angle2, angle1); + checkforemptylines = false; + } + + // Reject empty lines used for triggers and special events. + // Identical floor and ceiling on both sides, + // identical light levels on both sides, + // and no middle texture. + if (checkforemptylines && R_IsEmptyLine(line, gl_frontsector, gl_backsector)) + return; + } + + HWR_ProcessSeg(); // Doesn't need arguments because they're defined globally :D + return; + } +} + static void HWR_AddLine(seg_t *line) { angle_t angle1, angle2; - // SoM: Backsector needs to be run through R_FakeFlat - static sector_t tempsec; - fixed_t v1x, v1y, v2x, v2y; // the seg's vertexes as fixed_t - boolean dont_draw = false; - if (line->polyseg && !(line->polyseg->flags & POF_RENDERSIDES)) return; @@ -2369,73 +2470,12 @@ static void HWR_AddLine(seg_t *line) gl_backsector = line->backsector; - if (LIKELY(!HWR_UsePortals())) - { -doaddline: - if (!line->backsector) - { - gld_clipper_SafeAddClipRange(angle2, angle1); - } - else - { - gl_backsector = R_FakeFlat(gl_backsector, &tempsec, NULL, NULL, true); - - if (CheckClip(gl_frontsector, gl_backsector)) - { - gld_clipper_SafeAddClipRange(angle2, angle1); - checkforemptylines = false; - } - - // Reject empty lines used for triggers and special events. - // Identical floor and ceiling on both sides, - // identical light levels on both sides, - // and no middle texture. - if (checkforemptylines && R_IsEmptyLine(line, gl_frontsector, gl_backsector)) - return; - } - - if (LIKELY(gl_portal_state != GLPORTAL_SEARCH && !dont_draw))// no need to do this during the portal check - HWR_ProcessSeg(); // Doesn't need arguments because they're defined globally :D - - return; - } - - // do extra checks on the seg when rendering portals: - // don't render segs that are behind the portal destination line - if (portalclipline && - !HWR_PortalCheckPointSide(line->v1->x, line->v1->y) && - !HWR_PortalCheckPointSide(line->v2->x, line->v2->y)) - { - return; - } - - if (gl_portal_state == GLPORTAL_STENCIL || gl_portal_state == GLPORTAL_DEPTH) - goto doaddline; - - if (line->linedef->special == 40) - { - if (line->side == 0) - { - // Find the other side! - INT32 line2 = P_FindSpecialLineFromTag(40, line->linedef->tag, -1); - - if (line->linedef == &lines[line2]) - line2 = P_FindSpecialLineFromTag(40, line->linedef->tag, line2); - - if (line2 >= 0) // found it! - { - if (gl_portal_state == GLPORTAL_SEARCH) - HWR_Portal_Add2Lines(line->linedef-lines, line2, line); - else if (gl_portal_state == GLPORTAL_INSIDE) - dont_draw = true; - } - } - else - return;// dont do anything with the other side i guess? - } - - goto doaddline; + if (UNLIKELY(HWR_UsePortals())) + DoAddLine(line, angle1, angle2); + else + DoAddLine(line, angle1, angle2); } +}; // HWR_CheckBBox // Checks BSP node/subtree bounding box. @@ -3153,7 +3193,10 @@ doaddline: while (count--) { if (LIKELY(!line->polyseg)) // ignore segs that belong to polyobjects + { HWR_AddLine(line); + } + line++; } } @@ -3176,10 +3219,19 @@ doaddline: // Just call with BSP root. // +namespace +{ + enum class BspType + { + kPortal, + kNormal, + }; + +template static void HWR_RenderBSPNode(INT32 bspnum) { - register const node_t *bsp; - register INT32 side; + const node_t *bsp; + INT32 side; ps_numbspcalls.value.i++; while (!(bspnum & NF_SUBSECTOR)) // Keep going until found a subsector @@ -3189,61 +3241,48 @@ static void HWR_RenderBSPNode(INT32 bspnum) // Decide which side the view point is on. side = R_PointOnSideFast(viewx, viewy, bsp); - // Recursively divide front space (toward the viewer). - HWR_RenderBSPNode(bsp->children[side]); + if constexpr (Type == BspType::kPortal) + { + // Recursively divide front space (toward the viewer). + if (HWR_PortalCheckBBox(bsp->bbox[side])) + HWR_RenderBSPNode(bsp->children[side]); - // Possibly divide back space (away from the viewer). - if (!(HWR_CheckBBox(bsp->bbox[side^1]))) - return; + // Possibly divide back space (away from the viewer). + if (!(HWR_CheckBBox(bsp->bbox[side^1]) && HWR_PortalCheckBBox(bsp->bbox[side^1]))) + return; + } + + if constexpr (Type == BspType::kNormal) + { + // Recursively divide front space (toward the viewer). + HWR_RenderBSPNode(bsp->children[side]); + + // Possibly divide back space (away from the viewer). + if (!(HWR_CheckBBox(bsp->bbox[side^1]))) + return; + } bspnum = bsp->children[side^1]; } + if constexpr (Type == BspType::kPortal) + { + // PORTAL CULLING + if (portalcullsector) + { + // skip all subsectors encountered before the portal + // destination's front sector + if (portalcullsector != subsectors[bspnum & ~NF_SUBSECTOR].sector) + return; + else + portalcullsector = NULL; + } + } + // e6y: support for extended nodes HWR_Subsector(bspnum == -1 ? 0 : bspnum & ~NF_SUBSECTOR); } - -// -// Same thing but with extra portal checks -// -static void HWR_RenderPortalBSPNode(INT32 bspnum) -{ - register const node_t *bsp; - register INT32 side; - ps_numbspcalls.value.i++; - - while (!(bspnum & NF_SUBSECTOR)) // Keep going until found a subsector - { - bsp = &nodes[bspnum]; - - // Decide which side the view point is on. - side = R_PointOnSideFast(viewx, viewy, bsp); - - // Recursively divide front space (toward the viewer). - if (HWR_PortalCheckBBox(bsp->bbox[side])) - HWR_RenderPortalBSPNode(bsp->children[side]); - - // Possibly divide back space (away from the viewer). - if (!(HWR_CheckBBox(bsp->bbox[side^1]) && HWR_PortalCheckBBox(bsp->bbox[side^1]))) - return; - - bspnum = bsp->children[side^1]; - } - - // PORTAL CULLING - if (portalcullsector) - { - // skip all subsectors encountered before the portal - // destination's front sector - if (portalcullsector != subsectors[bspnum & ~NF_SUBSECTOR].sector) - return; - else - portalcullsector = NULL; - } - - // e6y: support for extended nodes - HWR_Subsector(bspnum == -1 ? 0 : bspnum & ~NF_SUBSECTOR); -} +}; // ========================================================================== // gl_things.c @@ -3492,6 +3531,8 @@ static void HWR_DrawSpriteShadow(gl_vissprite_t *spr, patch_t *gpatch, GLPatch_t } } +#define std_R_QuickCamDist(x, y) std::max(abs(((x)>>FRACBITS) - (viewx>>FRACBITS)), abs(((y)>>FRACBITS) - (viewy>>FRACBITS))) + // This is expecting a pointer to an array containing 4 wallVerts for a sprite static void HWR_RotateSpritePolyToAim(gl_vissprite_t *spr, FOutVector *wallVerts, const boolean precip, const boolean papersprite) { @@ -3501,12 +3542,12 @@ static void HWR_RotateSpritePolyToAim(gl_vissprite_t *spr, FOutVector *wallVerts } // uncapped/interpolation - interpmobjstate_t interp = {0}; + interpmobjstate_t interp = {}; float basey, lowy; INT32 dist = -1; if (cv_maxinterpdist.value) - dist = R_QuickCamDist(spr->mobj->x, spr->mobj->y); + dist = std_R_QuickCamDist(spr->mobj->x, spr->mobj->y); // do interpolation if (R_UsingFrameInterpolation() && !paused && (!cv_maxinterpdist.value || dist < cv_maxinterpdist.value)) @@ -3568,8 +3609,8 @@ static inline void HWR_ApplyDispoffset(gl_vissprite_t *spr, FOutVector *wallVert { HWR_RotateSpritePolyToAim(spr, wallVerts, false, papersprite); - float sprdist = sqrtf((spr->x1 - gl_viewx)*(spr->x1 - gl_viewx) + (spr->z1 - gl_viewy)*(spr->z1 - gl_viewy) + (spr->gzt - gl_viewz)*(spr->gzt - gl_viewz)); - float distfact = ((2.0f*spr->dispoffset) + 20.0f) / sprdist; + const float sprdist = sqrtf((spr->x1 - gl_viewx)*(spr->x1 - gl_viewx) + (spr->z1 - gl_viewy)*(spr->z1 - gl_viewy) + (spr->gzt - gl_viewz)*(spr->gzt - gl_viewz)); + const float distfact = ((2.0f*spr->dispoffset) + 20.0f) / sprdist; for (size_t i = 0; i < 4; i++) { @@ -3731,11 +3772,13 @@ static void HWR_SplitSprite(gl_vissprite_t *spr, const boolean papersprite) for (i = 1; i < sector->numlights; i++) { fixed_t h = P_GetLightZAt(§or->lightlist[i], spr->mobj->x, spr->mobj->y); + if (!(h <= temp)) continue; if (!lightset) - lightlevel = min(*list[i-1].lightlevel, 255); + lightlevel = std::min(static_cast(*list[i-1].lightlevel), 255); + colormap = list[i-1].extra_colormap; break; } @@ -3753,7 +3796,7 @@ static void HWR_SplitSprite(gl_vissprite_t *spr, const boolean papersprite) { if (!lightset) { - lightlevel = min(*list[i].lightlevel, 255); + lightlevel = std::min(static_cast(*list[i].lightlevel), 255); HWR_ObjectLightLevelPost(spr, sector, &lightlevel, false); } @@ -3762,9 +3805,9 @@ static void HWR_SplitSprite(gl_vissprite_t *spr, const boolean papersprite) if (i + 1 < sector->numlights) { - temp = P_GetLightZAt(&list[i+1], v1x, v1y); - bheight = FixedToFloat(temp); - temp = P_GetLightZAt(&list[i+1], v2x, v2y); + temp = P_GetLightZAt(&list[i+1], v1x, v1y); + bheight = FixedToFloat(temp); + temp = P_GetLightZAt(&list[i+1], v2x, v2y); endbheight = FixedToFloat(temp); } else @@ -3781,7 +3824,7 @@ static void HWR_SplitSprite(gl_vissprite_t *spr, const boolean papersprite) // 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); wallVerts[3].t = towtop + ((realtop - top) * towmult); @@ -3961,7 +4004,7 @@ static void HWR_DrawSprite(gl_vissprite_t *spr) if (!lightset) { - lightlevel = min(sector->lightlevel, 255); + lightlevel = std::min(static_cast(sector->lightlevel), 255); HWR_ObjectLightLevelPost(spr, sector, &lightlevel, false); } @@ -4067,7 +4110,7 @@ static void HWR_DrawPrecipitationSprite(gl_vissprite_t *spr) light = R_GetPlaneLight(sector, spr->mobj->z + spr->mobj->height, false); // Always use the light at the top instead of whatever I was doing before if (!(spr->mobj->frame & FF_FULLBRIGHT)) - lightlevel = min(*sector->lightlist[light].lightlevel, 255); + lightlevel = std::min(static_cast(*sector->lightlist[light].lightlevel), 255); if (sector->lightlist[light].extra_colormap) colormap = sector->lightlist[light].extra_colormap; @@ -4075,7 +4118,7 @@ static void HWR_DrawPrecipitationSprite(gl_vissprite_t *spr) else { if (!(spr->mobj->frame & FF_FULLBRIGHT)) - lightlevel = min(sector->lightlevel, 255); + lightlevel = std::min(static_cast(sector->lightlevel), 255); if (sector->extra_colormap) colormap = sector->extra_colormap; @@ -4223,7 +4266,7 @@ static void *HWR_CreateDrawNode(gl_drawnode_type_t type) if (!drawnodes) { alloceddrawnodes = DRAWNODES_INIT_SIZE; - drawnodes = Z_Malloc(alloceddrawnodes * sizeof(gl_drawnode_t), PU_LEVEL, &drawnodes); + drawnodes = static_cast(Z_Malloc(alloceddrawnodes * sizeof(gl_drawnode_t), PU_LEVEL, &drawnodes)); } else if (numdrawnodes >= alloceddrawnodes) { @@ -4249,7 +4292,7 @@ static void *HWR_CreateDrawNode(gl_drawnode_type_t type) static void HWR_AddTransparentWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, INT32 texnum, boolean noencore, FBITFIELD blend, boolean fogwall, INT32 lightlevel, extracolormap_t *wallcolormap) { - wallinfo_t *wallinfo = HWR_CreateDrawNode(DRAWNODE_WALL); + wallinfo_t *wallinfo = static_cast(HWR_CreateDrawNode(DRAWNODE_WALL)); M_Memcpy(wallinfo->wallVerts, wallVerts, sizeof (wallinfo->wallVerts)); M_Memcpy(&wallinfo->Surf, pSurf, sizeof (FSurfaceInfo)); @@ -4263,7 +4306,7 @@ static void HWR_AddTransparentWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, I static void HWR_AddTransparentFloor(lumpnum_t lumpnum, extrasubsector_t *xsub, boolean isceiling, fixed_t fixedheight, INT32 lightlevel, INT32 alpha, sector_t *FOFSector, FBITFIELD blend, boolean fogplane, extracolormap_t *planecolormap) { - planeinfo_t *planeinfo = HWR_CreateDrawNode(DRAWNODE_PLANE); + planeinfo_t *planeinfo = static_cast(HWR_CreateDrawNode(DRAWNODE_PLANE)); planeinfo->isceiling = isceiling; planeinfo->fixedheight = fixedheight; @@ -4281,7 +4324,7 @@ static void HWR_AddTransparentFloor(lumpnum_t lumpnum, extrasubsector_t *xsub, b // When that happens it'll just be done through HWR_AddTransparentFloor and HWR_RenderPlane static void HWR_AddTransparentPolyobjectFloor(lumpnum_t lumpnum, polyobj_t *polysector, boolean isceiling, fixed_t fixedheight, INT32 lightlevel, INT32 alpha, sector_t *FOFSector, FBITFIELD blend, extracolormap_t *planecolormap) { - polyplaneinfo_t *polyplaneinfo = HWR_CreateDrawNode(DRAWNODE_POLYOBJECT_PLANE); + polyplaneinfo_t *polyplaneinfo = static_cast(HWR_CreateDrawNode(DRAWNODE_POLYOBJECT_PLANE)); polyplaneinfo->isceiling = isceiling; polyplaneinfo->fixedheight = fixedheight; @@ -4320,7 +4363,7 @@ static void HWR_RenderDrawNodes(void) PS_START_TIMING(ps_hw_nodesorttime); - sortindex = Z_Malloc(sizeof(INT32) * numdrawnodes, PU_STATIC, NULL); + sortindex = static_cast(Z_Malloc(sizeof(INT32) * numdrawnodes, PU_STATIC, NULL)); // Reversed order for (i = 0; i < numdrawnodes; i++) @@ -4519,7 +4562,7 @@ static void HWR_AddSprites(sector_t *sec) { // Use the smaller setting if (limit_dist) - limit_dist = min(current_bsp_culling_distance/mapobjectscale, limit_dist); + limit_dist = std::min(current_bsp_culling_distance/mapobjectscale, limit_dist); else limit_dist = current_bsp_culling_distance/mapobjectscale; } @@ -4565,7 +4608,7 @@ static void HWR_AddPrecipitationSprites(void) } if (current_bsp_culling_distance) - drawdist = min((fixed_t)current_bsp_culling_distance, drawdist); + drawdist = std::min((fixed_t)current_bsp_culling_distance, drawdist); R_GetRenderBlockMapDimensions(drawdist, &xl, &xh, &yl, &yh); @@ -4632,10 +4675,10 @@ static void HWR_ProjectSprite(mobj_t *thing) return; // uncapped/interpolation - interpmobjstate_t interp = {0}; + interpmobjstate_t interp = {}; if (cv_maxinterpdist.value) - dist = R_QuickCamDist(thing->x, thing->y); + dist = std_R_QuickCamDist(thing->x, thing->y); if (R_UsingFrameInterpolation() && !paused && (!cv_maxinterpdist.value || dist < cv_maxinterpdist.value)) { @@ -4926,21 +4969,21 @@ static void HWR_ProjectSprite(mobj_t *thing) if ((vis->mobj->flags & MF_BOSS) && (vis->mobj->flags2 & MF2_FRET) && (leveltime & 1)) // Bosses "flash" { if (vis->mobj->type == MT_CYBRAKDEMON) - vis->colormap = R_GetTranslationColormap(TC_ALLWHITE, 0, GTC_CACHE); + vis->colormap = static_cast(R_GetTranslationColormap(TC_ALLWHITE, SKINCOLOR_NONE, GTC_CACHE)); else if (vis->mobj->type == MT_METALSONIC_BATTLE) - vis->colormap = R_GetTranslationColormap(TC_METALSONIC, 0, GTC_CACHE); + vis->colormap = static_cast(R_GetTranslationColormap(TC_METALSONIC, SKINCOLOR_NONE, GTC_CACHE)); else - vis->colormap = R_GetTranslationColormap(TC_BOSS, 0, GTC_CACHE); + vis->colormap = static_cast(R_GetTranslationColormap(TC_BOSS, SKINCOLOR_NONE, GTC_CACHE)); } else if (thing->color) { // New colormap stuff for skins Tails 06-07-2002 if (thing->colorized) - vis->colormap = R_GetTranslationColormap(TC_RAINBOW, thing->color, GTC_CACHE); + vis->colormap = static_cast(R_GetTranslationColormap(TC_RAINBOW, static_cast(thing->color), GTC_CACHE)); else if (thing->skin && thing->sprite == SPR_PLAY) // This thing is a player! - vis->colormap = R_GetLocalTranslationColormap(thing->skin, thing->localskin, thing->color, GTC_CACHE, thing->skinlocal); + vis->colormap = static_cast(R_GetLocalTranslationColormap(static_cast(thing->skin), static_cast(thing->localskin), static_cast(thing->color), GTC_CACHE, thing->skinlocal)); else - vis->colormap = R_GetTranslationColormap(TC_DEFAULT, thing->color, GTC_CACHE); + vis->colormap = static_cast(R_GetTranslationColormap(TC_DEFAULT, static_cast(thing->color), GTC_CACHE)); } else { @@ -4990,10 +5033,10 @@ static void HWR_ProjectPrecipitationSprite(precipmobj_t *thing) } // uncapped/interpolation - interpmobjstate_t interp = {0}; + interpmobjstate_t interp = {}; if (cv_maxinterpdist.value) - dist = R_QuickCamDist(thing->x, thing->y); + dist = std_R_QuickCamDist(thing->x, thing->y); // do interpolation if (R_UsingFrameInterpolation() && !paused && (!cv_maxinterpdist.value || dist < cv_maxinterpdist.value)) @@ -5201,11 +5244,11 @@ void HWR_BuildSkyDome(void) sky->vertex_count = 2 * sky->rows * (sky->columns * 2 + 2) + sky->columns * 2; if (!sky->loops) - sky->loops = malloc((sky->rows * 2 + 2) * sizeof(sky->loops[0])); + sky->loops = static_cast(malloc((sky->rows * 2 + 2) * sizeof(sky->loops[0]))); // create vertex array if (!sky->data) - sky->data = malloc(sky->vertex_count * sizeof(sky->data[0])); + sky->data = static_cast(malloc(sky->vertex_count * sizeof(sky->data[0]))); sky->texture = texturetranslation[skytexture]; sky->width = texture->width; @@ -5413,48 +5456,55 @@ void HWR_SetStencilState(int state, int level) GL_SetSpecialState(HWD_SET_PORTAL_MODE, state); } -typedef void (*bspfunc)(INT32 bspnum); - // Renders the current viewpoint, though takes portal arguments for recursive portals. +namespace +{ + enum class RenderViewpointType + { + kPortal, + kNormal, + }; + +template void HWR_RenderViewpoint(gl_portal_t *rootportal, const float fpov, player_t *player, int stencil_level, boolean allow_portals) { gl_portallist_t portallist; const boolean skybox = (skyboxmo[0] && cv_skybox.value); - const boolean useportals = HWR_UsePortals() && allow_portals; - bspfunc bspFunc = (useportals && portalclipline) ? HWR_RenderPortalBSPNode : HWR_RenderBSPNode; portallist.base = portallist.cap = NULL; + HWR_SetPortalState(GLPORTAL_OFF); // there may be portals and they need to be drawn as regural walls - if (useportals && stencil_level < cv_maxportals.value) // if recursion limit is not reached + if constexpr (Type == RenderViewpointType::kPortal) { - gl_portal_t *portal; - - // search for portals in current frame - currentportallist = &portallist; - HWR_SetPortalState(GLPORTAL_SEARCH); - - HWR_ClearClipper(); - - if (rootportal) - HWR_PortalClipping(rootportal); - - validcount++; - - // no actual rendering happens - bspFunc((INT32)numnodes-1); - - // for each found portal: - // note: if necessary, could sort the portals here? - for (portal = portallist.base; portal; portal = portal->next) + if (allow_portals && stencil_level < cv_maxportals.value) // if recursion limit is not reached { - HWR_RenderPortal(portal, rootportal, fpov, player, stencil_level); - } + gl_portal_t *portal; - HWR_SetPortalState(GLPORTAL_INSIDE); // when portal walls are encountered in following bsp traversal, nothing should be drawn + // search for portals in current frame + currentportallist = &portallist; + HWR_SetPortalState(GLPORTAL_SEARCH); + + HWR_ClearClipper(); + + if (rootportal) + HWR_PortalClipping(rootportal); + + validcount++; + + // no actual rendering happens + HWR_RenderBSPNode((INT32)numnodes-1); + + // for each found portal: + // note: if necessary, could sort the portals here? + for (portal = portallist.base; portal; portal = portal->next) + { + HWR_RenderPortal(portal, rootportal, fpov, player, stencil_level); + } + + HWR_SetPortalState(GLPORTAL_INSIDE); // when portal walls are encountered in following bsp traversal, nothing should be drawn + } } - else - HWR_SetPortalState(GLPORTAL_OFF); // there may be portals and they need to be drawn as regural walls // draw normal things in current frame in current incremented stencil buffer area HWR_SetStencilState(HWR_STENCIL_NORMAL, stencil_level); @@ -5464,10 +5514,13 @@ void HWR_RenderViewpoint(gl_portal_t *rootportal, const float fpov, player_t *pl HWR_ClearSprites(); HWR_ClearClipper(); - if (useportals && rootportal) + if constexpr (Type == RenderViewpointType::kPortal) { - HWR_PortalFrame(rootportal);// for portalclipsector, it could have gone null from search - HWR_PortalClipping(rootportal); + if (allow_portals && rootportal) + { + HWR_PortalFrame(rootportal);// for portalclipsector, it could have gone null from search + HWR_PortalClipping(rootportal); + } } if (HWR_IsWireframeMode()) @@ -5482,21 +5535,33 @@ void HWR_RenderViewpoint(gl_portal_t *rootportal, const float fpov, player_t *pl if (LIKELY(cv_glbatching.value)) HWR_StartBatching(); - if (useportals && !rootportal && portallist.base && !skybox) // if portals have been drawn in the main view, then render skywalls differently - gl_collect_skywalls = true; + if constexpr (Type == RenderViewpointType::kPortal) + { + if (allow_portals && !rootportal && portallist.base && !skybox) // if portals have been drawn in the main view, then render skywalls differently + gl_collect_skywalls = true; - // HAYA: Save the old portal state, and turn portals off while normally rendering the BSP tree. - // This fixes specific effects not working, such as horizon lines. - SINT8 oldgl_portal_state = gl_portal_state; + // HAYA: Save the old portal state, and turn portals off while normally rendering the BSP tree. + // This fixes specific effects not working, such as horizon lines. + SINT8 oldgl_portal_state = gl_portal_state; - if (gl_portal_state != GLPORTAL_OFF) // if we already haven't hit the recursion limit or we already ended our portal shenanigans - HWR_SetPortalState(GLPORTAL_INSIDE); // TURN IT OFF + if (gl_portal_state != GLPORTAL_OFF) // if we already haven't hit the recursion limit or we already ended our portal shenanigans + HWR_SetPortalState(GLPORTAL_INSIDE); // TURN IT OFF - // Recursively "render" the BSP tree. - bspFunc((INT32)numnodes-1); + // Recursively "render" the BSP tree. + if (allow_portals && portalclipline) + HWR_RenderBSPNode((INT32)numnodes-1); + else + HWR_RenderBSPNode((INT32)numnodes-1); - // woo we back - HWR_SetPortalState(oldgl_portal_state); + // woo we back + HWR_SetPortalState(oldgl_portal_state); + } + + if constexpr (Type == RenderViewpointType::kNormal) + { + // Recursively "render" the BSP tree. + HWR_RenderBSPNode((INT32)numnodes-1); + } if (allow_portals) // looks weird, but this is only true when its not skybox rendering skipping precip in skyboxes like software does HWR_AddPrecipitationSprites(); @@ -5506,17 +5571,20 @@ void HWR_RenderViewpoint(gl_portal_t *rootportal, const float fpov, player_t *pl if (LIKELY(cv_glbatching.value)) HWR_RenderBatches(); - if (skyWallVertexArraySize) // if there are skywalls to draw using the alternate method + if constexpr (Type == RenderViewpointType::kPortal) { - HWR_SetStencilState(HWR_STENCIL_SKY, -1); - HWR_DrawSkyWallList(); - HWR_SkyWallList_Clear(); - HWR_SetStencilState(HWR_STENCIL_NORMAL, 1); - drewsky = false; - HWR_DrawSkyBackground(); - HWR_SetStencilState(HWR_STENCIL_NORMAL, 0); - GL_ClearBuffer(false, false, true, 0);// clear skywall markings from the stencil buffer - HWR_SetTransform(fpov);// restore transform + if (skyWallVertexArraySize) // if there are skywalls to draw using the alternate method + { + HWR_SetStencilState(HWR_STENCIL_SKY, -1); + HWR_DrawSkyWallList(); + HWR_SkyWallList_Clear(); + HWR_SetStencilState(HWR_STENCIL_NORMAL, 1); + drewsky = false; + HWR_DrawSkyBackground(); + HWR_SetStencilState(HWR_STENCIL_NORMAL, 0); + GL_ClearBuffer(false, false, true, 0);// clear skywall markings from the stencil buffer + HWR_SetTransform(fpov);// restore transform + } } gl_collect_skywalls = false; @@ -5539,9 +5607,15 @@ void HWR_RenderViewpoint(gl_portal_t *rootportal, const float fpov, player_t *pl if (HWR_IsWireframeMode()) GL_SetSpecialState(HWD_SET_WIREFRAME, 0); - HWR_FreePortalList(portallist); + HWR_FreePortalList(portallist); // always call this just in case } +}; +extern "C" { + void HWR_RenderPortalViewpoint(gl_portal_t *rootportal, const float fpov, player_t *player, int stencil_level, boolean allow_portals) { + HWR_RenderViewpoint(rootportal, fpov, player, stencil_level, allow_portals); + } +} // ========================================================================== // Render the current frame. @@ -5588,7 +5662,10 @@ static void HWR_RenderFrame(player_t *player, boolean skybox) } portalclipline = NULL; - HWR_RenderViewpoint(NULL, fpov, player, 0, !skybox); + if (UNLIKELY(HWR_UsePortals())) + HWR_RenderViewpoint(NULL, fpov, player, 0, !skybox); + else + HWR_RenderViewpoint(NULL, fpov, player, 0, !skybox); // Unset transform and shader GL_SetTransform(NULL); diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h index 9fd4faa5d..7681309c1 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -20,6 +20,10 @@ #ifndef __HWR_MAIN_H__ #define __HWR_MAIN_H__ +#ifdef __cplusplus +extern "C" { +#endif + #include "hw_gl.h" #include "hw_glob.h" #include "hw_data.h" @@ -34,10 +38,6 @@ #define GLENCORE -#ifdef __cplusplus -extern "C" { -#endif - // Startup & Shutdown the hardware mode renderer void HWR_Startup(void); void HWR_Shutdown(void); @@ -110,6 +110,7 @@ void HWR_AddCommands(void); void HWR_RenderPlayerView(void); void HWR_RenderViewpoint(gl_portal_t *rootportal, const float fpov, player_t *player, int stencil_level, boolean allow_portals); +void HWR_RenderPortalViewpoint(gl_portal_t *rootportal, const float fpov, player_t *player, int stencil_level, boolean allow_portals); void HWR_ClearSkyDome(void); void HWR_BuildSkyDome(void); diff --git a/src/hardware/hw_portal.c b/src/hardware/hw_portal.c index fe643df13..939a60300 100644 --- a/src/hardware/hw_portal.c +++ b/src/hardware/hw_portal.c @@ -169,7 +169,7 @@ void HWR_RenderPortal(gl_portal_t* portal, gl_portal_t* rootportal, const float // go to portal frame lmao HWR_PortalFrame(portal); // call HWR_RenderViewpoint - HWR_RenderViewpoint(portal, fpov, player, stencil_level + 1, true); + HWR_RenderPortalViewpoint(portal, fpov, player, stencil_level + 1, true); // return to current frame if (rootportal) HWR_PortalFrame(rootportal); diff --git a/src/hardware/hw_portal.h b/src/hardware/hw_portal.h index f42d2f61c..494110d79 100644 --- a/src/hardware/hw_portal.h +++ b/src/hardware/hw_portal.h @@ -14,6 +14,10 @@ #ifndef __HW_PORTAL__ #define __HW_PORTAL__ +#ifdef __cplusplus +extern "C" { +#endif + #ifdef HWRENDER #include "../doomstat.h" @@ -77,5 +81,9 @@ void HWR_FreePortalList(gl_portallist_t portallist); boolean HWR_PortalCheckPointSide(fixed_t x, fixed_t y); boolean HWR_PortalCheckBBox(const fixed_t *bspcoord); +#endif + +#ifdef __cplusplus +}// extern "C" #endif #endif diff --git a/src/hardware/r_opengl/r_opengl.h b/src/hardware/r_opengl/r_opengl.h index b70febad4..e0d7e13ac 100644 --- a/src/hardware/r_opengl/r_opengl.h +++ b/src/hardware/r_opengl/r_opengl.h @@ -20,6 +20,10 @@ #ifndef _R_OPENGL_H_ #define _R_OPENGL_H_ +#ifdef __cplusplus +extern "C" { +#endif + #ifdef HAVE_SDL #define _MATH_DEFINES_DEFINED @@ -143,4 +147,8 @@ typedef enum GLF_NOTEXENV = 0x02, } oglflags_t; +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/m_fixed.h b/src/m_fixed.h index ae77c83b9..c0afae941 100644 --- a/src/m_fixed.h +++ b/src/m_fixed.h @@ -15,6 +15,10 @@ #ifndef __M_FIXED__ #define __M_FIXED__ +#ifdef __cplusplus +extern "C" { +#endif + #include "doomtype.h" #ifdef __GNUC__ #include @@ -370,4 +374,8 @@ void FM_MultMatrix(matrix_t *dest, const matrix_t *multme); void FM_Translate(matrix_t *dest, fixed_t x, fixed_t y, fixed_t z); void FM_Scale(matrix_t *dest, fixed_t x, fixed_t y, fixed_t z); +#ifdef __cplusplus +} // extern "C" +#endif + #endif //m_fixed.h diff --git a/src/st_stuff.h b/src/st_stuff.h index d0ed92b1a..5ffb3334f 100644 --- a/src/st_stuff.h +++ b/src/st_stuff.h @@ -14,6 +14,10 @@ #ifndef __STSTUFF_H__ #define __STSTUFF_H__ +#ifdef __cplusplus +extern "C" { +#endif + #include "doomtype.h" #include "d_event.h" #include "d_player.h" @@ -142,4 +146,8 @@ extern UINT16 objectsdrawn; extern consvar_t cv_lessflicker; extern consvar_t cv_stagetitle; +#ifdef __cplusplus +} // extern "C" +#endif + #endif From 729c60c9b0abbba8778e55f1d67a8e19c7e0ddf3 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 29 Jun 2025 10:20:33 +0100 Subject: [PATCH 08/13] thanks michaelsoft very cool --- src/hardware/hw_main.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index 0667c9806..a1185f38d 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -11,14 +11,15 @@ /// \file /// \brief hardware renderer, using the standard HardWareRender driver DLL for SRB2 +#ifdef HWRENDER + #include -#include +#define _USE_MATH_DEFINES +#include #include "../doomstat.h" #include "../doomdef.h" -#ifdef HWRENDER - #include "hw_main.h" #include "hw_glob.h" #include "hw_gl.h" From 0dcdcc3da1e04ea0189d6b224cfc92b281a2c61b Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 30 Jun 2025 07:54:34 +0200 Subject: [PATCH 09/13] fix hw_main compiler warning --- src/hardware/hw_main.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index a1185f38d..acbd865b8 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -1026,7 +1026,7 @@ static void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, // 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) + if (std::fpclassify(diff) == FP_ZERO) pegmul = 0.0; else pegmul = (pegb - pegt) / diff; @@ -1038,7 +1038,7 @@ static void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, endpegt = wallVerts[2].t; endpegb = wallVerts[1].t; - if (fpclassify(diff) == FP_ZERO) + if (std::fpclassify(diff) == FP_ZERO) endpegmul = 0.0; else endpegmul = (endpegb - endpegt) / diff; @@ -2028,7 +2028,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom if ((roverflags & FF_TRANSLUCENT && rover->alpha < 256) || rover->blend) { - blendmode = rover->blend ? HWR_GetBlendModeFlag(rover->blend) : PF_Translucent; + blendmode = rover->blend ? HWR_GetBlendModeFlag(rover->blend) : static_cast(PF_Translucent); Surf.PolyColor.s.alpha = CLAMP(rover->alpha, 0, 255); } @@ -2145,7 +2145,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom if ((roverflags & FF_TRANSLUCENT && rover->alpha < 256) || rover->blend) { - blendmode = rover->blend ? HWR_GetBlendModeFlag(rover->blend) : PF_Translucent; + blendmode = rover->blend ? HWR_GetBlendModeFlag(rover->blend) : static_cast(PF_Translucent); Surf.PolyColor.s.alpha = CLAMP(rover->alpha, 0, 255); } @@ -3079,7 +3079,7 @@ static void HWR_Subsector(size_t num) false, *rover->bottomheight, *gl_frontsector->lightlist[light].lightlevel, - CLAMP(rover->alpha, 0 ,255), rover->master->frontsector, HWR_RippleBlend(gl_frontsector, rover, false) | (rover->blend ? HWR_GetBlendModeFlag(rover->blend) : PF_Translucent), + CLAMP(rover->alpha, 0 ,255), rover->master->frontsector, HWR_RippleBlend(gl_frontsector, rover, false) | (rover->blend ? HWR_GetBlendModeFlag(rover->blend) : static_cast(PF_Translucent)), false, gl_frontsector->lightlist[light].extra_colormap); } else @@ -3125,7 +3125,7 @@ static void HWR_Subsector(size_t num) true, *rover->topheight, *gl_frontsector->lightlist[light].lightlevel, - CLAMP(rover->alpha, 0 ,255), rover->master->frontsector, HWR_RippleBlend(gl_frontsector, rover, false) | (rover->blend ? HWR_GetBlendModeFlag(rover->blend) : PF_Translucent), + CLAMP(rover->alpha, 0 ,255), rover->master->frontsector, HWR_RippleBlend(gl_frontsector, rover, false) | (rover->blend ? HWR_GetBlendModeFlag(rover->blend) : static_cast(PF_Translucent)), false, gl_frontsector->lightlist[light].extra_colormap); } else @@ -5171,7 +5171,7 @@ static void HWR_SkyDomeVertex(gl_sky_t *sky, gl_skyvertex_t *vbo, int r, int c, float z = (realRadius * (float)sin(topAngle)); float timesRepeat = (4 * (256.0f / sky->width)); - if (fpclassify(timesRepeat) == FP_ZERO) + if (std::fpclassify(timesRepeat) == FP_ZERO) timesRepeat = 1.0f; if (!foglayer) From 72a67d306fd7dce569abd8850dbc0374727eb81e Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 30 Jun 2025 08:17:08 +0200 Subject: [PATCH 10/13] slightly cleanup addline stuff no clue why i just didnt do this before lel --- src/hardware/hw_bsp.c | 7 +-- src/hardware/hw_main.cpp | 100 ++++++++++++++++----------------------- src/r_bsp.cpp | 6 +-- src/r_defs.h | 1 + 4 files changed, 50 insertions(+), 64 deletions(-) diff --git a/src/hardware/hw_bsp.c b/src/hardware/hw_bsp.c index 934f13a14..76231750c 100644 --- a/src/hardware/hw_bsp.c +++ b/src/hardware/hw_bsp.c @@ -371,12 +371,13 @@ static poly_t *CutOutSubsecPoly(seg_t *lseg, INT32 count, poly_t *poly) line_t *line = lseg->linedef; // portal check - if (!gl_maphasportals && line->special == 40 && lseg->side == 0) + if (!gl_maphasportals && line->special == PORTALSPECIAL && lseg->side == 0) { // Find the other side! - INT32 line2 = P_FindSpecialLineFromTag(40, line->tag, -1); + INT32 line2 = P_FindSpecialLineFromTag(PORTALSPECIAL, line->tag, -1); + if (line == &lines[line2]) - line2 = P_FindSpecialLineFromTag(40, line->tag, line2); + line2 = P_FindSpecialLineFromTag(PORTALSPECIAL, line->tag, line2); if (line2 >= 0) // found it! gl_maphasportals = 1; } diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index acbd865b8..cef5ec941 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -2327,6 +2327,40 @@ static inline void DoAddLine(seg_t* line, angle_t angle1, angle_t angle2) // SoM: Backsector needs to be run through R_FakeFlat static sector_t tempsec; + auto do_addline = [&](bool dontdraw) { + if (!line->backsector) + { + gld_clipper_SafeAddClipRange(angle2, angle1); + } + else + { + gl_backsector = R_FakeFlat(gl_backsector, &tempsec, NULL, NULL, true); + + if (CheckClip(gl_frontsector, gl_backsector)) + { + gld_clipper_SafeAddClipRange(angle2, angle1); + checkforemptylines = false; + } + + // Reject empty lines used for triggers and special events. + // Identical floor and ceiling on both sides, + // identical light levels on both sides, + // and no middle texture. + if (checkforemptylines && R_IsEmptyLine(line, gl_frontsector, gl_backsector)) + return; + } + + if constexpr (Type == AddLineType::kPortal) + { + if (gl_portal_state != GLPORTAL_SEARCH && !dontdraw)// no need to do this during the portal check + HWR_ProcessSeg(); // Doesn't need arguments because they're defined globally :D + } + else if constexpr (Type == AddLineType::kNormal) + { + HWR_ProcessSeg(); // Doesn't need arguments because they're defined globally :D + } + }; + if constexpr (Type == AddLineType::kPortal) { boolean dont_draw = false; @@ -2343,15 +2377,15 @@ static inline void DoAddLine(seg_t* line, angle_t angle1, angle_t angle2) if (gl_portal_state == GLPORTAL_STENCIL || gl_portal_state == GLPORTAL_DEPTH) goto doaddline; - if (line->linedef->special == 40) + if (line->linedef->special == PORTALSPECIAL) { if (line->side == 0) { // Find the other side! - INT32 line2 = P_FindSpecialLineFromTag(40, line->linedef->tag, -1); + INT32 line2 = P_FindSpecialLineFromTag(PORTALSPECIAL, line->linedef->tag, -1); if (line->linedef == &lines[line2]) - line2 = P_FindSpecialLineFromTag(40, line->linedef->tag, line2); + line2 = P_FindSpecialLineFromTag(PORTALSPECIAL, line->linedef->tag, line2); if (line2 >= 0) // found it! { @@ -2366,59 +2400,11 @@ static inline void DoAddLine(seg_t* line, angle_t angle1, angle_t angle2) } doaddline: - if (!line->backsector) - { - gld_clipper_SafeAddClipRange(angle2, angle1); - } - else - { - gl_backsector = R_FakeFlat(gl_backsector, &tempsec, NULL, NULL, true); - - if (CheckClip(gl_frontsector, gl_backsector)) - { - gld_clipper_SafeAddClipRange(angle2, angle1); - checkforemptylines = false; - } - - // Reject empty lines used for triggers and special events. - // Identical floor and ceiling on both sides, - // identical light levels on both sides, - // and no middle texture. - if (checkforemptylines && R_IsEmptyLine(line, gl_frontsector, gl_backsector)) - return; - } - - if (LIKELY(gl_portal_state != GLPORTAL_SEARCH && !dont_draw))// no need to do this during the portal check - HWR_ProcessSeg(); // Doesn't need arguments because they're defined globally :D - return; + do_addline(dont_draw); // no need to do this during the portal check } - - if constexpr (Type == AddLineType::kNormal) + else if constexpr (Type == AddLineType::kNormal) { - if (!line->backsector) - { - gld_clipper_SafeAddClipRange(angle2, angle1); - } - else - { - gl_backsector = R_FakeFlat(gl_backsector, &tempsec, NULL, NULL, true); - - if (CheckClip(gl_frontsector, gl_backsector)) - { - gld_clipper_SafeAddClipRange(angle2, angle1); - checkforemptylines = false; - } - - // Reject empty lines used for triggers and special events. - // Identical floor and ceiling on both sides, - // identical light levels on both sides, - // and no middle texture. - if (checkforemptylines && R_IsEmptyLine(line, gl_frontsector, gl_backsector)) - return; - } - - HWR_ProcessSeg(); // Doesn't need arguments because they're defined globally :D - return; + do_addline(false); } } @@ -3252,8 +3238,7 @@ static void HWR_RenderBSPNode(INT32 bspnum) if (!(HWR_CheckBBox(bsp->bbox[side^1]) && HWR_PortalCheckBBox(bsp->bbox[side^1]))) return; } - - if constexpr (Type == BspType::kNormal) + else if constexpr (Type == BspType::kNormal) { // Recursively divide front space (toward the viewer). HWR_RenderBSPNode(bsp->children[side]); @@ -5557,8 +5542,7 @@ void HWR_RenderViewpoint(gl_portal_t *rootportal, const float fpov, player_t *pl // woo we back HWR_SetPortalState(oldgl_portal_state); } - - if constexpr (Type == RenderViewpointType::kNormal) + else if constexpr (Type == RenderViewpointType::kNormal) { // Recursively "render" the BSP tree. HWR_RenderBSPNode((INT32)numnodes-1); diff --git a/src/r_bsp.cpp b/src/r_bsp.cpp index f0fb7cb4e..482b7c57f 100644 --- a/src/r_bsp.cpp +++ b/src/r_bsp.cpp @@ -385,15 +385,15 @@ static void R_AddLine(seg_t *line) backsector = line->backsector; // Portal line - if (line->linedef->special == 40 && line->side == 0) + if (line->linedef->special == PORTALSPECIAL && line->side == 0) { if (portalrender < cv_maxportals.value) { // Find the other side! - INT32 line2 = P_FindSpecialLineFromTag(40, line->linedef->tag, -1); + INT32 line2 = P_FindSpecialLineFromTag(PORTALSPECIAL, line->linedef->tag, -1); if (line->linedef == &lines[line2]) - line2 = P_FindSpecialLineFromTag(40, line->linedef->tag, line2); + line2 = P_FindSpecialLineFromTag(PORTALSPECIAL, line->linedef->tag, line2); if (line2 >= 0) // found it! { diff --git a/src/r_defs.h b/src/r_defs.h index c130547db..e1fc574bc 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -420,6 +420,7 @@ typedef enum } slopetype_t; #define HORIZONSPECIAL 41 +#define PORTALSPECIAL 40 typedef struct line_s { From 148fcc8dab66d56a7d64d5285a97fdcf2fe7017c Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 30 Jun 2025 12:07:47 +0200 Subject: [PATCH 11/13] friendship with constexpr started --- src/hardware/hw_main.cpp | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index cef5ec941..9405bdb9a 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -102,10 +102,10 @@ sector_t *gl_backsector; static boolean gl_maphashorizonlines = false; // values for the far clipping plane -static float clipping_distances[] = {1024.0f, 2048.0f, 4096.0f, 6144.0f, 8192.0f, 12288.0f, 16384.0f}; +static constexpr float clipping_distances[] = {1024.0f, 2048.0f, 4096.0f, 6144.0f, 8192.0f, 12288.0f, 16384.0f}; // values for bsp culling // slightly higher than the far clipping plane to compensate for impreciseness -static INT32 bsp_culling_distances[] = {(1024+512)*FRACUNIT, (2048+512)*FRACUNIT, (4096+512)*FRACUNIT, +static constexpr INT32 bsp_culling_distances[] = {(1024+512)*FRACUNIT, (2048+512)*FRACUNIT, (4096+512)*FRACUNIT, (6144+512)*FRACUNIT, (8192+512)*FRACUNIT, (12288+512)*FRACUNIT, (16384+512)*FRACUNIT}; // Performance stats @@ -4155,8 +4155,8 @@ static int CompareVisSprites(const void *p1, const void *p2) // "boolean to int" // check for precip first, because then sprX->mobj is actually a precipmobj_t and does not have flags2 or tracer - int transparency1 = (!spr1->precip && (spr1->mobj->flags2 & MF2_SHADOW)) || (spr1->mobj->frame & FF_TRANSMASK); - int transparency2 = (!spr2->precip && (spr2->mobj->flags2 & MF2_SHADOW)) || (spr2->mobj->frame & FF_TRANSMASK); + const int transparency1 = (!spr1->precip && (spr1->mobj->flags2 & MF2_SHADOW)) || (spr1->mobj->frame & FF_TRANSMASK); + const int transparency2 = (!spr2->precip && (spr2->mobj->flags2 & MF2_SHADOW)) || (spr2->mobj->frame & FF_TRANSMASK); idiff = transparency1 - transparency2; if (idiff != 0) return idiff; @@ -4369,7 +4369,8 @@ static void HWR_RenderDrawNodes(void) for (i = run_start+1; i < numdrawnodes; i++) { - if (drawnodes[sortindex[i]].type != DRAWNODE_PLANE) break; + if (drawnodes[sortindex[i]].type != DRAWNODE_PLANE) + break; } run_end = i-1; @@ -4705,8 +4706,8 @@ static void HWR_ProjectSprite(mobj_t *thing) return; const boolean mirrored = thing->mirrored; - const boolean vflip = (thing->eflags & MFE_VERTICALFLIP); - const boolean hflip = (!(thing->frame & FF_HORIZONTALFLIP) != !mirrored); + const boolean vflip = (thing->eflags & MFE_VERTICALFLIP); + const boolean hflip = (!(thing->frame & FF_HORIZONTALFLIP) != !mirrored); this_scale = FixedToFloat(interp.scale); spritexscale = FixedToFloat(interp.spritexscale); @@ -4723,7 +4724,7 @@ static void HWR_ProjectSprite(mobj_t *thing) #ifdef ROTSPRITE // determine here if sprite should rotate for optimization const boolean sliprollrotate = (cv_sliptideroll.value && (thing->player && thing->player->sliproll)); - const boolean shouldrotate = (interp.sloperoll || interp.slopepitch || interp.roll || interp.pitch || thing->rollangle || sliprollrotate); + const boolean shouldrotate = (interp.sloperoll || interp.slopepitch || interp.roll || interp.pitch || thing->rollangle || sliprollrotate); #endif //Fab : 02-08-98: 'skin' override spritedef currently used for skin @@ -5144,8 +5145,8 @@ static gl_sky_t gl_sky; static void HWR_SkyDomeVertex(gl_sky_t *sky, gl_skyvertex_t *vbo, int r, int c, signed char yflip, float delta, boolean foglayer) { - static const float scale = 10000.0f; - static const float maxSideAngle = DEG2RADGL(60.0f); + static constexpr float scale = 10000.0f; + static constexpr float maxSideAngle = DEG2RADGL(60.0f); float topAngle = DEG2RADGL(c / (float)sky->columns * 360.0f); float sideAngle = (maxSideAngle * (float)(sky->rows - r) / (float)sky->rows); @@ -5285,7 +5286,7 @@ void HWR_BuildSkyDome(void) static boolean drewsky = false; // precompute to save a bit of division -static const float FINEDEGREE = (360.0f/(float)FINEANGLES); +static constexpr float FINEDEGREE = (360.0f/(float)FINEANGLES); static void HWR_DrawSkyBackground(void) { @@ -5512,7 +5513,7 @@ void HWR_RenderViewpoint(gl_portal_t *rootportal, const float fpov, player_t *pl if (HWR_IsWireframeMode()) GL_SetSpecialState(HWD_SET_WIREFRAME, 1); - ps_numbspcalls.value.i = 0; + ps_numbspcalls.value.i = 0; ps_numpolyobjects.value.i = 0; PS_START_TIMING(ps_bsptime); @@ -5584,7 +5585,7 @@ void HWR_RenderViewpoint(gl_portal_t *rootportal, const float fpov, player_t *pl HWR_DrawModels(); PS_STOP_TIMING(ps_hw_spritedrawtime); - ps_numdrawnodes.value.i = 0; + ps_numdrawnodes.value.i = 0; ps_hw_nodesorttime.value.p = 0; ps_hw_nodedrawtime.value.p = 0; HWR_RenderDrawNodes(); @@ -5685,10 +5686,6 @@ static void HWR_RollTransform(FTransform *tr, angle_t roll) void HWR_RenderPlayerView(void) { - player_t * player = &players[displayplayers[viewssnum]]; - - const boolean skybox = (skyboxmo[0] && cv_skybox.value); // True if there's a skybox object and skyboxes are on - // Clear the color buffer, stops HOMs. Also seems to fix the skybox issue on Intel GPUs. if (viewssnum == 0) // Only do it if it's the first screen being rendered { @@ -5719,6 +5716,9 @@ void HWR_RenderPlayerView(void) if (viewssnum > 3) return; + player_t * player = &players[displayplayers[viewssnum]]; + const boolean skybox = (skyboxmo[0] && cv_skybox.value); // True if there's a skybox object and skyboxes are on + // Render the skybox if there is one. PS_START_TIMING(ps_skyboxtime); drewsky = false; @@ -6055,7 +6055,7 @@ static void HWR_DoPostProcessor(player_t *player) //UINT8 viewnum = R_GetViewNumber(); // see below //camera_t *thiscam = &camera[viewnum]; - camera_t *thiscam = &camera[0]; + const camera_t *thiscam = &camera[0]; // Not supported in splitscreen - someone want to add support? const boolean screenwave = (!splitscreen && (thiscam->postimg & POSTIMG_WATER || thiscam->postimg & POSTIMG_HEAT)); From 3f5328371a0c280f954bf64c1a95bc75cbcfaa4f Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 1 Jul 2025 15:26:18 +0200 Subject: [PATCH 12/13] put interp distance stuff into a function just some code dupe cleanup also account for c++ so we can use the same macro lel --- src/hardware/hw_main.cpp | 20 +++----------------- src/hardware/hw_md2.c | 2 +- src/r_things.cpp | 33 ++++++++++++++++----------------- src/r_things.h | 6 ++++++ 4 files changed, 26 insertions(+), 35 deletions(-) diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index 9405bdb9a..c7bba9f2a 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -3517,8 +3517,6 @@ static void HWR_DrawSpriteShadow(gl_vissprite_t *spr, patch_t *gpatch, GLPatch_t } } -#define std_R_QuickCamDist(x, y) std::max(abs(((x)>>FRACBITS) - (viewx>>FRACBITS)), abs(((y)>>FRACBITS) - (viewy>>FRACBITS))) - // This is expecting a pointer to an array containing 4 wallVerts for a sprite static void HWR_RotateSpritePolyToAim(gl_vissprite_t *spr, FOutVector *wallVerts, const boolean precip, const boolean papersprite) { @@ -3530,13 +3528,9 @@ static void HWR_RotateSpritePolyToAim(gl_vissprite_t *spr, FOutVector *wallVerts // uncapped/interpolation interpmobjstate_t interp = {}; float basey, lowy; - INT32 dist = -1; - - if (cv_maxinterpdist.value) - dist = std_R_QuickCamDist(spr->mobj->x, spr->mobj->y); // do interpolation - if (R_UsingFrameInterpolation() && !paused && (!cv_maxinterpdist.value || dist < cv_maxinterpdist.value)) + if (R_UsingFrameInterpolation() && !paused && R_CheckInterpDist(spr->mobj)) { if (precip) { @@ -4647,7 +4641,6 @@ static void HWR_ProjectSprite(mobj_t *thing) angle_t camang = 0; #endif INT32 heightsec, phs; - INT32 dist = -1; fixed_t spr_width, spr_height; fixed_t spr_offset, spr_topoffset; @@ -4664,10 +4657,7 @@ static void HWR_ProjectSprite(mobj_t *thing) // uncapped/interpolation interpmobjstate_t interp = {}; - if (cv_maxinterpdist.value) - dist = std_R_QuickCamDist(thing->x, thing->y); - - if (R_UsingFrameInterpolation() && !paused && (!cv_maxinterpdist.value || dist < cv_maxinterpdist.value)) + if (R_UsingFrameInterpolation() && !paused && R_CheckInterpDist(thing)) { R_InterpolateMobjState(thing, rendertimefrac, &interp); } @@ -5008,7 +4998,6 @@ static void HWR_ProjectPrecipitationSprite(precipmobj_t *thing) size_t lumpoff; unsigned rot = 0; UINT8 flip; - INT32 dist = -1; if (!thing) return; @@ -5022,11 +5011,8 @@ static void HWR_ProjectPrecipitationSprite(precipmobj_t *thing) // uncapped/interpolation interpmobjstate_t interp = {}; - if (cv_maxinterpdist.value) - dist = std_R_QuickCamDist(thing->x, thing->y); - // do interpolation - if (R_UsingFrameInterpolation() && !paused && (!cv_maxinterpdist.value || dist < cv_maxinterpdist.value)) + if (R_UsingFrameInterpolation() && !paused && R_CheckInterpDist((mobj_t*)thing)) { R_InterpolatePrecipMobjState(thing, rendertimefrac, &interp); } diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index 2696cf89d..e1b31bda0 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -1187,7 +1187,7 @@ void HWR_DrawMD2(gl_vissprite_t *spr) spriteinfo_t *sprinfo; interpmobjstate_t interp; - if (R_UsingFrameInterpolation() && !paused && (!cv_maxinterpdist.value || R_QuickCamDist(spr->mobj->x, spr->mobj->y) < cv_maxinterpdist.value)) + if (R_UsingFrameInterpolation() && !paused && R_CheckInterpDist(spr->mobj)) { R_InterpolateMobjState(spr->mobj, rendertimefrac, &interp); } diff --git a/src/r_things.cpp b/src/r_things.cpp index 683904ccb..000139ce1 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -1164,8 +1164,6 @@ fixed_t R_GetSpriteDirectionalLighting(angle_t angle) return extralight; } -#define std_R_QuickCamDist(x, y) std::max(abs(((x)>>FRACBITS) - (viewx>>FRACBITS)), abs(((y)>>FRACBITS) - (viewy>>FRACBITS))) - // // R_ProjectSprite // Generates a vissprite for a thing @@ -1206,7 +1204,6 @@ static void R_ProjectSprite(mobj_t *thing) //SoM: 3/17/2000 fixed_t gz, gzt; INT32 heightsec, phs; - INT32 dist = -1; INT32 light = 0; lighttable_t **lights_array = spritelights; fixed_t this_scale; @@ -1233,14 +1230,11 @@ static void R_ProjectSprite(mobj_t *thing) const boolean hflip = (!(thing->frame & FF_HORIZONTALFLIP) != !mirrored); const boolean papersprite = (thing->frame & FF_PAPERSPRITE); - if (cv_maxinterpdist.value) - dist = std_R_QuickCamDist(thing->x, thing->y); - // uncapped/interpolation interpmobjstate_t interp = {}; // do interpolation - if (R_UsingFrameInterpolation() && !paused && (!cv_maxinterpdist.value || dist < cv_maxinterpdist.value)) + if (R_UsingFrameInterpolation() && !paused && R_CheckInterpDist(oldthing)) { R_InterpolateMobjState(oldthing, rendertimefrac, &interp); } @@ -1862,25 +1856,20 @@ static void R_ProjectPrecipitationSprite(precipmobj_t *thing) fixed_t gz, gzt; fixed_t this_scale; - INT32 dist = 1; - if (!thing || thing->subsector == NULL) return; - if (cv_maxinterpdist.value) - dist = std_R_QuickCamDist(thing->x, thing->y); - - // uncapped/interpolation - interpmobjstate_t interp = {}; - // okay... this is a hack, but weather isn't networked, so it should be ok if (!P_PrecipThinker(thing)) { return; } + // uncapped/interpolation + interpmobjstate_t interp = {}; + // do interpolation - if (R_UsingFrameInterpolation() && !paused && (!cv_maxinterpdist.value || dist < cv_maxinterpdist.value)) + if (R_UsingFrameInterpolation() && !paused && R_CheckInterpDist((mobj_t*)thing)) { R_InterpolatePrecipMobjState(thing, rendertimefrac, &interp); } @@ -2919,7 +2908,7 @@ boolean R_ThingVisible (mobj_t *thing) if (splitscreen) { - if ((viewssnum == 0 && (thing->eflags & MFE_DRAWONLYFORP1)) + if ((viewssnum == 0 && (thing->eflags & MFE_DRAWONLYFORP1)) || (viewssnum == 1 && (thing->eflags & MFE_DRAWONLYFORP2)) || (viewssnum == 2 && (thing->eflags & MFE_DRAWONLYFORP2)) || (viewssnum == 3 && (thing->eflags & MFE_DRAWONLYFORP4))) @@ -2942,6 +2931,16 @@ boolean R_ThingWithinDist(mobj_t *thing, INT32 limit_dist) return true; } +boolean R_CheckInterpDist(mobj_t *thing) +{ + if (!cv_maxinterpdist.value) + return true; + + const INT32 dist = R_QuickCamDist(thing->x, thing->y); + + return (dist < cv_maxinterpdist.value); +} + boolean R_ThingIsFullBright(mobj_t *thing) { return ((thing->frame & FF_BRIGHTMASK) == FF_FULLBRIGHT); diff --git a/src/r_things.h b/src/r_things.h index 45f1fc30e..e7afe7498 100644 --- a/src/r_things.h +++ b/src/r_things.h @@ -39,7 +39,12 @@ extern "C" { // as an non-fixed-point integer. // It is very rough, tho it is used only for optimizing out unnecessary // interpolation, so it is kinda ok on big distances. + +#ifdef __cplusplus +#define R_QuickCamDist(x, y) std::max(std::abs(((x)>>FRACBITS) - (viewx>>FRACBITS)), std::abs(((y)>>FRACBITS) - (viewy>>FRACBITS))) +#else #define R_QuickCamDist(x, y) max(abs(((x)>>FRACBITS) - (viewx>>FRACBITS)), abs(((y)>>FRACBITS) - (viewy>>FRACBITS))) +#endif // Constant arrays used for psprite clipping // and initializing clipping. @@ -84,6 +89,7 @@ void R_DrawMasked(maskcount_t* masks, INT32 nummasks); boolean R_ThingVisible(mobj_t *thing); boolean R_ThingWithinDist(mobj_t *thing, INT32 limit_dist); +boolean R_CheckInterpDist(mobj_t *thing); boolean R_ThingIsFullBright(mobj_t *thing); boolean R_ThingIsSemiBright(mobj_t *thing); From 7e06fc986f2d64e863ff9695678d645956d057ff Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 1 Jul 2025 15:20:26 +0200 Subject: [PATCH 13/13] this is INT32 so cast to that lel --- src/hardware/hw_main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index c7bba9f2a..f266cf64f 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -3893,7 +3893,7 @@ static void HWR_DrawSprite(gl_vissprite_t *spr) return; const boolean papersprite = (spr->mobj->frame & FF_PAPERSPRITE); - sector_t *sector = spr->mobj->subsector->sector; + const sector_t *sector = spr->mobj->subsector->sector; if (sector->numlights) { @@ -3978,13 +3978,13 @@ static void HWR_DrawSprite(gl_vissprite_t *spr) // colormap test INT32 lightlevel = 255; - boolean lightset = HWR_OverrideObjectLightLevel(spr->mobj, &lightlevel); + const boolean lightset = HWR_OverrideObjectLightLevel(spr->mobj, &lightlevel); extracolormap_t *colormap = sector->extra_colormap; const boolean fullbright = R_ThingIsFullBright(spr->mobj); if (!lightset) { - lightlevel = std::min(static_cast(sector->lightlevel), 255); + lightlevel = std::min(static_cast(sector->lightlevel), 255); HWR_ObjectLightLevelPost(spr, sector, &lightlevel, false); }