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;
}
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);

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);
void EndPlayInput(bool cont);
void SaveRecording(const char *filename);
void DoState(PointerWrap &p, bool doNot=false);
void DoState(PointerWrap &p);
std::string GetInputDisplay();

View file

@ -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;

View file

@ -21,6 +21,7 @@
#define _STATE_H_
#include <string>
#include <vector>
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<u8>& buffer);
void LoadFromBuffer(std::vector<u8>& buffer);
void VerifyBuffer(std::vector<u8>& 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);