diff --git a/src/r_main.c b/src/r_main.c index 244b96cae..70c271f5d 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -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; diff --git a/src/r_plane.c b/src/r_plane.c index 18e5fda52..2c2fe3432 100644 --- a/src/r_plane.c +++ b/src/r_plane.c @@ -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); -} diff --git a/src/r_plane.h b/src/r_plane.h index c101e3218..a269fed6a 100644 --- a/src/r_plane.h +++ b/src/r_plane.h @@ -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; diff --git a/src/r_portal.c b/src/r_portal.c index 0c0a34b7d..ad5d32e70 100644 --- a/src/r_portal.c +++ b/src/r_portal.c @@ -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); +} diff --git a/src/r_portal.h b/src/r_portal.h index f7d2fb2fe..e5ff0fb9f 100644 --- a/src/r_portal.h +++ b/src/r_portal.h @@ -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