1

Always run SyncCellStorage as a task

This commit is contained in:
Eddoursul 2022-07-16 18:19:30 +02:00
parent 1fedd07be1
commit deaac1c723
3 changed files with 88 additions and 85 deletions

Binary file not shown.

View File

@ -269,9 +269,7 @@ namespace ArtifactTracker
g_bBookShelf = false;
std::thread([]() {
std::this_thread::sleep_for(std::chrono::milliseconds(1200));
SKSE::GetTaskInterface()->AddTask([&]() {
ArtifactTracker::SyncCellStorage();
});
}).detach();
} else {
SyncCellStorage();
@ -377,8 +375,8 @@ namespace ArtifactTracker
log::info("Adding new storage in {}", cell->GetName());
#endif
SKSE::GetTaskInterface()->AddTask([&]() {
cellStorage = RE::PlayerCharacter::GetSingleton()->PlaceObjectAtMe(g_cellContainer, true).get();
SKSE::GetTaskInterface()->AddTask([]() {
const auto cellStorage = RE::PlayerCharacter::GetSingleton()->PlaceObjectAtMe(g_cellContainer, true).get();
if (cellStorage) {
cellStorage->Disable();
@ -406,13 +404,16 @@ namespace ArtifactTracker
log::info("Running SyncCellStorage");
#endif
const RE::FormID ignoreFormID = a_ignoreRef ? a_ignoreRef->formID : NULL;
SKSE::GetTaskInterface()->AddTask([ignoreFormID]() {
std::unordered_set<RE::FormID> cellItems;
const auto cell = g_cellStorage->GetParentCell();
const auto inv = g_cellStorage->GetInventory();
cell->ForEachReference([&](RE::TESObjectREFR& a_ref) {
if (a_ignoreRef && a_ignoreRef->formID == a_ref.formID) {
if (ignoreFormID && ignoreFormID == a_ref.formID) {
return true;
}
@ -466,7 +467,6 @@ namespace ArtifactTracker
for (const auto& [item, data] : inv) {
const auto& [count, entry] = data;
if (count > 0 && !cellItems.contains(item->formID)) {
g_cellStorage->RemoveItem(item, count, RE::ITEM_REMOVE_REASON::kRemove, nullptr, nullptr);
if (!RefListHasItem(g_persistentStorage, item->formID)) {
@ -483,6 +483,7 @@ namespace ArtifactTracker
}
cellItems.clear();
});
}
void OnContainerChanged(const RE::TESContainerChangedEvent* a_event, RE::TESForm* form)
@ -759,7 +760,7 @@ namespace ArtifactTracker
g_iFollowerIndex = iCurrentFollowers;
std::thread([]() {
std::this_thread::sleep_for(std::chrono::milliseconds(3000)); // wait for followers to load into the new cell
SKSE::GetTaskInterface()->AddTask([&]() {
SKSE::GetTaskInterface()->AddTask([]() {
RescanFoundArtifacts();
});
}).detach();

View File

@ -84,7 +84,10 @@ auto EventListener::ProcessEvent(
SKSE::log::info("MenuOpenCloseEvent");
#endif
if (a_event->opening) {
bool bOpening = a_event->opening;
SKSE::GetTaskInterface()->AddTask([bOpening]() {
if (bOpening) {
RE::BSInputDeviceManager::GetSingleton()->AddEventSink(EventListener::GetSingleton());
} else {
RE::BSInputDeviceManager::GetSingleton()->RemoveEventSink(EventListener::GetSingleton());
@ -98,8 +101,9 @@ auto EventListener::ProcessEvent(
}
if (ArtifactTracker::IsHome()) {
ArtifactTracker::SetContainerMode(a_event->opening);
ArtifactTracker::SetContainerMode(bOpening);
}
});
}
return RE::BSEventNotifyControl::kContinue;
@ -116,9 +120,7 @@ auto EventListener::ProcessEvent(
if (ref && ArtifactTracker::IsArtifact(ref->GetBaseObject())) {
std::thread([]() {
std::this_thread::sleep_for(std::chrono::milliseconds(200));
SKSE::GetTaskInterface()->AddTask([&]() {
ArtifactTracker::SyncCellStorage();
});
}).detach();
}
}