common: surfflags_t: convert is_hint to function that checks for Q2_SURF_HINT

This commit is contained in:
Eric Wasylishen 2025-02-01 16:04:08 -07:00
parent 429921868a
commit f930305695
11 changed files with 47 additions and 28 deletions

View File

@ -794,7 +794,7 @@ struct gamedef_q2_t : public gamedef_t
return false;
// Q2RTX should light nodraw faces
if (light_nodraw && (flags.native_q2 & Q2_SURF_NODRAW)) {
if (light_nodraw && flags.is_nodraw()) {
return true;
}

View File

@ -182,6 +182,27 @@ bool surfflags_t::is_nodraw() const
return !!(native_q2 & Q2_SURF_NODRAW);
}
void surfflags_t::set_nodraw(bool nodraw)
{
if (nodraw)
native_q2 = static_cast<q2_surf_flags_t>(native_q2 | Q2_SURF_NODRAW);
else
native_q2 = static_cast<q2_surf_flags_t>(native_q2 & ~Q2_SURF_NODRAW);
}
bool surfflags_t::is_hint() const
{
return !!(native_q2 & Q2_SURF_HINT);
}
void surfflags_t::set_hint(bool hint)
{
if (hint)
native_q2 = static_cast<q2_surf_flags_t>(native_q2 | Q2_SURF_HINT);
else
native_q2 = static_cast<q2_surf_flags_t>(native_q2 & ~Q2_SURF_HINT);
}
bool surfflags_t::needs_write() const
{
return *this != surfflags_t();

View File

@ -241,8 +241,12 @@ struct surfflags_t
// an invisible surface (Q1 "skip" texture, Q2 SURF_NODRAW)
bool is_nodraw() const;
void set_nodraw(bool nodraw);
// hint surface
bool is_hint;
bool is_hint() const;
void set_hint(bool hint);
// is a skip surface from a hint brush
bool is_hintskip;

View File

@ -1028,13 +1028,10 @@ static void LoadExtendedTexinfoFlags(const fs::path &sourcefilename, const mbsp_
auto &flags = extended_texinfo_flags[index];
if (val.contains("is_nodraw")) {
if (val.at("is_nodraw").get<bool>())
flags.native_q2 = static_cast<q2_surf_flags_t>(flags.native_q2 | Q2_SURF_NODRAW);
else
flags.native_q2 = static_cast<q2_surf_flags_t>(flags.native_q2 & ~Q2_SURF_NODRAW);
flags.set_nodraw(val.at("is_nodraw").get<bool>());
}
if (val.contains("is_hint")) {
flags.is_hint = val.at("is_hint").get<bool>();
flags.set_hint(val.at("is_hint").get<bool>());
}
if (val.contains("is_hintskip")) {
flags.is_hintskip = val.at("is_hintskip").get<bool>();

View File

@ -1344,7 +1344,7 @@ void GLView::renderBSP(const QString &file, const mbsp_t &bsp, const bspxentries
if (bsp.loadversion->game->id == GAME_QUAKE_II) {
if (texinfo->flags.native_q2 & Q2_SURF_NODRAW) {
if (texinfo->flags.is_nodraw()) {
continue;
}

View File

@ -52,7 +52,7 @@ bool side_t::is_visible() const
// workaround for qbsp_q2_mist_clip.map - we want to treat nodraw faces as "!visible"
// so they're used as splitters after mist
if (get_texinfo().flags.is_nodraw()) {
if (get_texinfo().flags.is_hint) {
if (get_texinfo().flags.is_hint()) {
return true;
}
@ -568,12 +568,12 @@ std::optional<bspbrush_t> LoadBrush(const mapentity_t &src, mapbrush_t &mapbrush
// to the world extents (winding & bounds) which throws
// a lot of warnings. is this how this should be working?
#if 0
if (!hullnum.value_or(0) && mapbrush.is_hint) {
if (!hullnum.value_or(0) && mapbrush.is_hint()) {
/* Don't generate hintskip faces */
const maptexinfo_t &texinfo = src.get_texinfo();
// any face that isn't a hint is assumed to be hintskip
if (!texinfo.flags.is_hint) {
if (!texinfo.flags.is_hint()) {
continue;
}
}

View File

@ -317,7 +317,7 @@ static int TestBrushToPlanenum(
if (front && back) {
if (!(side.get_texinfo().flags.is_hintskip)) {
(*numsplits)++;
if (side.get_texinfo().flags.is_hint) {
if (side.get_texinfo().flags.is_hint()) {
*hintsplit = true;
}
}
@ -1067,7 +1067,7 @@ static side_t *SelectSplitPlane(
value -= epsilonbrush * 1000; // avoid!
// never split a hint side except with another hint
if (hintsplit && !(side.get_texinfo().flags.is_hint))
if (hintsplit && !(side.get_texinfo().flags.is_hint()))
value = -9999999;
// save off the side test so we don't need

View File

@ -48,7 +48,7 @@ static bool ShouldOmitFace(face_t *f)
return true;
}
if (map.mtexinfos.at(f->texinfo).flags.is_hint)
if (map.mtexinfos.at(f->texinfo).flags.is_hint())
return true;
// HACK: to save a few faces, don't output the interior faces of sky brushes
@ -364,7 +364,7 @@ static std::list<std::unique_ptr<face_t>> SubdivideFace(std::unique_ptr<face_t>
/* special (non-surface cached) faces don't need subdivision */
const maptexinfo_t &tex = f->get_texinfo();
if (tex.flags.is_nodraw() || tex.flags.is_hint || !qbsp_options.target_game->surf_is_subdivided(tex.flags)) {
if (tex.flags.is_nodraw() || tex.flags.is_hint() || !qbsp_options.target_game->surf_is_subdivided(tex.flags)) {
std::list<std::unique_ptr<face_t>> result;
result.push_back(std::move(f));
return result;

View File

@ -633,17 +633,15 @@ static surfflags_t SurfFlagsForEntity(
// the only annoyance is we can't access the various options (noskip,
// splitturb, etc) from there.
if (IsSkipName(texname))
flags.native_q2 = static_cast<q2_surf_flags_t>(flags.native_q2 | Q2_SURF_NODRAW);
flags.set_nodraw(true);
if (IsHintName(texname))
flags.set_hint(true);
if (qbsp_options.target_game->id != GAME_QUAKE_II) {
if (IsHintName(texname))
flags.is_hint = true;
if (IsSpecialName(texname, allow_litwater))
flags.native_q1 = static_cast<q1_surf_flags_t>(flags.native_q1 | TEX_SPECIAL);
} else {
flags.native_q2 = texinfo.flags.native_q2;
if ((flags.native_q2 & Q2_SURF_HINT) || IsHintName(texname))
flags.is_hint = true;
if ((flags.native_q2 & Q2_SURF_TRANS33) || (flags.native_q2 & Q2_SURF_TRANS66))
is_translucent = true;
}
@ -877,8 +875,7 @@ static void ParseTextureDef(const mapentity_t &entity, const mapfile::brush_side
// This fixes a bug in some old maps.
if ((extinfo.info->flags.native_q2 & (Q2_SURF_SKY | Q2_SURF_NODRAW)) == (Q2_SURF_SKY | Q2_SURF_NODRAW)) {
extinfo.info->flags.native_q2 =
static_cast<q2_surf_flags_t>(extinfo.info->flags.native_q2 & ~Q2_SURF_NODRAW);
extinfo.info->flags.set_nodraw(false);
if (qbsp_options.verbose.value()) {
logging::print("WARNING: {}: SKY | NODRAW mixed. Removing NODRAW.\n", mapface.line);
@ -1016,7 +1013,7 @@ static std::optional<mapface_t> ParseBrushFace(const mapfile::brush_side_t &inpu
tx.flags = SurfFlagsForEntity(tx, entity, face.contents);
// to save on texinfo, reset all invisible sides to default texvecs
if (tx.flags.is_nodraw() || tx.flags.is_hintskip || tx.flags.is_hint) {
if (tx.flags.is_nodraw() || tx.flags.is_hintskip || tx.flags.is_hint()) {
mapfile::brush_side_t temp;
temp.plane = face.get_plane();
temp.set_texinfo(mapfile::texdef_quake_ed_t{{0, 0}, 0, {1, 1}});
@ -1564,7 +1561,7 @@ static mapbrush_t ParseBrush(const mapfile::brush_t &in, mapentity_t &entity, te
continue;
}
if (face->get_texinfo().flags.is_hint) {
if (face->get_texinfo().flags.is_hint()) {
is_hint = true;
}
@ -2000,7 +1997,7 @@ bool IsNonRemoveWorldBrushEntity(const mapentity_t &entity)
inline bool MapBrush_IsHint(const mapbrush_t &brush)
{
for (auto &f : brush.faces) {
if (f.get_texinfo().flags.is_hint)
if (f.get_texinfo().flags.is_hint())
return true;
}

View File

@ -412,7 +412,7 @@ void MarkBrushSidesInvisible(bspbrush_t::container &brushes)
if (face.source) {
face.source->visible = false;
if (face.source->get_texinfo().flags.is_hint) {
if (face.source->get_texinfo().flags.is_hint()) {
face.source->visible = true; // hints are always visible
}
}

View File

@ -377,8 +377,8 @@ static void WriteExtendedTexinfoFlags()
if (tx.flags.is_nodraw()) {
t["is_nodraw"] = tx.flags.is_nodraw();
}
if (tx.flags.is_hint) {
t["is_hint"] = tx.flags.is_hint;
if (tx.flags.is_hint()) {
t["is_hint"] = tx.flags.is_hint();
}
if (tx.flags.no_dirt) {
t["no_dirt"] = tx.flags.no_dirt;