diff --git a/testmaps/q2_unknown_contents.map b/testmaps/q2_unknown_contents.map new file mode 100644 index 00000000..8698a083 --- /dev/null +++ b/testmaps/q2_unknown_contents.map @@ -0,0 +1,35 @@ +// Game: Quake 2 +// Format: Quake2 (Valve) +// entity 0 +{ +"mapversion" "220" +"classname" "worldspawn" +"_tb_textures" "textures/e1u1" +// brush 0 +{ +( -16 -48 -16 ) ( -16 -47 -16 ) ( -16 -48 -15 ) e1u1/color1_4 [ 0 -1 0 0 ] [ 0 0 -1 0 ] 0 1 1 1024 0 0 +( -32 -16 -16 ) ( -32 -16 -15 ) ( -31 -16 -16 ) e1u1/color1_4 [ 1 0 0 0 ] [ 0 0 -1 0 ] 0 1 1 1024 0 0 +( -32 -48 -16 ) ( -31 -48 -16 ) ( -32 -47 -16 ) e1u1/color1_4 [ -1 0 0 0 ] [ 0 -1 0 0 ] 0 1 1 1024 0 0 +( 16 32 16 ) ( 16 33 16 ) ( 17 32 16 ) e1u1/color1_4 [ 1 0 0 0 ] [ 0 -1 0 0 ] 0 1 1 1024 0 0 +( 16 16 0 ) ( 17 16 0 ) ( 16 16 1 ) e1u1/color1_4 [ -1 0 0 0 ] [ 0 0 -1 0 ] 0 1 1 1024 0 0 +( 16 32 0 ) ( 16 32 1 ) ( 16 33 0 ) e1u1/color1_4 [ 0 1 0 0 ] [ 0 0 -1 0 ] 0 1 1 1024 0 0 +} +// brush 1 +{ +( 48 32 0 ) ( 48 33 0 ) ( 48 32 1 ) e1u1/color1_2 [ 0 1 0 0 ] [ 0 0 -1 0 ] 0 1 1 1073741824 0 0 +( 0 -16 -16 ) ( 0 -16 -15 ) ( 1 -16 -16 ) e1u1/color1_2 [ 1 0 0 0 ] [ 0 0 -1 0 ] 0 1 1 1073741824 0 0 +( 0 -48 -16 ) ( 1 -48 -16 ) ( 0 -47 -16 ) e1u1/color1_2 [ -1 0 0 0 ] [ 0 -1 0 0 ] 0 1 1 1073741824 0 0 +( 48 32 16 ) ( 48 33 16 ) ( 49 32 16 ) e1u1/color1_2 [ 1 0 0 0 ] [ 0 -1 0 0 ] 0 1 1 1073741824 0 0 +( 48 16 0 ) ( 49 16 0 ) ( 48 16 1 ) e1u1/color1_2 [ -1 0 0 0 ] [ 0 0 -1 0 ] 0 1 1 1073741824 0 0 +( 80 32 0 ) ( 80 32 1 ) ( 80 33 0 ) e1u1/color1_2 [ 0 1 0 0 ] [ 0 0 -1 0 ] 0 1 1 1073741824 0 0 +} +// brush 2 +{ +( 112 32 0 ) ( 112 33 0 ) ( 112 32 1 ) e1u1/color1_3 [ 0 1 0 0 ] [ 0 0 -1 0 ] 0 1 1 0 1024 0 +( 64 -16 -16 ) ( 64 -16 -15 ) ( 65 -16 -16 ) e1u1/color1_3 [ 1 0 0 0 ] [ 0 0 -1 0 ] 0 1 1 0 1024 0 +( 64 -48 -16 ) ( 65 -48 -16 ) ( 64 -47 -16 ) e1u1/color1_3 [ -1 0 0 0 ] [ 0 -1 0 0 ] 0 1 1 0 1024 0 +( 112 32 16 ) ( 112 33 16 ) ( 113 32 16 ) e1u1/color1_3 [ 1 0 0 0 ] [ 0 -1 0 0 ] 0 1 1 0 1024 0 +( 112 16 0 ) ( 113 16 0 ) ( 112 16 1 ) e1u1/color1_3 [ -1 0 0 0 ] [ 0 0 -1 0 ] 0 1 1 0 1024 0 +( 144 32 0 ) ( 144 32 1 ) ( 144 33 0 ) e1u1/color1_3 [ 0 1 0 0 ] [ 0 0 -1 0 ] 0 1 1 0 1024 0 +} +} diff --git a/tests/test_qbsp_q2.cc b/tests/test_qbsp_q2.cc index 06d3ee53..e8e2bba8 100644 --- a/tests/test_qbsp_q2.cc +++ b/tests/test_qbsp_q2.cc @@ -1048,3 +1048,48 @@ TEST_CASE("q2_tjunc_matrix" * doctest::test_suite("testmaps_q2")) CHECK( has_tjunc(INDEX_SKY, INDEX_SKY)); } } + +TEST_CASE("q2_unknown_contents" * doctest::test_suite("testmaps_q2")) +{ + const auto [bsp, bspx, prt] = LoadTestmapQ2("q2_unknown_contents.map"); + + { + INFO("leaf with contents 1<<10 which is not a valid contents"); + + auto *leaf = BSP_FindLeafAtPoint(&bsp, &bsp.dmodels[0], {0, 0, 0}); + + // FIXME: should the unknown contents get converted to SOLID in the leaf? + CHECK(leaf->contents == (Q2_CONTENTS_SOLID)); + + CHECK(1 == Leaf_Brushes(&bsp, leaf).size()); + // FIXME: should the unknown contents have SOLID added in the brush? + CHECK((Q2_CONTENTS_SOLID | 1024)== + Leaf_Brushes(&bsp, leaf).at(0)->contents); + } + + { + INFO("leaf with contents 1<<30 which is not a valid contents"); + + auto *leaf = BSP_FindLeafAtPoint(&bsp, &bsp.dmodels[0], {64, 0, 0}); + + // FIXME: should the unknown contents get converted to SOLID in the leaf? + CHECK(leaf->contents == (Q2_CONTENTS_SOLID)); + + CHECK(1 == Leaf_Brushes(&bsp, leaf).size()); + // FIXME: should the unknown contents have SOLID added in the brush? + CHECK((Q2_CONTENTS_SOLID | nth_bit(30))== + Leaf_Brushes(&bsp, leaf).at(0)->contents); + } + + { + INFO("face with contents 1<<10 which is not a valid surrflags"); + + auto *top_face = BSP_FindFaceAtPoint(&bsp, &bsp.dmodels[0], {128, 0, 16}, {0, 0, 1}); + REQUIRE(top_face); + + auto *texinfo = BSP_GetTexinfo(&bsp, top_face->texinfo); + REQUIRE(texinfo); + + CHECK(texinfo->flags.native == 1024); + } +} \ No newline at end of file