tests: add a first test case for vis
This commit is contained in:
parent
b17633f746
commit
8438232d99
|
|
@ -7,25 +7,6 @@
|
|||
#include <vis/vis.hh>
|
||||
#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<uint8_t> lit;
|
||||
};
|
||||
|
||||
enum class runvis_t
|
||||
{
|
||||
no,
|
||||
yes
|
||||
};
|
||||
|
||||
static testresults_t QbspVisLight_Common(const std::filesystem::path &name, std::vector<std::string> extra_qbsp_args,
|
||||
std::vector<std::string> 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<std::string> extra_light_args, runvis_t run_vis = runvis_t::no)
|
||||
testresults_lit_t QbspVisLight_Q1(
|
||||
const std::filesystem::path &name, std::vector<std::string> 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<std::string> extra_light_args, runvis_t run_vis = runvis_t::no)
|
||||
testresults_t QbspVisLight_Q2(
|
||||
const std::filesystem::path &name, std::vector<std::string> extra_light_args, runvis_t run_vis)
|
||||
{
|
||||
return QbspVisLight_Common(name, {"-q2bsp"}, extra_light_args, run_vis);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<int, int> 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<uint8_t> lit;
|
||||
};
|
||||
|
||||
enum class runvis_t
|
||||
{
|
||||
no,
|
||||
yes
|
||||
};
|
||||
|
||||
testresults_lit_t QbspVisLight_Q1(
|
||||
const std::filesystem::path &name, std::vector<std::string> extra_light_args, runvis_t run_vis = runvis_t::no);
|
||||
testresults_t QbspVisLight_Q2(
|
||||
const std::filesystem::path &name, std::vector<std::string> extra_light_args, runvis_t run_vis = runvis_t::no);
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
#include <common/bsputils.hh>
|
||||
#include <common/qvec.hh>
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
#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));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue