diff --git a/include/qbsp/solidbsp.hh b/include/qbsp/solidbsp.hh index ff6b06f8..414a05ca 100644 --- a/include/qbsp/solidbsp.hh +++ b/include/qbsp/solidbsp.hh @@ -22,7 +22,9 @@ #ifndef QBSP_SOLIDBSP_HH #define QBSP_SOLIDBSP_HH -extern int splitnodes; +#include + +extern std::atomic splitnodes; void DetailToSolid(node_t *node); int Contents_Priority(int contents); diff --git a/qbsp/portals.cc b/qbsp/portals.cc index 35e80930..6dd477f2 100644 --- a/qbsp/portals.cc +++ b/qbsp/portals.cc @@ -667,7 +667,7 @@ CutNodePortals_r(node_t *node, portal_state_t *state) /* Display progress */ state->iNodesDone++; - Message(msgPercent, state->iNodesDone, splitnodes); + Message(msgPercent, state->iNodesDone, splitnodes.load()); CutNodePortals_r(front, state); CutNodePortals_r(back, state); diff --git a/qbsp/solidbsp.cc b/qbsp/solidbsp.cc index c9bad28f..e482eec9 100644 --- a/qbsp/solidbsp.cc +++ b/qbsp/solidbsp.cc @@ -23,14 +23,16 @@ #include +#include + #include "tbb/task_group.h" -int splitnodes; +std::atomic splitnodes; -static int leaffaces; -static int nodefaces; -static int c_solid, c_empty, c_water, c_detail, c_detail_illusionary, c_detail_fence; -static int c_illusionary_visblocker; +static std::atomic leaffaces; +static std::atomic nodefaces; +static std::atomic c_solid, c_empty, c_water, c_detail, c_detail_illusionary, c_detail_fence; +static std::atomic c_illusionary_visblocker; static bool usemidsplit; /** @@ -462,6 +464,8 @@ SelectPartition Selects a surface from a linked list of surfaces to split the group on returns NULL if the surface list can not be divided any more (a leaf) + +Called in parallel. ================== */ static surface_t * @@ -782,7 +786,9 @@ int Contents_Priority(int contents) LinkConvexFaces Determines the contents of the leaf and creates the final list of -original faces that have some fragment inside this leaf +original faces that have some fragment inside this leaf. + +Called in parallel. ================== */ static void @@ -879,7 +885,9 @@ First subdivides surface->faces. Then, duplicates the list of subdivided faces and returns it. For each surface->faces, ->original is set to the respective duplicate that -is returned here (why?) +is returned here (why?). + +Called in parallel. ================== */ static face_t * @@ -913,6 +921,8 @@ LinkNodeFaces(surface_t *surface) /* ================== PartitionSurfaces + +Called in parallel. ================== */ static void @@ -929,7 +939,7 @@ PartitionSurfaces(surface_t *surfaces, node_t *node) } splitnodes++; - Message(msgPercent, splitnodes, csgmergefaces); + Message(msgPercent, splitnodes.load(), csgmergefaces); node->faces = LinkNodeFaces(split); node->children[0] = (node_t *)AllocMem(NODE, 1, true); @@ -1041,16 +1051,16 @@ SolidBSP(const mapentity_t *entity, surface_t *surfhead, bool midsplit) PartitionSurfaces(surfhead, headnode); - Message(msgStat, "%8d split nodes", splitnodes); - Message(msgStat, "%8d solid leafs", c_solid); - Message(msgStat, "%8d empty leafs", c_empty); - Message(msgStat, "%8d water leafs", c_water); - Message(msgStat, "%8d detail leafs", c_detail); - Message(msgStat, "%8d detail illusionary leafs", c_detail_illusionary); - Message(msgStat, "%8d detail fence leafs", c_detail_fence); - Message(msgStat, "%8d illusionary visblocker leafs", c_illusionary_visblocker); - Message(msgStat, "%8d leaffaces", leaffaces); - Message(msgStat, "%8d nodefaces", nodefaces); + Message(msgStat, "%8d split nodes", splitnodes.load()); + Message(msgStat, "%8d solid leafs", c_solid.load()); + Message(msgStat, "%8d empty leafs", c_empty.load()); + Message(msgStat, "%8d water leafs", c_water.load()); + Message(msgStat, "%8d detail leafs", c_detail.load()); + Message(msgStat, "%8d detail illusionary leafs", c_detail_illusionary.load()); + Message(msgStat, "%8d detail fence leafs", c_detail_fence.load()); + Message(msgStat, "%8d illusionary visblocker leafs", c_illusionary_visblocker.load()); + Message(msgStat, "%8d leaffaces", leaffaces.load()); + Message(msgStat, "%8d nodefaces", nodefaces.load()); return headnode; } diff --git a/qbsp/surfaces.cc b/qbsp/surfaces.cc index 7dba31d2..d822db5e 100644 --- a/qbsp/surfaces.cc +++ b/qbsp/surfaces.cc @@ -409,7 +409,7 @@ MakeFaceEdges_r(mapentity_t *entity, node_t *node, int progress) FindFaceEdges(entity, f); } - Message(msgPercent, ++progress, splitnodes); + Message(msgPercent, ++progress, splitnodes.load()); progress = MakeFaceEdges_r(entity, node->children[0], progress); progress = MakeFaceEdges_r(entity, node->children[1], progress); diff --git a/qbsp/util.cc b/qbsp/util.cc index 618be54b..8ae9c33c 100644 --- a/qbsp/util.cc +++ b/qbsp/util.cc @@ -206,6 +206,8 @@ FreeAllMem(void) /* Keep track of output state */ static bool fInPercent = false; +std::mutex messageLock; + /* ================= Message @@ -216,6 +218,8 @@ Generic output of warnings, stats, etc void Message(int msgType, ...) { + std::unique_lock lck { messageLock }; + va_list argptr; char szBuffer[512]; char *szFmt;