mirror of
https://github.com/HarbourMasters/Shipwright.git
synced 2024-11-25 10:52:19 -05:00
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()`.
This commit is contained in:
parent
bd0672767a
commit
ba987c49e2
@ -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++) {
|
||||
|
Loading…
Reference in New Issue
Block a user