diff options
| author | Malkierian <malkierian@gmail.com> | 2023-11-14 14:46:38 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-11-14 16:46:38 -0500 |
| commit | ba987c49e2e4bfaaccdcff740709489bf59b34d5 (patch) | |
| tree | 565c350f8029084023693957f4736ba27096f667 | |
| parent | bd0672767af6b3f5e229b300b814e1d896731470 (diff) | |
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()`.
| -rw-r--r-- | soh/soh/SaveManager.cpp | 9 |
1 files 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<GameInteractor::OnExitGame>([this](uint32_t fileNum) { ThreadPoolWait(); }); + + smThreadPool = std::make_shared<BS::thread_pool>(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<GameInteractor::OnExitGame>([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<BS::thread_pool>(1); // Load files to initialize metadata for (int fileNum = 0; fileNum < MaxFiles; fileNum++) { |
