From 0392698bd308df26855d51d9dc656ed16ca0360d Mon Sep 17 00:00:00 2001 From: Jonathan Date: Sat, 5 Feb 2022 13:18:21 -0500 Subject: [PATCH] Fix for engines that require edges reference valid vertices (edge 0 references vertex 0 but it might not be set in some cases) Change `Brush_GetContents` again so that clip works --- qbsp/brush.cc | 7 +++---- qbsp/writebsp.cc | 6 ++++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/qbsp/brush.cc b/qbsp/brush.cc index 17580955..41c97703 100644 --- a/qbsp/brush.cc +++ b/qbsp/brush.cc @@ -668,14 +668,13 @@ static contentflags_t Brush_GetContents(const mapbrush_t *mapbrush) for (int i = 0; i < mapbrush->numfaces; i++) { const mapface_t &mapface = mapbrush->face(i); const mtexinfo_t &texinfo = map.mtexinfos.at(mapface.texinfo); + contentflags_t contents = options.target_game->face_get_contents(mapface.texname.data(), texinfo.flags, mapface.contents); - if (texinfo.flags.is_skip) { + if (contents.is_empty(options.target_game)) { continue; } - - contentflags_t contents = options.target_game->face_get_contents(mapface.texname.data(), texinfo.flags, mapface.contents); - // use the first non-skip as the base contents value + // use the first non-empty as the base contents value if (!base_contents_set) { base_contents_set = true; base_contents = contents; diff --git a/qbsp/writebsp.cc b/qbsp/writebsp.cc index dd61d83c..f24e16f3 100644 --- a/qbsp/writebsp.cc +++ b/qbsp/writebsp.cc @@ -439,6 +439,12 @@ void FinishBSPFile(void) options.fVerbose = true; LogPrint(LOG_PROGRESS, "---- {} ----\n", __func__); + if (map.bsp.dvertexes.empty()) { + // First vertex must remain unused because edge references it + map.bsp.dvertexes.emplace_back(); + Q_assert(map.bsp.dvertexes.size() == 1); + } + WriteExtendedTexinfoFlags(); WriteBSPFile();