mirror of
https://github.com/open-goal/jak-project
synced 2026-08-05 17:44:39 -04:00
decomp: add explicit failures for common config mistakes related to allowed_objs (#2062)
A common thing that can be forgotten about / confusing to new people is that: 1. if you add an object to the `allowed_objs` list but it's also in the `banned_objs` list -- the ban still takes precedence with no failure 2. if you add an object to the `allowed_objs` list but have not allowed the DGO in `inputs.jsonc` it will also silently log a failure and continue. This PR turns both situations into an explicit error with advice/a reminder on what to do to fix it.
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include <unordered_set>
|
||||
|
||||
namespace set_util {
|
||||
template <typename T>
|
||||
std::unordered_set<T> intersection(std::unordered_set<T>& set1, std::unordered_set<T>& set2) {
|
||||
if (set2.size() < set1.size()) {
|
||||
auto temp = set1;
|
||||
set1 = set2;
|
||||
set2 = temp;
|
||||
}
|
||||
std::unordered_set<T> m(set1.begin(), set1.end());
|
||||
std::unordered_set<T> res;
|
||||
for (auto a : set2)
|
||||
if (m.count(a)) {
|
||||
res.insert(a);
|
||||
m.erase(a);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
} // namespace set_util
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "common/util/Timer.h"
|
||||
#include "common/util/diff.h"
|
||||
#include "common/util/os.h"
|
||||
#include "common/util/set_util.h"
|
||||
#include "common/util/unicode_util.h"
|
||||
#include "common/versions.h"
|
||||
|
||||
@@ -66,6 +67,14 @@ int main(int argc, char** argv) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Check if any banned objects are also in the allowed objects list
|
||||
// if so, throw an error as this can be a confusing situation
|
||||
auto intersection = set_util::intersection(config.allowed_objects, config.banned_objects);
|
||||
if (!intersection.empty()) {
|
||||
lg::error("Aborting - There is an overlap between 'allowed_objects' and 'banned_objects'");
|
||||
return 1;
|
||||
}
|
||||
|
||||
in_folder = in_folder / config.game_name;
|
||||
// Verify the in_folder is correct
|
||||
if (!exists(in_folder)) {
|
||||
@@ -119,6 +128,21 @@ int main(int argc, char** argv) {
|
||||
lg::info("Setting up object file DB...");
|
||||
ObjectFileDB db(dgos, fs::path(config.obj_file_name_map_file), objs, strs, config);
|
||||
|
||||
// Explicitly fail if a file in the 'allowed_objects' list wasn't found in the DB
|
||||
// as this is another silent error that can be confusing
|
||||
if (!config.allowed_objects.empty()) {
|
||||
for (const auto& expected_obj : config.allowed_objects) {
|
||||
if (db.obj_files_by_name.count(expected_obj) == 0) {
|
||||
// TODO - this is wrong for jak1, fix eventually as this is now done in 3 places
|
||||
lg::error(
|
||||
"Expected to find '{}' in the ObjectFileDB but did not. Check "
|
||||
"./decompiler/config/{}/inputs.jsonc",
|
||||
expected_obj, config.game_name);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lg::info("[Mem] After DB setup: {} MB", get_peak_rss() / (1024 * 1024));
|
||||
|
||||
// write out DGO file info
|
||||
|
||||
Reference in New Issue
Block a user