diff --git a/include/light/light.hh b/include/light/light.hh index 463d1845..f3cb40fa 100644 --- a/include/light/light.hh +++ b/include/light/light.hh @@ -414,6 +414,8 @@ extern std::vector filebase; extern std::vector lit_filebase; extern std::vector lux_filebase; +const std::unordered_map> &UncompressedVis(); + bool IsOutputtingSupplementaryData(); std::vector> &LightSurfaces(); diff --git a/light/light.cc b/light/light.cc index 14cad9fb..d85bb9cc 100644 --- a/light/light.cc +++ b/light/light.cc @@ -91,6 +91,13 @@ static int lux_file_p; /// offset of end of space for luxfile data static int lux_file_end; +static std::unordered_map> all_uncompressed_vis; + +const std::unordered_map> &UncompressedVis() +{ + return all_uncompressed_vis; +} + std::vector modelinfo; std::vector tracelist; std::vector selfshadowlist; @@ -1526,6 +1533,7 @@ static void ResetLight() lux_file_p = 0; lux_file_end = 0; + all_uncompressed_vis.clear(); modelinfo.clear(); tracelist.clear(); selfshadowlist.clear(); @@ -1634,6 +1642,7 @@ int light_main(int argc, const char **argv) light_options.postinitialize(argc, argv); + all_uncompressed_vis = DecompressAllVis(&bsp, true); FindModelInfo(&bsp); FindDebugFace(&bsp); diff --git a/light/ltface.cc b/light/ltface.cc index 250389c6..14bc7d5f 100644 --- a/light/ltface.cc +++ b/light/ltface.cc @@ -42,7 +42,7 @@ std::atomic total_light_rays, total_light_ray_hits, total_samplepoints std::atomic total_bounce_rays, total_bounce_ray_hits; std::atomic total_surflight_rays, total_surflight_ray_hits; // mxd std::atomic fully_transparent_lightmaps; -bool warned_about_light_map_overflow, warned_about_light_style_overflow; +static bool warned_about_light_map_overflow, warned_about_light_style_overflow; /* Debug helper - move elsewhere? */ void PrintFaceInfo(const mface_t *face, const mbsp_t *bsp) @@ -439,39 +439,19 @@ static bool Mod_LeafPvs(const mbsp_t *bsp, const mleaf_t *leaf, uint8_t *out) memset(out, 0xFF, num_pvsclusterbytes); if (bsp->loadversion->game->id == GAME_QUAKE_II) { - if (leaf->cluster < 0) { + auto it = UncompressedVis().find(leaf->cluster); + if (it == UncompressedVis().end()) { return false; } - if (leaf->cluster >= bsp->dvis.bit_offsets.size() || - bsp->dvis.get_bit_offset(VIS_PVS, leaf->cluster) >= bsp->dvis.bits.size()) { - logging::print("Mod_LeafPvs: invalid visofs for cluster {}\n", leaf->cluster); - return false; - } - - DecompressVis(bsp->dvis.bits.data() + bsp->dvis.get_bit_offset(VIS_PVS, leaf->cluster), - bsp->dvis.bits.data() + bsp->dvis.bits.size(), out, out + num_pvsclusterbytes); + memcpy(out, it->second.data(), num_pvsclusterbytes); } else { - if (leaf->visofs < 0) { + auto it = UncompressedVis().find(leaf->visofs); + if (it == UncompressedVis().end()) { return false; } - const ptrdiff_t leafnum = (leaf - bsp->dleafs.data()); - - // this is confusing.. "visleaf numbers" are the leaf number minus 1. - // they also don't go as high, bsp->dmodels[0].visleafs instead of bsp->numleafs - const int visleaf = leafnum - 1; - if (visleaf < 0 || visleaf >= bsp->dmodels[0].visleafs) { - return false; - } - - if (leaf->visofs >= bsp->dvis.bits.size()) { - logging::print("Mod_LeafPvs: invalid visofs for leaf {}\n", leafnum); - return false; - } - - DecompressVis(bsp->dvis.bits.data() + leaf->visofs, bsp->dvis.bits.data() + bsp->dvis.bits.size(), out, - out + num_pvsclusterbytes); + memcpy(out, it->second.data(), num_pvsclusterbytes); } return true;