From 8438232d99afd84ac9ffceb15aebdbda5ecb9c1e Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Mon, 20 Feb 2023 16:37:04 -0700 Subject: [PATCH] tests: add a first test case for vis --- tests/test_ltface.cc | 27 ++++--------------------- tests/test_qbsp.hh | 24 ++++++++++++++++++++++ tests/test_vis.cc | 48 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+), 23 deletions(-) diff --git a/tests/test_ltface.cc b/tests/test_ltface.cc index 807da07f..26a115fe 100644 --- a/tests/test_ltface.cc +++ b/tests/test_ltface.cc @@ -7,25 +7,6 @@ #include #include "test_qbsp.hh" -struct testresults_t -{ - mbsp_t bsp; - bspxentries_t bspx; -}; - -struct testresults_lit_t -{ - mbsp_t bsp; - bspxentries_t bspx; - std::vector lit; -}; - -enum class runvis_t -{ - no, - yes -}; - static testresults_t QbspVisLight_Common(const std::filesystem::path &name, std::vector extra_qbsp_args, std::vector extra_light_args, runvis_t run_vis) { @@ -91,8 +72,8 @@ static testresults_t QbspVisLight_Common(const std::filesystem::path &name, std: } } -static testresults_lit_t QbspVisLight_Q1( - const std::filesystem::path &name, std::vector extra_light_args, runvis_t run_vis = runvis_t::no) +testresults_lit_t QbspVisLight_Q1( + const std::filesystem::path &name, std::vector extra_light_args, runvis_t run_vis) { auto res = QbspVisLight_Common(name, {}, extra_light_args, run_vis); @@ -105,8 +86,8 @@ static testresults_lit_t QbspVisLight_Q1( return testresults_lit_t{.bsp = res.bsp, .bspx = res.bspx, .lit = litdata}; } -static testresults_t QbspVisLight_Q2( - const std::filesystem::path &name, std::vector extra_light_args, runvis_t run_vis = runvis_t::no) +testresults_t QbspVisLight_Q2( + const std::filesystem::path &name, std::vector extra_light_args, runvis_t run_vis) { return QbspVisLight_Common(name, {"-q2bsp"}, extra_light_args, run_vis); } diff --git a/tests/test_qbsp.hh b/tests/test_qbsp.hh index 743a5d73..23a30bfa 100644 --- a/tests/test_qbsp.hh +++ b/tests/test_qbsp.hh @@ -27,3 +27,27 @@ int CountClipnodeNodes(const mbsp_t &bsp, int hullnum); bool PortalMatcher(const prtfile_winding_t &a, const prtfile_winding_t &b); std::map CountClipnodeLeafsByContentType(const mbsp_t &bsp, int hullnum); int CountClipnodeNodes(const mbsp_t &bsp, int hullnum); + +struct testresults_t +{ + mbsp_t bsp; + bspxentries_t bspx; +}; + +struct testresults_lit_t +{ + mbsp_t bsp; + bspxentries_t bspx; + std::vector lit; +}; + +enum class runvis_t +{ + no, + yes +}; + +testresults_lit_t QbspVisLight_Q1( + const std::filesystem::path &name, std::vector extra_light_args, runvis_t run_vis = runvis_t::no); +testresults_t QbspVisLight_Q2( + const std::filesystem::path &name, std::vector extra_light_args, runvis_t run_vis = runvis_t::no); \ No newline at end of file diff --git a/tests/test_vis.cc b/tests/test_vis.cc index e69de29b..cc08d097 100644 --- a/tests/test_vis.cc +++ b/tests/test_vis.cc @@ -0,0 +1,48 @@ +#include +#include + +#include + +#include "test_qbsp.hh" +#include "testutils.hh" + +TEST_CASE("qbsp_q2_detail_leak_test.map" * doctest::may_fail()) +{ + auto [bsp, bspx] = QbspVisLight_Q2("qbsp_q2_detail_leak_test.map", {}, runvis_t::yes); + const auto vis = DecompressAllVis(&bsp); + + auto leaf_sees = [&](const mleaf_t *a, const mleaf_t *b) -> bool { + auto &pvs = vis.at(a->cluster); + return !!(pvs[b->cluster >> 3] & (1 << (b->cluster & 7))); + }; + + // points arranged so the items can only see the corrseponding _curve point + const auto item_enviro = qvec3d(48, 464, 32); + const auto item_enviro_curve = qvec3d(-64, 848, 56); + const auto player_start_curve = qvec3d(-64, -432, 56); + const auto player_start = qvec3d(64, -176, 40); + + auto *item_enviro_leaf = BSP_FindLeafAtPoint(&bsp, &bsp.dmodels[0], item_enviro); + auto *item_enviro_curve_leaf = BSP_FindLeafAtPoint(&bsp, &bsp.dmodels[0], item_enviro_curve); + auto *player_start_curve_leaf = BSP_FindLeafAtPoint(&bsp, &bsp.dmodels[0], player_start_curve); + auto *player_start_leaf = BSP_FindLeafAtPoint(&bsp, &bsp.dmodels[0], player_start); + + CHECK(item_enviro_leaf->contents == 0); + CHECK(item_enviro_curve_leaf->contents == 0); + CHECK(player_start_curve_leaf->contents == 0); + CHECK(player_start_leaf->contents == 0); + + { + INFO("check item_enviro_leaf"); + CHECK(leaf_sees(item_enviro_leaf, item_enviro_curve_leaf)); + CHECK(!leaf_sees(item_enviro_leaf, player_start_curve_leaf)); + CHECK(!leaf_sees(item_enviro_leaf, player_start_leaf)); + } + + { + INFO("check player_start_leaf"); + CHECK(leaf_sees(player_start_leaf, player_start_curve_leaf)); + CHECK(!leaf_sees(player_start_leaf, item_enviro_curve_leaf)); + CHECK(!leaf_sees(player_start_leaf, item_enviro_leaf)); + } +}