Add visplane portal creation functionality and use it to replace the skybox rendering.

https://git.do.srb2.org/STJr/SRB2/-/commit/264386f84257a47fe5480bb6300df02d039a2491
This commit is contained in:
Alug committed 2024-10-25 21:03:27 +02:00
1 parent 27b77c2db4
commit 122bd69069
10 files changed
+125 -78

No files matched your search

+2 -6
View File
@@ -2895,13 +2895,9 @@ boolean P_SetupLevel(boolean skipprecip, boolean reloadinggamestate)
savedata.lives = 0;
}
// assume the skybox is visible on level load.
skyVisible = true;
memset(skyVisiblePerPlayer, true, sizeof(skyVisiblePerPlayer));
if (loadprecip) // uglier hack
{ // to make a newly loaded level start on the second frame.
INT32 buf = gametic % TICQUEUE;
{
INT32 buf = gametic % TICQUEUE; // to make a newly loaded level start on the second frame.
for (i = 0; i < MAXPLAYERS; i++)
{
if (playeringame[i])
+1 -1
View File
@@ -694,7 +694,7 @@ void P_Ticker(boolean run)
if (!player->mo)
continue;
const boolean skybox = (skyVisiblePerPlayer[i] && skyboxmo[0] && cv_skybox.value);
const boolean skybox = (skyboxmo[0] && cv_skybox.value);
if (skybox)
{
-1
View File
@@ -17,7 +17,6 @@
#include "r_state.h"
#include "r_portal.h" // Add seg portals
#include "r_splats.h"
#include "p_local.h" // camera
#include "p_slopes.h"
+2 -1
View File
@@ -25,7 +25,8 @@ extern side_t *sidedef;
extern line_t *linedef;
extern sector_t *frontsector;
extern sector_t *backsector;
extern portal_pair *g_portal; // is curline a portal seg?
typedef struct portal_s portal_t;
extern portal_t *g_portal; // is curline a portal seg?
// drawsegs are allocated on the fly... see r_segs.c
+5 -54
View File
@@ -62,8 +62,6 @@ fixed_t viewx, viewy, viewz;
angle_t viewangle, aimingangle, viewroll;
UINT8 viewssnum;
fixed_t viewcos, viewsin;
boolean skyVisible;
boolean skyVisiblePerPlayer[MAXSPLITSCREENPLAYERS]; // saved values of skyVisible for each splitscreen player
sector_t *viewsector;
player_t *viewplayer;
@@ -1322,10 +1320,6 @@ static void R_PortalFrame(portal_t *portal)
void R_RenderPlayerView(player_t *player)
{
portal_t *portal;
const boolean skybox = (skyboxmo[0] && cv_skybox.value);
UINT8 i;
// if this is display player 1
if (cv_homremoval.value && player == &players[displayplayers[0]])
{
@@ -1349,43 +1343,7 @@ void R_RenderPlayerView(player_t *player)
}
}
// load previous saved value of skyVisible for the player
for (i = 0; i <= splitscreen; i++)
{
if (player != &players[displayplayers[i]])
continue;
skyVisible = skyVisiblePerPlayer[i];
break;
}
Portal_InitList();
PS_START_TIMING(ps_skyboxtime);
if (skybox && skyVisible)
{
R_SkyboxFrame(viewssnum);
R_ClearClipSegs();
R_ClearDrawSegs();
R_ClearPlanes();
R_ClearSprites();
#ifdef FLOORSPLATS
R_ClearVisibleFloorSplats();
#endif
R_RenderBSPNode((INT32)numnodes - 1);
R_ClipSprites();
R_DrawPlanes();
#ifdef FLOORSPLATS
R_DrawVisibleFloorSplats();
#endif
R_DrawMasked();
}
PS_STOP_TIMING(ps_skyboxtime);
R_SetupFrame(viewssnum);
skyVisible = false;
framecount++;
validcount++;
@@ -1411,6 +1369,8 @@ void R_RenderPlayerView(player_t *player)
R_ClearVisibleFloorSplats();
#endif
Portal_InitList();
// The head node is the last node output.
ps_numbspcalls.value.i = ps_numpolyobjects.value.i = ps_numdrawnodes.value.i = 0;
@@ -1428,7 +1388,9 @@ void R_RenderPlayerView(player_t *player)
// Portal rendering. Hijacks the BSP traversal.
if (portal_base)
{
for(portal = portal_base; portal; portal = portal_base)
portal_t *portal;
for (portal = portal_base; portal; portal = portal_base)
{
portalrender = portal->pass; // Recursiveness depth.
@@ -1469,17 +1431,6 @@ void R_RenderPlayerView(player_t *player)
PS_START_TIMING(ps_sw_maskedtime);
R_DrawMasked();
PS_STOP_TIMING(ps_sw_maskedtime);
// save value to skyVisiblePerPlayer
// this is so that P1 can't affect whether P2 can see a skybox or not, or vice versa
for (i = 0; i <= splitscreen; i++)
{
if (player != &players[displayplayers[i]])
continue;
skyVisiblePerPlayer[i] = skyVisible;
break;
}
}
// =========================================================================
+30 -6
View File
@@ -23,6 +23,8 @@
#include "r_state.h"
#include "r_splats.h" // faB(21jan):testing
#include "r_sky.h"
#include "r_portal.h"
#include "v_video.h"
#include "w_wad.h"
#include "z_zone.h"
@@ -629,12 +631,6 @@ static void R_DrawSkyPlane(visplane_t *pl)
INT32 x;
INT32 angle;
if (!newview->sky)
{
skyVisible = true;
return;
}
wallcolfunc = walldrawerfunc;
// use correct aspect ratio scale
@@ -1197,3 +1193,31 @@ 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);
}
+2
View File
@@ -117,4 +117,6 @@ typedef struct planemgr_s
extern visffloor_t ffloor[MAXFFLOORS];
extern INT32 numffloors;
void Portal_AddSkyboxPortals (void);
#endif
+78 -5
View File
@@ -13,7 +13,9 @@
#include "r_portal.h"
#include "r_plane.h"
#include "r_main.h" // viewheight, viewwidth
#include "r_main.h"
#include "doomstat.h"
#include "p_spec.h" // Skybox viewpoints
#include "z_zone.h"
UINT8 portalrender; /**< When rendering a portal, it establishes the depth of the current BSP traversal. */
@@ -25,7 +27,7 @@ portal_t *portal_base, *portal_cap;
line_t *portalclipline;
INT32 portalclipstart, portalclipend;
boolean portalline; // is curline a portal seg?
portal_t *g_portal; // is curline a portal seg?
void Portal_InitList (void)
{
@@ -39,7 +41,7 @@ void Portal_InitList (void)
* the function is called, so it is useful for converting one-sided
* lines into portals.
*/
void Portal_ClipStoreFromRange (portal_t* portal)
void Portal_ClipRange (portal_t* portal)
{
INT32 start = portal->start;
INT32 end = portal->end;
@@ -179,9 +181,80 @@ void Portal_Add2Lines (const INT32 line1, const INT32 line2, const INT32 x1, con
portal->clipline = line2;
Portal_ClipStoreFromRange(portal);
Portal_ClipRange(portal);
portalline = true; // this tells R_StoreWallRange that curline is a portal seg
g_portal = portal; // this tells R_StoreWallRange that curline is a portal seg
}
/** Store the clipping window for a portal using a visplane.
*
* Since visplanes top/bottom windows work in an identical way,
* it can just be copied almost directly.
*/
static void Portal_ClipVisplane (const visplane_t* plane, portal_t* portal)
{
INT16 start = portal->start;
INT16 end = portal->end;
INT32 i;
for (i = 0; i < end - start; i++)
{
portal->ceilingclip[i] = plane->top[i + start];
portal->floorclip[i] = plane->bottom[i + start] + 1;
}
}
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)
{
INT16 start = plane->minx;
INT16 end = plane->maxx + 1;
mapheader_t *mh;
portal_t* portal;
if (!(start < end))
return;
portal = Portal_Add(start, end);
Portal_ClipVisplane(plane, portal);
portal->viewx = skyboxmo[0]->x;
portal->viewy = skyboxmo[0]->y;
portal->viewz = skyboxmo[0]->z;
portal->viewangle = viewangle + skyboxmo[0]->angle;
mh = mapheaderinfo[gamemap-1];
// If a relative viewpoint exists, offset the viewpoint.
if (skyboxmo[1])
{
fixed_t x = 0, y = 0;
if (mh->skybox_scalex > 0)
x = (viewx - skyboxmo[1]->x) / mh->skybox_scalex;
else if (mh->skybox_scalex < 0)
x = (viewx - skyboxmo[1]->x) * -mh->skybox_scalex;
if (mh->skybox_scaley > 0)
y = (viewy - skyboxmo[1]->y) / mh->skybox_scaley;
else if (mh->skybox_scaley < 0)
y = (viewy - skyboxmo[1]->y) * -mh->skybox_scaley;
portal->viewx += x;
portal->viewy += y;
}
if (mh->skybox_scalez > 0)
portal->viewz += viewz / mh->skybox_scalez;
else if (mh->skybox_scalez < 0)
portal->viewz += viewz * -mh->skybox_scalez;
portal->clipline = -1;
}
+5 -2
View File
@@ -12,9 +12,11 @@
/// \brief Software renderer portal struct, functions, linked list extern.
#include "r_data.h"
#include "r_plane.h" // visplanes
/** Portal structure.
/*
* Portal structure for the software renderer.
*/
typedef struct portal_s
{
@@ -44,6 +46,7 @@ extern UINT8 portalrender;
void Portal_InitList (void);
void Portal_Remove (portal_t* portal);
void Portal_Add2Lines (const INT32 line1, const INT32 line2, const INT32 x1, const INT32 x2);
void Portal_AddSkybox (const visplane_t* plane);
void Portal_ClipStoreFromRange (portal_t* portal);
void Portal_ClipRange (portal_t* portal);
void Portal_ClipApply (const portal_t* portal);
-2
View File
@@ -90,8 +90,6 @@ extern side_t *sides;
extern fixed_t viewx, viewy, viewz;
extern angle_t viewangle, aimingangle, viewroll;
extern UINT8 viewssnum; // splitscreen view number
extern boolean viewsky, skyVisible;
extern boolean skyVisiblePerPlayer[MAXSPLITSCREENPLAYERS]; // saved values of skyVisible of each splitscreen player
extern sector_t *viewsector;
extern player_t *viewplayer;
extern UINT8 portalrender;