From cf1f3103636b5221924c625145c2ddeb02833c27 Mon Sep 17 00:00:00 2001 From: Lactozilla Date: Fri, 25 Aug 2023 00:47:40 -0300 Subject: [PATCH] Add sector portals from visplanes while rendering a portal --- src/r_main.c | 7 +++++-- src/r_portal.c | 17 ++++++++++++----- src/r_portal.h | 4 +++- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/r_main.c b/src/r_main.c index c73039c2a..c999b0f5e 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -1513,8 +1513,8 @@ void R_RenderPlayerView(player_t *player) R_ClipSprites(drawsegs, NULL); PS_STOP_TIMING(ps_sw_spritecliptime); - // Add skybox portals caused by sky visplanes. - Portal_AddSkyboxPortals(); + // Add portals caused by visplanes. + Portal_AddPlanePortals(cv_skybox.value); // Portal rendering. Hijacks the BSP traversal. PS_START_TIMING(ps_sw_portaltime); @@ -1559,6 +1559,9 @@ void R_RenderPlayerView(player_t *player) R_RenderBSPNode((INT32)numnodes - 1); } + // Don't add skybox portals while IN a skybox portal, because that'll cause infinite recursion + Portal_AddPlanePortals(!portal->is_skybox); + Mask_Post(&masks[nummasks - 1]); R_ClipSprites(ds_p - (masks[nummasks - 1].drawsegs[1] - masks[nummasks - 1].drawsegs[0]), portal); diff --git a/src/r_portal.c b/src/r_portal.c index bb40b2c80..ffa5d1a0d 100644 --- a/src/r_portal.c +++ b/src/r_portal.c @@ -192,6 +192,7 @@ void Portal_Add2Lines (const INT32 line1, const INT32 line2, const INT32 x1, con Portal_GetViewpointForLine(portal, start, dest); portal->clipline = line2; + portal->is_skybox = false; portal->is_horizon = false; portal->horizon_sector = NULL; @@ -317,6 +318,7 @@ void Portal_AddSkybox (const visplane_t* plane) Portal_ClipVisplane(plane, portal); portal->clipline = -1; + portal->is_skybox = true; portal->is_horizon = false; portal->horizon_sector = NULL; @@ -396,7 +398,8 @@ void Portal_AddSectorPortal (const visplane_t* plane) // Shortcut if (secportal->type == SECPORTAL_SKYBOX) { - Portal_AddSkybox(plane); + if (skyboxmo[0]) + Portal_AddSkybox(plane); return; } @@ -409,6 +412,7 @@ void Portal_AddSectorPortal (const visplane_t* plane) portal->clipline = -1; portal->is_horizon = false; + portal->is_skybox = false; portal->horizon_sector = NULL; Portal_GetViewpointForSecPortal(portal, secportal); @@ -426,7 +430,7 @@ void Portal_AddTransferred (UINT32 secportalnum, const INT32 x1, const INT32 x2) return; portal_t* portal = Portal_Add(x1, x2); - + portal->is_skybox = false; portal->is_horizon = false; portal->horizon_sector = NULL; @@ -445,10 +449,10 @@ void Portal_AddTransferred (UINT32 secportalnum, const INT32 x1, const INT32 x2) portalline = true; } -/** Creates portals for the currently existing sky visplanes. +/** Creates portals for the currently existing portal visplanes. * The visplanes are also removed and cleared from the list. */ -void Portal_AddSkyboxPortals (void) +void Portal_AddPlanePortals (boolean add_skyboxes) { visplane_t *pl; @@ -456,6 +460,9 @@ void Portal_AddSkyboxPortals (void) { for (pl = visplanes[i]; pl; pl = pl->next) { + if (pl->minx >= pl->maxx) + continue; + boolean added_portal = false; // Render sector portal if recursiveness limit hasn't been reached @@ -466,7 +473,7 @@ void Portal_AddSkyboxPortals (void) } // Render skybox portal - if (!added_portal && pl->picnum == skyflatnum && cv_skybox.value && skyboxmo[0]) + if (!added_portal && pl->picnum == skyflatnum && add_skyboxes && skyboxmo[0]) { Portal_AddSkybox(pl); added_portal = true; diff --git a/src/r_portal.h b/src/r_portal.h index 69ecb8d7f..b3c4b0edc 100644 --- a/src/r_portal.h +++ b/src/r_portal.h @@ -34,6 +34,8 @@ typedef struct portal_s boolean is_horizon; sector_t *horizon_sector; + boolean is_skybox; + UINT8 pass; /**< Keeps track of the portal's recursion depth. */ INT32 clipline; /**< Optional clipline for line-based portals. */ @@ -63,5 +65,5 @@ void Portal_AddTransferred (UINT32 secportalnum, const INT32 x1, const INT32 x2) void Portal_ClipRange (portal_t* portal); void Portal_ClipApply (const portal_t* portal); -void Portal_AddSkyboxPortals (void); +void Portal_AddPlanePortals (boolean add_skyboxes); #endif