ever so slightly faster movie i/o? this has hit diminishing returns. binary mode is all that is left

This commit is contained in:
zeromus 2008-06-20 06:52:20 +00:00
parent f17b83fb22
commit d159696288
3 changed files with 68 additions and 28 deletions

View File

@ -47,6 +47,9 @@ using namespace std;
//todo - handle case where read+write is requested, but the file is actually readonly (could be confusing)
//todo - could we, given a field size, over-read from an inputstream and then parse out an integer?
//that would be faster than several reads, perhaps.
//sometimes we accidentally produce movie stop signals while we're trying to do other things with movies..
bool suppressMovieStop=false;
@ -143,7 +146,7 @@ void MovieRecord::parse(MovieData* md, std::istream* is)
//by the time we get in here, the initial pipe has already been extracted
//extract the commands
commands = uintDecFromIstream(is);
commands = uint32DecFromIstream(is);
//*is >> commands;
is->get(); //eat the pipe
@ -165,13 +168,12 @@ void MovieRecord::parse(MovieData* md, std::istream* is)
{
int x,y,b,bogo;
uint64 zaphit;
*is >> x >> y >> b >> bogo >> zaphit;
//todo: test uintDecFromIstream
zappers[port].x = x;
zappers[port].y = y;
zappers[port].b = b;
zappers[port].bogo = bogo;
zappers[port].zaphit = zaphit;
//*is >> x >> y >> b >> bogo >> zaphit;
zappers[port].x = uint32DecFromIstream(is);
zappers[port].y = uint32DecFromIstream(is);
zappers[port].b = uint32DecFromIstream(is);
zappers[port].bogo = uint32DecFromIstream(is);
zappers[port].zaphit = uint64DecFromIstream(is);
}
is->get(); //eat the pipe
@ -192,7 +194,9 @@ void MovieRecord::dump(MovieData* md, std::ostream* os, int index)
//fprintf(fp,"%08d",index);
//dump the misc commands
*os << '|' << setw(1) << (int)commands;
//*os << '|' << setw(1) << (int)commands;
os->put('|');
putdec<uint8,1,true>(os,commands);
//a special case: if fourscore is enabled, dump four gamepads
if(md->fourscore)
@ -211,7 +215,13 @@ void MovieRecord::dump(MovieData* md, std::ostream* os, int index)
if(md->ports[port] == SI_GAMEPAD)
dumpJoy(os, joysticks[port]);
else if(md->ports[port] == SI_ZAPPER)
*os << setw(3) << setfill('0') << (int)zappers[port].x << ' ' << setw(3) << setfill('0') << (int)zappers[port].y << setw(1) << ' ' << (int)zappers[port].b << ' ' << (int)zappers[port].bogo << ' ' << zappers[port].zaphit;
{
putdec<uint8,3,true>(os,zappers[port].x); os->put(' ');
putdec<uint8,3,true>(os,zappers[port].y); os->put(' ');
putdec<uint8,1,true>(os,zappers[port].b); os->put(' ');
putdec<uint8,1,true>(os,zappers[port].bogo); os->put(' ');
putdec<uint64,20,false>(os,zappers[port].zaphit);
}
}
os->put('|');
}

View File

@ -463,22 +463,6 @@ char *U8ToHexStr(uint8 a)
return TempArray;
}
unsigned int uintDecFromIstream(std::istream* is)
{
unsigned int ret = 0;
for(;;)
{
int d = is->get() - '0';
if(d<0 || d>9)
break;
ret *= 10;
ret += d;
}
is->unget();
return ret;
}
std::string stditoa(int n)
{
char tempbuf[16];
@ -486,4 +470,3 @@ std::string stditoa(int n)
return tempbuf;
}

View File

@ -58,4 +58,51 @@ char *U16ToHexStr(uint16 a);
std::string stditoa(int n);
//extracts a decimal uint from an istream
unsigned int uintDecFromIstream(std::istream* is);
template<typename T> T templateIntegerDecFromIstream(std::istream* is)
{
unsigned int ret = 0;
bool pre = true;
for(;;)
{
int d = is->get() - '0';
if((d<0 || d>9))
{
if(!pre)
break;
}
else
{
pre = false;
ret *= 10;
ret += d;
}
}
is->unget();
return ret;
}
inline uint32 uint32DecFromIstream(std::istream* is) { return templateIntegerDecFromIstream<uint32>(is); }
inline uint64 uint64DecFromIstream(std::istream* is) { return templateIntegerDecFromIstream<uint64>(is); }
//puts an optionally 0-padded decimal integer of type T into the ostream (0-padding is quicker)
template<typename T, int DIGITS, bool PAD> void putdec(std::ostream* os, T dec)
{
char temp[DIGITS];
int ctr = 0;
for(int i=0;i<DIGITS;i++)
{
int quot = dec/10;
int rem = dec%10;
temp[DIGITS-1-i] = '0' + rem;
if(!PAD)
{
if(rem != 0) ctr = i;
}
dec = quot;
}
if(!PAD)
os->write(temp+DIGITS-ctr-1,ctr+1);
else
os->write(temp,DIGITS);
}