diff --git a/include/qbsp/csg4.hh b/include/qbsp/csg4.hh index 12cade7b..7a284569 100644 --- a/include/qbsp/csg4.hh +++ b/include/qbsp/csg4.hh @@ -24,8 +24,6 @@ #include #include -extern int csgmergefaces; - int MakeSkipTexinfo(); face_t *NewFaceFromFace(const face_t *in); face_t *MirrorFace(const face_t *face); diff --git a/qbsp/csg4.cc b/qbsp/csg4.cc index fa9f0dcf..5c29e077 100644 --- a/qbsp/csg4.cc +++ b/qbsp/csg4.cc @@ -443,33 +443,35 @@ static void SaveInsideFaces(const std::list &faces, const brush_t &cli /* ================== -CopyBrushFaces +BrushIndexInMap -fixme-brushbsp: remove +Returns the index of the brush in the .map files. +Only call with an "original" brush (from entity->brushes). +Used for clipping priority. ================== */ -static std::list CopyBrushFaces(const brush_t &brush) +static int BrushIndexInMap(const mapentity_t *entity, const brush_t *brush) { - std::list facelist; + Q_assert(brush >= entity->brushes.data()); + Q_assert(brush < (entity->brushes.data() + entity->brushes.size())); - for (auto &face : brush.faces) { - brushfaces++; - auto *newface = new face_t(face); - newface->contents = { options.target_game->create_empty_contents(), brush.contents }; - newface->lmshift = { brush.lmshift, brush.lmshift }; - facelist.push_back(newface); - } - - return facelist; + return static_cast(brush - entity->brushes.data()); } -static std::list CSGFace_ClipAgainstSingleBrush(std::list input, const brush_t *srcbrush, const brush_t *clipbrush) +static std::list CSGFace_ClipAgainstSingleBrush(std::list input, const mapentity_t *srcentity, const brush_t *srcbrush, const brush_t *clipbrush) { if (srcbrush == clipbrush) { LogPrint(" ignoring self-clip\n"); return input; } + int srcindex = BrushIndexInMap(srcentity, srcbrush); + int clipindex = BrushIndexInMap(srcentity, clipbrush); + if (srcindex > clipindex) { + return input; + } + + std::list inside {input}; std::list outside; RemoveOutsideFaces(*clipbrush, &inside, &outside); @@ -540,7 +542,7 @@ Given `srcface`, which was produced from `srcbrush` and lies on `srcnode`: Frees srcface. ================== */ -std::list CSGFace(face_t *srcface, const mapentity_t* srcentity, const brush_t *srcbrush, const node_t *srcnode) +std::list CSGFace(face_t *srcface, const mapentity_t *srcentity, const brush_t *srcbrush, const node_t *srcnode) { const auto possible_clipbrushes = GatherPossibleClippingBrushes(srcentity, srcnode, srcface); @@ -549,7 +551,7 @@ std::list CSGFace(face_t *srcface, const mapentity_t* srcentity, const std::list result{srcface}; for (const brush_t *possible_clipbrush : possible_clipbrushes) { - result = CSGFace_ClipAgainstSingleBrush(std::move(result), srcbrush, possible_clipbrush); + result = CSGFace_ClipAgainstSingleBrush(std::move(result), srcentity, srcbrush, possible_clipbrush); } return result; diff --git a/qbsp/merge.cc b/qbsp/merge.cc index e38917b8..db24d7ab 100644 --- a/qbsp/merge.cc +++ b/qbsp/merge.cc @@ -231,7 +231,4 @@ void MergeAll(node_t *headnode) }); LogPrint(LOG_STAT, " {:8} mergefaces (from {}; {:.0}% merged)\n", mergefaces, premergefaces, (static_cast(mergefaces) / premergefaces) * 100.); - - // Quick hack to let solidbsp print out progress % - csgmergefaces = mergefaces; }