From 13612f18d0c89a0b6601c292d761bc32cdc94877 Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Sun, 1 May 2022 00:48:58 -0600 Subject: [PATCH] qbsp: factor out 'chops' condition in BrushGE --- common/bspfile.cc | 18 ++++++++++++++++++ include/common/bspfile.hh | 7 +++++++ qbsp/csg4.cc | 7 +------ 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/common/bspfile.cc b/common/bspfile.cc index a794d9a5..d21da8f3 100644 --- a/common/bspfile.cc +++ b/common/bspfile.cc @@ -58,6 +58,8 @@ struct gamedef_generic_t : public gamedef_t int32_t contents_priority(const contentflags_t &) const { throw std::bad_cast(); } + bool chops(const contentflags_t &) const { throw std::bad_cast(); } + contentflags_t create_extended_contents(const int32_t &) const { throw std::bad_cast(); } contentflags_t create_empty_contents(const int32_t &) const { throw std::bad_cast(); } @@ -169,6 +171,10 @@ struct gamedef_q1_like_t : public gamedef_t } } + bool chops(const contentflags_t &contents) const { + return contents_are_solid(contents) || contents_are_sky(contents) || (contents.extended & CFLAGS_DETAIL); + } + contentflags_t create_extended_contents(const int32_t &cflags) const { return {0, cflags}; } contentflags_t create_empty_contents(const int32_t &cflags = 0) const @@ -495,6 +501,13 @@ struct gamedef_q2_t : public gamedef_t } } + bool chops(const contentflags_t &contents) const + { + // TODO: ideally this could just check for Q2_CONTENTS_SOLID + // once we implement detail as Q2_CONTENTS_SOLID|Q2_CONTENTS_DETAIL + return contents_are_solid(contents) || (contents.extended & CFLAGS_DETAIL); + } + contentflags_t create_extended_contents(const int32_t &cflags) const { return {0, cflags}; } contentflags_t create_empty_contents(const int32_t &cflags) const { return {0, cflags}; } @@ -973,6 +986,11 @@ int32_t contentflags_t::priority(const gamedef_t *game) const return game->contents_priority(*this); } +bool contentflags_t::chops(const gamedef_t* game) const +{ + return game->chops(*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 56cacd1a..f8f73dcc 100644 --- a/include/common/bspfile.hh +++ b/include/common/bspfile.hh @@ -632,8 +632,14 @@ struct contentflags_t // also match. bool types_equal(const contentflags_t &other, const gamedef_t *game) const; + // when multiple brushes contribute to a leaf, the higher priority + // one determines the leaf contents int32_t priority(const gamedef_t *game) const; + // whether this should chop (if so, only lower priority content brushes get chopped) + // should return true only for solid / opaque content types + bool chops(const gamedef_t *game) const; + std::string to_string(const gamedef_t *game) const; }; @@ -1767,6 +1773,7 @@ struct gamedef_t virtual contentflags_t cluster_contents(const contentflags_t &contents0, const contentflags_t &contents1) const = 0; virtual int32_t get_content_type(const contentflags_t &contents) const = 0; virtual int32_t contents_priority(const contentflags_t &contents) const = 0; + virtual bool chops(const contentflags_t &) const = 0; virtual contentflags_t create_extended_contents(const int32_t &cflags = 0) const = 0; virtual contentflags_t create_empty_contents(const int32_t &cflags = 0) const = 0; virtual contentflags_t create_solid_contents(const int32_t &cflags = 0) const = 0; diff --git a/qbsp/csg4.cc b/qbsp/csg4.cc index 3a9c413f..845b9977 100644 --- a/qbsp/csg4.cc +++ b/qbsp/csg4.cc @@ -527,12 +527,7 @@ static bool BrushGE(const brush_t& a, const brush_t& b) { // only chop if at least one of the two contents is // opaque (solid, sky, or detail) - if (!(a.contents.is_solid(options.target_game) - || b.contents.is_solid(options.target_game) - || a.contents.is_sky(options.target_game) - || b.contents.is_sky(options.target_game) - || a.contents.is_detail(CFLAGS_DETAIL) - || b.contents.is_detail(CFLAGS_DETAIL))) { + if (!(a.contents.chops(options.target_game) || b.contents.chops(options.target_game))) { return false; }