From b8d081afe6bbbaabb07c37bc5f364f123260646f Mon Sep 17 00:00:00 2001 From: Alyssa Milburn Date: Mon, 18 Jul 2011 21:52:55 +0200 Subject: COMPOSER: Move Pipe code into resource.cpp. --- engines/composer/composer.cpp | 87 ------------------------------------------- engines/composer/composer.h | 30 +-------------- engines/composer/resource.cpp | 87 +++++++++++++++++++++++++++++++++++++++++++ engines/composer/resource.h | 31 +++++++++++++++ 4 files changed, 119 insertions(+), 116 deletions(-) (limited to 'engines') diff --git a/engines/composer/composer.cpp b/engines/composer/composer.cpp index 656030f1f1..484f3cecae 100644 --- a/engines/composer/composer.cpp +++ b/engines/composer/composer.cpp @@ -31,7 +31,6 @@ #include "common/fs.h" #include "common/keyboard.h" #include "common/substream.h" -#include "common/memstream.h" #include "common/savefile.h" #include "graphics/cursorman.h" @@ -124,92 +123,6 @@ enum { kFuncGetSpriteSize = 35029 }; -Pipe::Pipe(Common::SeekableReadStream *stream) { - _offset = 0; - _stream = stream; - - nextFrame(); -} - -void Pipe::nextFrame() { - if (_offset == (uint)_stream->size()) - return; - - _stream->seek(_offset, SEEK_SET); - - uint32 tagCount = _stream->readUint32LE(); - _offset += 4; - for (uint i = 0; i < tagCount; i++) { - uint32 tag = _stream->readUint32BE(); - uint32 count = _stream->readUint32LE(); - _offset += 8; - - ResourceMap &resMap = _types[tag]; - - _offset += (12 * count); - //uint32 baseOffset = _offset; - for (uint j = 0; j < count; j++) { - uint32 offset = _stream->readUint32LE(); - uint32 size = _stream->readUint32LE(); - uint16 id = _stream->readUint16LE(); - uint32 unknown = _stream->readUint16LE(); // frame id? - debug(9, "pipe: %s/%d: offset %d, size %d, unknown %d", tag2str(tag), id, offset, size, unknown); - - PipeResourceEntry entry; - entry.size = size; - entry.offset = _offset; - resMap[id].entries.push_back(entry); - - _offset += size; - } - _stream->seek(_offset, SEEK_SET); - } -} - -bool Pipe::hasResource(uint32 tag, uint16 id) const { - if (!_types.contains(tag)) - return false; - - return _types[tag].contains(id); -} - -Common::SeekableReadStream *Pipe::getResource(uint32 tag, uint16 id, bool buffering) { - if (!_types.contains(tag)) - error("Pipe does not contain '%s' %04x", tag2str(tag), id); - - const ResourceMap &resMap = _types[tag]; - - if (!resMap.contains(id)) - error("Archive does not contain '%s' %04x", tag2str(tag), id); - - const PipeResource &res = resMap[id]; - - if (res.entries.size() == 1) { - Common::SeekableReadStream *stream = new Common::SeekableSubReadStream(_stream, - res.entries[0].offset, res.entries[0].offset + res.entries[0].size); - if (buffering) - _types[tag].erase(id); - return stream; - } - - // If there are multiple entries in the pipe, we have to concaternate them together. - - uint32 size = 0; - for (uint i = 0; i < res.entries.size(); i++) - size += res.entries[i].size; - - byte *buffer = (byte *)malloc(size); - uint32 offset = 0; - for (uint i = 0; i < res.entries.size(); i++) { - _stream->seek(res.entries[i].offset, SEEK_SET); - _stream->read(buffer + offset, res.entries[i].size); - offset += res.entries[i].size; - } - if (buffering) - _types[tag].erase(id); - return new Common::MemoryReadStream(buffer, size, DisposeAfterUse::YES); -} - Button::Button(Common::SeekableReadStream *stream, uint16 id) { _id = id; diff --git a/engines/composer/composer.h b/engines/composer/composer.h index 012bef160f..95f262f1ec 100644 --- a/engines/composer/composer.h +++ b/engines/composer/composer.h @@ -59,37 +59,9 @@ enum GameType { class Archive; struct Animation; class ComposerEngine; +class Pipe; struct Sprite; -struct PipeResourceEntry { - uint32 size; - uint32 offset; -}; - -struct PipeResource { - Common::Array entries; -}; - -class Pipe { -public: - Pipe(Common::SeekableReadStream *stream); - void nextFrame(); - - Animation *_anim; - - bool hasResource(uint32 tag, uint16 id) const; - Common::SeekableReadStream *getResource(uint32 tag, uint16 id, bool buffering); - -protected: - Common::SeekableReadStream *_stream; - - typedef Common::HashMap ResourceMap; - typedef Common::HashMap TypeMap; - TypeMap _types; - - uint32 _offset; -}; - enum { kButtonRect = 0, kButtonEllipse = 1, diff --git a/engines/composer/resource.cpp b/engines/composer/resource.cpp index 390649ba52..cd77fa16fc 100644 --- a/engines/composer/resource.cpp +++ b/engines/composer/resource.cpp @@ -23,6 +23,7 @@ #include "composer/resource.h" #include "common/debug.h" +#include "common/memstream.h" #include "common/substream.h" #include "common/util.h" #include "common/textconsole.h" @@ -247,4 +248,90 @@ bool ComposerArchive::openStream(Common::SeekableReadStream *stream) { return true; } +Pipe::Pipe(Common::SeekableReadStream *stream) { + _offset = 0; + _stream = stream; + + nextFrame(); +} + +void Pipe::nextFrame() { + if (_offset == (uint)_stream->size()) + return; + + _stream->seek(_offset, SEEK_SET); + + uint32 tagCount = _stream->readUint32LE(); + _offset += 4; + for (uint i = 0; i < tagCount; i++) { + uint32 tag = _stream->readUint32BE(); + uint32 count = _stream->readUint32LE(); + _offset += 8; + + ResourceMap &resMap = _types[tag]; + + _offset += (12 * count); + //uint32 baseOffset = _offset; + for (uint j = 0; j < count; j++) { + uint32 offset = _stream->readUint32LE(); + uint32 size = _stream->readUint32LE(); + uint16 id = _stream->readUint16LE(); + uint32 unknown = _stream->readUint16LE(); // frame id? + debug(9, "pipe: %s/%d: offset %d, size %d, unknown %d", tag2str(tag), id, offset, size, unknown); + + PipeResourceEntry entry; + entry.size = size; + entry.offset = _offset; + resMap[id].entries.push_back(entry); + + _offset += size; + } + _stream->seek(_offset, SEEK_SET); + } +} + +bool Pipe::hasResource(uint32 tag, uint16 id) const { + if (!_types.contains(tag)) + return false; + + return _types[tag].contains(id); +} + +Common::SeekableReadStream *Pipe::getResource(uint32 tag, uint16 id, bool buffering) { + if (!_types.contains(tag)) + error("Pipe does not contain '%s' %04x", tag2str(tag), id); + + const ResourceMap &resMap = _types[tag]; + + if (!resMap.contains(id)) + error("Archive does not contain '%s' %04x", tag2str(tag), id); + + const PipeResource &res = resMap[id]; + + if (res.entries.size() == 1) { + Common::SeekableReadStream *stream = new Common::SeekableSubReadStream(_stream, + res.entries[0].offset, res.entries[0].offset + res.entries[0].size); + if (buffering) + _types[tag].erase(id); + return stream; + } + + // If there are multiple entries in the pipe, we have to concaternate them together. + + uint32 size = 0; + for (uint i = 0; i < res.entries.size(); i++) + size += res.entries[i].size; + + byte *buffer = (byte *)malloc(size); + uint32 offset = 0; + for (uint i = 0; i < res.entries.size(); i++) { + _stream->seek(res.entries[i].offset, SEEK_SET); + _stream->read(buffer + offset, res.entries[i].size); + offset += res.entries[i].size; + } + if (buffering) + _types[tag].erase(id); + return new Common::MemoryReadStream(buffer, size, DisposeAfterUse::YES); +} + } // End of namespace Composer diff --git a/engines/composer/resource.h b/engines/composer/resource.h index 4cadd80e22..4248ad949a 100644 --- a/engines/composer/resource.h +++ b/engines/composer/resource.h @@ -31,6 +31,8 @@ namespace Composer { +class Animation; + #define ID_LBRC MKTAG('L','B','R','C') // Main FourCC #define ID_ANIM MKTAG('A','N','I','M') // Animation @@ -88,6 +90,35 @@ public: bool openStream(Common::SeekableReadStream *stream); }; +struct PipeResourceEntry { + uint32 size; + uint32 offset; +}; + +struct PipeResource { + Common::Array entries; +}; + +class Pipe { +public: + Pipe(Common::SeekableReadStream *stream); + void nextFrame(); + + Animation *_anim; + + bool hasResource(uint32 tag, uint16 id) const; + Common::SeekableReadStream *getResource(uint32 tag, uint16 id, bool buffering); + +protected: + Common::SeekableReadStream *_stream; + + typedef Common::HashMap ResourceMap; + typedef Common::HashMap TypeMap; + TypeMap _types; + + uint32 _offset; +}; + } // End of namespace Composer #endif -- cgit v1.2.3