diff --git a/common/bsputils.cc b/common/bsputils.cc index c18cfbe0..f3fa9a3b 100644 --- a/common/bsputils.cc +++ b/common/bsputils.cc @@ -625,6 +625,57 @@ void DecompressRow(const uint8_t *in, const int numbytes, uint8_t *decompressed) } while (out - decompressed < row); } +size_t DecompressedVisSize(const mbsp_t *bsp) +{ + if (bsp->loadversion->game->id == GAME_QUAKE_II) { + return (bsp->dvis.bit_offsets.size() + 7) / 8; + } + + return (bsp->dmodels[0].visleafs + 7) / 8; +} + +// from DarkPlaces +void Mod_Q1BSP_DecompressVis(const uint8_t *in, const uint8_t *inend, uint8_t *out, uint8_t *outend) +{ + int c; + uint8_t *outstart = out; + while (out < outend) { + if (in == inend) { + logging::print("Mod_Q1BSP_DecompressVis: input underrun (decompressed {} of {} output bytes)\n", + (out - outstart), (outend - outstart)); + return; + } + + c = *in++; + if (c) { + *out++ = c; + continue; + } + + if (in == inend) { + logging::print( + "Mod_Q1BSP_DecompressVis: input underrun (during zero-run) (decompressed {} of {} output bytes)\n", + (out - outstart), (outend - outstart)); + return; + } + + const int run_length = *in++; + if (!run_length) { + logging::print("Mod_Q1BSP_DecompressVis: 0 repeat\n"); + return; + } + + for (c = run_length; c > 0; c--) { + if (out == outend) { + logging::print("Mod_Q1BSP_DecompressVis: output overrun (decompressed {} of {} output bytes)\n", + (out - outstart), (outend - outstart)); + return; + } + *out++ = 0; + } + } +} + bspx_decoupled_lm_perface BSPX_DecoupledLM(const bspxentries_t &entries, int face_num) { auto &lump_bytes = entries.at("DECOUPLED_LM"); diff --git a/include/common/bsputils.hh b/include/common/bsputils.hh index 506d0686..b104223b 100644 --- a/include/common/bsputils.hh +++ b/include/common/bsputils.hh @@ -107,6 +107,8 @@ void Face_DebugPrint(const mbsp_t *bsp, const mface_t *face); void CompressRow(const uint8_t *vis, const size_t numbytes, std::back_insert_iterator> it); void DecompressRow(const uint8_t *in, const int numbytes, uint8_t *decompressed); +size_t DecompressedVisSize(const mbsp_t *bsp); +void Mod_Q1BSP_DecompressVis(const uint8_t *in, const uint8_t *inend, uint8_t *out, uint8_t *outend); bspx_decoupled_lm_perface BSPX_DecoupledLM(const bspxentries_t &entries, int face_num); diff --git a/light/ltface.cc b/light/ltface.cc index 1d378d30..d957d396 100644 --- a/light/ltface.cc +++ b/light/ltface.cc @@ -449,57 +449,6 @@ static void CalcPoints( } } -static size_t DecompressedVisSize(const mbsp_t *bsp) -{ - if (bsp->loadversion->game->id == GAME_QUAKE_II) { - return (bsp->dvis.bit_offsets.size() + 7) / 8; - } - - return (bsp->dmodels[0].visleafs + 7) / 8; -} - -// from DarkPlaces -static void Mod_Q1BSP_DecompressVis(const uint8_t *in, const uint8_t *inend, uint8_t *out, uint8_t *outend) -{ - int c; - uint8_t *outstart = out; - while (out < outend) { - if (in == inend) { - logging::print("Mod_Q1BSP_DecompressVis: input underrun (decompressed {} of {} output bytes)\n", - (out - outstart), (outend - outstart)); - return; - } - - c = *in++; - if (c) { - *out++ = c; - continue; - } - - if (in == inend) { - logging::print( - "Mod_Q1BSP_DecompressVis: input underrun (during zero-run) (decompressed {} of {} output bytes)\n", - (out - outstart), (outend - outstart)); - return; - } - - const int run_length = *in++; - if (!run_length) { - logging::print("Mod_Q1BSP_DecompressVis: 0 repeat\n"); - return; - } - - for (c = run_length; c > 0; c--) { - if (out == outend) { - logging::print("Mod_Q1BSP_DecompressVis: output overrun (decompressed {} of {} output bytes)\n", - (out - outstart), (outend - outstart)); - return; - } - *out++ = 0; - } - } -} - static bool Mod_LeafPvs(const mbsp_t *bsp, const mleaf_t *leaf, uint8_t *out) { const size_t num_pvsclusterbytes = DecompressedVisSize(bsp); diff --git a/vis/soundpvs.cc b/vis/soundpvs.cc index 8a790bbd..b5908322 100644 --- a/vis/soundpvs.cc +++ b/vis/soundpvs.cc @@ -168,6 +168,8 @@ void CalcPHS(mbsp_t *bsp) std::vector compressed(leafbytes * 2); std::vector uncompressed_orig(leafbytes); + std::vector uncompressed_test(leafbytes); + int32_t count = 0; for (int32_t i = 0; i < portalleafs; i++) { const uint8_t *scan = bsp->dvis.bits.data() + bsp->dvis.get_bit_offset(VIS_PVS, i); @@ -175,6 +177,13 @@ void CalcPHS(mbsp_t *bsp) DecompressRow(scan, leafbytes, uncompressed.data()); std::copy(uncompressed.begin(), uncompressed.end(), uncompressed_orig.begin()); + // migrating to this... for now, just check it produces the same value as the legacy function + Mod_Q1BSP_DecompressVis(scan, + bsp->dvis.bits.data() + bsp->dvis.bits.size(), + uncompressed_test.data(), + uncompressed_test.data() + uncompressed_test.size()); + Q_assert(uncompressed_test == uncompressed); + scan = uncompressed_orig.data(); for (int32_t j = 0; j < leafbytes; j++) {