Use ForEachReference with locking to iterate through references
This commit is contained in:
parent
c94b76dcf0
commit
a374e0c71f
Binary file not shown.
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user