Skip to content

Commit

Permalink
Merge pull request #121 from hakasapl/70-improve-warnings-view-for-users
Browse files Browse the repository at this point in the history
output texture mismatch warnings at the end sorted by matched mod
  • Loading branch information
hakasapl authored Nov 25, 2024
2 parents e56421c + 44bbe4d commit 813badd
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 31 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 7 additions & 5 deletions ParallaxGenLib/include/ParallaxGenWarnings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <mutex>
#include <unordered_set>
#include <map>

#include "ParallaxGenDirectory.hpp"

Expand All @@ -22,11 +23,9 @@ class ParallaxGenWarnings {
};

// Trackers for warnings
static std::unordered_set<std::pair<std::wstring, std::wstring>, PairHash>
MismatchWarnTracker; /** Keeps tabs on WARN mismatch messages to avoid duplicates */
static std::unordered_map<std::wstring, std::unordered_set<std::wstring>> MismatchWarnTracker; // matched mod to set of base mods
static std::mutex MismatchWarnTrackerMutex; /** Mutex for MismatchWarnTracker */
static std::unordered_set<std::pair<std::wstring, std::wstring>, PairHash>
MismatchWarnDebugTracker; /** Keeps tabs on DEBUG mismatch messages to avoid duplicates */
static std::unordered_map<std::wstring, std::unordered_set<std::pair<std::wstring,std::wstring>, PairHash>> MismatchWarnDebugTracker;
static std::mutex MismatchWarnDebugTrackerMutex; /** Mutex for MismatchWarnDebugTracker */

static std::unordered_set<std::pair<std::wstring, std::wstring>, PairHash>
Expand All @@ -46,7 +45,7 @@ class ParallaxGenWarnings {
static void init(ParallaxGenDirectory *PGD, const std::unordered_map<std::wstring, int> *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
Expand All @@ -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();
};
2 changes: 2 additions & 0 deletions ParallaxGenLib/src/ParallaxGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
62 changes: 36 additions & 26 deletions ParallaxGenLib/src/ParallaxGenWarnings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ using namespace std;
ParallaxGenDirectory *ParallaxGenWarnings::PGD = nullptr;
const std::unordered_map<std::wstring, int> *ParallaxGenWarnings::ModPriority = nullptr;

unordered_set<pair<wstring, wstring>, ParallaxGenWarnings::PairHash> ParallaxGenWarnings::MismatchWarnTracker;
unordered_map<wstring, unordered_set<wstring>> ParallaxGenWarnings::MismatchWarnTracker;
mutex ParallaxGenWarnings::MismatchWarnTrackerMutex;
unordered_set<pair<wstring, wstring>, ParallaxGenWarnings::PairHash> ParallaxGenWarnings::MismatchWarnDebugTracker;

unordered_map<std::wstring, unordered_set<pair<wstring, wstring>, ParallaxGenWarnings::PairHash>>
ParallaxGenWarnings::MismatchWarnDebugTracker;
mutex ParallaxGenWarnings::MismatchWarnDebugTrackerMutex;

unordered_set<pair<wstring, wstring>, ParallaxGenWarnings::PairHash> ParallaxGenWarnings::MeshWarnTracker;
Expand All @@ -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;
}
Expand All @@ -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<mutex> 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<mutex> 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) {
Expand Down

0 comments on commit 813badd

Please sign in to comment.