diff --git a/Core/SaveState.cpp b/Core/SaveState.cpp index 16779e73d6..0b62c55341 100644 --- a/Core/SaveState.cpp +++ b/Core/SaveState.cpp @@ -319,7 +319,7 @@ namespace SaveState I18NCategory *s = GetI18NCategory("Screen"); osm.Show("Failed to load state. Error in the file system.", 2.0); if (callback) - (*callback)(false, cbUserData); + callback(false, cbUserData); } } @@ -327,12 +327,12 @@ namespace SaveState { std::string fn = GenerateSaveSlotFilename(slot, STATE_EXTENSION); if (!fn.empty()) { - Save(fn, callback, cbUserData); + Save(fn + ".tmp", callback, cbUserData); } else { I18NCategory *s = GetI18NCategory("Screen"); osm.Show("Failed to save state. Error in the file system.", 2.0); if (callback) - (*callback)(false, cbUserData); + callback(false, cbUserData); } } diff --git a/Core/SaveState.h b/Core/SaveState.h index 840c75fc66..856143c20a 100644 --- a/Core/SaveState.h +++ b/Core/SaveState.h @@ -18,11 +18,12 @@ #include #include +#include "base/functional.h" #include "Common/ChunkFile.h" namespace SaveState { - typedef void (*Callback)(bool status, void *cbUserData); + typedef std::function Callback; // TODO: Better place for this? const int REVISION = 4; @@ -44,22 +45,22 @@ namespace SaveState // Load the specified file into the current state (async.) // Warning: callback will be called on a different thread. - void Load(const std::string &filename, Callback callback = 0, void *cbUserData = 0); + void Load(const std::string &filename, Callback callback = nullptr, void *cbUserData = 0); // Save the current state to the specified file (async.) // Warning: callback will be called on a different thread. - void Save(const std::string &filename, Callback callback = 0, void *cbUserData = 0); + void Save(const std::string &filename, Callback callback = nullptr, void *cbUserData = 0); CChunkFileReader::Error SaveToRam(std::vector &state); CChunkFileReader::Error LoadFromRam(std::vector &state); // For testing / automated tests. Runs a save state verification pass (async.) // Warning: callback will be called on a different thread. - void Verify(Callback callback = 0, void *cbUserData = 0); + void Verify(Callback callback = nullptr, void *cbUserData = 0); // To go back to a previous snapshot (only if enabled.) // Warning: callback will be called on a different thread. - void Rewind(Callback callback = 0, void *cbUserData = 0); + void Rewind(Callback callback = nullptr, void *cbUserData = 0); // Returns true if there are rewind snapshots available. bool CanRewind(); diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index 4bdf350781..e72aea920d 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -332,11 +332,11 @@ void EmuScreen::onVKeyDown(int virtualKeyCode) { } break; case VIRTKEY_SAVE_STATE: - SaveState::SaveSlot(g_Config.iCurrentStateSlot, 0); + SaveState::SaveSlot(g_Config.iCurrentStateSlot, nullptr); break; case VIRTKEY_LOAD_STATE: if (SaveState::HasSaveInSlot(g_Config.iCurrentStateSlot)) { - SaveState::LoadSlot(g_Config.iCurrentStateSlot, 0); + SaveState::LoadSlot(g_Config.iCurrentStateSlot, nullptr); } break; case VIRTKEY_NEXT_SLOT: @@ -800,7 +800,7 @@ void EmuScreen::autoLoad() { //check if save state has save, if so, load int lastSlot = SaveState::GetNewestSlot(); if (g_Config.bEnableAutoLoad && lastSlot != -1) { - SaveState::LoadSlot(lastSlot, 0, 0); + SaveState::LoadSlot(lastSlot, nullptr, 0); g_Config.iCurrentStateSlot = lastSlot; } } diff --git a/UI/MainScreen.cpp b/UI/MainScreen.cpp index 28af8c37b6..c109ad1c50 100644 --- a/UI/MainScreen.cpp +++ b/UI/MainScreen.cpp @@ -1235,21 +1235,21 @@ UI::EventReturn GamePauseScreen::OnReportFeedback(UI::EventParams &e) { } UI::EventReturn GamePauseScreen::OnLoadState(UI::EventParams &e) { - SaveState::LoadSlot(saveSlots_->GetSelection(), 0, 0); + SaveState::LoadSlot(saveSlots_->GetSelection(), nullptr, 0); screenManager()->finishDialog(this, DR_CANCEL); return UI::EVENT_DONE; } UI::EventReturn GamePauseScreen::OnSaveState(UI::EventParams &e) { - SaveState::SaveSlot(saveSlots_->GetSelection(), 0, 0); + SaveState::SaveSlot(saveSlots_->GetSelection(), nullptr, 0); screenManager()->finishDialog(this, DR_CANCEL); return UI::EVENT_DONE; } UI::EventReturn GamePauseScreen::OnRewind(UI::EventParams &e) { - SaveState::Rewind(0, 0); + SaveState::Rewind(nullptr, 0); screenManager()->finishDialog(this, DR_CANCEL); return UI::EVENT_DONE;