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