From 8c1095715c491d9d977dfa6aeeb98e20f7df0c5f Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Thu, 9 Jun 2022 23:48:26 -0600 Subject: [PATCH] qbsp: refactor out is_detail(int32_t types = CFLAGS_DETAIL_MASK) since it's going to depend on game now --- common/bspfile.cc | 54 +++++++++++++++++++++++++++++++++++++++ include/common/bspfile.hh | 12 ++++----- qbsp/brush.cc | 6 ++--- qbsp/csg4.cc | 14 +++++----- qbsp/solidbsp.cc | 4 +-- qbsp/surfaces.cc | 2 +- 6 files changed, 73 insertions(+), 19 deletions(-) diff --git a/common/bspfile.cc b/common/bspfile.cc index b9a84527..94589140 100644 --- a/common/bspfile.cc +++ b/common/bspfile.cc @@ -72,6 +72,12 @@ struct gamedef_generic_t : public gamedef_t bool contents_are_any_detail(const contentflags_t &) const { throw std::bad_cast(); } + bool contents_are_detail_solid(const contentflags_t &contents) const { throw std::bad_cast(); } + + bool contents_are_detail_fence(const contentflags_t &contents) const { throw std::bad_cast(); } + + bool contents_are_detail_illusionary(const contentflags_t &contents) const { throw std::bad_cast(); } + bool contents_are_empty(const contentflags_t &) const { throw std::bad_cast(); } bool contents_are_solid(const contentflags_t &) const { throw std::bad_cast(); } @@ -213,6 +219,21 @@ struct gamedef_q1_like_t : public gamedef_t return ((contents.extended & CFLAGS_DETAIL_MASK) != 0); } + bool contents_are_detail_solid(const contentflags_t &contents) const + { + return ((contents.extended & CFLAGS_DETAIL) != 0); + } + + bool contents_are_detail_fence(const contentflags_t &contents) const + { + return ((contents.extended & CFLAGS_DETAIL_FENCE) != 0); + } + + bool contents_are_detail_illusionary(const contentflags_t &contents) const + { + return ((contents.extended & CFLAGS_DETAIL_ILLUSIONARY) != 0); + } + bool contents_are_empty(const contentflags_t &contents) const { if (contents.extended & CFLAGS_CONTENTS_MASK) @@ -539,6 +560,24 @@ struct gamedef_q2_t : public gamedef_t return ((contents.native & Q2_CONTENTS_DETAIL) != 0); } + bool contents_are_detail_solid(const contentflags_t &contents) const + { + // fixme-brushbsp: check native flag + return ((contents.extended & CFLAGS_DETAIL) != 0); + } + + bool contents_are_detail_fence(const contentflags_t &contents) const + { + // fixme-brushbsp: check native flag + return ((contents.extended & CFLAGS_DETAIL_FENCE) != 0); + } + + bool contents_are_detail_illusionary(const contentflags_t &contents) const + { + // fixme-brushbsp: check native flag + return ((contents.extended & CFLAGS_DETAIL_ILLUSIONARY) != 0); + } + bool contents_are_empty(const contentflags_t &contents) const { if (contents.extended & CFLAGS_CONTENTS_MASK) @@ -1009,6 +1048,21 @@ bool contentflags_t::is_any_detail(const gamedef_t *game) const return game->contents_are_any_detail(*this); } +bool contentflags_t::is_detail_solid(const gamedef_t *game) const +{ + return game->contents_are_detail_solid(*this); +} + +bool contentflags_t::is_detail_fence(const gamedef_t *game) const +{ + return game->contents_are_detail_fence(*this); +} + +bool contentflags_t::is_detail_illusionary(const gamedef_t *game) const +{ + return game->contents_are_detail_illusionary(*this); +} + bool contentflags_t::is_empty(const gamedef_t *game) const { return game->contents_are_empty(*this); diff --git a/include/common/bspfile.hh b/include/common/bspfile.hh index 3eb0abb8..281cb3df 100644 --- a/include/common/bspfile.hh +++ b/include/common/bspfile.hh @@ -604,14 +604,11 @@ struct contentflags_t constexpr bool operator!=(const contentflags_t &other) const { return !(*this == other); } - // check if these contents are marked as any (or a specific kind of) detail brush. - constexpr bool is_detail(int32_t types = CFLAGS_DETAIL_MASK) const - { - return (extended & CFLAGS_DETAIL_MASK) & types; - } - // is any kind of detail? (solid, liquid, etc.) bool is_any_detail(const gamedef_t *game) const; + bool is_detail_solid(const gamedef_t *game) const; + bool is_detail_fence(const gamedef_t *game) const; + bool is_detail_illusionary(const gamedef_t *game) const; bool is_empty(const gamedef_t *game) const; @@ -1800,6 +1797,9 @@ struct gamedef_t virtual contentflags_t create_sky_contents(const int32_t &cflags = 0) const = 0; virtual contentflags_t create_liquid_contents(const int32_t &liquid_type, const int32_t &cflags = 0) const = 0; virtual bool contents_are_any_detail(const contentflags_t &contents) const = 0; + virtual bool contents_are_detail_solid(const contentflags_t &contents) const = 0; + virtual bool contents_are_detail_fence(const contentflags_t &contents) const = 0; + virtual bool contents_are_detail_illusionary(const contentflags_t &contents) const = 0; virtual bool contents_are_empty(const contentflags_t &contents) const = 0; virtual bool contents_are_solid(const contentflags_t &contents) const = 0; virtual bool contents_are_sky(const contentflags_t &contents) const = 0; diff --git a/qbsp/brush.cc b/qbsp/brush.cc index 389dfc50..404e661d 100644 --- a/qbsp/brush.cc +++ b/qbsp/brush.cc @@ -990,11 +990,11 @@ static void Brush_LoadEntity(mapentity_t *dst, const mapentity_t *src, const int stats.solid++; } else if (brush->contents.is_sky(options.target_game)) { stats.sky++; - } else if (brush->contents.is_detail(CFLAGS_DETAIL)) { + } else if (brush->contents.is_detail_solid(options.target_game)) { stats.detail++; - } else if (brush->contents.is_detail(CFLAGS_DETAIL_ILLUSIONARY)) { + } else if (brush->contents.is_detail_illusionary(options.target_game)) { stats.detail_illusionary++; - } else if (brush->contents.is_detail(CFLAGS_DETAIL_FENCE)) { + } else if (brush->contents.is_detail_fence(options.target_game)) { stats.detail_fence++; } else { stats.liquid++; diff --git a/qbsp/csg4.cc b/qbsp/csg4.cc index da2affe3..6154d34b 100644 --- a/qbsp/csg4.cc +++ b/qbsp/csg4.cc @@ -262,13 +262,13 @@ static bool ShouldClipbrushEatBrush(const brush_t &brush, const brush_t &clipbru return false; } - if (clipbrush.contents.is_detail(CFLAGS_DETAIL_ILLUSIONARY) && - !brush.contents.is_detail(CFLAGS_DETAIL_ILLUSIONARY)) { + if (clipbrush.contents.is_detail_illusionary(options.target_game) && + !brush.contents.is_detail_illusionary(options.target_game)) { /* CONTENTS_DETAIL_ILLUSIONARY never clips anything but itself */ return false; } - if (clipbrush.contents.is_detail(CFLAGS_DETAIL_FENCE) && !brush.contents.is_detail(CFLAGS_DETAIL_FENCE)) { + if (clipbrush.contents.is_detail_fence(options.target_game) && !brush.contents.is_detail_fence(options.target_game)) { /* CONTENTS_DETAIL_FENCE never clips anything but itself */ return false; } @@ -293,12 +293,12 @@ static bool ShouldClipbrushEatBrush(const brush_t &brush, const brush_t &clipbru (brush.contents.is_sky(options.target_game) && (!clipbrush.contents.is_solid(options.target_game) && !clipbrush.contents.is_sky(options.target_game))) - || (brush.contents.is_detail(CFLAGS_DETAIL) && (!clipbrush.contents.is_solid(options.target_game) && - !clipbrush.contents.is_sky(options.target_game) && - !clipbrush.contents.is_detail(CFLAGS_DETAIL))) + || (brush.contents.is_detail_solid(options.target_game) && (!clipbrush.contents.is_solid(options.target_game) && + !clipbrush.contents.is_sky(options.target_game) && + !clipbrush.contents.is_detail_solid(options.target_game))) || (brush.contents.is_liquid(options.target_game) && - clipbrush.contents.is_detail(CFLAGS_DETAIL_ILLUSIONARY)) + clipbrush.contents.is_detail_illusionary(options.target_game)) || (brush.contents.is_fence() && clipbrush.contents.is_liquid(options.target_game))) { return false; diff --git a/qbsp/solidbsp.cc b/qbsp/solidbsp.cc index 8d068899..2dc4e017 100644 --- a/qbsp/solidbsp.cc +++ b/qbsp/solidbsp.cc @@ -81,9 +81,9 @@ void DetailToSolid(node_t *node) } // We need to remap CONTENTS_DETAIL to a standard quake content type - if (node->contents.is_detail(CFLAGS_DETAIL)) { + if (node->contents.is_detail_solid(options.target_game)) { node->contents = options.target_game->create_solid_contents(); - } else if (node->contents.is_detail(CFLAGS_DETAIL_ILLUSIONARY)) { + } else if (node->contents.is_detail_illusionary(options.target_game)) { node->contents = options.target_game->create_empty_contents(); } /* N.B.: CONTENTS_DETAIL_FENCE is not remapped to CONTENTS_SOLID until the very last moment, diff --git a/qbsp/surfaces.cc b/qbsp/surfaces.cc index 1fdae8e5..7fe7ddae 100644 --- a/qbsp/surfaces.cc +++ b/qbsp/surfaces.cc @@ -568,7 +568,7 @@ static std::list ClipFacesToTree_r(node_t *node, const brush_t *srcbru if (node->planenum == PLANENUM_LEAF) { // fixme-brushbsp: move to contentflags_t? if (node->contents.is_solid(options.target_game) - || node->contents.is_detail(CFLAGS_DETAIL) + || node->contents.is_detail_solid(options.target_game) || node->contents.is_sky(options.target_game)) { // solids eat any faces that reached this point return {};