movie speedups

This commit is contained in:
zeromus 2010-05-28 03:59:19 +00:00
parent 988753e116
commit bccf3f2f85
3 changed files with 32 additions and 3 deletions

View File

@ -11,4 +11,18 @@ bool EMUFILE::readAllBytes(std::vector<u8>* dstbuf, const std::string& fname)
dstbuf->resize(size);
file.fread(&dstbuf->at(0),size);
return true;
}
EMUFILE* EMUFILE::memwrap(EMUFILE* fp)
{
EMUFILE_FILE* file;
EMUFILE_MEMORY* mem;
file = dynamic_cast<EMUFILE_FILE*>(fp);
mem = dynamic_cast<EMUFILE_MEMORY*>(fp);
if(mem) return mem;
mem = new EMUFILE_MEMORY(file->size());
if(file->size()==0) return mem;
file->fread(mem->buf(),file->size());
delete file;
return mem;
}

View File

@ -52,6 +52,10 @@ public:
: failbit(false)
{}
//takes control of the provided EMUFILE and returns a new EMUFILE which is guranteed to be in memory
static EMUFILE* memwrap(EMUFILE* fp);
virtual ~EMUFILE() {}
static bool readAllBytes(std::vector<u8>* buf, const std::string& fname);
@ -141,9 +145,19 @@ public:
virtual int fgetc() {
u8 temp;
if(_fread(&temp,1) != 1)
return EOF;
else return temp;
//need an optimized codepath
//if(_fread(&temp,1) != 1)
// return EOF;
//else return temp;
u32 remain = len-pos;
if(remain<1) {
failbit = true;
return -1;
}
temp = buf()[pos];
pos++;
return temp;
}
virtual int fputc(int c) {
u8 temp = (u8)c;

View File

@ -906,6 +906,7 @@ bool FCEUI_LoadMovie(const char *fname, bool _read_only, bool tasedit, int _paus
strcpy(curMovieFilename, fname);
FCEUFILE *fp = FCEU_fopen(fname,0,"rb",0);
fp->stream = EMUFILE::memwrap(fp->stream);
if (!fp) return false;
if(fp->isArchive() && !_read_only) {
FCEU_PrintError("Cannot open a movie in read+write from an archive.");