From b82c266971000e5fa6fa3f68bde4e12a02c91195 Mon Sep 17 00:00:00 2001 From: zeromus Date: Tue, 17 Jun 2008 07:55:27 +0000 Subject: [PATCH] fixed a bad bug in memorystream which makes movie savestates work better and now they work faster too --- src/cart.cpp | 2 +- src/movie.cpp | 23 +++++------------------ src/movie.h | 3 +-- src/state.cpp | 7 +++++-- src/utils/memorystream.h | 3 +++ 5 files changed, 15 insertions(+), 23 deletions(-) diff --git a/src/cart.cpp b/src/cart.cpp index ebc31a44..90d80a36 100644 --- a/src/cart.cpp +++ b/src/cart.cpp @@ -658,7 +658,7 @@ void FCEU_SaveGameSave(CartInfo *LocalHWInfo) } } -// hack, movie.c has to communicate with this function somehow +// hack, movie.cpp has to communicate with this function somehow int disableBatteryLoading=0; void FCEU_LoadGameSave(CartInfo *LocalHWInfo) diff --git a/src/movie.cpp b/src/movie.cpp index 06f5761d..6c9855e9 100644 --- a/src/movie.cpp +++ b/src/movie.cpp @@ -276,8 +276,9 @@ void MovieData::installValue(std::string& key, std::string& val) } } -void MovieData::dump(std::ostream *os) +int MovieData::dump(std::ostream *os) { + int start = os->tellp(); *os << "version " << version << endl; *os << "emuVersion " << emuVersion << endl; *os << "recordCount " << recordCount << endl; @@ -296,16 +297,10 @@ void MovieData::dump(std::ostream *os) *os << "savestate " << BytesToString(&savestate[0],savestate.size()) << endl; for(int i=0;i<(int)records.size();i++) records[i].dump(this,os,i); + int end = os->tellp(); + return end-start; } -int MovieData::dumpLen() -{ - memorystream ms; - dump(&ms); - return ms.size(); -} - - int FCEUMOV_GetFrame(void) { return currFrameCounter; @@ -761,16 +756,8 @@ void FCEU_DrawMovies(uint8 *XBuf) int FCEUMOV_WriteState(std::ostream* os) { //we are supposed to dump the movie data into the savestate - if(movieMode == MOVIEMODE_RECORD || movieMode == MOVIEMODE_PLAY) - { - int todo = currMovieData.dumpLen(); - - if(os) - currMovieData.dump(os); - - return todo; - } + return currMovieData.dump(os); else return 0; } diff --git a/src/movie.h b/src/movie.h index 2e1dbecc..a8f0d48c 100644 --- a/src/movie.h +++ b/src/movie.h @@ -163,8 +163,7 @@ public: void truncateAt(int frame); void installValue(std::string& key, std::string& val); - void dump(std::ostream* os); - int dumpLen(); + int dump(std::ostream* os); void clearRecordRange(int start, int len); static bool loadSavestateFrom(std::vector* buf); diff --git a/src/state.cpp b/src/state.cpp index f8a5bd1c..0cc62a74 100644 --- a/src/state.cpp +++ b/src/state.cpp @@ -406,10 +406,13 @@ bool FCEUSS_SaveMS(std::ostream* outstream, int compressionLevel) //do not save the movie state if we are in tasedit! that is a huge waste of time and space! if(!FCEUMOV_Mode(MOVIEMODE_TASEDIT)) { - uint32 size = FCEUMOV_WriteState((std::ostream*)0); + os->seekp(5,std::ios::cur); + int size = FCEUMOV_WriteState(os); + os->seekp(-(size+5),std::ios::cur); os->put(7); write32le(size, os); - FCEUMOV_WriteState(os); + os->seekp(size,std::ios::cur); + totalsize += 5 + size; } } diff --git a/src/utils/memorystream.h b/src/utils/memorystream.h index c5c38425..f0aa949a 100644 --- a/src/utils/memorystream.h +++ b/src/utils/memorystream.h @@ -210,7 +210,10 @@ protected: if(which & std::ios_base::in) setg(buf, buf+pos, buf + length); if(which & std::ios_base::out) + { + ww = pos; setp(buf+pos, buf + capacity); + } return pos; }