From fc9c64e5e78b51eea4772b2ac92077b964d6488e Mon Sep 17 00:00:00 2001 From: zeromus Date: Thu, 12 Jun 2008 07:10:46 +0000 Subject: [PATCH] make movies load faster --- src/movie.cpp | 26 +++++++++++++++++++------- src/utils/xstring.cpp | 16 ++++++++++++++++ src/utils/xstring.h | 4 ++++ 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/src/movie.cpp b/src/movie.cpp index 602bdafa..c5df4035 100644 --- a/src/movie.cpp +++ b/src/movie.cpp @@ -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<=0;bit--) + //{ + // int c = is->get(); + // if(c == -1) + // return; + // if(c != ' ') + // joystate |= (1<> 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; diff --git a/src/utils/xstring.cpp b/src/utils/xstring.cpp index c43cdb41..0a4b8e17 100644 --- a/src/utils/xstring.cpp +++ b/src/utils/xstring.cpp @@ -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; +} \ No newline at end of file diff --git a/src/utils/xstring.h b/src/utils/xstring.h index bad33e62..10a614c8 100644 --- a/src/utils/xstring.h +++ b/src/utils/xstring.h @@ -21,6 +21,7 @@ #include #include #include +#include #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); \ No newline at end of file