refactor: move Mod_Q1BSP_DecompressVis to bsputils.cc
This commit is contained in:
parent
2b8f8c826d
commit
52fcb7a234
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -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<std::vector<uint8_t>> 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);
|
||||
|
||||
|
|
|
|||
|
|
@ -431,57 +431,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);
|
||||
|
|
|
|||
|
|
@ -168,6 +168,8 @@ void CalcPHS(mbsp_t *bsp)
|
|||
std::vector<uint8_t> compressed(leafbytes * 2);
|
||||
std::vector<uint8_t> uncompressed_orig(leafbytes);
|
||||
|
||||
std::vector<uint8_t> 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++) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue