Decouple save states from UI.

It's the UI's job to decide how and what things are displayed, not Core's.
This also reduces reasons for linkage issues.
This commit is contained in:
Unknown W. Brackets committed 2016-05-27 21:25:05 -07:00
1 parent 2862253f12
commit 27d135d48a
7 files changed
+58 -35

No files matched your search

+22 -21
View File
@@ -43,7 +43,6 @@
#include "Core/MIPS/JitCommon/JitBlockCache.h"
#include "HW/MemoryStick.h"
#include "GPU/GPUState.h"
#include "UI/OnScreenDisplay.h"
namespace SaveState
{
@@ -389,9 +388,8 @@ namespace SaveState
Load(fn, callback, cbUserData);
} else {
I18NCategory *sy = GetI18NCategory("System");
osm.Show(sy->T("Failed to load state. Error in the file system."), 2.0);
if (callback)
callback(false, cbUserData);
callback(false, sy->T("Failed to load state. Error in the file system."), cbUserData);
}
}
@@ -400,7 +398,7 @@ namespace SaveState
std::string fn = GenerateSaveSlotFilename(gameFilename, slot, STATE_EXTENSION);
std::string shot = GenerateSaveSlotFilename(gameFilename, slot, SCREENSHOT_EXTENSION);
if (!fn.empty()) {
auto renameCallback = [=](bool status, void *data) {
auto renameCallback = [=](bool status, const std::string &message, void *data) {
if (status) {
if (File::Exists(fn)) {
File::Delete(fn);
@@ -408,17 +406,16 @@ namespace SaveState
File::Rename(fn + ".tmp", fn);
}
if (callback) {
callback(status, data);
callback(status, message, data);
}
};
// Let's also create a screenshot.
SaveScreenshot(shot, Callback(), 0);
Save(fn + ".tmp", renameCallback, cbUserData);
} else {
I18NCategory *sc = GetI18NCategory("Screen");
osm.Show("Failed to save state. Error in the file system.", 2.0);
I18NCategory *sy = GetI18NCategory("System");
if (callback)
callback(false, cbUserData);
callback(false, sy->T("Failed to save state. Error in the file system."), cbUserData);
}
}
@@ -564,6 +561,7 @@ namespace SaveState
Operation &op = operations[i];
CChunkFileReader::Error result;
bool callbackResult;
std::string callbackMessage;
std::string reason;
I18NCategory *sc = GetI18NCategory("Screen");
@@ -580,16 +578,16 @@ namespace SaveState
INFO_LOG(COMMON, "Loading state from %s", op.filename.c_str());
result = CChunkFileReader::Load(op.filename, PPSSPP_GIT_VERSION, state, &reason);
if (result == CChunkFileReader::ERROR_NONE) {
osm.Show(sc->T("Loaded State"), 2.0);
callbackMessage = sc->T("Loaded State");
callbackResult = true;
hasLoadedState = true;
} else if (result == CChunkFileReader::ERROR_BROKEN_STATE) {
HandleFailure();
osm.Show(i18nLoadFailure, 2.0);
callbackMessage = i18nLoadFailure;
ERROR_LOG(COMMON, "Load state failure: %s", reason.c_str());
callbackResult = false;
} else {
osm.Show(sc->T(reason.c_str(), i18nLoadFailure), 2.0);
callbackMessage = sc->T(reason.c_str(), i18nLoadFailure);
callbackResult = false;
}
break;
@@ -598,45 +596,48 @@ namespace SaveState
INFO_LOG(COMMON, "Saving state to %s", op.filename.c_str());
result = CChunkFileReader::Save(op.filename, g_paramSFO.GetValueString("TITLE"), PPSSPP_GIT_VERSION, state);
if (result == CChunkFileReader::ERROR_NONE) {
osm.Show(sc->T("Saved State"), 2.0);
callbackMessage = sc->T("Saved State");
callbackResult = true;
} else if (result == CChunkFileReader::ERROR_BROKEN_STATE) {
HandleFailure();
osm.Show(i18nSaveFailure, 2.0);
callbackMessage = i18nSaveFailure;
ERROR_LOG(COMMON, "Save state failure: %s", reason.c_str());
callbackResult = false;
} else {
osm.Show(i18nSaveFailure, 2.0);
callbackMessage = i18nSaveFailure;
callbackResult = false;
}
break;
case SAVESTATE_VERIFY:
INFO_LOG(COMMON, "Verifying save state system");
callbackResult = CChunkFileReader::Verify(state) == CChunkFileReader::ERROR_NONE;
if (callbackResult) {
INFO_LOG(COMMON, "Verified save state system");
} else {
ERROR_LOG(COMMON, "Save state system verification failed");
}
break;
case SAVESTATE_REWIND:
INFO_LOG(COMMON, "Rewinding to recent savestate snapshot");
result = rewindStates.Restore();
if (result == CChunkFileReader::ERROR_NONE) {
osm.Show(sc->T("Loaded State"), 2.0);
callbackMessage = sc->T("Loaded State");
callbackResult = true;
hasLoadedState = true;
} else if (result == CChunkFileReader::ERROR_BROKEN_STATE) {
// Cripes. Good news is, we might have more. Let's try those too, better than a reset.
if (HandleFailure()) {
// Well, we did rewind, even if too much...
osm.Show(sc->T("Loaded State"), 2.0);
callbackMessage = sc->T("Loaded State");
callbackResult = true;
hasLoadedState = true;
} else {
osm.Show(i18nLoadFailure, 2.0);
callbackMessage = i18nLoadFailure;
callbackResult = false;
}
} else {
osm.Show(i18nLoadFailure, 2.0);
callbackMessage = i18nLoadFailure;
callbackResult = false;
}
break;
@@ -655,7 +656,7 @@ namespace SaveState
}
if (op.callback)
op.callback(callbackResult, op.cbUserData);
op.callback(callbackResult, callbackMessage, op.cbUserData);
}
if (operations.size()) {
// Avoid triggering frame skipping due to slowdown