From d19c389246d501a549200093a603760173c8415d Mon Sep 17 00:00:00 2001 From: nitsuja Date: Wed, 28 Dec 2011 02:33:41 -0600 Subject: [PATCH] clean up some savestate code --- Source/Core/Core/Src/Movie.cpp | 8 +------- Source/Core/Core/Src/Movie.h | 2 +- Source/Core/Core/Src/State.cpp | 32 +++++++++++++++----------------- Source/Core/Core/Src/State.h | 10 ++++++---- 4 files changed, 23 insertions(+), 29 deletions(-) diff --git a/Source/Core/Core/Src/Movie.cpp b/Source/Core/Core/Src/Movie.cpp index 590f8bb5e8..ba489dfcf6 100644 --- a/Source/Core/Core/Src/Movie.cpp +++ b/Source/Core/Core/Src/Movie.cpp @@ -591,14 +591,8 @@ cleanup: return false; } -void DoState(PointerWrap &p, bool doNot) +void DoState(PointerWrap &p) { - if(doNot) - { - if(p.GetMode() == PointerWrap::MODE_READ) - g_currentSaveVersion = 0; - return; - } static const int MOVIE_STATE_VERSION = 1; g_currentSaveVersion = MOVIE_STATE_VERSION; p.Do(g_currentSaveVersion); diff --git a/Source/Core/Core/Src/Movie.h b/Source/Core/Core/Src/Movie.h index 16d0ba4997..09a0f5d84a 100644 --- a/Source/Core/Core/Src/Movie.h +++ b/Source/Core/Core/Src/Movie.h @@ -139,7 +139,7 @@ void PlayController(SPADStatus *PadStatus, int controllerID); bool PlayWiimote(int wiimote, u8* data, const struct WiimoteEmu::ReportFeatures& rptf, int irMode); void EndPlayInput(bool cont); void SaveRecording(const char *filename); -void DoState(PointerWrap &p, bool doNot=false); +void DoState(PointerWrap &p); std::string GetInputDisplay(); diff --git a/Source/Core/Core/Src/State.cpp b/Source/Core/Core/Src/State.cpp index 8ba238f2d7..3f85bbd79e 100644 --- a/Source/Core/Core/Src/State.cpp +++ b/Source/Core/Core/Src/State.cpp @@ -103,25 +103,19 @@ void DoState(PointerWrap &p) { u32 version = STATE_VERSION; { - u32 cookie = version + 0xBAADBABE; + static const u32 COOKIE_BASE = 0xBAADBABE; + u32 cookie = version + COOKIE_BASE; p.Do(cookie); - version = cookie - 0xBAADBABE; + version = cookie - COOKIE_BASE; } if (version != STATE_VERSION) { - if (version == 5 && STATE_VERSION == 6) - { - // from version 5 to 6, the only difference was the addition of calling Movie::DoState, - // so (because it's easy) let's not break compatibility in this case - } - else - { - // if the version doesn't match, fail. - // this will trigger a message like "Can't load state from other revisions" - p.SetMode(PointerWrap::MODE_MEASURE); - return; - } + // if the version doesn't match, fail. + // this will trigger a message like "Can't load state from other revisions" + // we could use the version numbers to maintain some level of backward compatibility, but currently don't. + p.SetMode(PointerWrap::MODE_MEASURE); + return; } p.DoMarker("Version"); @@ -142,7 +136,7 @@ void DoState(PointerWrap &p) p.DoMarker("HW"); CoreTiming::DoState(p); p.DoMarker("CoreTiming"); - Movie::DoState(p, version<6); + Movie::DoState(p); p.DoMarker("Movie"); // Resume the video thread @@ -397,7 +391,7 @@ void LoadFileStateCallback(u64 userdata, int cyclesLate) Core::DisplayMessage("Unable to Load : Can't load state from other revisions !", 4000); // since we're probably in an inconsistent state now (and might crash or whatever), undo. - if(g_loadDepth < 2) + if (g_loadDepth < 2) UndoLoadState(); } } @@ -435,11 +429,13 @@ void VerifyFileStateCallback(u64 userdata, int cyclesLate) PointerWrap p(&ptr, PointerWrap::MODE_VERIFY); DoState(p); - if (p.GetMode() == PointerWrap::MODE_READ) + if (p.GetMode() == PointerWrap::MODE_VERIFY) Core::DisplayMessage(StringFromFormat("Verified state at %s", g_current_filename.c_str()).c_str(), 2000); else Core::DisplayMessage("Unable to Verify : Can't verify state from other revisions !", 4000); } + + g_op_in_progress = false; } void Init() @@ -486,6 +482,8 @@ static std::string MakeStateFilename(int number) void ScheduleFileEvent(const std::string &filename, int ev, bool immediate) { + if (g_op_in_progress) + Flush(); if (g_op_in_progress) return; g_op_in_progress = true; diff --git a/Source/Core/Core/Src/State.h b/Source/Core/Core/Src/State.h index 2c3a38cd8c..048ad726ee 100644 --- a/Source/Core/Core/Src/State.h +++ b/Source/Core/Core/Src/State.h @@ -21,6 +21,7 @@ #define _STATE_H_ #include +#include namespace State { @@ -46,15 +47,16 @@ void SaveAs(const std::string &filename); void LoadAs(const std::string &filename); void VerifyAt(const std::string &filename); -void SaveToBuffer(u8 **buffer); -void LoadFromBuffer(u8 **buffer); -void VerifyBuffer(u8 **buffer); +void SaveToBuffer(std::vector& buffer); +void LoadFromBuffer(std::vector& buffer); +void VerifyBuffer(std::vector& buffer); void LoadLastSaved(); void UndoSaveState(); void UndoLoadState(); -void Flush(); // wait until previously scheduled savestate event (if any) is done +// wait until previously scheduled savestate event (if any) is done +void Flush(); // for calling back into UI code without introducing a dependency on it in core typedef void(*CallbackFunc)(void);