Section Save Modification (#2947)

* Modified `SaveManager::AddSaveFunction` to return the section index assigned to the section name for ease of remembering it on the other end. Also added a clarifying comment.

* Modified SaveFunc to accept a boolean for whether the section is being saved individually or as part of a game save (fullSave == true means game save, so all sections registered for game save sync).
This commit is contained in:
Malkierian 2023-06-14 20:39:14 -07:00 committed by GitHub
parent 279c40cb7d
commit 5daf5a14ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 11 deletions

View File

@ -339,7 +339,7 @@ void LoadStatsVersion1() {
});
}
void SaveStats(SaveContext* saveContext, int sectionID) {
void SaveStats(SaveContext* saveContext, int sectionID, bool fullSave) {
SaveManager::Instance->SaveData("buildVersion", saveContext->sohStats.buildVersion);
SaveManager::Instance->SaveData("buildVersionMajor", saveContext->sohStats.buildVersionMajor);
SaveManager::Instance->SaveData("buildVersionMinor", saveContext->sohStats.buildVersionMinor);

View File

@ -268,7 +268,7 @@ void SaveManager::LoadRandomizerVersion2() {
});
}
void SaveManager::SaveRandomizer(SaveContext* saveContext, int sectionID) {
void SaveManager::SaveRandomizer(SaveContext* saveContext, int sectionID, bool fullSave) {
if(!saveContext->n64ddFlag) return;
@ -716,7 +716,7 @@ void SaveManager::SaveFileThreaded(int fileNum, SaveContext* saveContext, int se
}
currentJsonContext = &sectionBlock["data"];
sectionHandlerPair.second.func(saveContext, sectionID);
sectionHandlerPair.second.func(saveContext, sectionID, true);
}
} else {
SaveFuncInfo svi = sectionSaveHandlers.find(sectionID)->second;
@ -731,7 +731,7 @@ void SaveManager::SaveFileThreaded(int fileNum, SaveContext* saveContext, int se
nlohmann::json& sectionBlock = saveBlock["sections"][sectionName];
sectionBlock["version"] = sectionVersion;
currentJsonContext = &sectionBlock["data"];
svi.func(saveContext, sectionID);
svi.func(saveContext, sectionID, false);
}
#if defined(__SWITCH__) || defined(__WIIU__)
@ -750,6 +750,7 @@ void SaveManager::SaveFileThreaded(int fileNum, SaveContext* saveContext, int se
}
// SaveSection creates a copy of gSaveContext to prevent mid-save data modification, and passes its reference to SaveFileThreaded
// This should never be called with threaded == false except during file creation
void SaveManager::SaveSection(int fileNum, int sectionID, bool threaded) {
// Don't save in Boss rush.
if (fileNum == 0xFF || fileNum == 0xFE) {
@ -871,11 +872,11 @@ void SaveManager::AddLoadFunction(const std::string& name, int version, LoadFunc
sectionLoadHandlers[name][version] = func;
}
void SaveManager::AddSaveFunction(const std::string& name, int version, SaveFunc func, bool saveWithBase, int parentSection = -1) {
int SaveManager::AddSaveFunction(const std::string& name, int version, SaveFunc func, bool saveWithBase, int parentSection = -1) {
if (sectionRegistry.contains(name)) {
SPDLOG_ERROR("Adding save function for section that already has one: " + name);
assert(false);
return;
return -1;
}
int index = sectionIndex;
@ -887,6 +888,7 @@ void SaveManager::AddSaveFunction(const std::string& name, int version, SaveFunc
SaveFuncInfo sfi = { name, version, func, saveWithBase, parentSection };
sectionSaveHandlers.emplace(index, sfi);
sectionRegistry.emplace(name, index);
return index;
}
void SaveManager::AddPostFunction(const std::string& name, PostFunc func) {
@ -1656,7 +1658,7 @@ void SaveManager::LoadBaseVersion4() {
SaveManager::Instance->LoadData("dogParams", gSaveContext.dogParams);
}
void SaveManager::SaveBase(SaveContext* saveContext, int sectionID) {
void SaveManager::SaveBase(SaveContext* saveContext, int sectionID, bool fullSave) {
SaveManager::Instance->SaveData("entranceIndex", saveContext->entranceIndex);
SaveManager::Instance->SaveData("linkAge", saveContext->linkAge);
SaveManager::Instance->SaveData("cutsceneIndex", saveContext->cutsceneIndex);

View File

@ -44,7 +44,7 @@ class SaveManager {
using InitFunc = void (*)(bool isDebug);
using LoadFunc = void (*)();
using SaveFunc = void (*)(SaveContext* saveContext, int sectionID);
using SaveFunc = void (*)(SaveContext* saveContext, int sectionID, bool fullSave);
using PostFunc = void (*)(int version);
typedef struct {
@ -75,7 +75,7 @@ class SaveManager {
// Adds a function that is called when saving. This should only be called once for each function, the version is
// filled in automatically.
void AddSaveFunction(const std::string& name, int version, SaveFunc func, bool saveWithBase, int parentSection);
int AddSaveFunction(const std::string& name, int version, SaveFunc func, bool saveWithBase, int parentSection);
// Adds a function to be called after loading is complete. This is to handle any cleanup required from loading old
// versions.
@ -144,13 +144,13 @@ class SaveManager {
static void LoadRandomizerVersion1();
static void LoadRandomizerVersion2();
static void SaveRandomizer(SaveContext* saveContext, int sectionID);
static void SaveRandomizer(SaveContext* saveContext, int sectionID, bool fullSave);
static void LoadBaseVersion1();
static void LoadBaseVersion2();
static void LoadBaseVersion3();
static void LoadBaseVersion4();
static void SaveBase(SaveContext* saveContext, int sectionID);
static void SaveBase(SaveContext* saveContext, int sectionID, bool fullSave);
std::vector<InitFunc> initFuncs;