qbsp: rename brush_t -> bspbrush_t for consistency with qbsp3

This commit is contained in:
Eric Wasylishen 2022-06-24 00:01:02 -06:00
parent 12a5c6555c
commit 038651fca6
11 changed files with 46 additions and 47 deletions

View File

@ -28,13 +28,12 @@
class mapentity_t; 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 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. * 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; uint32_t file_order;
aabb3d bounds; aabb3d bounds;
std::vector<face_t> faces; std::vector<face_t> faces;
@ -57,7 +56,7 @@ enum class rotation_t
origin_brush origin_brush
}; };
std::optional<brush_t> LoadBrush(const mapentity_t *src, const mapbrush_t *mapbrush, const contentflags_t &contents, std::optional<bspbrush_t> LoadBrush(const mapentity_t *src, const mapbrush_t *mapbrush, const contentflags_t &contents,
const qvec3d &rotate_offset, const rotation_t rottype, const int hullnum); const qvec3d &rotate_offset, const rotation_t rottype, const int hullnum);
void FreeBrushes(mapentity_t *ent); void FreeBrushes(mapentity_t *ent);

View File

@ -27,7 +27,7 @@
#include <tuple> #include <tuple>
#include <vector> #include <vector>
struct brush_t; struct bspbrush_t;
struct face_t; struct face_t;
face_t *NewFaceFromFace(const face_t *in); 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); face_t *MirrorFace(const face_t *face);
std::tuple<face_t *, face_t *> SplitFace(face_t *in, const qplane3d &split); std::tuple<face_t *, face_t *> SplitFace(face_t *in, const qplane3d &split);
void UpdateFaceSphere(face_t *in); void UpdateFaceSphere(face_t *in);
bool BrushGE(const brush_t &a, const brush_t &b); bool BrushGE(const bspbrush_t &a, const bspbrush_t &b);
std::vector<std::unique_ptr<brush_t>> ChopBrushes(const std::vector<std::unique_ptr<brush_t>> &input); std::vector<std::unique_ptr<bspbrush_t>> ChopBrushes(const std::vector<std::unique_ptr<bspbrush_t>> &input);

View File

@ -33,7 +33,7 @@
#include <unordered_map> #include <unordered_map>
#include <list> #include <list>
struct brush_t; struct bspbrush_t;
struct qbsp_plane_t : qplane3d struct qbsp_plane_t : qplane3d
{ {
@ -102,7 +102,7 @@ public:
entdict_t epairs; entdict_t epairs;
aabb3d bounds; aabb3d bounds;
std::vector<std::unique_ptr<brush_t>> brushes; std::vector<std::unique_ptr<bspbrush_t>> brushes;
int firstoutputfacenumber = -1; int firstoutputfacenumber = -1;
std::optional<size_t> outputmodelnumber = std::nullopt; std::optional<size_t> outputmodelnumber = std::nullopt;
@ -218,7 +218,7 @@ constexpr int HULL_COLLISION = -1;
/* Create BSP brushes from map brushes */ /* Create BSP brushes from map brushes */
void Brush_LoadEntity(mapentity_t *entity, const int hullnum); void Brush_LoadEntity(mapentity_t *entity, const int hullnum);
std::list<face_t *> CSGFace(face_t *srcface, const mapentity_t* srcentity, const brush_t *srcbrush, const node_t *srcnode); std::list<face_t *> 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); void TJunc(const mapentity_t *entity, node_t *headnode);
int MakeFaceEdges(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); 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 BSPX_Brushes_Init(struct bspxbrushes_s *ctx);
void ExportObj_Faces(const std::string &filesuffix, const std::vector<const face_t *> &faces); void ExportObj_Faces(const std::string &filesuffix, const std::vector<const face_t *> &faces);
void ExportObj_Brushes(const std::string &filesuffix, const std::vector<const brush_t *> &brushes); void ExportObj_Brushes(const std::string &filesuffix, const std::vector<const bspbrush_t *> &brushes);
void ExportObj_Nodes(const std::string &filesuffix, const node_t *nodes); void ExportObj_Nodes(const std::string &filesuffix, const node_t *nodes);
void ExportObj_Marksurfaces(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<std::unique_ptr<brush_t>> &list); void WriteBspBrushMap(const fs::path &name, const std::vector<std::unique_ptr<bspbrush_t>> &list);
bool IsValidTextureProjection(const qvec3f &faceNormal, const qvec3f &s_vec, const qvec3f &t_vec); bool IsValidTextureProjection(const qvec3f &faceNormal, const qvec3f &s_vec, const qvec3f &t_vec);

View File

@ -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 // there is a node_t structure for every node and leaf in the bsp tree
struct brush_t; struct bspbrush_t;
struct node_t struct node_t
{ {
@ -369,7 +369,7 @@ struct node_t
// information for leafs // information for leafs
contentflags_t contents; // leaf nodes (0 for decision nodes) contentflags_t contents; // leaf nodes (0 for decision nodes)
std::vector<brush_t *> original_brushes; std::vector<bspbrush_t *> original_brushes;
std::vector<face_t *> markfaces; // leaf nodes only, point to node faces std::vector<face_t *> markfaces; // leaf nodes only, point to node faces
portal_t *portals; portal_t *portals;
int visleafnum; // -1 = solid int visleafnum; // -1 = solid

View File

@ -31,7 +31,7 @@
extern std::atomic<int> splitnodes; extern std::atomic<int> splitnodes;
struct brush_t; struct bspbrush_t;
struct node_t; struct node_t;
struct face_t; struct face_t;
class mapentity_t; class mapentity_t;
@ -40,5 +40,5 @@ struct tree_t;
void DetailToSolid(node_t *node); void DetailToSolid(node_t *node);
void PruneNodes(node_t *node); void PruneNodes(node_t *node);
bool WindingIsTiny(const winding_t &w, double size = 0.2); bool WindingIsTiny(const winding_t &w, double size = 0.2);
twosided<std::unique_ptr<brush_t>> SplitBrush(std::unique_ptr<brush_t> brush, const qplane3d &split); twosided<std::unique_ptr<bspbrush_t>> SplitBrush(std::unique_ptr<bspbrush_t> brush, const qplane3d &split);
tree_t *BrushBSP(mapentity_t *entity, bool midsplit); tree_t *BrushBSP(mapentity_t *entity, bool midsplit);

View File

@ -755,7 +755,7 @@ LoadBrush
Converts a mapbrush to a bsp brush Converts a mapbrush to a bsp brush
=============== ===============
*/ */
std::optional<brush_t> LoadBrush(const mapentity_t *src, const mapbrush_t *mapbrush, const contentflags_t &contents, std::optional<bspbrush_t> LoadBrush(const mapentity_t *src, const mapbrush_t *mapbrush, const contentflags_t &contents,
const qvec3d &rotate_offset, const rotation_t rottype, const int hullnum) const qvec3d &rotate_offset, const rotation_t rottype, const int hullnum)
{ {
hullbrush_t hullbrush; hullbrush_t hullbrush;
@ -796,7 +796,7 @@ std::optional<brush_t> LoadBrush(const mapentity_t *src, const mapbrush_t *mapbr
} }
// create the brush // create the brush
brush_t brush{}; bspbrush_t brush{};
brush.contents = contents; brush.contents = contents;
brush.faces = std::move(facelist); brush.faces = std::move(facelist);
brush.bounds = hullbrush.bounds; brush.bounds = hullbrush.bounds;
@ -826,7 +826,7 @@ static void Brush_LoadEntity(mapentity_t *dst, const mapentity_t *src, const int
continue; continue;
} }
std::optional<brush_t> brush = LoadBrush(src, mapbrush, contents, {}, rotation_t::none, 0); std::optional<bspbrush_t> brush = LoadBrush(src, mapbrush, contents, {}, rotation_t::none, 0);
if (brush) { if (brush) {
rotate_offset = brush->bounds.centroid(); 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 != HULL_COLLISION && contents.is_clip(options.target_game)) {
if (hullnum == 0) { if (hullnum == 0) {
std::optional<brush_t> brush = LoadBrush(src, mapbrush, contents, rotate_offset, rottype, hullnum); std::optional<bspbrush_t> brush = LoadBrush(src, mapbrush, contents, rotate_offset, rottype, hullnum);
if (brush) { if (brush) {
dst->bounds += brush->bounds; 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.set_clips_same_type(clipsametype);
contents.illusionary_visblocker = func_illusionary_visblocker; contents.illusionary_visblocker = func_illusionary_visblocker;
std::optional<brush_t> brush = LoadBrush(src, mapbrush, contents, rotate_offset, rottype, hullnum); std::optional<bspbrush_t> brush = LoadBrush(src, mapbrush, contents, rotate_offset, rottype, hullnum);
if (!brush) if (!brush)
continue; 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); options.target_game->count_contents_in_stats(brush->contents, stats);
dst->brushes.push_back(std::make_unique<brush_t>(brush.value())); dst->brushes.push_back(std::make_unique<bspbrush_t>(brush.value()));
dst->bounds += brush->bounds; 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"); options.target_game->print_content_stats(stats, "brushes");
} }
void brush_t::update_bounds() void bspbrush_t::update_bounds()
{ {
this->bounds = {}; this->bounds = {};
for (const face_t &face : faces) { for (const face_t &face : faces) {

View File

@ -122,11 +122,11 @@ void ExportObj_Faces(const std::string &filesuffix, const std::vector<const face
} }
} }
void ExportObj_Brushes(const std::string &filesuffix, const std::vector<const brush_t *> &brushes) void ExportObj_Brushes(const std::string &filesuffix, const std::vector<const bspbrush_t *> &brushes)
{ {
std::vector<const face_t *> faces; std::vector<const face_t *> faces;
for (const brush_t *brush : brushes) for (const bspbrush_t *brush : brushes)
for (auto &face : brush->faces) for (auto &face : brush->faces)
faces.push_back(&face); faces.push_back(&face);

View File

@ -2284,7 +2284,7 @@ WriteBspBrushMap
from q3map from q3map
================== ==================
*/ */
void WriteBspBrushMap(const fs::path &name, const std::vector<std::unique_ptr<brush_t>> &list) void WriteBspBrushMap(const fs::path &name, const std::vector<std::unique_ptr<bspbrush_t>> &list)
{ {
logging::print("writing {}\n", name); logging::print("writing {}\n", name);
std::ofstream f(name); std::ofstream f(name);
@ -2330,16 +2330,16 @@ from q3map
*/ */
static void TestExpandBrushes(const mapentity_t *src) static void TestExpandBrushes(const mapentity_t *src)
{ {
std::vector<std::unique_ptr<brush_t>> hull1brushes; std::vector<std::unique_ptr<bspbrush_t>> hull1brushes;
for (int i = 0; i < src->nummapbrushes; i++) { for (int i = 0; i < src->nummapbrushes; i++) {
const mapbrush_t *mapbrush = &src->mapbrush(i); const mapbrush_t *mapbrush = &src->mapbrush(i);
std::optional<brush_t> hull1brush = LoadBrush( std::optional<bspbrush_t> hull1brush = LoadBrush(
src, mapbrush, {CONTENTS_SOLID}, {}, rotation_t::none, options.target_game->id == GAME_QUAKE_II ? HULL_COLLISION : 1); src, mapbrush, {CONTENTS_SOLID}, {}, rotation_t::none, options.target_game->id == GAME_QUAKE_II ? HULL_COLLISION : 1);
if (hull1brush) { if (hull1brush) {
hull1brushes.emplace_back( hull1brushes.emplace_back(
std::make_unique<brush_t>(std::move(*hull1brush))); std::make_unique<bspbrush_t>(std::move(*hull1brush)));
} }
} }

View File

@ -296,7 +296,7 @@ Adds any additional planes necessary to allow the brush to be expanded
against axial bounding boxes against axial bounding boxes
================= =================
*/ */
static std::vector<std::tuple<size_t, const face_t *>> AddBrushBevels(const brush_t &b) static std::vector<std::tuple<size_t, const face_t *>> AddBrushBevels(const bspbrush_t &b)
{ {
// add already-present planes // add already-present planes
std::vector<std::tuple<size_t, const face_t *>> planes; std::vector<std::tuple<size_t, const face_t *>> planes;
@ -1019,7 +1019,7 @@ hull sizes
*/ */
static void BSPX_Brushes_AddModel( static void BSPX_Brushes_AddModel(
struct bspxbrushes_s *ctx, int modelnum, std::vector<std::unique_ptr<brush_t>> &brushes) struct bspxbrushes_s *ctx, int modelnum, std::vector<std::unique_ptr<bspbrush_t>> &brushes)
{ {
bspxbrushes_permodel permodel{1, modelnum}; bspxbrushes_permodel permodel{1, modelnum};

View File

@ -309,7 +309,7 @@ ChooseMidPlaneFromList
The clipping hull BSP doesn't worry about avoiding splits The clipping hull BSP doesn't worry about avoiding splits
================== ==================
*/ */
static const face_t *ChooseMidPlaneFromList(const std::vector<std::unique_ptr<brush_t>> &brushes, const aabb3d &bounds) static const face_t *ChooseMidPlaneFromList(const std::vector<std::unique_ptr<bspbrush_t>> &brushes, const aabb3d &bounds)
{ {
/* pick the plane that splits the least */ /* pick the plane that splits the least */
vec_t bestaxialmetric = VECT_MAX; vec_t bestaxialmetric = VECT_MAX;
@ -375,7 +375,7 @@ The real BSP heuristic
fixme-brushbsp: prefer splits that include a lot of brush sides? fixme-brushbsp: prefer splits that include a lot of brush sides?
================== ==================
*/ */
static const face_t *ChoosePlaneFromList(const std::vector<std::unique_ptr<brush_t>> &brushes, const aabb3d &bounds) static const face_t *ChoosePlaneFromList(const std::vector<std::unique_ptr<bspbrush_t>> &brushes, const aabb3d &bounds)
{ {
/* pick the plane that splits the least */ /* pick the plane that splits the least */
int minsplits = INT_MAX - 1; 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. Called in parallel.
================== ==================
*/ */
static const face_t *SelectPartition(const std::vector<std::unique_ptr<brush_t>> &brushes) static const face_t *SelectPartition(const std::vector<std::unique_ptr<bspbrush_t>> &brushes)
{ {
// calculate a bounding box of the entire surfaceset // calculate a bounding box of the entire surfaceset
aabb3d bounds; 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; vec_t max = 0;
side_t side = SIDE_FRONT; 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 // 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 https://github.com/id-Software/Quake-2-Tools/blob/master/bsp/qbsp3/brushbsp.c#L935
================ ================
*/ */
twosided<std::unique_ptr<brush_t>> SplitBrush(std::unique_ptr<brush_t> brush, const qplane3d &split) twosided<std::unique_ptr<bspbrush_t>> SplitBrush(std::unique_ptr<bspbrush_t> brush, const qplane3d &split)
{ {
twosided<std::unique_ptr<brush_t>> result; twosided<std::unique_ptr<bspbrush_t>> result;
// check all points // check all points
vec_t d_front = 0; vec_t d_front = 0;
@ -692,9 +692,9 @@ twosided<std::unique_ptr<brush_t>> SplitBrush(std::unique_ptr<brush_t> brush, co
// start with 2 empty brushes // start with 2 empty brushes
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
result[i] = std::make_unique<brush_t>(); result[i] = std::make_unique<bspbrush_t>();
result[i]->original = brush->original; 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]->contents = brush->contents;
result[i]->lmshift = brush->lmshift; result[i]->lmshift = brush->lmshift;
result[i]->func_areaportal = brush->func_areaportal; 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); DivideBounds(node->bounds, split, node->children[0]->bounds, node->children[1]->bounds);
} }
static bool AllDetail(const std::vector<std::unique_ptr<brush_t>> &brushes) static bool AllDetail(const std::vector<std::unique_ptr<bspbrush_t>> &brushes)
{ {
for (auto &brush : brushes) { for (auto &brush : brushes) {
if (!brush->contents.is_any_detail(options.target_game)) { 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. Called in parallel.
================== ==================
*/ */
static void CreateLeaf(std::vector<std::unique_ptr<brush_t>> brushes, node_t *leafnode) static void CreateLeaf(std::vector<std::unique_ptr<bspbrush_t>> brushes, node_t *leafnode)
{ {
leafnode->facelist.clear(); leafnode->facelist.clear();
leafnode->planenum = PLANENUM_LEAF; leafnode->planenum = PLANENUM_LEAF;
@ -850,7 +850,7 @@ PartitionBrushes
Called in parallel. Called in parallel.
================== ==================
*/ */
static void PartitionBrushes(std::vector<std::unique_ptr<brush_t>> brushes, node_t *node) static void PartitionBrushes(std::vector<std::unique_ptr<bspbrush_t>> brushes, node_t *node)
{ {
face_t *split = const_cast<face_t *>(SelectPartition(brushes)); face_t *split = const_cast<face_t *>(SelectPartition(brushes));
@ -876,7 +876,7 @@ static void PartitionBrushes(std::vector<std::unique_ptr<brush_t>> brushes, node
DivideNodeBounds(node, splitplane); DivideNodeBounds(node, splitplane);
// multiple surfaces, so split all the polysurfaces into front and back lists // multiple surfaces, so split all the polysurfaces into front and back lists
std::vector<std::unique_ptr<brush_t>> frontlist, backlist; std::vector<std::unique_ptr<bspbrush_t>> frontlist, backlist;
for (auto &brush : brushes) { for (auto &brush : brushes) {
// NOTE: we're destroying `brushes` here with the std::move() // 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(); mapbrushes = entity->brushes.size();
// set the original pointers // set the original pointers
std::vector<std::unique_ptr<brush_t>> brushcopies; std::vector<std::unique_ptr<bspbrush_t>> brushcopies;
for (const auto &original : entity->brushes) { for (const auto &original : entity->brushes) {
auto copy = std::make_unique<brush_t>(*original); auto copy = std::make_unique<bspbrush_t>(*original);
copy->original = original.get(); copy->original = original.get();
brushcopies.push_back(std::move(copy)); brushcopies.push_back(std::move(copy));
} }

View File

@ -351,7 +351,7 @@ TEST_CASE("duplicatePlanes", "[qbsp]")
CHECK(0 == worldspawn.brushes.size()); CHECK(0 == worldspawn.brushes.size());
CHECK(6 == worldspawn.mapbrush(0).numfaces); CHECK(6 == worldspawn.mapbrush(0).numfaces);
std::optional<brush_t> brush = std::optional<bspbrush_t> brush =
LoadBrush(&worldspawn, &worldspawn.mapbrush(0), {CONTENTS_SOLID}, {}, rotation_t::none, 0); LoadBrush(&worldspawn, &worldspawn.mapbrush(0), {CONTENTS_SOLID}, {}, rotation_t::none, 0);
REQUIRE(std::nullopt != brush); REQUIRE(std::nullopt != brush);
CHECK(6 == brush->faces.size()); CHECK(6 == brush->faces.size());