repair and speedup tasedit
This commit is contained in:
parent
f062107e60
commit
c366dc1f2b
|
@ -87,7 +87,7 @@ void MovieData::TryDumpIncremental()
|
|||
{
|
||||
if(currFrameCounter < (int)currMovieData.records.size())
|
||||
{
|
||||
MovieData::dumpSavestateTo(&currMovieData.records[currFrameCounter].savestate,Z_NO_COMPRESSION);
|
||||
MovieData::dumpSavestateTo(&currMovieData.records[currFrameCounter].savestate,Z_DEFAULT_COMPRESSION);
|
||||
currMovieData.greenZoneCount++;
|
||||
}
|
||||
}
|
||||
|
@ -437,6 +437,7 @@ void MovieData::dumpSavestateTo(std::vector<char>* buf, int compressionLevel)
|
|||
{
|
||||
memorystream ms(buf);
|
||||
FCEUSS_SaveMS(&ms,compressionLevel);
|
||||
ms.trim();
|
||||
}
|
||||
|
||||
//begin playing an existing movie
|
||||
|
@ -716,9 +717,12 @@ bool FCEUMOV_ReadState(FILE* st, uint32 size)
|
|||
fread(&buf[0],1,size,st);
|
||||
FILE* tmp = tmpfile();
|
||||
fwrite(&buf[0],1,size,tmp);
|
||||
FILE* wtf = fopen("d:\\wtf.txt","wb");
|
||||
fwrite(&buf[0],1,size,wtf);
|
||||
fclose(wtf);
|
||||
//---------
|
||||
//(debug)
|
||||
//FILE* wtf = fopen("d:\\wtf.txt","wb");
|
||||
//fwrite(&buf[0],1,size,wtf);
|
||||
//fclose(wtf);
|
||||
//---------
|
||||
fseek(tmp,0,SEEK_SET);
|
||||
MovieData tempMovieData = MovieData();
|
||||
LoadFM2(tempMovieData, tmp);
|
||||
|
@ -797,7 +801,8 @@ int FCEUMOV_PostLoad(void)
|
|||
if(!FCEUI_IsMovieActive())
|
||||
return 1;
|
||||
else
|
||||
return load_successful;
|
||||
//mbg tasedit hack!!!!!!!!!
|
||||
return load_successful || moviePleaseLogSavestates;
|
||||
}
|
||||
|
||||
int FCEUI_IsMovieActive(void)
|
||||
|
|
|
@ -389,25 +389,26 @@ bool FCEUSS_SaveMS(std::ostream* outstream, int compressionLevel)
|
|||
FCEUPPU_SaveState();
|
||||
FCEUSND_SaveState();
|
||||
totalsize=WriteStateChunk(os,1,SFCPU);
|
||||
ms.sync();
|
||||
totalsize+=WriteStateChunk(os,2,SFCPUC);
|
||||
ms.sync();
|
||||
totalsize+=WriteStateChunk(os,3,FCEUPPU_STATEINFO);
|
||||
ms.sync();
|
||||
totalsize+=WriteStateChunk(os,4,FCEUCTRL_STATEINFO);
|
||||
ms.sync();
|
||||
totalsize+=WriteStateChunk(os,5,FCEUSND_STATEINFO);
|
||||
ms.sync();
|
||||
if(FCEUI_IsMovieActive())
|
||||
{
|
||||
totalsize+=WriteStateChunk(os,6,FCEUMOV_STATEINFO);
|
||||
ms.sync();
|
||||
|
||||
//MBG tasedit HACK HACK HACK!
|
||||
//do not save the movie state if we are in tasedit! that is a huge waste of time and space!
|
||||
extern bool moviePleaseLogSavestates;
|
||||
if(!moviePleaseLogSavestates)
|
||||
{
|
||||
uint32 size = FCEUMOV_WriteState((std::ostream*)0);
|
||||
os->put(7);
|
||||
write32le(size, os);
|
||||
FCEUMOV_WriteState(os);
|
||||
totalsize += 5 + size;
|
||||
}
|
||||
}
|
||||
// save back buffer
|
||||
{
|
||||
extern uint8 *XBackBuf;
|
||||
|
@ -416,7 +417,6 @@ bool FCEUSS_SaveMS(std::ostream* outstream, int compressionLevel)
|
|||
write32le(size, os);
|
||||
os->write((char*)XBackBuf,size);
|
||||
totalsize += 5 + size;
|
||||
ms.sync();
|
||||
}
|
||||
|
||||
if(SPreSave) SPreSave();
|
||||
|
@ -453,7 +453,7 @@ bool FCEUSS_SaveMS(std::ostream* outstream, int compressionLevel)
|
|||
|
||||
//dump it to the destination file
|
||||
outstream->write((char*)header,16);
|
||||
outstream->write((char*)cbuf,comprlen);
|
||||
outstream->write((char*)cbuf,comprlen==-1?totalsize:comprlen);
|
||||
|
||||
if(cbuf != (uint8*)ms.buf()) delete[] cbuf;
|
||||
return error == Z_OK;
|
||||
|
@ -657,9 +657,17 @@ bool FCEUSS_LoadFP(FILE *st, ENUM_SSLOADPARAMS params)
|
|||
int stateversion = FCEU_de32lsb(header + 8);
|
||||
int comprlen = FCEU_de32lsb(header + 12);
|
||||
|
||||
//load the compressed chunk and decompress
|
||||
std::vector<uint8> cbuf(comprlen);
|
||||
//load the compressed chunk and decompress if necessary
|
||||
std::vector<uint8> buf(totalsize);
|
||||
if(comprlen == -1)
|
||||
{
|
||||
int ret = fread(&buf[0],1,totalsize,st);
|
||||
if(ret != totalsize)
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::vector<uint8> cbuf(comprlen);
|
||||
if(fread(&cbuf[0],1,comprlen,st) != comprlen)
|
||||
return false;
|
||||
|
||||
|
@ -667,6 +675,7 @@ bool FCEUSS_LoadFP(FILE *st, ENUM_SSLOADPARAMS params)
|
|||
int error = uncompress(&buf[0],&uncomprlen,&cbuf[0],comprlen);
|
||||
if(error != Z_OK || uncomprlen != totalsize)
|
||||
return false;
|
||||
}
|
||||
|
||||
//dump it back to a tempfile
|
||||
FILE* tmp = tmpfile();
|
||||
|
|
|
@ -30,13 +30,6 @@ private:
|
|||
|
||||
public:
|
||||
|
||||
//the logical length of the buffer
|
||||
size_t size()
|
||||
{
|
||||
sync();
|
||||
return length;
|
||||
}
|
||||
|
||||
memory_streambuf()
|
||||
: length(0)
|
||||
, myBuf(true)
|
||||
|
@ -73,13 +66,19 @@ public:
|
|||
sync();
|
||||
}
|
||||
|
||||
|
||||
~memory_streambuf()
|
||||
{
|
||||
//only cleanup if we own the seq
|
||||
if(myBuf) delete[] buf;
|
||||
}
|
||||
|
||||
//the logical length of the buffer
|
||||
size_t size()
|
||||
{
|
||||
sync();
|
||||
return length;
|
||||
}
|
||||
|
||||
//to avoid copying, rebuilds the provided vector and copies the streambuf contents into it
|
||||
void toVector(std::vector<T>& out)
|
||||
{
|
||||
|
@ -93,6 +92,14 @@ public:
|
|||
return std::vector<T>(buf,buf+length);
|
||||
}
|
||||
|
||||
//if the memorystream wraps a vector, the vector will be trimmed to the correct size,.
|
||||
//you probably need to use this if you are using the vector wrapper
|
||||
void trim()
|
||||
{
|
||||
if(!usevec) return;
|
||||
usevec->resize(size());
|
||||
}
|
||||
|
||||
//tells the current read or write position
|
||||
std::streampos tell(std::ios::openmode which)
|
||||
{
|
||||
|
@ -234,13 +241,13 @@ public:
|
|||
{}
|
||||
|
||||
memorystream(char* usebuf, int buflength)
|
||||
: streambuf(usebuf, buflength)
|
||||
, std::basic_iostream<char, std::char_traits<char> >(&streambuf)
|
||||
: std::basic_iostream<char, std::char_traits<char> >(&streambuf)
|
||||
, streambuf(usebuf, buflength)
|
||||
{}
|
||||
|
||||
memorystream(std::vector<char>* usevec)
|
||||
: streambuf(usevec)
|
||||
, std::basic_iostream<char, std::char_traits<char> >(&streambuf)
|
||||
: std::basic_iostream<char, std::char_traits<char> >(&streambuf)
|
||||
, streambuf(usevec)
|
||||
{}
|
||||
|
||||
//the underlying memory_streambuf
|
||||
|
@ -255,4 +262,8 @@ public:
|
|||
void sync() { streambuf.sync(); }
|
||||
//rewinds the cursors to offset 0
|
||||
void rewind() { streambuf.seekpos(0,std::ios::in | std::ios::out); }
|
||||
|
||||
//if the memorystream wraps a vector, the vector will be trimmed to the correct size,.
|
||||
//you probably need to use this if you are using the vector wrapper
|
||||
void trim() { streambuf.trim(); }
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue