From a02a4ec3161e7481041c824f4e20c84e811a05c5 Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Tue, 18 Jul 2023 17:57:51 -0600 Subject: [PATCH] imglib: fix wad3 loading (thanks to erysdren for the fix) add a basic half-life test case (box map) --- CMakeLists.txt | 2 + common/imglib.cc | 2 +- testmaps.hh.in | 2 + testmaps/deprecated/hlwad.wad | Bin 0 -> 6296 bytes testmaps/hl_basic.map | 79 ++++++++++++++++++++++++++++++++++ tests/test_qbsp.cc | 20 +++++++++ 6 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 testmaps/deprecated/hlwad.wad create mode 100644 testmaps/hl_basic.map diff --git a/CMakeLists.txt b/CMakeLists.txt index 01b66a5e..dfeaece7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -101,6 +101,8 @@ find_package(TBB REQUIRED) set(TEST_QUAKE_MAP_EXPORT_DIR "" CACHE PATH "When running unit tests, export Quake maps to this directory (useful for testing in game)") set(TEST_QUAKE2_MAP_EXPORT_DIR "" CACHE PATH "When running unit tests, export Quake 2 maps to this directory (useful for testing in game)") +set(TEST_HEXEN2_MAP_EXPORT_DIR "" CACHE PATH "When running unit tests, export Hexen 2 maps to this directory (useful for testing in game)") +set(TEST_HALFLIFE_MAP_EXPORT_DIR "" CACHE PATH "When running unit tests, export Half-Life maps to this directory (useful for testing in game)") add_subdirectory(3rdparty) add_subdirectory(common) diff --git a/common/imglib.cc b/common/imglib.cc index aec33786..dc6484fe 100644 --- a/common/imglib.cc +++ b/common/imglib.cc @@ -220,7 +220,7 @@ std::optional load_mip( if (game->id == GAME_HALF_LIFE) { bool valid_mip_palette = true; - int32_t mip3_size = (header.width >> 3) + (header.height >> 3); + int32_t mip3_size = (header.width >> 3) * (header.height >> 3); size_t palette_size = sizeof(uint16_t) + (sizeof(qvec3b) * 256); if (header.offsets[3] <= 0) { diff --git a/testmaps.hh.in b/testmaps.hh.in index e5e7486a..267784dd 100644 --- a/testmaps.hh.in +++ b/testmaps.hh.in @@ -1,3 +1,5 @@ inline const char *testmaps_dir = "@CMAKE_CURRENT_SOURCE_DIR@/testmaps"; inline const char *test_quake_maps_dir = "@TEST_QUAKE_MAP_EXPORT_DIR@"; inline const char *test_quake2_maps_dir = "@TEST_QUAKE2_MAP_EXPORT_DIR@"; +inline const char *test_hexen2_maps_dir = "@TEST_HEXEN2_MAP_EXPORT_DIR@"; +inline const char *test_halflife_maps_dir = "@TEST_HALFLIFE_MAP_EXPORT_DIR@"; diff --git a/testmaps/deprecated/hlwad.wad b/testmaps/deprecated/hlwad.wad new file mode 100644 index 0000000000000000000000000000000000000000..6d75867e79a537894597d3961f2a1b39a226e051 GIT binary patch literal 6296 zcmeI1e>7iZ9LHaiBuSEFGD#*$l9?ovNs^f)nItnIvu~1plbK91NkWp$gd|ClBuVz2 zBuSEFW+q9JB+1N7O82Yv&;FRxxo2nRbnfSz&;9kB=bYzxo%j2mbKiH%M%Q(#fH-}K zkjcY#%Gnj@y-gM-m*XrvSGKvbwT0Fd`f^a5^GXm^3WccY3DSItpBMs?e#FpAko+gT zzeEX0@}DStlK&+Ci4u_HKT-H3|4IH6B_PRvqVP%nTj~3M1-vWSR~kPvK#7mU=S&37 zwmzzhPpi`wQ~W=_-=B4=PVF=6Kb}zrt|*Txa2}|_`Je_DfI3_V8gLP4!o{Ekmw*tz zUJ5#J83-|~kizQ06(Gd6tHA)S1VdN@MsO7v!_{B{*MKRk1v9vIIm^8cEZ};ugd4yL zZUk$%32a~;*ur|SgPXw~ZUG0l6&zs$IKgepx$s7Cf!o0q?f^Hq6Wrl0@PJL=37f$S z?gnqT2YldO@P+%p54M0m+z$cp00hE=5CmHx7`8zOJOrT-2I26qkWs^Sh=d&=gGV3= z9))Ol3}Rp>$l-B_g(rku8+JiF?1lt*5)xq#B&n!8rK*~&ruMYDdWwd|UQNwZEv;v? zwbOKTp4HV&*VB7WUq8dZ;CVyCOe3Q#W8-WSlNU@)bIiNCk3S%!Ux|qalaiW~lRr*LX-Q4}BrUBqJ^j;+jJC|o&$6@Ib8h2!z>G`?0ccQQFm;V0A zfq`EK2d9RHej6U19vS(4baZBH?AZAD?8L> LoadTestmap( destdir = test_quake2_maps_dir; } else if (qbsp_options.target_game->id == GAME_QUAKE) { destdir = test_quake_maps_dir; + } else if (qbsp_options.target_game->id == GAME_HEXEN_II) { + destdir = test_hexen2_maps_dir; + } else if (qbsp_options.target_game->id == GAME_HALF_LIFE) { + destdir = test_halflife_maps_dir; } // copy .bsp to game's basedir/maps directory, for easy in-game testing @@ -1901,3 +1905,19 @@ TEST_CASE("q1_missing_texture") CHECK("" == bsp.dtex.textures[1].name); CHECK(bsp.dtex.textures[1].null_texture); } + +TEST_CASE("hl_basic") +{ + const auto [bsp, bspx, prt] = LoadTestmap("hl_basic.map", {"-hlbsp"}); + CHECK(prt); + + REQUIRE(2 == bsp.dtex.textures.size()); + + // FIXME: we shouldn't really be writing skip + CHECK(bsp.dtex.textures[0].null_texture); + + CHECK("hltest" == bsp.dtex.textures[1].name); + CHECK(!bsp.dtex.textures[1].null_texture); + CHECK(64 == bsp.dtex.textures[1].width); + CHECK(64 == bsp.dtex.textures[1].height); +}