1

Moved delayed bookshelf processing to the DLL

This commit is contained in:
Eddoursul 2022-07-09 14:15:35 +02:00
parent 31b9d5642e
commit 39b9e5cc04
7 changed files with 15 additions and 75 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -7,6 +7,7 @@ namespace ArtifactTracker
{ {
bool g_bLoaded; bool g_bLoaded;
bool g_bHomeContainer; bool g_bHomeContainer;
bool g_bBookShelf;
RE::TESBoundObject* g_cellContainer; RE::TESBoundObject* g_cellContainer;
RE::BGSListForm* g_listNew; RE::BGSListForm* g_listNew;
RE::BGSListForm* g_listStored; RE::BGSListForm* g_listStored;
@ -175,6 +176,8 @@ namespace ArtifactTracker
&& IsInSameCell(refr.get()) && IsInSameCell(refr.get())
&& !g_persistentMap.contains(refr.get()->formID); && !g_persistentMap.contains(refr.get()->formID);
g_bBookShelf = g_bHomeContainer && refr->GetBaseObject()->formID == 0xDC9E7;
#ifdef _DEBUG #ifdef _DEBUG
if (g_bHomeContainer) { if (g_bHomeContainer) {
RE::DebugNotification("Delayed processing enabled"); RE::DebugNotification("Delayed processing enabled");
@ -183,9 +186,18 @@ namespace ArtifactTracker
} else if (g_bHomeContainer) { } else if (g_bHomeContainer) {
g_bHomeContainer = false; g_bHomeContainer = false;
if (g_bBookShelf) {
g_bBookShelf = false;
std::thread([]() {
std::this_thread::sleep_for(std::chrono::milliseconds(1200));
ArtifactTracker::SyncCellStorage();
}).detach();
} else {
SyncCellStorage(); SyncCellStorage();
} }
} }
}
bool IsHome() bool IsHome()
{ {

View File

@ -4,6 +4,7 @@ namespace ArtifactTracker
{ {
extern bool g_bLoaded; extern bool g_bLoaded;
extern bool g_bHomeContainer; extern bool g_bHomeContainer;
extern bool g_bBookShelf;
extern RE::TESBoundObject* g_cellContainer; extern RE::TESBoundObject* g_cellContainer;
extern RE::BGSListForm* g_listNew; extern RE::BGSListForm* g_listNew;
extern RE::BGSListForm* g_listStored; extern RE::BGSListForm* g_listStored;

View File

@ -93,6 +93,7 @@ auto EventListener::ProcessEvent(
RE::BSTEventSource<RE::TESActivateEvent>* a_eventSource) RE::BSTEventSource<RE::TESActivateEvent>* a_eventSource)
-> RE::BSEventNotifyControl -> RE::BSEventNotifyControl
{ {
// This listener is expected to be unregistered outside of home.
if (ArtifactTracker::IsHome() && a_event->actionRef->IsPlayerRef() && a_event->objectActivated) { if (ArtifactTracker::IsHome() && a_event->actionRef->IsPlayerRef() && a_event->objectActivated) {
const auto ref = a_event->objectActivated.get(); const auto ref = a_event->objectActivated.get();
if (ref && ArtifactTracker::IsArtifact(ref->GetBaseObject())) { if (ref && ArtifactTracker::IsArtifact(ref->GetBaseObject())) {

View File

@ -4,10 +4,6 @@ FormList Property ETR_ItemsNew Auto
FormList Property ETR_ItemsFound Auto FormList Property ETR_ItemsFound Auto
FormList Property ETR_ItemsStored Auto FormList Property ETR_ItemsStored Auto
Keyword Property LocTypePlayerHouse Auto
bool bAtHome = false
ObjectReference bookShelf = None
int iFollowerIndex = 0 int iFollowerIndex = 0
int iArtifactCount = 0 int iArtifactCount = 0
@ -59,34 +55,11 @@ Event OnPlayerLoadGame()
RescanFoundArtifacts() RescanFoundArtifacts()
RescanNewArtifacts() RescanNewArtifacts()
Location currentLocation = (GetReference() as ObjectReference).GetCurrentLocation()
bAtHome = currentLocation && currentLocation.HasKeyword(LocTypePlayerHouse)
if bAtHome
RegisterForModEvent("AT_HomeInventoryUpdate", "OnHomeInventoryUpdate")
RegisterForMenu("ContainerMenu")
GotoState("AtHome")
else
UnregisterForModEvent("AT_HomeInventoryUpdate")
UnregisterForMenu("ContainerMenu")
GotoState("")
endif
EndEvent EndEvent
Event OnLocationChange(Location akOldLoc, Location akNewLoc) Event OnLocationChange(Location akOldLoc, Location akNewLoc)
bAtHome = akNewLoc && akNewLoc.HasKeyword(LocTypePlayerHouse)
if bAtHome
RegisterForModEvent("AT_HomeInventoryUpdate", "OnHomeInventoryUpdate")
GotoState("AtHome")
elseif akOldLoc && akOldLoc.HasKeyword(LocTypePlayerHouse)
UnregisterForModEvent("AT_HomeInventoryUpdate")
GotoState("")
endif
int iCurrentFollowers = 0; int iCurrentFollowers = 0;
Actor[] aFollowers = GetPlayerFollowers() Actor[] aFollowers = GetPlayerFollowers()
int i = aFollowers.length int i = aFollowers.length
@ -111,53 +84,6 @@ Event OnUpdate()
EndEvent EndEvent
event OnHomeInventoryUpdate(string eventName, string strArg, float numArg, Form sender)
if bAtHome
SyncCellStorage()
endif
endevent
state AtHome
event OnBeginState()
RegisterForMenu("ContainerMenu")
endevent
event OnEndState()
UnregisterForMenu("ContainerMenu")
endevent
event OnMenuOpen(String MenuName)
if ! bAtHome
GotoState("")
return
endif
ObjectReference currentContainer = GetCurrentContainer()
if currentContainer as PlayerBookShelfContainerScript
bookShelf = currentContainer
endif
endevent
event OnMenuClose(String MenuName)
if bookShelf
ObjectReference ref = bookShelf
bookShelf = None
Utility.wait(1.0)
int iLimit = 10
while iLimit > 0 && (ref as PlayerBookShelfContainerScript).GetState() == "PlacingBooks"
iLimit -= 1
Utility.wait(0.5)
endwhile
SyncCellStorage()
endif
endevent
endstate
; NATIVE FUNCTIONS ; NATIVE FUNCTIONS
bool function Load() native global bool function Load() native global