From ef530c2f7d2eb5aece25f8a6c727f7bf2647e65f Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 1 Jul 2025 21:15:17 +0200 Subject: [PATCH] tiny optimizations hw_main again --- src/hardware/hw_main.cpp | 53 ++++++++++++++++++---------------------- src/hardware/hw_main.h | 4 +-- src/hardware/hw_portal.c | 10 +++++--- src/r_things.cpp | 4 +-- 4 files changed, 34 insertions(+), 37 deletions(-) diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index e938d1867..902c5f9f6 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -739,10 +739,10 @@ static void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, bool UINT8 numplanes, j; vertex_t v; // For determining the closest distance from the line to the camera, to split render planes for minimum distortion; - const float renderdist = 27000.0f; // How far out to properly render the plane - const float farrenderdist = 32768.0f; // From here, raise plane to horizon level to fill in the line with some texture distortion + static constexpr float renderdist = 27000.0f; // How far out to properly render the plane + static constexpr float farrenderdist = 32768.0f; // From here, raise plane to horizon level to fill in the line with some texture distortion - seg_t *line = &segs[subsector->firstline]; + const seg_t *line = &segs[subsector->firstline]; for (i = 0; i < subsector->numlines; i++, line++) { @@ -1083,12 +1083,12 @@ static void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, else solid = false; - height = FixedToFloat(P_GetLightZAt(&list[i], v1x, v1y)); + height = FixedToFloat(P_GetLightZAt(&list[i], v1x, v1y)); endheight = FixedToFloat(P_GetLightZAt(&list[i], v2x, v2y)); if (solid) { - bheight = FixedToFloat(P_GetFFloorBottomZAt(list[i].caster, v1x, v1y)); + bheight = FixedToFloat(P_GetFFloorBottomZAt(list[i].caster, v1x, v1y)); endbheight = FixedToFloat(P_GetFFloorBottomZAt(list[i].caster, v2x, v2y)); } @@ -1096,6 +1096,7 @@ static void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, { if (solid && top > bheight) top = bheight; + if (solid && endtop > endbheight) endtop = endbheight; } @@ -1111,15 +1112,12 @@ static void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, endbheight = endrealbot; } - if (endbheight >= endtop) - continue; - - 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 = CLAMP(bheight, realbot, top); + bot = CLAMP(bheight, realbot, top); endbot = CLAMP(endbheight, endrealbot, endtop); Surf->PolyColor.s.alpha = alpha; @@ -1148,6 +1146,7 @@ static void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, bot = realbot; endbot = endrealbot; + if ((endtop <= endrealbot) && (top <= realbot)) return; @@ -1388,7 +1387,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom // x offset the texture fixed_t texturehpeg = gl_sidedef->textureoffset + gl_curline->offset; - float cliplow = (float)texturehpeg; + float cliplow = (float)texturehpeg; float cliphigh = (float)(texturehpeg + (gl_curline->flength*FRACUNIT)); FUINT lightnum = gl_frontsector->lightlevel; @@ -2944,7 +2943,7 @@ static void HWR_Subsector(size_t num) if (sub->validcount == validcount) continue; - sector_t *controlSec = §ors[rover->secnum]; + const sector_t *controlSec = §ors[rover->secnum]; if (!controlSec->moved) continue; @@ -3637,10 +3636,10 @@ static void HWR_SplitSprite(gl_vissprite_t *spr, const boolean papersprite) hwrpatch = ((GLPatch_t *)gpatch->hardware); // Draw shadow BEFORE sprite - if (cv_shadow.value // Shadows enabled + if (UNLIKELY(cv_shadow.value // Shadows enabled && (spr->mobj->flags & (MF_SCENERY|MF_SPAWNCEILING|MF_NOGRAVITY)) != (MF_SCENERY|MF_SPAWNCEILING|MF_NOGRAVITY) // Ceiling scenery have no shadow. && !(spr->mobj->flags2 & MF2_DEBRIS) // Debris have no corona or shadow. - && (spr->mobj->z >= spr->mobj->floorz)) // Without this, your shadow shows on the floor, even after you die and fall through the ground. + && (spr->mobj->z >= spr->mobj->floorz))) // Without this, your shadow shows on the floor, even after you die and fall through the ground. { //////////////////// // SHADOW SPRITE! // @@ -3751,7 +3750,7 @@ 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); + const fixed_t h = P_GetLightZAt(§or->lightlist[i], spr->mobj->x, spr->mobj->y); if (!(h <= temp)) continue; @@ -3796,10 +3795,7 @@ static void HWR_SplitSprite(gl_vissprite_t *spr, const boolean papersprite) endbheight = endrealbot; } - if (endbheight >= endtop) - continue; - - if (bheight >= top) + if ((endbheight >= endtop) || (bheight >= top)) continue; // Found a break @@ -3958,10 +3954,10 @@ static void HWR_DrawSprite(gl_vissprite_t *spr) } // Draw shadow BEFORE sprite - if (cv_shadow.value // Shadows enabled + if (UNLIKELY(cv_shadow.value // Shadows enabled && (spr->mobj->flags & (MF_SCENERY|MF_SPAWNCEILING|MF_NOGRAVITY)) != (MF_SCENERY|MF_SPAWNCEILING|MF_NOGRAVITY) // Ceiling scenery have no shadow. && !(spr->mobj->flags2 & MF2_DEBRIS) // Debris have no corona or shadow. - && (spr->mobj->z >= spr->mobj->floorz)) // Without this, your shadow shows on the floor, even after you die and fall through the ground. + && (spr->mobj->z >= spr->mobj->floorz))) // Without this, your shadow shows on the floor, even after you die and fall through the ground. { //////////////////// // SHADOW SPRITE! // @@ -4583,7 +4579,7 @@ static void HWR_AddPrecipitationSprites(void) drawdist = ((fixed_t)(cv_drawdist_precip.value) * (cv_mobjscaleprecip.value ? mapobjectscale : FRACUNIT)); // No to infinite precipitation draw distance. - if (drawdist == 0) + if (cv_drawdist_precip.value == 0) { return; } @@ -5439,10 +5435,11 @@ namespace }; template -void HWR_RenderViewpoint(gl_portal_t *rootportal, const float fpov, player_t *player, int stencil_level, boolean allow_portals) +void HWR_RenderViewpoint(gl_portal_t *rootportal, player_t *player, int stencil_level, boolean allow_portals) { gl_portallist_t portallist; + const float fpov = FixedToFloat(R_GetPlayerFov(player)); const boolean skybox = (skyboxmo[0] && cv_skybox.value); portallist.base = portallist.cap = NULL; @@ -5584,8 +5581,8 @@ void HWR_RenderViewpoint(gl_portal_t *rootportal, const float fpov, player_t *pl }; 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); + void HWR_RenderPortalViewpoint(gl_portal_t *rootportal, player_t *player, int stencil_level, boolean allow_portals) { + HWR_RenderViewpoint(rootportal, player, stencil_level, allow_portals); } } @@ -5594,8 +5591,6 @@ extern "C" { // ========================================================================== static void HWR_RenderFrame(player_t *player, boolean skybox) { - const float fpov = FixedToFloat(R_GetPlayerFov(player)); - // set window position gl_viewwindowx = gl_baseviewwindowx; gl_viewwindowy = gl_baseviewwindowy; @@ -5635,9 +5630,9 @@ static void HWR_RenderFrame(player_t *player, boolean skybox) portalclipline = NULL; if (UNLIKELY(HWR_UsePortals())) - HWR_RenderViewpoint(NULL, fpov, player, 0, !skybox); + HWR_RenderViewpoint(NULL, player, 0, !skybox); else - HWR_RenderViewpoint(NULL, fpov, player, 0, !skybox); + HWR_RenderViewpoint(NULL, 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 7681309c1..2ffbfd506 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -109,8 +109,8 @@ void HWR_SetViewSize(void); 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_RenderViewpoint(gl_portal_t *rootportal, player_t *player, int stencil_level, boolean allow_portals); +void HWR_RenderPortalViewpoint(gl_portal_t *rootportal, 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 939a60300..909214171 100644 --- a/src/hardware/hw_portal.c +++ b/src/hardware/hw_portal.c @@ -45,8 +45,8 @@ static gl_portal_t* HWR_Portal_Add (seg_t *seg) // Linked list. if (!currentportallist->base) { - currentportallist->base = portal; - currentportallist->cap = portal; + currentportallist->base = portal; + currentportallist->cap = portal; } else { @@ -146,7 +146,7 @@ static void HWR_RenderPortalSeg(gl_portal_t* portal, SINT8 state) gl_curline = portal->seg; gl_frontsector = portal->seg->frontsector; - gl_backsector = portal->seg->backsector; + gl_backsector = portal->seg->backsector; HWR_ProcessSeg(); gl_drawing_stencil = false; @@ -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_RenderPortalViewpoint(portal, fpov, player, stencil_level + 1, true); + HWR_RenderPortalViewpoint(portal, player, stencil_level + 1, true); // return to current frame if (rootportal) HWR_PortalFrame(rootportal); @@ -202,7 +202,9 @@ boolean HWR_PortalCheckPointSide(fixed_t x, fixed_t y) // so first check if the point is precisely on the line, and then if not, check the side. vertex_t closest_point; + P_ClosestPointOnLine(x, y, portalclipline, &closest_point); + if (closest_point.x != x || closest_point.y != y) { if (P_PointOnLineSide(x, y, portalclipline) != 1) diff --git a/src/r_things.cpp b/src/r_things.cpp index 000139ce1..a502159b5 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -2901,12 +2901,12 @@ void R_ClipSprites(drawseg_t* dsstart, portal_t* portal) } /* Check if thing may be drawn from our current view. */ -boolean R_ThingVisible (mobj_t *thing) +boolean R_ThingVisible(mobj_t *thing) { if (UNLIKELY((thing->sprite == SPR_NULL) || (thing->flags2 & MF2_DONTDRAW))) return false; - if (splitscreen) + if (UNLIKELY(splitscreen)) { if ((viewssnum == 0 && (thing->eflags & MFE_DRAWONLYFORP1)) || (viewssnum == 1 && (thing->eflags & MFE_DRAWONLYFORP2))