make movies load faster

This commit is contained in:
zeromus 2008-06-12 07:10:46 +00:00
parent 043aabf009
commit fc9c64e5e7
3 changed files with 39 additions and 7 deletions

View File

@ -113,15 +113,26 @@ void MovieRecord::dumpJoy(std::ostream* os, uint8 joystate)
void MovieRecord::parseJoy(std::istream* is, uint8& joystate)
{
char buf[8];
is->read(buf,8);
joystate = 0;
for(int bit=7;bit>=0;bit--)
for(int i=0;i<8;i++)
{
int c = is->get();
if(c == -1)
return;
if(c != ' ')
joystate |= (1<<bit);
joystate <<= 1;
joystate |= ((buf[i]!=' ')?1:0);
}
//older, slower(?) way:
//joystate = 0;
//for(int bit=7;bit>=0;bit--)
//{
// int c = is->get();
// if(c == -1)
// return;
// if(c != ' ')
// joystate |= (1<<bit);
//}
}
void MovieRecord::parse(MovieData* md, std::istream* is)
@ -129,7 +140,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
*is >> commands;
commands = uintDecFromIstream(is);
is->get(); //eat the pipe
//a special case: if fourscore is enabled, parse four gamepads
@ -150,6 +161,7 @@ void MovieRecord::parse(MovieData* md, std::istream* is)
{
int x,y,b;
*is >> x >> y >> b;
//todo: test uintDecFromIstream
zappers[port].x = x;
zappers[port].y = y;
zappers[port].b = b;

View File

@ -462,3 +462,19 @@ char *U8ToHexStr(uint8 a)
TempArray[2] = 0;
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;
}

View File

@ -21,6 +21,7 @@
#include <string.h>
#include <stdlib.h>
#include <vector>
#include <iostream>
#include "../types.h"
@ -53,3 +54,6 @@ char *U32ToDecStr(char* buf, uint32 a);
char *U8ToDecStr(uint8 a);
char *U8ToHexStr(uint8 a);
char *U16ToHexStr(uint16 a);
//extracts a decimal uint from an istream
unsigned int uintDecFromIstream(std::istream* is);