From 4b4a1738fd1b0967d2a1c305d8412a152f7093f2 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Wed, 10 Aug 2022 23:06:37 -0400 Subject: [PATCH] more partial revert --- include/qbsp/portals.hh | 4 ++-- include/qbsp/qbsp.hh | 2 +- qbsp/brushbsp.cc | 5 ++--- qbsp/faces.cc | 6 ++++-- qbsp/outside.cc | 6 +++--- qbsp/portals.cc | 14 +++++++------- qbsp/qbsp.cc | 12 ++++++++---- qbsp/tree.cc | 4 +++- 8 files changed, 30 insertions(+), 23 deletions(-) diff --git a/include/qbsp/portals.hh b/include/qbsp/portals.hh index 93cf54c0..40d5fabc 100644 --- a/include/qbsp/portals.hh +++ b/include/qbsp/portals.hh @@ -40,8 +40,8 @@ struct portal_t std::unique_ptr winding; bool sidefound; // false if ->side hasn't been checked - mapface_t *sides[2]; // [0] = the brush side visible on nodes[0] - it could come from a brush in nodes[1]. NULL = - // non-visible + side_t *sides[2]; // [0] = the brush side visible on nodes[0] - it could come from a brush in nodes[1]. NULL = + // non-visible face_t *face[2]; // output face in bsp file }; diff --git a/include/qbsp/qbsp.hh b/include/qbsp/qbsp.hh index 50ef77b3..3a176209 100644 --- a/include/qbsp/qbsp.hh +++ b/include/qbsp/qbsp.hh @@ -663,7 +663,7 @@ struct node_t uint32_t firstleafbrush; // Q2 uint32_t numleafbrushes; int32_t area; - std::vector original_brushes; + std::vector original_brushes; }; void InitQBSP(int argc, const char **argv); diff --git a/qbsp/brushbsp.cc b/qbsp/brushbsp.cc index 16e97153..2b303e87 100644 --- a/qbsp/brushbsp.cc +++ b/qbsp/brushbsp.cc @@ -387,8 +387,7 @@ static void LeafNode(node_t *leafnode, bspbrush_t::container brushes, bspstats_t leafnode->contents = qbsp_options.target_game->combine_contents(leafnode->contents, brush->contents); } for (auto &brush : brushes) { - Q_assert(brush->mapbrush != nullptr); - leafnode->original_brushes.push_back(brush->mapbrush); + leafnode->original_brushes.push_back(brush->original_brush()); } qbsp_options.target_game->count_contents_in_stats(leafnode->contents, *stats.leafstats); @@ -492,7 +491,7 @@ static twosided SplitBrush(bspbrush_t::ptr brush, size_t planen for (int i = 0; i < 2; i++) { result[i] = bspbrush_t::make_ptr(); - result[i]->original_ptr = brush->original_ptr; + result[i]->original_ptr = brush->original_ptr ? brush->original_ptr : brush; result[i]->mapbrush = brush->mapbrush; // fixme-brushbsp: add a bspbrush_t copy constructor to make sure we get all fields result[i]->contents = brush->contents; diff --git a/qbsp/faces.cc b/qbsp/faces.cc index af2fe533..6dfb75ea 100644 --- a/qbsp/faces.cc +++ b/qbsp/faces.cc @@ -472,16 +472,18 @@ see also FindPortalSide which populates p->side */ static std::unique_ptr FaceFromPortal(portal_t *p, bool pside) { - mapface_t *side = p->sides[pside]; + side_t *side = p->sides[pside]; if (!side) return nullptr; // portal does not bridge different visible contents + Q_assert(side->source); + auto f = std::make_unique(); f->texinfo = side->texinfo; f->planenum = (side->planenum & ~1) | (pside ? 1 : 0); f->portal = p; - f->original_side = side; + f->original_side = side->source; #if 0 bool make_face = diff --git a/qbsp/outside.cc b/qbsp/outside.cc index da4028b6..18307466 100644 --- a/qbsp/outside.cc +++ b/qbsp/outside.cc @@ -396,13 +396,13 @@ static void MarkVisibleBrushSides_R(node_t *node) // optimized case: just mark the brush sides in the neighbouring // leaf that are coplanar for (auto *brush : neighbour_leaf->original_brushes) { - for (auto &side : brush->faces) { + for (auto &side : brush->sides) { // fixme-brushbsp: should this be get_plane() ? // fixme-brushbsp: planenum - if (qv::epsilonEqual(side.get_positive_plane(), portal->plane)) { + if (side.source && qv::epsilonEqual(side.get_positive_plane(), portal->plane)) { // we've found a brush side in an original brush in the neighbouring // leaf, on a portal to this (non-opaque) leaf, so mark it as visible. - side.visible = true; + side.source->visible = true; } } } diff --git a/qbsp/portals.cc b/qbsp/portals.cc index 7c31920f..bd120d4d 100644 --- a/qbsp/portals.cc +++ b/qbsp/portals.cc @@ -573,8 +573,8 @@ static mapentity_t *AreanodeEntityForLeaf(node_t *node) } for (auto &brush : node->original_brushes) { - if (brush->func_areaportal) { - return brush->func_areaportal; + if (brush->mapbrush->func_areaportal) { + return brush->mapbrush->func_areaportal; } } return nullptr; @@ -791,8 +791,8 @@ static void FindPortalSide(portal_t *p) return; // bestside[0] is the brushside visible on portal side[0] which is the positive side of the plane, always - mapface_t *bestside[2] = {nullptr, nullptr}; - mapface_t *exactside[2] = {nullptr, nullptr}; + side_t *bestside[2] = {nullptr, nullptr}; + side_t *exactside[2] = {nullptr, nullptr}; float bestdot = 0; const qbsp_plane_t &p1 = p->onnode->get_plane(); @@ -813,7 +813,7 @@ static void FindPortalSide(portal_t *p) continue; } - for (auto &side : brush->faces) { + for (auto &side : brush->sides) { if (side.bevel) continue; if ((side.planenum & ~1) == p->onnode->planenum) { @@ -898,8 +898,8 @@ static void MarkVisibleSides_r(node_t *node) if (!p->sidefound) FindPortalSide(p); for (int i = 0; i < 2; ++i) { - if (p->sides[i]) { - p->sides[i]->visible = true; + if (p->sides[i] && p->sides[i]->source) { + p->sides[i]->source->visible = true; } } } diff --git a/qbsp/qbsp.cc b/qbsp/qbsp.cc index dd11df09..4eed75eb 100644 --- a/qbsp/qbsp.cc +++ b/qbsp/qbsp.cc @@ -306,13 +306,13 @@ static void ExportBrushList_r(const mapentity_t *entity, node_t *node) node->firstleafbrush = map.bsp.dleafbrushes.size(); for (auto &b : node->original_brushes) { - if (!b->outputnumber.has_value()) { - b->outputnumber = {static_cast(map.bsp.dbrushes.size())}; + if (!b->mapbrush->outputnumber.has_value()) { + b->mapbrush->outputnumber = {static_cast(map.bsp.dbrushes.size())}; dbrush_t &brush = map.bsp.dbrushes.emplace_back( dbrush_t{static_cast(map.bsp.dbrushsides.size()), 0, b->contents.native}); - for (auto &side : b->faces) { + for (auto &side : b->mapbrush->faces) { map.bsp.dbrushsides.push_back( {(uint32_t) ExportMapPlane(side.planenum), (int32_t)ExportMapTexinfo(side.texinfo)}); brush.numsides++; @@ -322,7 +322,7 @@ static void ExportBrushList_r(const mapentity_t *entity, node_t *node) brush_state.total_brushes++; } - map.bsp.dleafbrushes.push_back(b->outputnumber.value()); + map.bsp.dleafbrushes.push_back(b->mapbrush->outputnumber.value()); } } } @@ -486,6 +486,10 @@ static void ProcessEntity(mapentity_t *entity, const int hullnum) // fixme-brushbsp: return here? } else { + + if (entity->outputmodelnumber.value() == 34) + __debugbreak(); + if (qbsp_options.forcegoodtree.value()) { tree = BrushBSP(entity, brushes, false); } else { diff --git a/qbsp/tree.cc b/qbsp/tree.cc index 5723b90c..7bec5456 100644 --- a/qbsp/tree.cc +++ b/qbsp/tree.cc @@ -82,7 +82,9 @@ static void ConvertNodeToLeaf(node_t *node, const contentflags_t &contents) node->original_brushes = std::move(node->children[base]->original_brushes); node->original_brushes.insert(node->original_brushes.end(), node->children[base ^ 1]->original_brushes.begin(), node->children[base ^ 1]->original_brushes.end()); - std::sort(node->original_brushes.begin(), node->original_brushes.end()); + std::sort(node->original_brushes.begin(), node->original_brushes.end(), [](const bspbrush_t *a, const bspbrush_t *b) { + return a->mapbrush < b->mapbrush; + }); auto unique = std::unique(node->original_brushes.begin(), node->original_brushes.end()); node->original_brushes.erase(unique, node->original_brushes.end());