1

Use ForEachReference with locking to iterate through references

This commit is contained in:
Eddoursul 2022-07-11 21:18:07 +02:00
parent c94b76dcf0
commit a374e0c71f
2 changed files with 18 additions and 13 deletions

Binary file not shown.

View File

@ -376,7 +376,10 @@ namespace ArtifactTracker
g_persistentStorage->AddForm(cellStorage);
g_persistentMap[cellStorage->formID] = cellStorage;
ToggleHomeMode(cellStorage);
SyncCellStorage();
std::thread([]() {
std::this_thread::sleep_for(std::chrono::milliseconds(500));
SyncCellStorage();
}).detach();
} else {
log::error("Failed to create cell storage in OnCellEnter");
ToggleHomeMode(nullptr);
@ -401,19 +404,19 @@ namespace ArtifactTracker
const auto cell = g_cellStorage->GetParentCell();
const auto inv = g_cellStorage->GetInventory();
for (const auto& a_ref : cell->references) {
if (a_ignoreRef && a_ignoreRef->formID == a_ref->formID) {
continue;
cell->ForEachReference([&](RE::TESObjectREFR& a_ref) {
if (a_ignoreRef && a_ignoreRef->formID == a_ref.formID) {
return true;
}
const auto baseObj = a_ref->GetBaseObject();
const auto baseObj = a_ref.GetBaseObject();
if (IsValidContainer(a_ref.get())) {
if (g_cellContainer == baseObj || baseObj->formID == 0xDC9E7 || g_persistentMap.contains(a_ref->formID)) { // skip persistent and PlayerBookShelfContainer
continue;
if (IsValidContainer(&a_ref)) {
if (g_cellContainer == baseObj || baseObj->formID == 0xDC9E7 || g_persistentMap.contains(a_ref.formID)) { // skip persistent and PlayerBookShelfContainer
return true;
}
const auto contInv = a_ref->GetInventory([&](RE::TESBoundObject& a_object) -> bool {
const auto contInv = a_ref.GetInventory([&](RE::TESBoundObject& a_object) -> bool {
return !cellItems.contains(a_object.formID) && IsArtifact(&a_object);
});
@ -431,11 +434,11 @@ namespace ArtifactTracker
}
}
continue;
return true;
}
if (a_ref->IsDisabled() || a_ref->IsMarkedForDeletion() || cellItems.contains(baseObj->formID) || !IsArtifact(baseObj)) {
continue;
if (a_ref.IsDisabled() || a_ref.IsMarkedForDeletion() || cellItems.contains(baseObj->formID) || !IsArtifact(baseObj)) {
return true;
}
cellItems.insert(baseObj->formID);
@ -449,7 +452,9 @@ namespace ArtifactTracker
ListRemoveItem(g_listFound, baseObj);
g_listStored->AddForm(baseObj);
}
}
return true;
});
for (const auto& [item, data] : inv) {
const auto& [count, entry] = data;