clean up some savestate code

This commit is contained in:
nitsuja 2011-12-28 02:33:41 -06:00 committed by skidau
parent 8ef75dac67
commit d19c389246
4 changed files with 23 additions and 29 deletions

View File

@ -591,14 +591,8 @@ cleanup:
return false; 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; static const int MOVIE_STATE_VERSION = 1;
g_currentSaveVersion = MOVIE_STATE_VERSION; g_currentSaveVersion = MOVIE_STATE_VERSION;
p.Do(g_currentSaveVersion); p.Do(g_currentSaveVersion);

View File

@ -139,7 +139,7 @@ void PlayController(SPADStatus *PadStatus, int controllerID);
bool PlayWiimote(int wiimote, u8* data, const struct WiimoteEmu::ReportFeatures& rptf, int irMode); bool PlayWiimote(int wiimote, u8* data, const struct WiimoteEmu::ReportFeatures& rptf, int irMode);
void EndPlayInput(bool cont); void EndPlayInput(bool cont);
void SaveRecording(const char *filename); void SaveRecording(const char *filename);
void DoState(PointerWrap &p, bool doNot=false); void DoState(PointerWrap &p);
std::string GetInputDisplay(); std::string GetInputDisplay();

View File

@ -103,25 +103,19 @@ void DoState(PointerWrap &p)
{ {
u32 version = STATE_VERSION; u32 version = STATE_VERSION;
{ {
u32 cookie = version + 0xBAADBABE; static const u32 COOKIE_BASE = 0xBAADBABE;
u32 cookie = version + COOKIE_BASE;
p.Do(cookie); p.Do(cookie);
version = cookie - 0xBAADBABE; version = cookie - COOKIE_BASE;
} }
if (version != STATE_VERSION) if (version != STATE_VERSION)
{ {
if (version == 5 && STATE_VERSION == 6) // if the version doesn't match, fail.
{ // this will trigger a message like "Can't load state from other revisions"
// from version 5 to 6, the only difference was the addition of calling Movie::DoState, // we could use the version numbers to maintain some level of backward compatibility, but currently don't.
// so (because it's easy) let's not break compatibility in this case p.SetMode(PointerWrap::MODE_MEASURE);
} return;
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;
}
} }
p.DoMarker("Version"); p.DoMarker("Version");
@ -142,7 +136,7 @@ void DoState(PointerWrap &p)
p.DoMarker("HW"); p.DoMarker("HW");
CoreTiming::DoState(p); CoreTiming::DoState(p);
p.DoMarker("CoreTiming"); p.DoMarker("CoreTiming");
Movie::DoState(p, version<6); Movie::DoState(p);
p.DoMarker("Movie"); p.DoMarker("Movie");
// Resume the video thread // 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); 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. // since we're probably in an inconsistent state now (and might crash or whatever), undo.
if(g_loadDepth < 2) if (g_loadDepth < 2)
UndoLoadState(); UndoLoadState();
} }
} }
@ -435,11 +429,13 @@ void VerifyFileStateCallback(u64 userdata, int cyclesLate)
PointerWrap p(&ptr, PointerWrap::MODE_VERIFY); PointerWrap p(&ptr, PointerWrap::MODE_VERIFY);
DoState(p); 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); Core::DisplayMessage(StringFromFormat("Verified state at %s", g_current_filename.c_str()).c_str(), 2000);
else else
Core::DisplayMessage("Unable to Verify : Can't verify state from other revisions !", 4000); Core::DisplayMessage("Unable to Verify : Can't verify state from other revisions !", 4000);
} }
g_op_in_progress = false;
} }
void Init() void Init()
@ -486,6 +482,8 @@ static std::string MakeStateFilename(int number)
void ScheduleFileEvent(const std::string &filename, int ev, bool immediate) void ScheduleFileEvent(const std::string &filename, int ev, bool immediate)
{ {
if (g_op_in_progress)
Flush();
if (g_op_in_progress) if (g_op_in_progress)
return; return;
g_op_in_progress = true; g_op_in_progress = true;

View File

@ -21,6 +21,7 @@
#define _STATE_H_ #define _STATE_H_
#include <string> #include <string>
#include <vector>
namespace State namespace State
{ {
@ -46,15 +47,16 @@ void SaveAs(const std::string &filename);
void LoadAs(const std::string &filename); void LoadAs(const std::string &filename);
void VerifyAt(const std::string &filename); void VerifyAt(const std::string &filename);
void SaveToBuffer(u8 **buffer); void SaveToBuffer(std::vector<u8>& buffer);
void LoadFromBuffer(u8 **buffer); void LoadFromBuffer(std::vector<u8>& buffer);
void VerifyBuffer(u8 **buffer); void VerifyBuffer(std::vector<u8>& buffer);
void LoadLastSaved(); void LoadLastSaved();
void UndoSaveState(); void UndoSaveState();
void UndoLoadState(); 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 // for calling back into UI code without introducing a dependency on it in core
typedef void(*CallbackFunc)(void); typedef void(*CallbackFunc)(void);