more partial revert

This commit is contained in:
Jonathan 2022-08-10 23:06:37 -04:00
parent 02e80645e6
commit 4b4a1738fd
8 changed files with 30 additions and 23 deletions

View File

@ -40,8 +40,8 @@ struct portal_t
std::unique_ptr<winding_t> winding; std::unique_ptr<winding_t> winding;
bool sidefound; // false if ->side hasn't been checked 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 = side_t *sides[2]; // [0] = the brush side visible on nodes[0] - it could come from a brush in nodes[1]. NULL =
// non-visible // non-visible
face_t *face[2]; // output face in bsp file face_t *face[2]; // output face in bsp file
}; };

View File

@ -663,7 +663,7 @@ struct node_t
uint32_t firstleafbrush; // Q2 uint32_t firstleafbrush; // Q2
uint32_t numleafbrushes; uint32_t numleafbrushes;
int32_t area; int32_t area;
std::vector<mapbrush_t *> original_brushes; std::vector<bspbrush_t *> original_brushes;
}; };
void InitQBSP(int argc, const char **argv); void InitQBSP(int argc, const char **argv);

View File

@ -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); leafnode->contents = qbsp_options.target_game->combine_contents(leafnode->contents, brush->contents);
} }
for (auto &brush : brushes) { for (auto &brush : brushes) {
Q_assert(brush->mapbrush != nullptr); leafnode->original_brushes.push_back(brush->original_brush());
leafnode->original_brushes.push_back(brush->mapbrush);
} }
qbsp_options.target_game->count_contents_in_stats(leafnode->contents, *stats.leafstats); qbsp_options.target_game->count_contents_in_stats(leafnode->contents, *stats.leafstats);
@ -492,7 +491,7 @@ static twosided<bspbrush_t::ptr> SplitBrush(bspbrush_t::ptr brush, size_t planen
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
result[i] = bspbrush_t::make_ptr(); 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; result[i]->mapbrush = brush->mapbrush;
// fixme-brushbsp: add a bspbrush_t copy constructor to make sure we get all fields // fixme-brushbsp: add a bspbrush_t copy constructor to make sure we get all fields
result[i]->contents = brush->contents; result[i]->contents = brush->contents;

View File

@ -472,16 +472,18 @@ see also FindPortalSide which populates p->side
*/ */
static std::unique_ptr<face_t> FaceFromPortal(portal_t *p, bool pside) static std::unique_ptr<face_t> FaceFromPortal(portal_t *p, bool pside)
{ {
mapface_t *side = p->sides[pside]; side_t *side = p->sides[pside];
if (!side) if (!side)
return nullptr; // portal does not bridge different visible contents return nullptr; // portal does not bridge different visible contents
Q_assert(side->source);
auto f = std::make_unique<face_t>(); auto f = std::make_unique<face_t>();
f->texinfo = side->texinfo; f->texinfo = side->texinfo;
f->planenum = (side->planenum & ~1) | (pside ? 1 : 0); f->planenum = (side->planenum & ~1) | (pside ? 1 : 0);
f->portal = p; f->portal = p;
f->original_side = side; f->original_side = side->source;
#if 0 #if 0
bool make_face = bool make_face =

View File

@ -396,13 +396,13 @@ static void MarkVisibleBrushSides_R(node_t *node)
// optimized case: just mark the brush sides in the neighbouring // optimized case: just mark the brush sides in the neighbouring
// leaf that are coplanar // leaf that are coplanar
for (auto *brush : neighbour_leaf->original_brushes) { 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: should this be get_plane() ?
// fixme-brushbsp: planenum // 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 // 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. // leaf, on a portal to this (non-opaque) leaf, so mark it as visible.
side.visible = true; side.source->visible = true;
} }
} }
} }

View File

@ -573,8 +573,8 @@ static mapentity_t *AreanodeEntityForLeaf(node_t *node)
} }
for (auto &brush : node->original_brushes) { for (auto &brush : node->original_brushes) {
if (brush->func_areaportal) { if (brush->mapbrush->func_areaportal) {
return brush->func_areaportal; return brush->mapbrush->func_areaportal;
} }
} }
return nullptr; return nullptr;
@ -791,8 +791,8 @@ static void FindPortalSide(portal_t *p)
return; return;
// bestside[0] is the brushside visible on portal side[0] which is the positive side of the plane, always // 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}; side_t *bestside[2] = {nullptr, nullptr};
mapface_t *exactside[2] = {nullptr, nullptr}; side_t *exactside[2] = {nullptr, nullptr};
float bestdot = 0; float bestdot = 0;
const qbsp_plane_t &p1 = p->onnode->get_plane(); const qbsp_plane_t &p1 = p->onnode->get_plane();
@ -813,7 +813,7 @@ static void FindPortalSide(portal_t *p)
continue; continue;
} }
for (auto &side : brush->faces) { for (auto &side : brush->sides) {
if (side.bevel) if (side.bevel)
continue; continue;
if ((side.planenum & ~1) == p->onnode->planenum) { if ((side.planenum & ~1) == p->onnode->planenum) {
@ -898,8 +898,8 @@ static void MarkVisibleSides_r(node_t *node)
if (!p->sidefound) if (!p->sidefound)
FindPortalSide(p); FindPortalSide(p);
for (int i = 0; i < 2; ++i) { for (int i = 0; i < 2; ++i) {
if (p->sides[i]) { if (p->sides[i] && p->sides[i]->source) {
p->sides[i]->visible = true; p->sides[i]->source->visible = true;
} }
} }
} }

View File

@ -306,13 +306,13 @@ static void ExportBrushList_r(const mapentity_t *entity, node_t *node)
node->firstleafbrush = map.bsp.dleafbrushes.size(); node->firstleafbrush = map.bsp.dleafbrushes.size();
for (auto &b : node->original_brushes) { for (auto &b : node->original_brushes) {
if (!b->outputnumber.has_value()) { if (!b->mapbrush->outputnumber.has_value()) {
b->outputnumber = {static_cast<uint32_t>(map.bsp.dbrushes.size())}; b->mapbrush->outputnumber = {static_cast<uint32_t>(map.bsp.dbrushes.size())};
dbrush_t &brush = map.bsp.dbrushes.emplace_back( dbrush_t &brush = map.bsp.dbrushes.emplace_back(
dbrush_t{static_cast<int32_t>(map.bsp.dbrushsides.size()), 0, b->contents.native}); dbrush_t{static_cast<int32_t>(map.bsp.dbrushsides.size()), 0, b->contents.native});
for (auto &side : b->faces) { for (auto &side : b->mapbrush->faces) {
map.bsp.dbrushsides.push_back( map.bsp.dbrushsides.push_back(
{(uint32_t) ExportMapPlane(side.planenum), (int32_t)ExportMapTexinfo(side.texinfo)}); {(uint32_t) ExportMapPlane(side.planenum), (int32_t)ExportMapTexinfo(side.texinfo)});
brush.numsides++; brush.numsides++;
@ -322,7 +322,7 @@ static void ExportBrushList_r(const mapentity_t *entity, node_t *node)
brush_state.total_brushes++; 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? // fixme-brushbsp: return here?
} else { } else {
if (entity->outputmodelnumber.value() == 34)
__debugbreak();
if (qbsp_options.forcegoodtree.value()) { if (qbsp_options.forcegoodtree.value()) {
tree = BrushBSP(entity, brushes, false); tree = BrushBSP(entity, brushes, false);
} else { } else {

View File

@ -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 = 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()); 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()); auto unique = std::unique(node->original_brushes.begin(), node->original_brushes.end());
node->original_brushes.erase(unique, node->original_brushes.end()); node->original_brushes.erase(unique, node->original_brushes.end());