Save movie's savestate to a separate file instead of encoding it in the movie file. (This gives significantly faster performance, and will make it easier for the user to edit the starting savestate if need be.)

This commit is contained in:
SuuperW 2018-09-03 05:35:05 -05:00
parent e697391dfd
commit 2a7103ec0b
3 changed files with 24 additions and 21 deletions

View File

@ -150,6 +150,7 @@ INT_PTR CALLBACK ReplayDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM
OPENFILENAME ofn;
char szChoice[MAX_PATH]={0};
char filename[MAX_PATH] = "";
const char* error;
switch(uMsg)
{
@ -198,7 +199,10 @@ INT_PTR CALLBACK ReplayDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM
return true;
case IDOK:
FCEUI_LoadMovie(playfilename, replayreadonly, false, 80000);
error = FCEUI_LoadMovie(playfilename, replayreadonly, false, 80000);
if (error)
MessageBox(hwndDlg, error, "Failed to load movie", MB_OK);
ZeroMemory(&playfilename, sizeof(playfilename));
EndDialog(hwndDlg, 0);
return true;

View File

@ -277,7 +277,6 @@ void MovieData::installRtcStart(std::string& val)
}
}
void MovieData::installComment(std::string& val) { comments.push_back(mbstowcs(val)); }
void MovieData::installSavestate(std::string& val) { BinaryDataFromString(val, &this->savestate); }
void MovieData::installSram(std::string& val) { BinaryDataFromString(val, &this->sram); }
void MovieData::installValue(std::string& key, std::string& val)
@ -337,8 +336,7 @@ int MovieData::dump(EMUFILE &fp, bool binary)
if (binary)
fp.fprintf("binary 1\n");
if (savestate.size() != 0)
fp.fprintf("savestate %s\n", BytesToString(&savestate[0],savestate.size()).c_str());
fp.fprintf("savestate %d\n", savestate?1:0);
if (sram.size() != 0)
fp.fprintf("sram %s\n", BytesToString(&sram[0],sram.size()).c_str());
@ -641,17 +639,21 @@ const char* _CDECL_ FCEUI_LoadMovie(const char *fname, bool _read_only, bool tas
oldSettings = new MovieData(true);
LoadSettingsFromMovie(currMovieData);
if (currMovieData.savestate.size() == 0)
if (currMovieData.savestate)
{
// SS file name should be the same as the movie file name, except for extension
std::string ssName = fname;
ssName.erase(ssName.length() - 3, 3);
ssName.append("dst");
if (!savestate_load(ssName.c_str()))
return "Could not load movie's savestate. There should be a .dst file with the same name as the movie, in the same folder.";
}
else
{
firstReset = true;
NDS_Reset();
firstReset = false;
}
else
{
EMUFILE_MEMORY efs = EMUFILE_MEMORY(&currMovieData.savestate);
savestate_load(efs);
}
////WE NEED TO LOAD A SAVESTATE
//if(currMovieData.savestate.size() != 0)
@ -771,12 +773,12 @@ void FCEUI_SaveMovie(const char *fname, std::wstring author, START_FROM startFro
if (startFrom == START_SAVESTATE)
{
// ?? MovieData::dumpSavestateTo(&currMovieData.savestate,Z_BEST_COMPRESSION);
EMUFILE_MEMORY efs;
savestate_save(efs, Z_BEST_COMPRESSION);
currMovieData.savestate.resize(efs.size());
efs.fseek(0, SEEK_SET);
efs.fread(currMovieData.savestate.begin()._Ptr, efs.size());
// SS file name should be the same as the movie file name, except for extension
std::string ssName = fname;
ssName.erase(ssName.length() - 3, 3);
ssName.append("dst");
savestate_save(ssName.c_str());
currMovieData.savestate = true;
}
else
{

View File

@ -143,7 +143,7 @@ public:
u32 romChecksum;
std::string romSerial;
std::string romFilename;
std::vector<u8> savestate;
bool savestate = false;
std::vector<u8> sram;
std::vector<MovieRecord> records;
std::vector<std::wstring> comments;
@ -207,9 +207,6 @@ public:
void clearRecordRange(int start, int len);
void insertEmpty(int at, int frames);
static bool loadSavestateFrom(std::vector<u8>* buf);
static void dumpSavestateTo(std::vector<u8>* buf, int compressionLevel);
static bool loadSramFrom(std::vector<u8>* buf);
//void TryDumpIncremental();
@ -234,11 +231,11 @@ private:
void installFirmLanguage(std::string& val) { firmLanguage = atoi(val.c_str()); }
void installAdvancedTiming(std::string& val) { advancedTiming = atoi(val.c_str()) != 0; }
void installJitBlockSize(std::string& val) { jitBlockSize = atoi(val.c_str()); }
void installSavestate(std::string& val) { savestate = atoi(val.c_str()) != 0; }
void installRomChecksum(std::string& val);
void installRtcStart(std::string& val);
void installComment(std::string& val);
void installSavestate(std::string& val);
void installSram(std::string& val);
typedef void(MovieData::* ivm)(std::string&);