diff options
author | Nicola Mettifogo | 2010-02-08 16:14:04 +0000 |
---|---|---|
committer | Nicola Mettifogo | 2010-02-08 16:14:04 +0000 |
commit | b658c61155ff189fe4381ba774993a69a3f572ea (patch) | |
tree | f1253fedfa1acdf0f4e71b13cfb78cc552809847 | |
parent | a9a0fdc69474f0491aa2662cb83ff8b7661ebd1a (diff) | |
download | scummvm-rg350-b658c61155ff189fe4381ba774993a69a3f572ea.tar.gz scummvm-rg350-b658c61155ff189fe4381ba774993a69a3f572ea.tar.bz2 scummvm-rg350-b658c61155ff189fe4381ba774993a69a3f572ea.zip |
Let ArjFile return a SeekableReadStream instead of implementing
the same interface itself. The caller is now responsible for
deleting the returned streams.
svn-id: r47994
-rw-r--r-- | common/unarj.cpp | 51 | ||||
-rw-r--r-- | common/unarj.h | 14 | ||||
-rw-r--r-- | engines/drascula/converse.cpp | 32 | ||||
-rw-r--r-- | engines/drascula/drascula.cpp | 12 | ||||
-rw-r--r-- | engines/drascula/drascula.h | 12 | ||||
-rw-r--r-- | engines/drascula/graphics.cpp | 86 | ||||
-rw-r--r-- | engines/drascula/rooms.cpp | 80 | ||||
-rw-r--r-- | engines/drascula/sound.cpp | 13 |
8 files changed, 126 insertions, 174 deletions
diff --git a/common/unarj.cpp b/common/unarj.cpp index 793012946e..ec5d2e74f0 100644 --- a/common/unarj.cpp +++ b/common/unarj.cpp @@ -189,14 +189,12 @@ static uint32 GetCRC(byte *data, int len) { return CRC ^ 0xFFFFFFFF; } -ArjFile::ArjFile() : _uncompressed(0) { +ArjFile::ArjFile() { InitCRC(); _fallBack = false; } ArjFile::~ArjFile() { - close(); - for (uint i = 0; i < _headers.size(); i++) delete _headers[i]; } @@ -346,18 +344,14 @@ ArjHeader *readHeader(SeekableReadStream &stream) { } -bool ArjFile::open(const Common::String &filename) { - if (_uncompressed) - error("Attempt to open another instance of archive"); +SeekableReadStream *ArjFile::open(const Common::String &filename) { - if (_fallBack) { - _uncompressed = SearchMan.createReadStreamForMember(filename); - if (_uncompressed) - return true; + if (_fallBack && SearchMan.hasFile(filename)) { + return SearchMan.createReadStreamForMember(filename); } if (!_fileMap.contains(filename)) - return false; + return 0; ArjHeader *hdr = _headers[_fileMap[filename]]; @@ -390,42 +384,9 @@ bool ArjFile::open(const Common::String &filename) { delete decoder; } - - _uncompressed = new MemoryReadStream(uncompressedData, hdr->origSize, DisposeAfterUse::YES); - assert(_uncompressed); - - return true; -} - -void ArjFile::close() { - delete _uncompressed; - _uncompressed = NULL; -} - -uint32 ArjFile::read(void *dataPtr, uint32 dataSize) { - assert(_uncompressed); - return _uncompressed->read(dataPtr, dataSize); + return new MemoryReadStream(uncompressedData, hdr->origSize, true); } -bool ArjFile::eos() const { - assert(_uncompressed); - return _uncompressed->eos(); -} - -int32 ArjFile::pos() const { - assert(_uncompressed); - return _uncompressed->pos(); -} - -int32 ArjFile::size() const { - assert(_uncompressed); - return _uncompressed->size(); -} - -bool ArjFile::seek(int32 offset, int whence) { - assert(_uncompressed); - return _uncompressed->seek(offset, whence); -} // // Source for init_getbits: arj_file.c (decode_start_stub) diff --git a/common/unarj.h b/common/unarj.h index 992240be67..eaf2bb4f85 100644 --- a/common/unarj.h +++ b/common/unarj.h @@ -37,7 +37,7 @@ typedef HashMap<String, int, IgnoreCase_Hash, IgnoreCase_EqualTo> ArjFilesMap; // TODO: Get rid of this class, by implementing an ArjArchive subclass of Common::Archive. // Then ArjFile can be substituted by a SearchSet full of ArjArchives plus SearchMan. -class ArjFile : public SeekableReadStream, public NonCopyable { +class ArjFile : public NonCopyable { public: ArjFile(); ~ArjFile(); @@ -46,15 +46,7 @@ public: void registerArchive(const String &filename); - bool open(const Common::String &filename); - void close(); - - uint32 read(void *dataPtr, uint32 dataSize); - bool eos() const; - int32 pos() const; - int32 size() const; - bool seek(int32 offset, int whence = SEEK_SET); - bool isOpen() { return _uncompressed != 0; } + SeekableReadStream *open(const Common::String &filename); private: bool _fallBack; @@ -62,8 +54,6 @@ private: Array<ArjHeader *> _headers; ArjFilesMap _fileMap; StringMap _archMap; - - SeekableReadStream *_uncompressed; }; } // End of namespace Common diff --git a/engines/drascula/converse.cpp b/engines/drascula/converse.cpp index 707ae55b63..0cd9794cc3 100644 --- a/engines/drascula/converse.cpp +++ b/engines/drascula/converse.cpp @@ -133,11 +133,11 @@ void DrasculaEngine::cleanupString(char *string) { void DrasculaEngine::converse(int index) { char fileName[20]; sprintf(fileName, "op_%d.cal", index); - _arj.open(fileName); - if (!_arj.isOpen()) + Common::SeekableReadStream *stream = _arj.open(fileName); + if (!stream) error("missing data file %s", fileName); - int size = _arj.size(); + int size = stream->size(); int game1 = kDialogOptionUnselected, game2 = kDialogOptionUnselected, game3 = kDialogOptionUnselected; @@ -150,19 +150,19 @@ void DrasculaEngine::converse(int index) { selectVerb(kVerbNone); - getStringFromLine(_arj, size, phrase1); - getStringFromLine(_arj, size, phrase2); - getStringFromLine(_arj, size, phrase3); - getStringFromLine(_arj, size, phrase4); - getStringFromLine(_arj, size, sound1); - getStringFromLine(_arj, size, sound2); - getStringFromLine(_arj, size, sound3); - getStringFromLine(_arj, size, sound4); - getIntFromLine(_arj, size, &answer1); - getIntFromLine(_arj, size, &answer2); - getIntFromLine(_arj, size, &answer3); - - _arj.close(); + getStringFromLine(stream, size, phrase1); + getStringFromLine(stream, size, phrase2); + getStringFromLine(stream, size, phrase3); + getStringFromLine(stream, size, phrase4); + getStringFromLine(stream, size, sound1); + getStringFromLine(stream, size, sound2); + getStringFromLine(stream, size, sound3); + getStringFromLine(stream, size, sound4); + getIntFromLine(stream, size, &answer1); + getIntFromLine(stream, size, &answer2); + getIntFromLine(stream, size, &answer3); + + delete stream; if (currentChapter == 2 && !strcmp(fileName, "op_5.cal") && flags[38] == 1 && flags[33] == 1) { strcpy(phrase3, _text[405]); diff --git a/engines/drascula/drascula.cpp b/engines/drascula/drascula.cpp index 824a5eb2dd..56fbe48714 100644 --- a/engines/drascula/drascula.cpp +++ b/engines/drascula/drascula.cpp @@ -604,15 +604,15 @@ bool DrasculaEngine::runCurrentChapter() { } } -char *DrasculaEngine::getLine(Common::SeekableReadStream &stream, char *buf, int len) { +char *DrasculaEngine::getLine(Common::SeekableReadStream *stream, char *buf, int len) { byte c; char *b; for (;;) { b = buf; while (true) { - c = ~stream.readByte(); - if (stream.eos()) break; + c = ~stream->readByte(); + if (stream->eos()) break; if (c == '\r') continue; @@ -621,7 +621,7 @@ char *DrasculaEngine::getLine(Common::SeekableReadStream &stream, char *buf, int *b++ = c; } *b = '\0'; - if (stream.eos() && b == buf) + if (stream->eos() && b == buf) return NULL; if (b != buf) break; @@ -629,13 +629,13 @@ char *DrasculaEngine::getLine(Common::SeekableReadStream &stream, char *buf, int return buf; } -void DrasculaEngine::getIntFromLine(Common::SeekableReadStream &stream, int len, int* result) { +void DrasculaEngine::getIntFromLine(Common::SeekableReadStream *stream, int len, int* result) { char buf[256]; getLine(stream, buf, len); sscanf(buf, "%d", result); } -void DrasculaEngine::getStringFromLine(Common::SeekableReadStream &stream, int len, char* result) { +void DrasculaEngine::getStringFromLine(Common::SeekableReadStream *stream, int len, char* result) { char buf[256]; getLine(stream, buf, len); sscanf(buf, "%s", result); diff --git a/engines/drascula/drascula.h b/engines/drascula/drascula.h index c783374f55..e4ff03ffc0 100644 --- a/engines/drascula/drascula.h +++ b/engines/drascula/drascula.h @@ -541,8 +541,8 @@ public: void mixVideo(byte *OldScreen, byte *NewScreen); void decodeRLE(byte *BufferRLE, byte *MiVideoRLE); void decodeOffset(byte *BufferOFF, byte *MiVideoOFF, int length); - byte *TryInMem(Common::SeekableReadStream &stream); - int playFrameSSN(Common::SeekableReadStream &stream); + byte *TryInMem(Common::SeekableReadStream *stream); + int playFrameSSN(Common::SeekableReadStream *stream); bool _useMemForArj; byte CHUNK; @@ -553,7 +553,7 @@ public: int flag_tv; - void showFrame(Common::SeekableReadStream &stream, bool firstFrame = false); + void showFrame(Common::SeekableReadStream *stream, bool firstFrame = false); int getTime(); void reduce_hare_chico(int, int, int, int, int, int, int, byte *, byte *); void quadrant_1(); @@ -577,9 +577,9 @@ public: void MusicFadeout(); void playFile(const char *fname); - char *getLine(Common::SeekableReadStream &stream, char *buf, int len); - void getIntFromLine(Common::SeekableReadStream &stream, int len, int* result); - void getStringFromLine(Common::SeekableReadStream &stream, int len, char* result); + char *getLine(Common::SeekableReadStream *stream, char *buf, int len); + void getIntFromLine(Common::SeekableReadStream *stream, int len, int* result); + void getStringFromLine(Common::SeekableReadStream *stream, int len, char* result); void grr(); void updateAnim(int y, int destX, int destY, int width, int height, int count, byte* src, int delayVal = 3, bool copyRectangle = false); diff --git a/engines/drascula/graphics.cpp b/engines/drascula/graphics.cpp index c049b58719..6298c89527 100644 --- a/engines/drascula/graphics.cpp +++ b/engines/drascula/graphics.cpp @@ -93,39 +93,39 @@ void DrasculaEngine::loadPic(const char *NamePcc, byte *targetSurface, int color uint dataSize = 0; byte *pcxData; - _arj.open(NamePcc); - if (!_arj.isOpen()) + Common::SeekableReadStream *stream = _arj.open(NamePcc); + if (!stream) error("missing game data %s %c", NamePcc, 7); - dataSize = _arj.size() - 128 - (256 * 3); + dataSize = stream->size() - 128 - (256 * 3); pcxData = (byte *)malloc(dataSize); - _arj.seek(128, SEEK_SET); - _arj.read(pcxData, dataSize); + stream->seek(128, SEEK_SET); + stream->read(pcxData, dataSize); decodeRLE(pcxData, targetSurface); free(pcxData); for (int i = 0; i < 256; i++) { - cPal[i * 3 + 0] = _arj.readByte(); - cPal[i * 3 + 1] = _arj.readByte(); - cPal[i * 3 + 2] = _arj.readByte(); + cPal[i * 3 + 0] = stream->readByte(); + cPal[i * 3 + 1] = stream->readByte(); + cPal[i * 3 + 2] = stream->readByte(); } - _arj.close(); + delete stream; setRGB((byte *)cPal, colorCount); } -void DrasculaEngine::showFrame(Common::SeekableReadStream &stream, bool firstFrame) { - int dataSize = stream.readSint32LE(); +void DrasculaEngine::showFrame(Common::SeekableReadStream *stream, bool firstFrame) { + int dataSize = stream->readSint32LE(); byte *pcxData = (byte *)malloc(dataSize); - stream.read(pcxData, dataSize); + stream->read(pcxData, dataSize); for (int i = 0; i < 256; i++) { - cPal[i * 3 + 0] = stream.readByte(); - cPal[i * 3 + 1] = stream.readByte(); - cPal[i * 3 + 2] = stream.readByte(); + cPal[i * 3 + 0] = stream->readByte(); + cPal[i * 3 + 1] = stream->readByte(); + cPal[i * 3 + 2] = stream->readByte(); } byte *prevFrame = (byte *)malloc(64000); @@ -388,12 +388,12 @@ void DrasculaEngine::screenSaver() { ghost = (byte *)malloc(65536); // carga_ghost(); - _arj.open("ghost.drv"); - if (!_arj.isOpen()) + Common::SeekableReadStream *stream = _arj.open("ghost.drv"); + if (!stream) error("Cannot open file ghost.drv"); - _arj.read(ghost, 65536); - _arj.close(); + stream->read(ghost, 65536); + delete stream; updateEvents(); xr = mouseX; @@ -477,14 +477,14 @@ void DrasculaEngine::playFLI(const char *filefli, int vel) { globalSpeed = 1000 / vel; FrameSSN = 0; _useMemForArj = false; - _arj.open(filefli); + Common::SeekableReadStream *stream = _arj.open(filefli); // TODO: mSession is treated like a stream from playFrameSSN, so turn it // into a stream, and pass it to playFrameSSN. Get rid of _useMemForArj // as well. - mSession = TryInMem(_arj); + mSession = TryInMem(stream); LastFrame = _system->getMillis(); - while (playFrameSSN(_arj) && (!term_int)) { + while (playFrameSSN(stream) && (!term_int)) { if (getScan() == Common::KEYCODE_ESCAPE) term_int = 1; } @@ -492,16 +492,16 @@ void DrasculaEngine::playFLI(const char *filefli, int vel) { if (_useMemForArj) free(memPtr); - _arj.close(); + delete stream; } -int DrasculaEngine::playFrameSSN(Common::SeekableReadStream &stream) { +int DrasculaEngine::playFrameSSN(Common::SeekableReadStream *stream) { int Exit = 0; uint32 length; byte *BufferSSN; if (!_useMemForArj) - CHUNK = stream.readByte(); + CHUNK = stream->readByte(); else { memcpy(&CHUNK, mSession, 1); mSession += 1; @@ -511,9 +511,9 @@ int DrasculaEngine::playFrameSSN(Common::SeekableReadStream &stream) { case kFrameSetPal: if (!_useMemForArj) { for (int i = 0; i < 256; i++) { - dacSSN[i * 3 + 0] = stream.readByte(); - dacSSN[i * 3 + 1] = stream.readByte(); - dacSSN[i * 3 + 2] = stream.readByte(); + dacSSN[i * 3 + 0] = stream->readByte(); + dacSSN[i * 3 + 1] = stream->readByte(); + dacSSN[i * 3 + 2] = stream->readByte(); } } else { memcpy(dacSSN, mSession, 768); @@ -526,8 +526,8 @@ int DrasculaEngine::playFrameSSN(Common::SeekableReadStream &stream) { break; case kFrameInit: if (!_useMemForArj) { - CMP = stream.readByte(); - length = stream.readUint32LE(); + CMP = stream->readByte(); + length = stream->readUint32LE(); } else { memcpy(&CMP, mSession, 1); mSession += 1; @@ -537,7 +537,7 @@ int DrasculaEngine::playFrameSSN(Common::SeekableReadStream &stream) { if (CMP == kFrameCmpRle) { BufferSSN = (byte *)malloc(length); if (!_useMemForArj) { - stream.read(BufferSSN, length); + stream->read(BufferSSN, length); } else { memcpy(BufferSSN, mSession, length); mSession += length; @@ -559,7 +559,7 @@ int DrasculaEngine::playFrameSSN(Common::SeekableReadStream &stream) { if (CMP == kFrameCmpOff) { BufferSSN = (byte *)malloc(length); if (!_useMemForArj) { - stream.read(BufferSSN, length); + stream->read(BufferSSN, length); } else { memcpy(BufferSSN, mSession, length); mSession += length; @@ -590,16 +590,16 @@ int DrasculaEngine::playFrameSSN(Common::SeekableReadStream &stream) { return (!Exit); } -byte *DrasculaEngine::TryInMem(Common::SeekableReadStream &stream) { +byte *DrasculaEngine::TryInMem(Common::SeekableReadStream *stream) { int length; - stream.seek(0, SEEK_END); - length = stream.pos(); - stream.seek(0, SEEK_SET); + stream->seek(0, SEEK_END); + length = stream->pos(); + stream->seek(0, SEEK_SET); memPtr = (byte *)malloc(length); if (memPtr == NULL) return NULL; - stream.read(memPtr, length); + stream->read(memPtr, length); _useMemForArj = true; return memPtr; @@ -660,17 +660,17 @@ bool DrasculaEngine::animate(const char *animationFile, int FPS) { int NFrames = 1; int cnt = 2; - _arj.open(animationFile); + Common::SeekableReadStream *stream = _arj.open(animationFile); - if (!_arj.isOpen()) { + if (!stream) { error("Animation file %s not found", animationFile); } - NFrames = _arj.readSint32LE(); - showFrame(_arj, true); + NFrames = stream->readSint32LE(); + showFrame(stream, true); _system->delayMillis(1000 / FPS); while (cnt < NFrames) { - showFrame(_arj); + showFrame(stream); _system->delayMillis(1000 / FPS); cnt++; byte key = getScan(); @@ -679,7 +679,7 @@ bool DrasculaEngine::animate(const char *animationFile, int FPS) { if (key != 0) break; } - _arj.close(); + delete stream; return ((term_int == 1) || (getScan() == Common::KEYCODE_ESCAPE)); } diff --git a/engines/drascula/rooms.cpp b/engines/drascula/rooms.cpp index 8019fa9729..bd73386bbd 100644 --- a/engines/drascula/rooms.cpp +++ b/engines/drascula/rooms.cpp @@ -1649,69 +1649,69 @@ void DrasculaEngine::enterRoom(int roomIndex) { strcpy(currentData, fileName); - _arj.open(fileName); - if (!_arj.isOpen()) { + Common::SeekableReadStream *stream = _arj.open(fileName); + if (!stream) { error("missing data file %s", fileName); } - int size = _arj.size(); + int size = stream->size(); - getIntFromLine(_arj, size, &roomNumber); - getIntFromLine(_arj, size, &roomMusic); - getStringFromLine(_arj, size, roomDisk); - getIntFromLine(_arj, size, &palLevel); + getIntFromLine(stream, size, &roomNumber); + getIntFromLine(stream, size, &roomMusic); + getStringFromLine(stream, size, roomDisk); + getIntFromLine(stream, size, &palLevel); if (currentChapter == 2) - getIntFromLine(_arj, size, &martin); + getIntFromLine(stream, size, &martin); if (currentChapter == 2 && martin != 0) { curWidth = martin; - getIntFromLine(_arj, size, &curHeight); - getIntFromLine(_arj, size, &feetHeight); - getIntFromLine(_arj, size, &stepX); - getIntFromLine(_arj, size, &stepY); + getIntFromLine(stream, size, &curHeight); + getIntFromLine(stream, size, &feetHeight); + getIntFromLine(stream, size, &stepX); + getIntFromLine(stream, size, &stepY); - getStringFromLine(_arj, size, pant1); - getStringFromLine(_arj, size, pant2); - getStringFromLine(_arj, size, pant3); - getStringFromLine(_arj, size, pant4); + getStringFromLine(stream, size, pant1); + getStringFromLine(stream, size, pant2); + getStringFromLine(stream, size, pant3); + getStringFromLine(stream, size, pant4); strcpy(menuBackground, pant4); } - getIntFromLine(_arj, size, &numRoomObjs); + getIntFromLine(stream, size, &numRoomObjs); for (l = 0; l < numRoomObjs; l++) { - getIntFromLine(_arj, size, &objectNum[l]); - getStringFromLine(_arj, size, objName[l]); - getIntFromLine(_arj, size, &x1[l]); - getIntFromLine(_arj, size, &y1[l]); - getIntFromLine(_arj, size, &x2[l]); - getIntFromLine(_arj, size, &y2[l]); - getIntFromLine(_arj, size, &roomObjX[l]); - getIntFromLine(_arj, size, &roomObjY[l]); - getIntFromLine(_arj, size, &trackObj[l]); - getIntFromLine(_arj, size, &visible[l]); - getIntFromLine(_arj, size, &isDoor[l]); + getIntFromLine(stream, size, &objectNum[l]); + getStringFromLine(stream, size, objName[l]); + getIntFromLine(stream, size, &x1[l]); + getIntFromLine(stream, size, &y1[l]); + getIntFromLine(stream, size, &x2[l]); + getIntFromLine(stream, size, &y2[l]); + getIntFromLine(stream, size, &roomObjX[l]); + getIntFromLine(stream, size, &roomObjY[l]); + getIntFromLine(stream, size, &trackObj[l]); + getIntFromLine(stream, size, &visible[l]); + getIntFromLine(stream, size, &isDoor[l]); if (isDoor[l] != 0) { - getStringFromLine(_arj, size, _targetSurface[l]); - getIntFromLine(_arj, size, &_destX[l]); - getIntFromLine(_arj, size, &_destY[l]); - getIntFromLine(_arj, size, &trackCharacter_alkeva[l]); - getIntFromLine(_arj, size, &roomExits[l]); + getStringFromLine(stream, size, _targetSurface[l]); + getIntFromLine(stream, size, &_destX[l]); + getIntFromLine(stream, size, &_destY[l]); + getIntFromLine(stream, size, &trackCharacter_alkeva[l]); + getIntFromLine(stream, size, &roomExits[l]); updateDoor(l); } } - getIntFromLine(_arj, size, &floorX1); - getIntFromLine(_arj, size, &floorY1); - getIntFromLine(_arj, size, &floorX2); - getIntFromLine(_arj, size, &floorY2); + getIntFromLine(stream, size, &floorX1); + getIntFromLine(stream, size, &floorY1); + getIntFromLine(stream, size, &floorX2); + getIntFromLine(stream, size, &floorY2); if (currentChapter != 2) { - getIntFromLine(_arj, size, &upperLimit); - getIntFromLine(_arj, size, &lowerLimit); + getIntFromLine(stream, size, &upperLimit); + getIntFromLine(stream, size, &lowerLimit); } - _arj.close(); + delete stream; if (currentChapter == 2 && martin != 0) { loadPic(pant2, extraSurface); diff --git a/engines/drascula/sound.cpp b/engines/drascula/sound.cpp index 17d7b88d4c..d8cd838b21 100644 --- a/engines/drascula/sound.cpp +++ b/engines/drascula/sound.cpp @@ -163,23 +163,24 @@ void DrasculaEngine::MusicFadeout() { } void DrasculaEngine::playFile(const char *fname) { - if (_arj.open(fname)) { - int soundSize = _arj.size(); + Common::SeekableReadStream *stream = _arj.open(fname); + if (stream) { + int soundSize = stream->size(); byte *soundData = (byte *)malloc(soundSize); if (!(!strcmp(fname, "3.als") && soundSize == 145166 && _lang != kSpanish)) { - _arj.seek(32); + stream->seek(32); } else { // WORKAROUND: File 3.als with English speech files has a big silence at // its beginning and end. We seek past the silence at the beginning, // and ignore the silence at the end // Fixes bug #2111815 - "DRASCULA: Voice delayed" - _arj.seek(73959, SEEK_SET); + stream->seek(73959, SEEK_SET); soundSize = 117158 - 73959; } - _arj.read(soundData, soundSize); - _arj.close(); + stream->read(soundData, soundSize); + delete stream; _subtitlesDisabled = !ConfMan.getBool("subtitles"); if (ConfMan.getBool("speech_mute")) |