Add sector portals from visplanes while rendering a portal

This commit is contained in:
Lactozilla 2023-08-25 00:47:40 -03:00
parent 87d40fc3cc
commit cf1f310363
3 changed files with 20 additions and 8 deletions

View file

@ -1513,8 +1513,8 @@ void R_RenderPlayerView(player_t *player)
R_ClipSprites(drawsegs, NULL); R_ClipSprites(drawsegs, NULL);
PS_STOP_TIMING(ps_sw_spritecliptime); PS_STOP_TIMING(ps_sw_spritecliptime);
// Add skybox portals caused by sky visplanes. // Add portals caused by visplanes.
Portal_AddSkyboxPortals(); Portal_AddPlanePortals(cv_skybox.value);
// Portal rendering. Hijacks the BSP traversal. // Portal rendering. Hijacks the BSP traversal.
PS_START_TIMING(ps_sw_portaltime); PS_START_TIMING(ps_sw_portaltime);
@ -1559,6 +1559,9 @@ void R_RenderPlayerView(player_t *player)
R_RenderBSPNode((INT32)numnodes - 1); 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]); Mask_Post(&masks[nummasks - 1]);
R_ClipSprites(ds_p - (masks[nummasks - 1].drawsegs[1] - masks[nummasks - 1].drawsegs[0]), portal); R_ClipSprites(ds_p - (masks[nummasks - 1].drawsegs[1] - masks[nummasks - 1].drawsegs[0]), portal);

View file

@ -192,6 +192,7 @@ void Portal_Add2Lines (const INT32 line1, const INT32 line2, const INT32 x1, con
Portal_GetViewpointForLine(portal, start, dest); Portal_GetViewpointForLine(portal, start, dest);
portal->clipline = line2; portal->clipline = line2;
portal->is_skybox = false;
portal->is_horizon = false; portal->is_horizon = false;
portal->horizon_sector = NULL; portal->horizon_sector = NULL;
@ -317,6 +318,7 @@ void Portal_AddSkybox (const visplane_t* plane)
Portal_ClipVisplane(plane, portal); Portal_ClipVisplane(plane, portal);
portal->clipline = -1; portal->clipline = -1;
portal->is_skybox = true;
portal->is_horizon = false; portal->is_horizon = false;
portal->horizon_sector = NULL; portal->horizon_sector = NULL;
@ -396,7 +398,8 @@ void Portal_AddSectorPortal (const visplane_t* plane)
// Shortcut // Shortcut
if (secportal->type == SECPORTAL_SKYBOX) if (secportal->type == SECPORTAL_SKYBOX)
{ {
Portal_AddSkybox(plane); if (skyboxmo[0])
Portal_AddSkybox(plane);
return; return;
} }
@ -409,6 +412,7 @@ void Portal_AddSectorPortal (const visplane_t* plane)
portal->clipline = -1; portal->clipline = -1;
portal->is_horizon = false; portal->is_horizon = false;
portal->is_skybox = false;
portal->horizon_sector = NULL; portal->horizon_sector = NULL;
Portal_GetViewpointForSecPortal(portal, secportal); Portal_GetViewpointForSecPortal(portal, secportal);
@ -426,7 +430,7 @@ void Portal_AddTransferred (UINT32 secportalnum, const INT32 x1, const INT32 x2)
return; return;
portal_t* portal = Portal_Add(x1, x2); portal_t* portal = Portal_Add(x1, x2);
portal->is_skybox = false;
portal->is_horizon = false; portal->is_horizon = false;
portal->horizon_sector = NULL; portal->horizon_sector = NULL;
@ -445,10 +449,10 @@ void Portal_AddTransferred (UINT32 secportalnum, const INT32 x1, const INT32 x2)
portalline = true; 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. * The visplanes are also removed and cleared from the list.
*/ */
void Portal_AddSkyboxPortals (void) void Portal_AddPlanePortals (boolean add_skyboxes)
{ {
visplane_t *pl; visplane_t *pl;
@ -456,6 +460,9 @@ void Portal_AddSkyboxPortals (void)
{ {
for (pl = visplanes[i]; pl; pl = pl->next) for (pl = visplanes[i]; pl; pl = pl->next)
{ {
if (pl->minx >= pl->maxx)
continue;
boolean added_portal = false; boolean added_portal = false;
// Render sector portal if recursiveness limit hasn't been reached // Render sector portal if recursiveness limit hasn't been reached
@ -466,7 +473,7 @@ void Portal_AddSkyboxPortals (void)
} }
// Render skybox portal // 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); Portal_AddSkybox(pl);
added_portal = true; added_portal = true;

View file

@ -34,6 +34,8 @@ typedef struct portal_s
boolean is_horizon; boolean is_horizon;
sector_t *horizon_sector; sector_t *horizon_sector;
boolean is_skybox;
UINT8 pass; /**< Keeps track of the portal's recursion depth. */ UINT8 pass; /**< Keeps track of the portal's recursion depth. */
INT32 clipline; /**< Optional clipline for line-based portals. */ 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_ClipRange (portal_t* portal);
void Portal_ClipApply (const portal_t* portal); void Portal_ClipApply (const portal_t* portal);
void Portal_AddSkyboxPortals (void); void Portal_AddPlanePortals (boolean add_skyboxes);
#endif #endif