diff --git a/CHANGELOG.md b/CHANGELOG.md index a2be6b5..8d1f6f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Fixed unicode character handling - Fixed exceptions when plugin patching is not enabled +- Improved warning output for texture mismatches ## [0.7.1] - 2024-11-18 diff --git a/ParallaxGenLib/include/ParallaxGenWarnings.hpp b/ParallaxGenLib/include/ParallaxGenWarnings.hpp index c70a4e1..132ffb5 100644 --- a/ParallaxGenLib/include/ParallaxGenWarnings.hpp +++ b/ParallaxGenLib/include/ParallaxGenWarnings.hpp @@ -2,6 +2,7 @@ #include #include +#include #include "ParallaxGenDirectory.hpp" @@ -22,11 +23,9 @@ class ParallaxGenWarnings { }; // Trackers for warnings - static std::unordered_set, PairHash> - MismatchWarnTracker; /** Keeps tabs on WARN mismatch messages to avoid duplicates */ + static std::unordered_map> MismatchWarnTracker; // matched mod to set of base mods static std::mutex MismatchWarnTrackerMutex; /** Mutex for MismatchWarnTracker */ - static std::unordered_set, PairHash> - MismatchWarnDebugTracker; /** Keeps tabs on DEBUG mismatch messages to avoid duplicates */ + static std::unordered_map, PairHash>> MismatchWarnDebugTracker; static std::mutex MismatchWarnDebugTrackerMutex; /** Mutex for MismatchWarnDebugTracker */ static std::unordered_set, PairHash> @@ -46,7 +45,7 @@ class ParallaxGenWarnings { static void init(ParallaxGenDirectory *PGD, const std::unordered_map *ModPriority); /** - * @brief Posts warning about a mismatch between diffuse/normal and a matched path. Will not repost the same warning. + * @brief store warning about a mismatch between diffuse/normal and a matched path. Will not repost the same warning. * * @param MatchedPath Path that was matched (for example _m or _p file) * @param BaseTex diffuse/normal that it was matched from @@ -60,4 +59,7 @@ class ParallaxGenWarnings { * @param NIFPath NIF that it was patched on */ static void meshWarn(const std::wstring &MatchedPath, const std::wstring &NIFPath); + + /// @brief print a summary of the already gathered warnings + static void printWarnings(); }; diff --git a/ParallaxGenLib/src/ParallaxGen.cpp b/ParallaxGenLib/src/ParallaxGen.cpp index 8908fe1..97aee79 100644 --- a/ParallaxGenLib/src/ParallaxGen.cpp +++ b/ParallaxGenLib/src/ParallaxGen.cpp @@ -92,6 +92,8 @@ void ParallaxGen::patchMeshes(const PatcherUtil::PatcherSet &Patchers, const uno } } + ParallaxGenWarnings::printWarnings(); + // Write DiffJSON file spdlog::info("Saving diff JSON file..."); const filesystem::path DiffJSONPath = OutputDir / getDiffJSONName(); diff --git a/ParallaxGenLib/src/ParallaxGenWarnings.cpp b/ParallaxGenLib/src/ParallaxGenWarnings.cpp index f01f77c..f21b7d7 100644 --- a/ParallaxGenLib/src/ParallaxGenWarnings.cpp +++ b/ParallaxGenLib/src/ParallaxGenWarnings.cpp @@ -8,9 +8,11 @@ using namespace std; ParallaxGenDirectory *ParallaxGenWarnings::PGD = nullptr; const std::unordered_map *ParallaxGenWarnings::ModPriority = nullptr; -unordered_set, ParallaxGenWarnings::PairHash> ParallaxGenWarnings::MismatchWarnTracker; +unordered_map> ParallaxGenWarnings::MismatchWarnTracker; mutex ParallaxGenWarnings::MismatchWarnTrackerMutex; -unordered_set, ParallaxGenWarnings::PairHash> ParallaxGenWarnings::MismatchWarnDebugTracker; + +unordered_map, ParallaxGenWarnings::PairHash>> + ParallaxGenWarnings::MismatchWarnDebugTracker; mutex ParallaxGenWarnings::MismatchWarnDebugTrackerMutex; unordered_set, ParallaxGenWarnings::PairHash> ParallaxGenWarnings::MeshWarnTracker; @@ -33,6 +35,9 @@ void ParallaxGenWarnings::mismatchWarn(const wstring &MatchedPath, const wstring auto MatchedPathMod = PGD->getMod(MatchedPath); auto BaseTexMod = PGD->getMod(BaseTex); + if (BaseTexMod.empty()) + BaseTexMod = L"Vanilla Game"; + if (MatchedPathMod.empty() || BaseTexMod.empty()) { return; } @@ -41,37 +46,42 @@ void ParallaxGenWarnings::mismatchWarn(const wstring &MatchedPath, const wstring return; } - auto Key = make_pair(MatchedPathMod, BaseTexMod); + MismatchWarnDebugTracker[MatchedPathMod].insert(std::make_pair(MatchedPath,BaseTex)); + MismatchWarnTracker[MatchedPathMod].insert(BaseTexMod); +} - // Issue debug log - { - auto KeyDebug = make_pair(MatchedPath, BaseTex); - const lock_guard Lock(MismatchWarnDebugTrackerMutex); - if (MismatchWarnDebugTracker.find(KeyDebug) != MismatchWarnDebugTracker.end()) { - return; +void ParallaxGenWarnings::printWarnings() { + if (!MismatchWarnTracker.empty()) { + spdlog::warn("Potential Texture mismatches were found, there may be visual issues, Please verify for each warning if " + "this is intended, address them and re-run ParallaxGen if needed."); + spdlog::warn("See https://github.com/hakasapl/ParallaxGen/wiki/FAQ for further information"); + spdlog::warn("************************************************************"); + } + for (auto MatchedMod : MismatchWarnTracker) { + spdlog::warn(L"\"{}\" assets are used with:", MatchedMod.first); + for (auto BaseMod : MatchedMod.second) { + spdlog::warn(L" - diffuse/normal textures from \"{}\"", BaseMod); } - - MismatchWarnDebugTracker.insert(KeyDebug); - - spdlog::debug(L"[Potential Texture Mismatch] Matched path {} from mod {} does not come from the same diffuse or normal {} from mod {}", - MatchedPath, MatchedPathMod, BaseTex, BaseTexMod); + spdlog::warn(""); + } + if (!MismatchWarnTracker.empty()) { + spdlog::warn("************************************************************"); } - // check if mod warning was already issued + if (!MismatchWarnDebugTracker.empty()) { - const lock_guard Lock(MismatchWarnTrackerMutex); - if (MismatchWarnTracker.find(Key) != MismatchWarnTracker.end()) { - return; - } - - // add to tracker if not - MismatchWarnTracker.insert(Key); + spdlog::debug("Potential texture mismatches:"); } + for (auto MatchedMod : MismatchWarnDebugTracker) + { + spdlog::debug(L"Mod \"{}\":", MatchedMod.first); - // log warning - spdlog::warn(L"[Potential Texture Mismatch] Mod \"{}\" assets were used with diffuse or normal from mod \"{}\". Please verify that " - L"this is intended.", - MatchedPathMod, BaseTexMod); + for (auto TexturePair : MatchedMod.second) { + auto BaseTexMod = PGD->getMod(TexturePair.second); + spdlog::debug(L" - {} used with {} from \"{}\"", + TexturePair.first, TexturePair.second, BaseTexMod); + } + } } void ParallaxGenWarnings::meshWarn(const wstring &MatchedPath, const wstring &NIFPath) {