From d3edc19de9300cbfdf3f3cf3848b596842441520 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 8 Dec 2024 02:10:00 +0100 Subject: [PATCH] Revert "try recursion limit for _RenderBSPNode" This reverts commit 501b8b7bf5e1d90cbb605eeec997b20287999158. --- src/hardware/hw_main.c | 94 ++++++++++++------------------------------ src/r_bsp.c | 89 +++++++++++---------------------------- 2 files changed, 52 insertions(+), 131 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 7a11e2d18..44f0a4b1a 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -3127,87 +3127,47 @@ 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) { - node_t *bsp; - INT32 stack_bsp[MAX_BSP_DEPTH]; - INT32 stack_side[MAX_BSP_DEPTH]; - int sp = 0; + const node_t *bsp; + INT32 side; + ps_numbspcalls.value.i++; - while (true) + while (!(bspnum & NF_SUBSECTOR)) // Found a subsector? { - ps_numbspcalls.value.i++; + 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_PointOnSideFast(viewx, viewy, bsp); - bsp = &nodes[bspnum]; + // Recursively divide front space. + if (HWR_PortalCheckBBox(bsp->bbox[side])) + HWR_RenderBSPNode(bsp->children[side]); - const INT32 side = R_PointOnSideFast(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! + // Possibly divide back space + if (!(HWR_CheckBBox(bsp->bbox[side^1]) && HWR_PortalCheckBBox(bsp->bbox[side^1]))) return; - } - // 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]]; + bspnum = bsp->children[side^1]; } + + // 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); } // ========================================================================== diff --git a/src/r_bsp.c b/src/r_bsp.c index bb7d343fa..f87e10ae8 100644 --- a/src/r_bsp.c +++ b/src/r_bsp.c @@ -1316,78 +1316,39 @@ 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. - -#define MAX_BSP_DEPTH 112 +// +// killough 5/2/98: reformatted, removed tail recursion void R_RenderBSPNode(INT32 bspnum) { - node_t *bsp; - INT32 stack_bsp[MAX_BSP_DEPTH]; - INT32 stack_side[MAX_BSP_DEPTH]; - int sp = 0; + const node_t *bsp; + INT32 side; - while (true) + ps_numbspcalls.value.i++; + + while (!(bspnum & NF_SUBSECTOR)) // Found a subsector? { - // Front sides. - while ((short)bspnum >= 0) - { - if (sp == MAX_BSP_DEPTH) - break; + bsp = &nodes[bspnum]; - bsp = &nodes[bspnum]; - - // Decide which side the view point is on. - const INT32 side = R_PointOnSideFast(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]]; + // Decide which side the view point is on. + side = R_PointOnSideFast(viewx, viewy, bsp); + // Recursively divide front space. + R_RenderBSPNode(bsp->children[side]); // Possibly divide back space. - // 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; - } + if (!R_CheckBBox(bsp->bbox[side^1])) + return; - // Back side next. - - sp--; - - bsp = &nodes[stack_bsp[sp]]; - } - - bspnum = bsp->children[stack_side[sp]]; + bspnum = bsp->children[side^1]; } + + // PORTAL CULLING + if (portalcullsector) + { + if (subsectors[bspnum & ~NF_SUBSECTOR].sector != portalcullsector) + return; + portalcullsector = NULL; + } + + R_Subsector(bspnum == -1 ? 0 : bspnum & ~NF_SUBSECTOR); }