TBTR: Add template replacement index validation to CheckCaches

pull/507/head
Jonathan G Rennison 1 year ago
parent 279e9c7ec6
commit 04aedf4798

@ -1863,6 +1863,14 @@ void CheckCaches(bool force_check, std::function<void(const char *)> log, CheckC
if (tv->Next()) assert_msg(tv->Next()->Prev() == tv, "%u", tv->index);
}
{
extern std::string ValidateTemplateReplacementCaches();
std::string template_validation_result = ValidateTemplateReplacementCaches();
if (!template_validation_result.empty()) {
CCLOG("Template replacement cache validation failed: %s", template_validation_result.c_str());
}
}
if (!TraceRestrictSlot::ValidateVehicleIndex()) CCLOG("Trace restrict slot vehicle index validation failed");
TraceRestrictSlot::ValidateSlotOccupants(log);

@ -35,6 +35,8 @@
#include "3rdparty/robin_hood/robin_hood.h"
#include <functional>
#include "safeguards.h"
TemplatePool _template_pool("TemplatePool");
@ -330,3 +332,21 @@ void ReindexTemplateReplacementsRecursive()
}
}
}
std::string ValidateTemplateReplacementCaches()
{
robin_hood::unordered_flat_map<GroupID, TemplateID> saved_template_replacement_index = std::move(_template_replacement_index);
robin_hood::unordered_flat_map<GroupID, TemplateID> saved_template_replacement_index_recursive = std::move(_template_replacement_index_recursive);
ReindexTemplateReplacements();
bool match = (saved_template_replacement_index == _template_replacement_index);
bool match_recursive = (saved_template_replacement_index_recursive == _template_replacement_index_recursive);
_template_replacement_index = std::move(saved_template_replacement_index);
_template_replacement_index_recursive = std::move(saved_template_replacement_index_recursive);
if (!match) return "Index cache does not match";
if (!match_recursive) return "Recursive index cache does not match";
return "";
}

Loading…
Cancel
Save