From f8ccd2dedeeb8fa240cb91afc383441612ddd542 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sat, 13 Sep 2008 22:41:30 +0000 Subject: SCUMM: Got rid of class Chunk svn-id: r34518 --- engines/scumm/smush/smush_player.cpp | 148 +++++++++++++++++------------------ 1 file changed, 72 insertions(+), 76 deletions(-) (limited to 'engines/scumm/smush/smush_player.cpp') diff --git a/engines/scumm/smush/smush_player.cpp b/engines/scumm/smush/smush_player.cpp index 70359cfcb3..fcc0541d2c 100644 --- a/engines/scumm/smush/smush_player.cpp +++ b/engines/scumm/smush/smush_player.cpp @@ -23,8 +23,6 @@ * */ - - #include "engines/engine.h" #include "common/config-manager.h" @@ -42,7 +40,6 @@ #include "scumm/sound.h" #include "scumm/util.h" #include "scumm/smush/channel.h" -#include "scumm/smush/chunk.h" #include "scumm/smush/codec37.h" #include "scumm/smush/codec47.h" #include "scumm/smush/smush_font.h" @@ -315,16 +312,7 @@ void SmushPlayer::release() { _codec47 = 0; } -void SmushPlayer::checkBlock(const Chunk &b, Chunk::type type_expected, int32 min_size) { - if (type_expected != b.getType()) { - error("Chunk type is different from expected : %x != %x", b.getType(), type_expected); - } - if (min_size > b.size()) { - error("Chunk size is inferior than minimum required size : %d < %d", b.size(), min_size); - } -} - -void SmushPlayer::handleSoundBuffer(int32 track_id, int32 index, int32 max_frames, int32 flags, int32 vol, int32 pan, Chunk &b, int32 size) { +void SmushPlayer::handleSoundBuffer(int32 track_id, int32 index, int32 max_frames, int32 flags, int32 vol, int32 pan, Common::SeekableReadStream &b, int32 size) { debugC(DEBUG_SMUSH, "SmushPlayer::handleSoundBuffer(%d, %d)", track_id, index); // if ((flags & 128) == 128) { // return; @@ -347,8 +335,7 @@ void SmushPlayer::handleSoundBuffer(int32 track_id, int32 index, int32 max_frame c->appendData(b, size); } -void SmushPlayer::handleSoundFrame(Chunk &b) { - checkBlock(b, MKID_BE('PSAD')); +void SmushPlayer::handleSoundFrame(int32 subSize, Common::SeekableReadStream &b) { debugC(DEBUG_SMUSH, "SmushPlayer::handleSoundFrame()"); int32 track_id = b.readUint16LE(); @@ -360,28 +347,28 @@ void SmushPlayer::handleSoundFrame(Chunk &b) { if (index == 0) { debugC(DEBUG_SMUSH, "track_id:%d, max_frames:%d, flags:%d, vol:%d, pan:%d", track_id, max_frames, flags, vol, pan); } - int32 size = b.size() - 10; + int32 size = subSize - 10; handleSoundBuffer(track_id, index, max_frames, flags, vol, pan, b, size); } -void SmushPlayer::handleStore(Chunk &b) { +void SmushPlayer::handleStore(int32 subSize, Common::SeekableReadStream &b) { debugC(DEBUG_SMUSH, "SmushPlayer::handleStore()"); - checkBlock(b, MKID_BE('STOR'), 4); + assert(subSize >= 4); _storeFrame = true; } -void SmushPlayer::handleFetch(Chunk &b) { +void SmushPlayer::handleFetch(int32 subSize, Common::SeekableReadStream &b) { debugC(DEBUG_SMUSH, "SmushPlayer::handleFetch()"); - checkBlock(b, MKID_BE('FTCH'), 6); + assert(subSize >= 6); if (_frameBuffer != NULL) { memcpy(_dst, _frameBuffer, _width * _height); } } -void SmushPlayer::handleIACT(Chunk &b) { - checkBlock(b, MKID_BE('IACT'), 8); +void SmushPlayer::handleIACT(int32 subSize, Common::SeekableReadStream &b) { debugC(DEBUG_SMUSH, "SmushPlayer::IACT()"); + assert(subSize >= 8); int code = b.readUint16LE(); int flags = b.readUint16LE(); @@ -402,7 +389,7 @@ void SmushPlayer::handleIACT(Chunk &b) { int index = b.readUint16LE(); int nbframes = b.readUint16LE(); int32 size = b.readUint32LE(); - int32 bsize = b.size() - 18; + int32 bsize = subSize - 18; if (_vm->_game.id != GID_CMI) { int32 track = track_id; @@ -506,7 +493,7 @@ void SmushPlayer::handleIACT(Chunk &b) { } } -void SmushPlayer::handleTextResource(Chunk &b) { +void SmushPlayer::handleTextResource(uint32 subType, int32 subSize, Common::SeekableReadStream &b) { int pos_x = b.readSint16LE(); int pos_y = b.readSint16LE(); int flags = b.readSint16LE(); @@ -518,10 +505,10 @@ void SmushPlayer::handleTextResource(Chunk &b) { const char *str; char *string = NULL, *string2 = NULL; - if (b.getType() == MKID_BE('TEXT')) { - string = (char *)malloc(b.size() - 16); + if (subType == MKID_BE('TEXT')) { + string = (char *)malloc(subSize - 16); str = string; - b.read(string, b.size() - 16); + b.read(string, subSize - 16); } else { int string_id = b.readUint16LE(); if (!_strings) @@ -689,7 +676,7 @@ bool SmushPlayer::readString(const char *file) { return false; } -void SmushPlayer::readPalette(byte *out, Chunk &in) { +void SmushPlayer::readPalette(byte *out, Common::SeekableReadStream &in) { in.read(out, 0x300); } @@ -698,11 +685,10 @@ static byte delta_color(byte org_color, int16 delta_color) { return CLIP(t, 0, 255); } -void SmushPlayer::handleDeltaPalette(Chunk &b) { - checkBlock(b, MKID_BE('XPAL')); +void SmushPlayer::handleDeltaPalette(int32 subSize, Common::SeekableReadStream &b) { debugC(DEBUG_SMUSH, "SmushPlayer::handleDeltaPalette()"); - if (b.size() == 0x300 * 3 + 4) { + if (subSize == 0x300 * 3 + 4) { b.readUint16LE(); b.readUint16LE(); @@ -712,7 +698,7 @@ void SmushPlayer::handleDeltaPalette(Chunk &b) { } readPalette(_pal, b); setDirtyColors(0, 255); - } else if (b.size() == 6) { + } else if (subSize == 6) { b.readUint16LE(); b.readUint16LE(); @@ -727,9 +713,9 @@ void SmushPlayer::handleDeltaPalette(Chunk &b) { } } -void SmushPlayer::handleNewPalette(Chunk &b) { - checkBlock(b, MKID_BE('NPAL'), 0x300); +void SmushPlayer::handleNewPalette(int32 subSize, Common::SeekableReadStream &b) { debugC(DEBUG_SMUSH, "SmushPlayer::handleNewPalette()"); + assert(subSize >= 0x300); if (_skipPalette) return; @@ -792,13 +778,13 @@ void SmushPlayer::decodeFrameObject(int codec, const uint8 *src, int left, int t } #ifdef USE_ZLIB -void SmushPlayer::handleZlibFrameObject(Chunk &b) { +void SmushPlayer::handleZlibFrameObject(int32 subSize, Common::SeekableReadStream &b) { if (_skipNext) { _skipNext = false; return; } - int32 chunkSize = b.size(); + int32 chunkSize = subSize; byte *chunkBuffer = (byte *)malloc(chunkSize); assert(chunkBuffer); b.read(chunkBuffer, chunkSize); @@ -823,8 +809,8 @@ void SmushPlayer::handleZlibFrameObject(Chunk &b) { } #endif -void SmushPlayer::handleFrameObject(Chunk &b) { - checkBlock(b, MKID_BE('FOBJ'), 14); +void SmushPlayer::handleFrameObject(int32 subSize, Common::SeekableReadStream &b) { + assert(subSize >= 14); if (_skipNext) { _skipNext = false; return; @@ -839,7 +825,7 @@ void SmushPlayer::handleFrameObject(Chunk &b) { b.readUint16LE(); b.readUint16LE(); - int32 chunk_size = b.size() - 14; + int32 chunk_size = subSize - 14; byte *chunk_buffer = (byte *)malloc(chunk_size); assert(chunk_buffer); b.read(chunk_buffer, chunk_size); @@ -849,8 +835,7 @@ void SmushPlayer::handleFrameObject(Chunk &b) { free(chunk_buffer); } -void SmushPlayer::handleFrame(Chunk &b) { - checkBlock(b, MKID_BE('FRME')); +void SmushPlayer::handleFrame(int32 frameSize, Common::SeekableReadStream &b) { debugC(DEBUG_SMUSH, "SmushPlayer::handleFrame(%d)", _frame); _skipNext = false; @@ -858,54 +843,57 @@ void SmushPlayer::handleFrame(Chunk &b) { _vm->_insane->procPreRendering(); } - while (!b.eos()) { - Chunk *sub = b.subBlock(); - switch (sub->getType()) { + while (frameSize > 0) { + const uint32 subType = b.readUint32BE(); + const int32 subSize = b.readUint32BE(); + const int32 subOffset = b.pos(); + switch (subType) { case MKID_BE('NPAL'): - handleNewPalette(*sub); + handleNewPalette(subSize, b); break; case MKID_BE('FOBJ'): - handleFrameObject(*sub); + handleFrameObject(subSize, b); break; #ifdef USE_ZLIB case MKID_BE('ZFOB'): - handleZlibFrameObject(*sub); + handleZlibFrameObject(subSize, b); break; #endif case MKID_BE('PSAD'): if (!_compressedFileMode) - handleSoundFrame(*sub); + handleSoundFrame(subSize, b); break; case MKID_BE('TRES'): - handleTextResource(*sub); + handleTextResource(subType, subSize, b); break; case MKID_BE('XPAL'): - handleDeltaPalette(*sub); + handleDeltaPalette(subSize, b); break; case MKID_BE('IACT'): - handleIACT(*sub); + handleIACT(subSize, b); break; case MKID_BE('STOR'): - handleStore(*sub); + handleStore(subSize, b); break; case MKID_BE('FTCH'): - handleFetch(*sub); + handleFetch(subSize, b); break; case MKID_BE('SKIP'): - _vm->_insane->procSKIP(*sub); + _vm->_insane->procSKIP(subSize, b); break; case MKID_BE('TEXT'): - handleTextResource(*sub); + handleTextResource(subType, subSize, b); break; default: - error("Unknown frame subChunk found : %s, %d", tag2str(sub->getType()), sub->size()); + error("Unknown frame subChunk found : %s, %d", tag2str(subType), subSize); } - b.reseek(); - if (sub->size() & 1) + frameSize -= subSize + 8; + b.seek(subOffset + subSize, SEEK_SET); + if (subSize & 1) { b.skip(1); - - delete sub; + frameSize--; + } } if (_insanity) { @@ -920,9 +908,9 @@ void SmushPlayer::handleFrame(Chunk &b) { _frame++; } -void SmushPlayer::handleAnimHeader(Chunk &b) { - checkBlock(b, MKID_BE('AHDR'), 0x300 + 6); +void SmushPlayer::handleAnimHeader(int32 subSize, Common::SeekableReadStream &b) { debugC(DEBUG_SMUSH, "SmushPlayer::handleAnimHeader()"); + assert(subSize >= 0x300 + 6); /* _version = */ b.readUint16LE(); _nbframes = b.readUint16LE(); @@ -984,7 +972,6 @@ SmushFont *SmushPlayer::getFont(int font) { } void SmushPlayer::parseNextFrame() { - Chunk *sub; if (_seekPos >= 0) { if (_smixer) @@ -992,15 +979,23 @@ void SmushPlayer::parseNextFrame() { if (_seekFile.size() > 0) { delete _base; - _base = new Chunk(_seekFile); + + ScummFile *tmp = new ScummFile(); + if (!g_scumm->openFile(*tmp, _seekFile)) + error("SmushPlayer: Unable to open file %s", _seekFile.c_str()); + _base = tmp; + _base->readUint32BE(); + _base->readUint32BE(); if (_seekPos > 0) { assert(_seekPos > 8); // In this case we need to get palette and number of frames - sub = _base->subBlock(); - checkBlock(*sub, MKID_BE('AHDR')); - handleAnimHeader(*sub); - delete sub; + const uint32 subType = _base->readUint32BE(); + const int32 subSize = _base->readUint32BE(); + const int32 subOffset = _base->pos(); + assert(subType == MKID_BE('AHDR')); + handleAnimHeader(subSize, *_base); + _base->seek(subOffset + subSize, SEEK_SET); _middleAudio = true; _seekPos -= 8; @@ -1014,7 +1009,7 @@ void SmushPlayer::parseNextFrame() { _skipPalette = true; } - _base->seek(_seekPos, SEEK_SET); + _base->seek(_seekPos + 8, SEEK_SET); _frame = _seekFrame; _startFrame = _frame; _startTime = _vm->_system->getMillis(); @@ -1029,21 +1024,22 @@ void SmushPlayer::parseNextFrame() { return; } - sub = _base->subBlock(); + const uint32 subType = _base->readUint32BE(); + const int32 subSize = _base->readUint32BE(); + const int32 subOffset = _base->pos(); - switch (sub->getType()) { + switch (subType) { case MKID_BE('AHDR'): // FT INSANE may seek file to the beginning - handleAnimHeader(*sub); + handleAnimHeader(subSize, *_base); break; case MKID_BE('FRME'): - handleFrame(*sub); + handleFrame(subSize, *_base); break; default: - error("Unknown Chunk found at %x: %x, %d", _base->pos(), sub->getType(), sub->size()); + error("Unknown Chunk found at %x: %x, %d", subOffset, subType, subSize); } - delete sub; - _base->reseek(); + _base->seek(subOffset + subSize, SEEK_SET); if (_insanity) _vm->_sound->processSound(); -- cgit v1.2.3