From ba987c49e2e4bfaaccdcff740709489bf59b34d5 Mon Sep 17 00:00:00 2001 From: Malkierian Date: Tue, 14 Nov 2023 14:46:38 -0700 Subject: [PATCH] SaveManager cleanup (#3386) * Move threadpool initialization and `OnExitGame` registration from `SaveManager::Init` to SM's constructor. Comment on `Init` to mention it's not an initializer for `SaveManager`. Added check for `SaveManager::SaveSection` to prevent firing a save worker if the game is already exited from a reset. * Removed `IsSaveLoaded` check in favor of another `ThreadPoolWait()` at the start of `SaveManager::Init()`. --- soh/soh/SaveManager.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/soh/soh/SaveManager.cpp b/soh/soh/SaveManager.cpp index 14ab736dc..2d1f6e68b 100644 --- a/soh/soh/SaveManager.cpp +++ b/soh/soh/SaveManager.cpp @@ -65,6 +65,10 @@ SaveManager::SaveManager() { AddInitFunction(InitFileImpl); + GameInteractor::Instance->RegisterGameHook([this](uint32_t fileNum) { ThreadPoolWait(); }); + + smThreadPool = std::make_shared(1); + for (SaveFileMetaInfo& info : fileMetaInfo) { info.valid = false; info.deaths = 0; @@ -357,12 +361,14 @@ void SaveManager::SaveRandomizer(SaveContext* saveContext, int sectionID, bool f }); } +// Init() here is an extension of InitSram, and thus not truly an initializer for SaveManager itself. don't put any class initialization stuff here void SaveManager::Init() { + // Wait on saves that snuck through the Wait in OnExitGame + ThreadPoolWait(); const std::filesystem::path sSavePath(LUS::Context::GetPathRelativeToAppDirectory("Save")); const std::filesystem::path sGlobalPath = sSavePath / std::string("global.sav"); auto sOldSavePath = LUS::Context::GetPathRelativeToAppDirectory("oot_save.sav"); auto sOldBackupSavePath = LUS::Context::GetPathRelativeToAppDirectory("oot_save.bak"); - GameInteractor::Instance->RegisterGameHook([this](uint32_t fileNum) { ThreadPoolWait(); }); // If the save directory does not exist, create it if (!std::filesystem::exists(sSavePath)) { @@ -403,7 +409,6 @@ void SaveManager::Init() { } else { CreateDefaultGlobal(); } - smThreadPool = std::make_shared(1); // Load files to initialize metadata for (int fileNum = 0; fileNum < MaxFiles; fileNum++) {