try recursion limit for _RenderBSPNode

its 112 seems like the best compromise, hope it doesent break maps i didnt test visually or smth
This commit is contained in:
Alug committed 2024-11-15 19:55:23 +01:00
1 parent 99d78d62fb
commit 501b8b7bf5
2 files changed
+131 -50

No files matched your search

+67 -25
View File
@@ -3088,45 +3088,87 @@ static void HWR_Subsector(size_t num)
}
//
// RenderBSPNode
// Renders all subsectors below a given node,
// traversing subtree recursively.
// Just call with BSP root.
#define MAX_BSP_DEPTH 112
static void HWR_RenderBSPNode(INT32 bspnum)
{
ps_numbspcalls.value.i++;
node_t *bsp;
INT32 stack_bsp[MAX_BSP_DEPTH];
INT32 stack_side[MAX_BSP_DEPTH];
int sp = 0;
while (!(bspnum & NF_SUBSECTOR)) // Found a subsector?
while (true)
{
const node_t *bsp = &nodes[bspnum];
ps_numbspcalls.value.i++;
// Decide which side the view point is on.
side = R_PointOnSide(viewx, viewy, bsp);
// Front sides.
while ((short)bspnum >= 0)
{
if (sp == MAX_BSP_DEPTH)
break;
// Recursively divide front space.
if (HWR_PortalCheckBBox(bsp->bbox[side]))
HWR_RenderBSPNode(bsp->children[side]);
bsp = &nodes[bspnum];
// Possibly divide back space
if (!(HWR_CheckBBox(bsp->bbox[side^1]) && HWR_PortalCheckBBox(bsp->bbox[side^1])))
const INT32 side = R_PointOnSide(viewx, viewy, bsp);
stack_bsp[sp] = bspnum;
stack_side[sp] = side ^ 1;
sp++;
bspnum = bsp->children[side];
}
if (portalclipline && portalcullsector)
{
// skip all subsectors encountered before the portal
// destination's front sector
if (portalcullsector != subsectors[bspnum & ~NF_SUBSECTOR].sector)
goto skipsubsector;
else
portalcullsector = NULL;
}
HWR_Subsector(bspnum == -1 ? 0 : bspnum & ~NF_SUBSECTOR);
skipsubsector:
if (sp == 0)
{
// back at root node and not visible. All done!
return;
}
bspnum = bsp->children[side^1];
// Back sides.
sp--;
bsp = &nodes[stack_bsp[sp]];
// Possibly divide back space.
// Walk back up the tree until we find
// a node that has a visible backspace.
while (!(HWR_CheckBBox(bsp->bbox[stack_side[sp]]) && HWR_PortalCheckBBox(bsp->bbox[stack_side[sp]])))
{
if (sp == 0)
{
// back at root node and not visible. All done!
return;
}
// Back side next.
sp--;
bsp = &nodes[stack_bsp[sp]];
}
bspnum = bsp->children[stack_side[sp]];
}
// PORTAL CULLING
if (portalclipline && portalcullsector)
{
// skip all subsectors encountered before the portal
// destination's front sector
if (portalcullsector != subsectors[bspnum & ~NF_SUBSECTOR].sector)
return;
else
portalcullsector = NULL;
}
// e6y: support for extended nodes
HWR_Subsector(bspnum == -1 ? 0 : bspnum & ~NF_SUBSECTOR);
}
// ==========================================================================
+64 -25
View File
@@ -1305,39 +1305,78 @@ INT32 R_GetPlaneLight(sector_t *sector, fixed_t planeheight, boolean underside)
// Renders all subsectors below a given node,
// traversing subtree recursively.
// Just call with BSP root.
//
// killough 5/2/98: reformatted, removed tail recursion
#define MAX_BSP_DEPTH 112
void R_RenderBSPNode(INT32 bspnum)
{
const node_t *bsp;
INT32 side;
node_t *bsp;
INT32 stack_bsp[MAX_BSP_DEPTH];
INT32 stack_side[MAX_BSP_DEPTH];
int sp = 0;
ps_numbspcalls.value.i++;
while (!(bspnum & NF_SUBSECTOR)) // Found a subsector?
while (true)
{
bsp = &nodes[bspnum];
// Front sides.
while ((short)bspnum >= 0)
{
if (sp == MAX_BSP_DEPTH)
break;
// Decide which side the view point is on.
side = R_PointOnSide(viewx, viewy, bsp);
// Recursively divide front space.
R_RenderBSPNode(bsp->children[side]);
bsp = &nodes[bspnum];
// Decide which side the view point is on.
const INT32 side = R_PointOnSide(viewx, viewy, bsp);
stack_bsp[sp] = bspnum;
stack_side[sp] = side ^ 1;
sp++;
bspnum = bsp->children[side];
}
// PORTAL CULLING
if (portalcullsector)
{
if (subsectors[bspnum & ~NF_SUBSECTOR].sector != portalcullsector)
goto skipsubsector;
portalcullsector = NULL;
}
R_Subsector(bspnum == -1 ? 0 : bspnum & ~NF_SUBSECTOR);
skipsubsector:
if (sp == 0)
{
// back at root node and not visible. All done!
return;
}
// Back sides.
sp--;
bsp = &nodes[stack_bsp[sp]];
// Possibly divide back space.
if (!R_CheckBBox(bsp->bbox[side^1]))
return;
// Walk back up the tree until we find
// a node that has a visible backspace.
while (!R_CheckBBox(bsp->bbox[stack_side[sp]]))
{
if (sp == 0)
{
// back at root node and not visible. All done!
return;
}
bspnum = bsp->children[side^1];
// Back side next.
sp--;
bsp = &nodes[stack_bsp[sp]];
}
bspnum = bsp->children[stack_side[sp]];
}
// PORTAL CULLING
if (portalcullsector)
{
if (subsectors[bspnum & ~NF_SUBSECTOR].sector != portalcullsector)
return;
portalcullsector = NULL;
}
R_Subsector(bspnum == -1 ? 0 : bspnum & ~NF_SUBSECTOR);
}