diff --git a/include/qbsp/portals.hh b/include/qbsp/portals.hh index 2aa377eb..7d3f36aa 100644 --- a/include/qbsp/portals.hh +++ b/include/qbsp/portals.hh @@ -50,7 +50,13 @@ public: bool uses_detail; }; +struct portalstats_t { + std::atomic c_tinyportals; +}; + contentflags_t ClusterContents(const node_t *node); +void MakeNodePortal(node_t *node, portalstats_t &stats); +void SplitNodePortals(node_t *node, portalstats_t &stats); void MakeTreePortals(tree_t *tree); void FreeTreePortals_r(node_t *node); void AssertNoPortals(node_t *node); diff --git a/qbsp/portals.cc b/qbsp/portals.cc index a6ea2af6..e5f8253a 100644 --- a/qbsp/portals.cc +++ b/qbsp/portals.cc @@ -262,10 +262,6 @@ std::optional BaseWindingForNode(node_t *node) return w; } -struct portalstats_t { - std::atomic c_tinyportals; -}; - /* ================== MakeNodePortal diff --git a/qbsp/prtfile.cc b/qbsp/prtfile.cc index 4c8dd0bc..d091c848 100644 --- a/qbsp/prtfile.cc +++ b/qbsp/prtfile.cc @@ -28,6 +28,8 @@ #include #include +#include "tbb/task_group.h" + /* ============================================================================== @@ -263,6 +265,27 @@ static void WritePortalfile(node_t *headnode, portal_state_t *state) } } +/* +================ +CreateVisPortals_r +================ +*/ +void CreateVisPortals_r(node_t *node, portalstats_t &stats) +{ + // stop as soon as we get to a detail_seperator, which + // means that everything below is in a single cluster + if (node->planenum == PLANENUM_LEAF || node->detail_separator ) + return; + + MakeNodePortal(node, stats); + SplitNodePortals(node, stats); + + tbb::task_group g; + g.run([&]() { CreateVisPortals_r(node->children[0], stats); }); + g.run([&]() { CreateVisPortals_r(node->children[1], stats); }); + g.wait(); +} + /* ================== WritePortalFile