Refactored a bit of code regarding visplane bound trimming for portals; reset ffloor's f_clip/c_clip so that FOFs on portals don't interfere with previously acquired bounds.

This commit is contained in:
Nev3r 2019-06-07 13:10:12 +02:00
parent d2692ddd24
commit 8c3ddd61d5
5 changed files with 73 additions and 48 deletions

View File

@ -1081,6 +1081,7 @@ void R_RenderPlayerView(player_t *player)
// Portal rendering. Hijacks the BSP traversal.
if (portal_base)
{
INT32 i, p;
portal_t *portal;
for(portal = portal_base; portal; portal = portal_base)
@ -1113,6 +1114,16 @@ void R_RenderPlayerView(player_t *player)
masks[nummasks - 1].viewsector = viewsector;
curdrawsegs = ds_p;
// opening / clipping determination
for (i = 0; i < viewwidth; i++)
{
for (p = 0; p < MAXFFLOORS; p++)
{
ffloor[p].f_clip[i] = (INT16)viewheight;
ffloor[p].c_clip[i] = -1;
}
}
R_RenderBSPNode((INT32)numnodes - 1);
masks[nummasks - 1].drawsegs[1] = ds_p - drawsegs;
masks[nummasks - 1].vissprites[1] = visspritecount;

View File

@ -45,9 +45,8 @@
//#define QUINCUNX
//SoM: 3/23/2000: Use Boom visplane hashing.
#define MAXVISPLANES 512
static visplane_t *visplanes[MAXVISPLANES];
visplane_t *visplanes[MAXVISPLANES];
static visplane_t *freetail;
static visplane_t **freehead = &freetail;
@ -1178,31 +1177,3 @@ void R_PlaneBounds(visplane_t *plane)
plane->high = hi;
plane->low = low;
}
/** Creates portals for the currently existing sky visplanes.
* The visplanes are also removed and cleared from the list.
*/
void Portal_AddSkyboxPortals (void)
{
visplane_t *pl;
INT32 i;
UINT16 count = 0;
for (i = 0; i < MAXVISPLANES; i++, pl++)
{
for (pl = visplanes[i]; pl; pl = pl->next)
{
if (pl->picnum == skyflatnum)
{
Portal_AddSkybox(pl);
pl->minx = 0;
pl->maxx = -1;
count++;
}
}
}
CONS_Debug(DBG_RENDER, "Skybox portals: %d\n", count);
}

View File

@ -18,6 +18,8 @@
#include "r_data.h"
#include "p_polyobj.h"
#define MAXVISPLANES 512
//
// Now what is a visplane, anyway?
// Simple: kinda floor/ceiling polygon optimised for SRB2 rendering.
@ -53,6 +55,7 @@ typedef struct visplane_s
#endif
} visplane_t;
extern visplane_t *visplanes[MAXVISPLANES];
extern visplane_t *floorplane;
extern visplane_t *ceilingplane;

View File

@ -18,6 +18,7 @@
#include "p_spec.h" // Skybox viewpoints
#include "z_zone.h"
#include "r_things.h"
#include "r_sky.h"
UINT8 portalrender; /**< When rendering a portal, it establishes the depth of the current BSP traversal. */
sector_t *portalcullsector;
@ -215,25 +216,19 @@ static void Portal_ClipVisplane (const visplane_t* plane, portal_t* portal)
extern INT32 viewwidth;
/** Creates a skybox portal out of a visplane.
*
* Applies the necessary offsets and rotation to give
* a depth illusion to the skybox.
*/
void Portal_AddSkybox (const visplane_t* plane)
static boolean TrimVisplaneBounds (const visplane_t* plane, INT16* start, INT16* end)
{
INT16 start = plane->minx;
INT16 end = plane->maxx + 1;
mapheader_t *mh;
portal_t* portal;
*start = plane->minx;
*end = plane->maxx + 1;
// Visplanes have 1-px pads on their sides (extra columns).
// Trim them, else it may render out of bounds.
if (end > viewwidth)
end = viewwidth;
if (*end > viewwidth)
*end = viewwidth;
if (!(*start < *end))
return true;
if (!(start < end))
return;
/** Trims a visplane's horizontal gap to match its render area.
*
@ -242,17 +237,33 @@ void Portal_AddSkybox (const visplane_t* plane)
* valid area.
*/
while (plane->bottom[start] == 0 && plane->top[start] == 65535 && start < end)
while (plane->bottom[*start] == 0 && plane->top[*start] == 65535 && *start < *end)
{
start++;
(*start)++;
}
while (plane->bottom[end - 1] == 0 && plane->top[start] == 65535 && end > start)
while (plane->bottom[*end - 1] == 0 && plane->top[*start] == 65535 && *end > *start)
{
end--;
(*end)--;
}
return false;
}
/** Creates a skybox portal out of a visplane.
*
* Applies the necessary offsets and rotation to give
* a depth illusion to the skybox.
*/
void Portal_AddSkybox (const visplane_t* plane)
{
INT16 start, end;
mapheader_t *mh;
portal_t* portal;
if (TrimVisplaneBounds(plane, &start, &end))
return;
portal = Portal_Add(start, end);
@ -291,3 +302,31 @@ void Portal_AddSkybox (const visplane_t* plane)
portal->clipline = -1;
}
/** Creates portals for the currently existing sky visplanes.
* The visplanes are also removed and cleared from the list.
*/
void Portal_AddSkyboxPortals (void)
{
visplane_t *pl;
INT32 i;
UINT16 count = 0;
for (i = 0; i < MAXVISPLANES; i++, pl++)
{
for (pl = visplanes[i]; pl; pl = pl->next)
{
if (pl->picnum == skyflatnum)
{
Portal_AddSkybox(pl);
pl->minx = 0;
pl->maxx = -1;
count++;
}
}
}
CONS_Debug(DBG_RENDER, "Skybox portals: %d\n", count);
}

View File

@ -56,4 +56,5 @@ void Portal_AddSkybox (const visplane_t* plane);
void Portal_ClipRange (portal_t* portal);
void Portal_ClipApply (const portal_t* portal);
void Portal_AddSkyboxPortals (void);
#endif