From 5cae1919ced1a3f8a60704e0e6c2d743e1212b87 Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Wed, 4 May 2022 21:04:36 -0600 Subject: [PATCH] qbsp: fix areaportals --- include/qbsp/brush.hh | 3 +++ include/qbsp/qbsp.hh | 1 - qbsp/brush.cc | 5 ++++- qbsp/csg4.cc | 1 - qbsp/qbsp.cc | 5 +++-- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/include/qbsp/brush.hh b/include/qbsp/brush.hh index 9d6836fb..98f45c39 100644 --- a/include/qbsp/brush.hh +++ b/include/qbsp/brush.hh @@ -26,6 +26,8 @@ #include #include +class mapentity_t; + struct brush_t { /** @@ -39,6 +41,7 @@ struct brush_t contentflags_t contents; /* BSP contents */ short lmshift; /* lightmap scaling (qu/lightmap pixel), passed to the light util */ std::optional outputnumber; /* only set for original brushes */ + mapentity_t *func_areaportal; void update_bounds(); }; diff --git a/include/qbsp/qbsp.hh b/include/qbsp/qbsp.hh index 31b7768f..0df420d9 100644 --- a/include/qbsp/qbsp.hh +++ b/include/qbsp/qbsp.hh @@ -326,7 +326,6 @@ struct face_t : face_fragment_t twosided contents; twosided lmshift; - mapentity_t *src_entity; // source entity qvec3d origin; vec_t radius; diff --git a/qbsp/brush.cc b/qbsp/brush.cc index e020a4ab..d34184a9 100644 --- a/qbsp/brush.cc +++ b/qbsp/brush.cc @@ -376,7 +376,6 @@ static std::vector CreateBrushFaces(const mapentity_t *src, hullbrush_t f.texinfo = hullnum > 0 ? 0 : mapface.texinfo; f.planenum = FindPlane(plane, &f.planeside); - f.src_entity = const_cast(src); // FIXME: get rid of consts on src in the callers? CheckFace(&f, mapface); UpdateFaceSphere(&f); @@ -942,6 +941,10 @@ static void Brush_LoadEntity(mapentity_t *dst, const mapentity_t *src, const int brush->lmshift = lmshift; + if (classname == std::string_view("func_areaportal")) { + brush->func_areaportal = const_cast(src); // FIXME: get rid of consts on src in the callers? + } + if (brush->contents.is_solid(options.target_game)) { stats.solid++; } else if (brush->contents.is_sky(options.target_game)) { diff --git a/qbsp/csg4.cc b/qbsp/csg4.cc index 9b0fbbd6..27955452 100644 --- a/qbsp/csg4.cc +++ b/qbsp/csg4.cc @@ -78,7 +78,6 @@ face_t *NewFaceFromFace(const face_t *in) newf->planeside = in->planeside; newf->contents = in->contents; newf->lmshift = in->lmshift; - newf->src_entity = in->src_entity; newf->origin = in->origin; newf->radius = in->radius; diff --git a/qbsp/qbsp.cc b/qbsp/qbsp.cc index dd7c8673..7e1e0ebc 100644 --- a/qbsp/qbsp.cc +++ b/qbsp/qbsp.cc @@ -426,7 +426,8 @@ static void FloodAreas_r(node_t *node) { if (node->planenum == PLANENUM_LEAF && node->contents.native == Q2_CONTENTS_AREAPORTAL) { // grab the func_areanode entity - mapentity_t *entity = node->markfaces[0]->src_entity; + mapentity_t *entity = node->original_brushes.at(0)->func_areaportal; + Q_assert(entity != nullptr); // this node is part of an area portal; // if the current area has allready touched this @@ -523,7 +524,7 @@ static void SetAreaPortalAreas_r(node_t *node) return; // already set // grab the func_areanode entity - mapentity_t *entity = node->markfaces[0]->src_entity; + mapentity_t *entity = node->original_brushes.at(0)->func_areaportal; node->area = entity->portalareas[0]; if (!entity->portalareas[1]) {