From 35fe26b7a68496b47943af6caf23d4589277551b Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Mon, 19 Dec 2022 00:55:20 -0700 Subject: [PATCH] qbsp: fix FindTargetEntity (was breaking hiprotate) --- common/entdata.cc | 2 +- include/common/entdata.h | 2 +- qbsp/brush.cc | 5 +- testmaps/qbsp_hiprotate.map | 104 ++++++++++++++++++++++++++++++++++++ tests/test_qbsp.cc | 39 ++++++++------ 5 files changed, 134 insertions(+), 18 deletions(-) create mode 100644 testmaps/qbsp_hiprotate.map diff --git a/common/entdata.cc b/common/entdata.cc index f05b000f..a7ab815c 100644 --- a/common/entdata.cc +++ b/common/entdata.cc @@ -32,7 +32,7 @@ entdict_t::entdict_t() = default; entdict_t::entdict_t(parser_base_t &parser) { parse(parser); } -std::string entdict_t::get(const std::string_view &key) const +const std::string &entdict_t::get(const std::string_view &key) const { if (auto it = find(key); it != keyvalues.end()) { return it->second; diff --git a/include/common/entdata.h b/include/common/entdata.h index 45dd44ef..5729281a 100644 --- a/include/common/entdata.h +++ b/include/common/entdata.h @@ -42,7 +42,7 @@ public: entdict_t(); entdict_t(parser_base_t &parser); - std::string get(const std::string_view &key) const; + const std::string &get(const std::string_view &key) const; vec_t get_float(const std::string_view &key) const; int32_t get_int(const std::string_view &key) const; // returns number of vector components read diff --git a/qbsp/brush.cc b/qbsp/brush.cc index 5b4ebe02..92f6e49c 100644 --- a/qbsp/brush.cc +++ b/qbsp/brush.cc @@ -206,14 +206,17 @@ static void CheckFace(side_t *face, const mapface_t &sourceface, std::optional maps{ + "qbsp_origin.map", + "qbsp_hiprotate.map" // same, but uses info_rotate instead of an origin brush + }; - REQUIRE(prt.has_value()); + for (const auto& map : maps) { + SUBCASE(map.c_str()) { + const auto [bsp, bspx, prt] = LoadTestmapQ1(map); - // 0 = world, 1 = rotate_object - REQUIRE(2 == bsp.dmodels.size()); + REQUIRE(prt.has_value()); - // check that the origin brush didn't clip away any solid faces, or generate faces - REQUIRE(6 == bsp.dmodels[1].numfaces); + // 0 = world, 1 = rotate_object + REQUIRE(2 == bsp.dmodels.size()); - // FIXME: should the origin brush update the dmodel's origin too? - REQUIRE(qvec3f(0, 0, 0) == bsp.dmodels[1].origin); + // check that the origin brush didn't clip away any solid faces, or generate faces + REQUIRE(6 == bsp.dmodels[1].numfaces); - // check that the origin brush updated the entity lump - parser_t parser(bsp.dentdata, { "qbsp_origin.bsp" }); - auto ents = EntData_Parse(parser); - auto it = std::find_if(ents.begin(), ents.end(), - [](const entdict_t &dict) -> bool { return dict.get("classname") == "rotate_object"; }); + // FIXME: should the origin brush update the dmodel's origin too? + REQUIRE(qvec3f(0, 0, 0) == bsp.dmodels[1].origin); - REQUIRE(it != ents.end()); - CHECK(it->get("origin") == "216 -216 340"); + // check that the origin brush updated the entity lump + parser_t parser(bsp.dentdata, {"qbsp_origin.bsp"}); + auto ents = EntData_Parse(parser); + auto it = std::find_if(ents.begin(), ents.end(), + [](const entdict_t &dict) -> bool { return dict.get("classname") == "rotate_object"; }); + + REQUIRE(it != ents.end()); + CHECK(it->get("origin") == "216 -216 340"); + } + } } TEST_CASE("simple" * doctest::test_suite("testmaps_q1"))