diff --git a/qbsp/portals.cc b/qbsp/portals.cc index d08c0ff5..db5e142e 100644 --- a/qbsp/portals.cc +++ b/qbsp/portals.cc @@ -453,8 +453,11 @@ static void FindPortalSide(portal_t *p) node_t *n = p->nodes[j]; auto p1 = map.planes.at(p->onnode->planenum); - for (brush_t *brush : n->original_brushes) + // iterate the n->original_brushes vector in reverse order, so later brushes + // in the map file order are prioritized + for (auto it = n->original_brushes.rbegin(); it != n->original_brushes.rend(); ++it) { + auto *brush = *it; if (!options.target_game->contents_contains(brush->contents, viscontents)) continue; for (face_t &side : brush->faces) diff --git a/qbsp/qbsp.cc b/qbsp/qbsp.cc index fb044970..4df23eba 100644 --- a/qbsp/qbsp.cc +++ b/qbsp/qbsp.cc @@ -896,15 +896,14 @@ static void ProcessEntity(mapentity_t *entity, const int hullnum) tree = BrushBSP(entity, false); } - FreeTreePortals_r(tree->headnode); - - PruneNodes(tree->headnode); - MakeTreePortals(tree); MarkVisibleSides(tree, entity); MakeFaces(tree->headnode); + FreeTreePortals_r(tree->headnode); + PruneNodes(tree->headnode); + if (hullnum <= 0 && entity == map.world_entity() && !map.leakfile) { WritePortalFile(tree); }