From 038651fca67c036433be0f3bd0e403809814282f Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Fri, 24 Jun 2022 00:01:02 -0600 Subject: [PATCH] qbsp: rename brush_t -> bspbrush_t for consistency with qbsp3 --- include/qbsp/brush.hh | 7 +++---- include/qbsp/csg4.hh | 6 +++--- include/qbsp/map.hh | 10 +++++----- include/qbsp/qbsp.hh | 4 ++-- include/qbsp/solidbsp.hh | 4 ++-- qbsp/brush.cc | 14 +++++++------- qbsp/exportobj.cc | 4 ++-- qbsp/map.cc | 8 ++++---- qbsp/qbsp.cc | 4 ++-- qbsp/solidbsp.cc | 30 +++++++++++++++--------------- qbsp/test_qbsp.cc | 2 +- 11 files changed, 46 insertions(+), 47 deletions(-) diff --git a/include/qbsp/brush.hh b/include/qbsp/brush.hh index 1e7f60c0..81150ca5 100644 --- a/include/qbsp/brush.hh +++ b/include/qbsp/brush.hh @@ -28,13 +28,12 @@ class mapentity_t; -struct brush_t -{ +struct bspbrush_t { /** * The brushes in the mapentity_t::brushes vector are considered originals. Brush fragments created during * the BrushBSP will have this pointing back to the original brush in mapentity_t::brushes. */ - brush_t *original; + bspbrush_t *original; uint32_t file_order; aabb3d bounds; std::vector faces; @@ -57,7 +56,7 @@ enum class rotation_t origin_brush }; -std::optional LoadBrush(const mapentity_t *src, const mapbrush_t *mapbrush, const contentflags_t &contents, +std::optional LoadBrush(const mapentity_t *src, const mapbrush_t *mapbrush, const contentflags_t &contents, const qvec3d &rotate_offset, const rotation_t rottype, const int hullnum); void FreeBrushes(mapentity_t *ent); diff --git a/include/qbsp/csg4.hh b/include/qbsp/csg4.hh index 80022ad3..3c410589 100644 --- a/include/qbsp/csg4.hh +++ b/include/qbsp/csg4.hh @@ -27,7 +27,7 @@ #include #include -struct brush_t; +struct bspbrush_t; struct face_t; face_t *NewFaceFromFace(const face_t *in); @@ -35,5 +35,5 @@ face_t *CopyFace(const face_t *in); face_t *MirrorFace(const face_t *face); std::tuple SplitFace(face_t *in, const qplane3d &split); void UpdateFaceSphere(face_t *in); -bool BrushGE(const brush_t &a, const brush_t &b); -std::vector> ChopBrushes(const std::vector> &input); +bool BrushGE(const bspbrush_t &a, const bspbrush_t &b); +std::vector> ChopBrushes(const std::vector> &input); diff --git a/include/qbsp/map.hh b/include/qbsp/map.hh index 423c591b..dae77604 100644 --- a/include/qbsp/map.hh +++ b/include/qbsp/map.hh @@ -33,7 +33,7 @@ #include #include -struct brush_t; +struct bspbrush_t; struct qbsp_plane_t : qplane3d { @@ -102,7 +102,7 @@ public: entdict_t epairs; aabb3d bounds; - std::vector> brushes; + std::vector> brushes; int firstoutputfacenumber = -1; std::optional outputmodelnumber = std::nullopt; @@ -218,7 +218,7 @@ constexpr int HULL_COLLISION = -1; /* Create BSP brushes from map brushes */ void Brush_LoadEntity(mapentity_t *entity, const int hullnum); -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 bspbrush_t *srcbrush, const node_t *srcnode); void TJunc(const mapentity_t *entity, node_t *headnode); int MakeFaceEdges(mapentity_t *entity, node_t *headnode); void ExportClipNodes(mapentity_t *entity, node_t *headnode, const int hullnum); @@ -232,10 +232,10 @@ void BSPX_Brushes_Finalize(struct bspxbrushes_s *ctx); void BSPX_Brushes_Init(struct bspxbrushes_s *ctx); void ExportObj_Faces(const std::string &filesuffix, const std::vector &faces); -void ExportObj_Brushes(const std::string &filesuffix, const std::vector &brushes); +void ExportObj_Brushes(const std::string &filesuffix, const std::vector &brushes); void ExportObj_Nodes(const std::string &filesuffix, const node_t *nodes); void ExportObj_Marksurfaces(const std::string &filesuffix, const node_t *nodes); -void WriteBspBrushMap(const fs::path &name, const std::vector> &list); +void WriteBspBrushMap(const fs::path &name, const std::vector> &list); bool IsValidTextureProjection(const qvec3f &faceNormal, const qvec3f &s_vec, const qvec3f &t_vec); diff --git a/include/qbsp/qbsp.hh b/include/qbsp/qbsp.hh index eeb12dad..58ba6e76 100644 --- a/include/qbsp/qbsp.hh +++ b/include/qbsp/qbsp.hh @@ -353,7 +353,7 @@ struct face_t : face_fragment_t // there is a node_t structure for every node and leaf in the bsp tree -struct brush_t; +struct bspbrush_t; struct node_t { @@ -369,7 +369,7 @@ struct node_t // information for leafs contentflags_t contents; // leaf nodes (0 for decision nodes) - std::vector original_brushes; + std::vector original_brushes; std::vector markfaces; // leaf nodes only, point to node faces portal_t *portals; int visleafnum; // -1 = solid diff --git a/include/qbsp/solidbsp.hh b/include/qbsp/solidbsp.hh index bbf4a8e8..c00689fa 100644 --- a/include/qbsp/solidbsp.hh +++ b/include/qbsp/solidbsp.hh @@ -31,7 +31,7 @@ extern std::atomic splitnodes; -struct brush_t; +struct bspbrush_t; struct node_t; struct face_t; class mapentity_t; @@ -40,5 +40,5 @@ struct tree_t; void DetailToSolid(node_t *node); void PruneNodes(node_t *node); bool WindingIsTiny(const winding_t &w, double size = 0.2); -twosided> SplitBrush(std::unique_ptr brush, const qplane3d &split); +twosided> SplitBrush(std::unique_ptr brush, const qplane3d &split); tree_t *BrushBSP(mapentity_t *entity, bool midsplit); diff --git a/qbsp/brush.cc b/qbsp/brush.cc index 59f98c20..b4b93d79 100644 --- a/qbsp/brush.cc +++ b/qbsp/brush.cc @@ -755,7 +755,7 @@ LoadBrush Converts a mapbrush to a bsp brush =============== */ -std::optional LoadBrush(const mapentity_t *src, const mapbrush_t *mapbrush, const contentflags_t &contents, +std::optional LoadBrush(const mapentity_t *src, const mapbrush_t *mapbrush, const contentflags_t &contents, const qvec3d &rotate_offset, const rotation_t rottype, const int hullnum) { hullbrush_t hullbrush; @@ -796,7 +796,7 @@ std::optional LoadBrush(const mapentity_t *src, const mapbrush_t *mapbr } // create the brush - brush_t brush{}; + bspbrush_t brush{}; brush.contents = contents; brush.faces = std::move(facelist); brush.bounds = hullbrush.bounds; @@ -826,7 +826,7 @@ static void Brush_LoadEntity(mapentity_t *dst, const mapentity_t *src, const int continue; } - std::optional brush = LoadBrush(src, mapbrush, contents, {}, rotation_t::none, 0); + std::optional brush = LoadBrush(src, mapbrush, contents, {}, rotation_t::none, 0); if (brush) { rotate_offset = brush->bounds.centroid(); @@ -946,7 +946,7 @@ static void Brush_LoadEntity(mapentity_t *dst, const mapentity_t *src, const int */ if (hullnum != HULL_COLLISION && contents.is_clip(options.target_game)) { if (hullnum == 0) { - std::optional brush = LoadBrush(src, mapbrush, contents, rotate_offset, rottype, hullnum); + std::optional brush = LoadBrush(src, mapbrush, contents, rotate_offset, rottype, hullnum); if (brush) { dst->bounds += brush->bounds; @@ -996,7 +996,7 @@ static void Brush_LoadEntity(mapentity_t *dst, const mapentity_t *src, const int contents.set_clips_same_type(clipsametype); contents.illusionary_visblocker = func_illusionary_visblocker; - std::optional brush = LoadBrush(src, mapbrush, contents, rotate_offset, rottype, hullnum); + std::optional brush = LoadBrush(src, mapbrush, contents, rotate_offset, rottype, hullnum); if (!brush) continue; @@ -1010,7 +1010,7 @@ static void Brush_LoadEntity(mapentity_t *dst, const mapentity_t *src, const int } options.target_game->count_contents_in_stats(brush->contents, stats); - dst->brushes.push_back(std::make_unique(brush.value())); + dst->brushes.push_back(std::make_unique(brush.value())); dst->bounds += brush->bounds; } @@ -1057,7 +1057,7 @@ void Brush_LoadEntity(mapentity_t *entity, const int hullnum) options.target_game->print_content_stats(stats, "brushes"); } -void brush_t::update_bounds() +void bspbrush_t::update_bounds() { this->bounds = {}; for (const face_t &face : faces) { diff --git a/qbsp/exportobj.cc b/qbsp/exportobj.cc index 5fb7ceac..02279a8c 100644 --- a/qbsp/exportobj.cc +++ b/qbsp/exportobj.cc @@ -122,11 +122,11 @@ void ExportObj_Faces(const std::string &filesuffix, const std::vector &brushes) +void ExportObj_Brushes(const std::string &filesuffix, const std::vector &brushes) { std::vector faces; - for (const brush_t *brush : brushes) + for (const bspbrush_t *brush : brushes) for (auto &face : brush->faces) faces.push_back(&face); diff --git a/qbsp/map.cc b/qbsp/map.cc index b46db3ca..278e74d8 100644 --- a/qbsp/map.cc +++ b/qbsp/map.cc @@ -2284,7 +2284,7 @@ WriteBspBrushMap from q3map ================== */ -void WriteBspBrushMap(const fs::path &name, const std::vector> &list) +void WriteBspBrushMap(const fs::path &name, const std::vector> &list) { logging::print("writing {}\n", name); std::ofstream f(name); @@ -2330,16 +2330,16 @@ from q3map */ static void TestExpandBrushes(const mapentity_t *src) { - std::vector> hull1brushes; + std::vector> hull1brushes; for (int i = 0; i < src->nummapbrushes; i++) { const mapbrush_t *mapbrush = &src->mapbrush(i); - std::optional hull1brush = LoadBrush( + std::optional hull1brush = LoadBrush( src, mapbrush, {CONTENTS_SOLID}, {}, rotation_t::none, options.target_game->id == GAME_QUAKE_II ? HULL_COLLISION : 1); if (hull1brush) { hull1brushes.emplace_back( - std::make_unique(std::move(*hull1brush))); + std::make_unique(std::move(*hull1brush))); } } diff --git a/qbsp/qbsp.cc b/qbsp/qbsp.cc index 00f1f1fe..8b0cfc4c 100644 --- a/qbsp/qbsp.cc +++ b/qbsp/qbsp.cc @@ -296,7 +296,7 @@ Adds any additional planes necessary to allow the brush to be expanded against axial bounding boxes ================= */ -static std::vector> AddBrushBevels(const brush_t &b) +static std::vector> AddBrushBevels(const bspbrush_t &b) { // add already-present planes std::vector> planes; @@ -1019,7 +1019,7 @@ hull sizes */ static void BSPX_Brushes_AddModel( - struct bspxbrushes_s *ctx, int modelnum, std::vector> &brushes) + struct bspxbrushes_s *ctx, int modelnum, std::vector> &brushes) { bspxbrushes_permodel permodel{1, modelnum}; diff --git a/qbsp/solidbsp.cc b/qbsp/solidbsp.cc index 9837d581..c4f20748 100644 --- a/qbsp/solidbsp.cc +++ b/qbsp/solidbsp.cc @@ -309,7 +309,7 @@ ChooseMidPlaneFromList The clipping hull BSP doesn't worry about avoiding splits ================== */ -static const face_t *ChooseMidPlaneFromList(const std::vector> &brushes, const aabb3d &bounds) +static const face_t *ChooseMidPlaneFromList(const std::vector> &brushes, const aabb3d &bounds) { /* pick the plane that splits the least */ vec_t bestaxialmetric = VECT_MAX; @@ -375,7 +375,7 @@ The real BSP heuristic fixme-brushbsp: prefer splits that include a lot of brush sides? ================== */ -static const face_t *ChoosePlaneFromList(const std::vector> &brushes, const aabb3d &bounds) +static const face_t *ChoosePlaneFromList(const std::vector> &brushes, const aabb3d &bounds) { /* pick the plane that splits the least */ int minsplits = INT_MAX - 1; @@ -477,7 +477,7 @@ returns NULL if the surface list can not be divided any more (a leaf) Called in parallel. ================== */ -static const face_t *SelectPartition(const std::vector> &brushes) +static const face_t *SelectPartition(const std::vector> &brushes) { // calculate a bounding box of the entire surfaceset aabb3d bounds; @@ -569,7 +569,7 @@ BrushMostlyOnSide ================== */ -side_t BrushMostlyOnSide(const brush_t &brush, const qplane3d &plane) +side_t BrushMostlyOnSide(const bspbrush_t &brush, const qplane3d &plane) { vec_t max = 0; side_t side = SIDE_FRONT; @@ -595,7 +595,7 @@ BrushVolume ================== */ -vec_t BrushVolume(const brush_t &brush) +vec_t BrushVolume(const bspbrush_t &brush) { // grab the first valid point as the corner @@ -635,9 +635,9 @@ input. https://github.com/id-Software/Quake-2-Tools/blob/master/bsp/qbsp3/brushbsp.c#L935 ================ */ -twosided> SplitBrush(std::unique_ptr brush, const qplane3d &split) +twosided> SplitBrush(std::unique_ptr brush, const qplane3d &split) { - twosided> result; + twosided> result; // check all points vec_t d_front = 0; @@ -692,9 +692,9 @@ twosided> SplitBrush(std::unique_ptr brush, co // start with 2 empty brushes for (int i = 0; i < 2; i++) { - result[i] = std::make_unique(); + result[i] = std::make_unique(); result[i]->original = brush->original; - // fixme-brushbsp: add a brush_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]->lmshift = brush->lmshift; result[i]->func_areaportal = brush->func_areaportal; @@ -806,7 +806,7 @@ inline void DivideNodeBounds(node_t *node, const qbsp_plane_t &split) DivideBounds(node->bounds, split, node->children[0]->bounds, node->children[1]->bounds); } -static bool AllDetail(const std::vector> &brushes) +static bool AllDetail(const std::vector> &brushes) { for (auto &brush : brushes) { if (!brush->contents.is_any_detail(options.target_game)) { @@ -826,7 +826,7 @@ original faces that have some fragment inside this leaf. Called in parallel. ================== */ -static void CreateLeaf(std::vector> brushes, node_t *leafnode) +static void CreateLeaf(std::vector> brushes, node_t *leafnode) { leafnode->facelist.clear(); leafnode->planenum = PLANENUM_LEAF; @@ -850,7 +850,7 @@ PartitionBrushes Called in parallel. ================== */ -static void PartitionBrushes(std::vector> brushes, node_t *node) +static void PartitionBrushes(std::vector> brushes, node_t *node) { face_t *split = const_cast(SelectPartition(brushes)); @@ -876,7 +876,7 @@ static void PartitionBrushes(std::vector> brushes, node DivideNodeBounds(node, splitplane); // multiple surfaces, so split all the polysurfaces into front and back lists - std::vector> frontlist, backlist; + std::vector> frontlist, backlist; for (auto &brush : brushes) { // NOTE: we're destroying `brushes` here with the std::move() @@ -977,9 +977,9 @@ tree_t *BrushBSP(mapentity_t *entity, bool midsplit) mapbrushes = entity->brushes.size(); // set the original pointers - std::vector> brushcopies; + std::vector> brushcopies; for (const auto &original : entity->brushes) { - auto copy = std::make_unique(*original); + auto copy = std::make_unique(*original); copy->original = original.get(); brushcopies.push_back(std::move(copy)); } diff --git a/qbsp/test_qbsp.cc b/qbsp/test_qbsp.cc index 0c381790..c9140929 100644 --- a/qbsp/test_qbsp.cc +++ b/qbsp/test_qbsp.cc @@ -351,7 +351,7 @@ TEST_CASE("duplicatePlanes", "[qbsp]") CHECK(0 == worldspawn.brushes.size()); CHECK(6 == worldspawn.mapbrush(0).numfaces); - std::optional brush = + std::optional brush = LoadBrush(&worldspawn, &worldspawn.mapbrush(0), {CONTENTS_SOLID}, {}, rotation_t::none, 0); REQUIRE(std::nullopt != brush); CHECK(6 == brush->faces.size());