diff options
author | Max Horn | 2010-11-19 17:03:07 +0000 |
---|---|---|
committer | Max Horn | 2010-11-19 17:03:07 +0000 |
commit | 2180b2d6b534d3786f89d02fe508c60c68b7ff89 (patch) | |
tree | ac7af0e5f5049537f4c81c401d5685bebbb47068 | |
parent | 111384473bb65741f7f2b945e1c00e6aeccc805c (diff) | |
download | scummvm-rg350-2180b2d6b534d3786f89d02fe508c60c68b7ff89.tar.gz scummvm-rg350-2180b2d6b534d3786f89d02fe508c60c68b7ff89.tar.bz2 scummvm-rg350-2180b2d6b534d3786f89d02fe508c60c68b7ff89.zip |
COMMON: Split common/stream.h into several headers
svn-id: r54385
140 files changed, 1000 insertions, 720 deletions
diff --git a/backends/fs/ds/ds-fs.cpp b/backends/fs/ds/ds-fs.cpp index 272f34fd33..2308824d57 100644 --- a/backends/fs/ds/ds-fs.cpp +++ b/backends/fs/ds/ds-fs.cpp @@ -33,6 +33,7 @@ #include "backends/fs/stdiostream.h" #include "dsmain.h" #include "fat/gba_nds_fat.h" +#include "common/bufferedstream.h" namespace DS { diff --git a/backends/fs/psp/psp-fs.cpp b/backends/fs/psp/psp-fs.cpp index aecf96363c..16a0e9cd5b 100644 --- a/backends/fs/psp/psp-fs.cpp +++ b/backends/fs/psp/psp-fs.cpp @@ -27,6 +27,7 @@ #include "engines/engine.h" #include "backends/fs/abstract-fs.h" #include "backends/fs/psp/psp-stream.h" +#include "common/bufferedstream.h" #include <sys/stat.h> #include <unistd.h> diff --git a/backends/platform/dc/dcmain.cpp b/backends/platform/dc/dcmain.cpp index 5fde919650..269f400cf5 100644 --- a/backends/platform/dc/dcmain.cpp +++ b/backends/platform/dc/dcmain.cpp @@ -31,7 +31,7 @@ #include "icon.h" #include "DCLauncherDialog.h" #include <common/config-manager.h> -#include <common/stream.h> +#include <common/memstream.h> #include "backends/plugins/dc/dc-provider.h" #include "sound/mixer_intern.h" diff --git a/backends/platform/ds/arm9/source/gbampsave.cpp b/backends/platform/ds/arm9/source/gbampsave.cpp index ab7f3cff91..462138d335 100644 --- a/backends/platform/ds/arm9/source/gbampsave.cpp +++ b/backends/platform/ds/arm9/source/gbampsave.cpp @@ -30,7 +30,7 @@ #include "fat/gba_nds_fat.h" #include "backends/fs/ds/ds-fs.h" #include "common/config-manager.h" - +#include "common/bufferedstream.h" #define SAVE_BUFFER_SIZE 100000 diff --git a/common/bufferedstream.h b/common/bufferedstream.h new file mode 100644 index 0000000000..dc074422bb --- /dev/null +++ b/common/bufferedstream.h @@ -0,0 +1,68 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +#ifndef COMMON_BUFFEREDSTREAM_H +#define COMMON_BUFFEREDSTREAM_H + +#include "common/stream.h" + +namespace Common { + +/** + * Take an arbitrary ReadStream and wrap it in a custom stream which + * transparently provides buffering. + * Users can specify how big the buffer should be, and whether the wrapped + * stream should be disposed when the wrapper is disposed. + * + * It is safe to call this with a NULL parameter (in this case, NULL is + * returned). + */ +ReadStream *wrapBufferedReadStream(ReadStream *parentStream, uint32 bufSize, DisposeAfterUse::Flag disposeParentStream); + +/** + * Take an arbitrary SeekableReadStream and wrap it in a custom stream which + * transparently provides buffering. + * Users can specify how big the buffer should be, and whether the wrapped + * stream should be disposed when the wrapper is disposed. + * + * It is safe to call this with a NULL parameter (in this case, NULL is + * returned). + */ +SeekableReadStream *wrapBufferedSeekableReadStream(SeekableReadStream *parentStream, uint32 bufSize, DisposeAfterUse::Flag disposeParentStream); + +/** + * Take an arbitrary WriteStream and wrap it in a custom stream which + * transparently provides buffering. + * Users can specify how big the buffer should be. Currently, the + * parent stream is \em always disposed when the wrapper is disposed. + * + * It is safe to call this with a NULL parameter (in this case, NULL is + * returned). + */ +WriteStream *wrapBufferedWriteStream(WriteStream *parentStream, uint32 bufSize); + +} // End of namespace Common + +#endif diff --git a/common/iff_container.cpp b/common/iff_container.cpp new file mode 100644 index 0000000000..c447d93f12 --- /dev/null +++ b/common/iff_container.cpp @@ -0,0 +1,81 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +#include "common/iff_container.h" +#include "common/substream.h" + +namespace Common { + +IFFParser::IFFParser(Common::ReadStream *stream, bool disposeStream) : _stream(stream), _disposeStream(disposeStream) { + setInputStream(stream); +} + +IFFParser::~IFFParser() { + if (_disposeStream) { + delete _stream; + } + _stream = 0; +} + +void IFFParser::setInputStream(Common::ReadStream *stream) { + assert(stream); + _formChunk.setInputStream(stream); + _chunk.setInputStream(stream); + + _formChunk.readHeader(); + if (_formChunk.id != ID_FORM) { + error("IFFParser input is not a FORM type IFF file"); + } + _formSize = _formChunk.size; + _formType = _formChunk.readUint32BE(); +} + +void IFFParser::parse(IFFCallback &callback) { + bool stop; + do { + _chunk.feed(); + _formChunk.incBytesRead(_chunk.size); + + if (_formChunk.hasReadAll()) { + break; + } + + _formChunk.incBytesRead(8); + _chunk.readHeader(); + + // invoke the callback + Common::SubReadStream stream(&_chunk, _chunk.size); + IFFChunk chunk(_chunk.id, _chunk.size, &stream); + stop = callback(chunk); + + // eats up all the remaining data in the chunk + while (!stream.eos()) { + stream.readByte(); + } + + } while (!stop); +} + +} // End of namespace Common diff --git a/common/iff_container.h b/common/iff_container.h index 6ff28574e5..16d4826238 100644 --- a/common/iff_container.h +++ b/common/iff_container.h @@ -223,41 +223,11 @@ protected: Common::ReadStream *_stream; bool _disposeStream; - void setInputStream(Common::ReadStream *stream) { - assert(stream); - _formChunk.setInputStream(stream); - _chunk.setInputStream(stream); - - _formChunk.readHeader(); - if (_formChunk.id != ID_FORM) { - error("IFFParser input is not a FORM type IFF file"); - } - _formSize = _formChunk.size; - _formType = _formChunk.readUint32BE(); - } + void setInputStream(Common::ReadStream *stream); public: - IFFParser(Common::ReadStream *stream, bool disposeStream = false) : _stream(stream), _disposeStream(disposeStream) { - setInputStream(stream); - } - ~IFFParser() { - if (_disposeStream) { - delete _stream; - } - _stream = 0; - } - - /** - * Returns the IFF FORM type. - * @return the IFF FORM type of the stream, or 0 if FORM header is not found. - */ - Common::IFF_ID getFORMType() const; - - /** - * Returns the size of the data. - * @return the size of the data in file, or -1 if FORM header is not found. - */ - uint32 getFORMSize() const; + IFFParser(Common::ReadStream *stream, bool disposeStream = false); + ~IFFParser(); /** * Callback type for the parser. @@ -268,31 +238,7 @@ public: * Parse the IFF container, invoking the callback on each chunk encountered. * The callback can interrupt the parsing by returning 'true'. */ - void parse(IFFCallback &callback) { - bool stop; - do { - _chunk.feed(); - _formChunk.incBytesRead(_chunk.size); - - if (_formChunk.hasReadAll()) { - break; - } - - _formChunk.incBytesRead(8); - _chunk.readHeader(); - - // invoke the callback - Common::SubReadStream stream(&_chunk, _chunk.size); - IFFChunk chunk(_chunk.id, _chunk.size, &stream); - stop = callback(chunk); - - // eats up all the remaining data in the chunk - while (!stream.eos()) { - stream.readByte(); - } - - } while (!stop); - } + void parse(IFFCallback &callback); }; diff --git a/common/macresman.cpp b/common/macresman.cpp index 22216763b8..f9a49cfe04 100644 --- a/common/macresman.cpp +++ b/common/macresman.cpp @@ -30,6 +30,8 @@ #include "common/fs.h" #include "common/macresman.h" #include "common/md5.h" +#include "common/substream.h" +#include "common/memstream.h" #ifdef MACOSX #include "common/config-manager.h" diff --git a/common/memstream.h b/common/memstream.h new file mode 100644 index 0000000000..0cb88b6126 --- /dev/null +++ b/common/memstream.h @@ -0,0 +1,199 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +#ifndef COMMON_MEMSTREAM_H +#define COMMON_MEMSTREAM_H + +#include "common/stream.h" + +namespace Common { + +/** + * Simple memory based 'stream', which implements the ReadStream interface for + * a plain memory block. + */ +class MemoryReadStream : public SeekableReadStream { +private: + const byte * const _ptrOrig; + const byte *_ptr; + const uint32 _size; + uint32 _pos; + byte _encbyte; + DisposeAfterUse::Flag _disposeMemory; + bool _eos; + +public: + + /** + * This constructor takes a pointer to a memory buffer and a length, and + * wraps it. If disposeMemory is true, the MemoryReadStream takes ownership + * of the buffer and hence free's it when destructed. + */ + MemoryReadStream(const byte *dataPtr, uint32 dataSize, DisposeAfterUse::Flag disposeMemory = DisposeAfterUse::NO) : + _ptrOrig(dataPtr), + _ptr(dataPtr), + _size(dataSize), + _pos(0), + _encbyte(0), + _disposeMemory(disposeMemory), + _eos(false) {} + + ~MemoryReadStream() { + if (_disposeMemory) + free(const_cast<byte *>(_ptrOrig)); + } + + void setEnc(byte value) { _encbyte = value; } + + uint32 read(void *dataPtr, uint32 dataSize); + + bool eos() const { return _eos; } + void clearErr() { _eos = false; } + + int32 pos() const { return _pos; } + int32 size() const { return _size; } + + bool seek(int32 offs, int whence = SEEK_SET); +}; + + +/** + * This is a wrapper around MemoryReadStream, but it adds non-endian + * read methods whose endianness is set on the stream creation. + */ +class MemoryReadStreamEndian : public MemoryReadStream { +private: + const bool _bigEndian; + +public: + MemoryReadStreamEndian(const byte *buf, uint32 len, bool bigEndian = false) : MemoryReadStream(buf, len), _bigEndian(bigEndian) {} + + uint16 readUint16() { + uint16 val; + read(&val, 2); + return (_bigEndian) ? TO_BE_16(val) : TO_LE_16(val); + } + + uint32 readUint32() { + uint32 val; + read(&val, 4); + return (_bigEndian) ? TO_BE_32(val) : TO_LE_32(val); + } + + FORCEINLINE int16 readSint16() { + return (int16)readUint16(); + } + + FORCEINLINE int32 readSint32() { + return (int32)readUint32(); + } +}; + +/** + * Simple memory based 'stream', which implements the WriteStream interface for + * a plain memory block. + */ +class MemoryWriteStream : public WriteStream { +private: + byte *_ptr; + const uint32 _bufSize; + uint32 _pos; +public: + MemoryWriteStream(byte *buf, uint32 len) : _ptr(buf), _bufSize(len), _pos(0) {} + + uint32 write(const void *dataPtr, uint32 dataSize) { + // Write at most as many bytes as are still available... + if (dataSize > _bufSize - _pos) + dataSize = _bufSize - _pos; + memcpy(_ptr, dataPtr, dataSize); + _ptr += dataSize; + _pos += dataSize; + return dataSize; + } + + uint32 pos() const { return _pos; } + uint32 size() const { return _bufSize; } +}; + +/** + * A sort of hybrid between MemoryWriteStream and Array classes. A stream + * that grows as it's written to. + */ +class MemoryWriteStreamDynamic : public WriteStream { +private: + uint32 _capacity; + uint32 _size; + byte *_ptr; + byte *_data; + uint32 _pos; + DisposeAfterUse::Flag _disposeMemory; + + void ensureCapacity(uint32 new_len) { + if (new_len <= _capacity) + return; + + byte *old_data = _data; + + _capacity = new_len + 32; + _data = (byte *)malloc(_capacity); + _ptr = _data + _pos; + + if (old_data) { + // Copy old data + memcpy(_data, old_data, _size); + free(old_data); + } + + _size = new_len; + } +public: + MemoryWriteStreamDynamic(DisposeAfterUse::Flag disposeMemory = DisposeAfterUse::NO) : _capacity(0), _size(0), _ptr(0), _data(0), _pos(0), _disposeMemory(disposeMemory) {} + + ~MemoryWriteStreamDynamic() { + if (_disposeMemory) + free(_data); + } + + uint32 write(const void *dataPtr, uint32 dataSize) { + ensureCapacity(_pos + dataSize); + memcpy(_ptr, dataPtr, dataSize); + _ptr += dataSize; + _pos += dataSize; + if (_pos > _size) + _size = _pos; + return dataSize; + } + + uint32 pos() const { return _pos; } + uint32 size() const { return _size; } + + byte *getData() { return _data; } + + bool seek(int32 offset, int whence = SEEK_SET); +}; + +} // End of namespace Common + +#endif diff --git a/common/module.mk b/common/module.mk index 239f8e9ccf..1bff1b6c29 100644 --- a/common/module.mk +++ b/common/module.mk @@ -11,6 +11,7 @@ MODULE_OBJS := \ file.o \ fs.o \ hashmap.o \ + iff_container.o \ macresman.o \ memorypool.o \ md5.o \ diff --git a/common/stream.cpp b/common/stream.cpp index 2abd6fc986..89653592f4 100644 --- a/common/stream.cpp +++ b/common/stream.cpp @@ -24,6 +24,9 @@ */ #include "common/stream.h" +#include "common/memstream.h" +#include "common/substream.h" +#include "common/bufferedstream.h" #include "common/str.h" #include "common/util.h" @@ -33,7 +36,7 @@ void WriteStream::writeString(const String &str) { write(str.c_str(), str.size()); } -MemoryReadStream *ReadStream::readStream(uint32 dataSize) { +SeekableReadStream *ReadStream::readStream(uint32 dataSize) { void *buf = malloc(dataSize); dataSize = read(buf, dataSize); assert(dataSize > 0); diff --git a/common/stream.h b/common/stream.h index 9674375dd2..1dceb31f16 100644 --- a/common/stream.h +++ b/common/stream.h @@ -32,7 +32,7 @@ namespace Common { class String; -class MemoryReadStream; +class SeekableReadStream; /** * Virtual base class for both ReadStream and WriteStream. @@ -301,7 +301,7 @@ public: * the end of the stream was reached. Which can be determined by * calling err() and eos(). */ - MemoryReadStream *readStream(uint32 dataSize); + SeekableReadStream *readStream(uint32 dataSize); }; @@ -389,297 +389,6 @@ public: virtual String readLine(); }; - -/** - * SubReadStream provides access to a ReadStream restricted to the range - * [currentPosition, currentPosition+end). - * - * Manipulating the parent stream directly /will/ mess up a substream. - * Likewise, manipulating two substreams of a parent stream will cause them to - * step on each others toes. - */ -class SubReadStream : virtual public ReadStream { -protected: - ReadStream *_parentStream; - DisposeAfterUse::Flag _disposeParentStream; - uint32 _pos; - uint32 _end; - bool _eos; -public: - SubReadStream(ReadStream *parentStream, uint32 end, DisposeAfterUse::Flag disposeParentStream = DisposeAfterUse::NO) - : _parentStream(parentStream), - _disposeParentStream(disposeParentStream), - _pos(0), - _end(end), - _eos(false) { - assert(parentStream); - } - ~SubReadStream() { - if (_disposeParentStream) - delete _parentStream; - } - - virtual bool eos() const { return _eos; } - virtual bool err() const { return _parentStream->err(); } - virtual void clearErr() { _eos = false; _parentStream->clearErr(); } - virtual uint32 read(void *dataPtr, uint32 dataSize); -}; - -/* - * SeekableSubReadStream provides access to a SeekableReadStream restricted to - * the range [begin, end). - * The same caveats apply to SeekableSubReadStream as do to SeekableReadStream. - * - * Manipulating the parent stream directly /will/ mess up a substream. - * @see SubReadStream - */ -class SeekableSubReadStream : public SubReadStream, public SeekableReadStream { -protected: - SeekableReadStream *_parentStream; - uint32 _begin; -public: - SeekableSubReadStream(SeekableReadStream *parentStream, uint32 begin, uint32 end, DisposeAfterUse::Flag disposeParentStream = DisposeAfterUse::NO); - - virtual int32 pos() const { return _pos - _begin; } - virtual int32 size() const { return _end - _begin; } - - virtual bool seek(int32 offset, int whence = SEEK_SET); -}; - -/** - * This is a wrapper around SeekableSubReadStream, but it adds non-endian - * read methods whose endianness is set on the stream creation. - * - * Manipulating the parent stream directly /will/ mess up a substream. - * @see SubReadStream - */ -class SeekableSubReadStreamEndian : public SeekableSubReadStream { -private: - const bool _bigEndian; - -public: - SeekableSubReadStreamEndian(SeekableReadStream *parentStream, uint32 begin, uint32 end, bool bigEndian = false, DisposeAfterUse::Flag disposeParentStream = DisposeAfterUse::NO) - : SeekableSubReadStream(parentStream, begin, end, disposeParentStream), _bigEndian(bigEndian) { - } - - uint16 readUint16() { - uint16 val; - read(&val, 2); - return (_bigEndian) ? TO_BE_16(val) : TO_LE_16(val); - } - - uint32 readUint32() { - uint32 val; - read(&val, 4); - return (_bigEndian) ? TO_BE_32(val) : TO_LE_32(val); - } - - FORCEINLINE int16 readSint16() { - return (int16)readUint16(); - } - - FORCEINLINE int32 readSint32() { - return (int32)readUint32(); - } -}; - -/** - * Take an arbitrary ReadStream and wrap it in a custom stream which - * transparently provides buffering. - * Users can specify how big the buffer should be, and whether the wrapped - * stream should be disposed when the wrapper is disposed. - * - * It is safe to call this with a NULL parameter (in this case, NULL is - * returned). - */ -ReadStream *wrapBufferedReadStream(ReadStream *parentStream, uint32 bufSize, DisposeAfterUse::Flag disposeParentStream); - -/** - * Take an arbitrary SeekableReadStream and wrap it in a custom stream which - * transparently provides buffering. - * Users can specify how big the buffer should be, and whether the wrapped - * stream should be disposed when the wrapper is disposed. - * - * It is safe to call this with a NULL parameter (in this case, NULL is - * returned). - */ -SeekableReadStream *wrapBufferedSeekableReadStream(SeekableReadStream *parentStream, uint32 bufSize, DisposeAfterUse::Flag disposeParentStream); - -/** - * Take an arbitrary WriteStream and wrap it in a custom stream which - * transparently provides buffering. - * Users can specify how big the buffer should be. Currently, the - * parent stream is \em always disposed when the wrapper is disposed. - * - * It is safe to call this with a NULL parameter (in this case, NULL is - * returned). - */ -WriteStream *wrapBufferedWriteStream(WriteStream *parentStream, uint32 bufSize); - -/** - * Simple memory based 'stream', which implements the ReadStream interface for - * a plain memory block. - */ -class MemoryReadStream : public SeekableReadStream { -private: - const byte * const _ptrOrig; - const byte *_ptr; - const uint32 _size; - uint32 _pos; - byte _encbyte; - DisposeAfterUse::Flag _disposeMemory; - bool _eos; - -public: - - /** - * This constructor takes a pointer to a memory buffer and a length, and - * wraps it. If disposeMemory is true, the MemoryReadStream takes ownership - * of the buffer and hence free's it when destructed. - */ - MemoryReadStream(const byte *dataPtr, uint32 dataSize, DisposeAfterUse::Flag disposeMemory = DisposeAfterUse::NO) : - _ptrOrig(dataPtr), - _ptr(dataPtr), - _size(dataSize), - _pos(0), - _encbyte(0), - _disposeMemory(disposeMemory), - _eos(false) {} - - ~MemoryReadStream() { - if (_disposeMemory) - free(const_cast<byte *>(_ptrOrig)); - } - - void setEnc(byte value) { _encbyte = value; } - - uint32 read(void *dataPtr, uint32 dataSize); - - bool eos() const { return _eos; } - void clearErr() { _eos = false; } - - int32 pos() const { return _pos; } - int32 size() const { return _size; } - - bool seek(int32 offs, int whence = SEEK_SET); -}; - - -/** - * This is a wrapper around MemoryReadStream, but it adds non-endian - * read methods whose endianness is set on the stream creation. - */ -class MemoryReadStreamEndian : public MemoryReadStream { -private: - const bool _bigEndian; - -public: - MemoryReadStreamEndian(const byte *buf, uint32 len, bool bigEndian = false) : MemoryReadStream(buf, len), _bigEndian(bigEndian) {} - - uint16 readUint16() { - uint16 val; - read(&val, 2); - return (_bigEndian) ? TO_BE_16(val) : TO_LE_16(val); - } - - uint32 readUint32() { - uint32 val; - read(&val, 4); - return (_bigEndian) ? TO_BE_32(val) : TO_LE_32(val); - } - - FORCEINLINE int16 readSint16() { - return (int16)readUint16(); - } - - FORCEINLINE int32 readSint32() { - return (int32)readUint32(); - } -}; - -/** - * Simple memory based 'stream', which implements the WriteStream interface for - * a plain memory block. - */ -class MemoryWriteStream : public WriteStream { -private: - byte *_ptr; - const uint32 _bufSize; - uint32 _pos; -public: - MemoryWriteStream(byte *buf, uint32 len) : _ptr(buf), _bufSize(len), _pos(0) {} - - uint32 write(const void *dataPtr, uint32 dataSize) { - // Write at most as many bytes as are still available... - if (dataSize > _bufSize - _pos) - dataSize = _bufSize - _pos; - memcpy(_ptr, dataPtr, dataSize); - _ptr += dataSize; - _pos += dataSize; - return dataSize; - } - - uint32 pos() const { return _pos; } - uint32 size() const { return _bufSize; } -}; - -/** - * A sort of hybrid between MemoryWriteStream and Array classes. A stream - * that grows as it's written to. - */ -class MemoryWriteStreamDynamic : public WriteStream { -private: - uint32 _capacity; - uint32 _size; - byte *_ptr; - byte *_data; - uint32 _pos; - DisposeAfterUse::Flag _disposeMemory; - - void ensureCapacity(uint32 new_len) { - if (new_len <= _capacity) - return; - - byte *old_data = _data; - - _capacity = new_len + 32; - _data = (byte *)malloc(_capacity); - _ptr = _data + _pos; - - if (old_data) { - // Copy old data - memcpy(_data, old_data, _size); - free(old_data); - } - - _size = new_len; - } -public: - MemoryWriteStreamDynamic(DisposeAfterUse::Flag disposeMemory = DisposeAfterUse::NO) : _capacity(0), _size(0), _ptr(0), _data(0), _pos(0), _disposeMemory(disposeMemory) {} - - ~MemoryWriteStreamDynamic() { - if (_disposeMemory) - free(_data); - } - - uint32 write(const void *dataPtr, uint32 dataSize) { - ensureCapacity(_pos + dataSize); - memcpy(_ptr, dataPtr, dataSize); - _ptr += dataSize; - _pos += dataSize; - if (_pos > _size) - _size = _pos; - return dataSize; - } - - uint32 pos() const { return _pos; } - uint32 size() const { return _size; } - - byte *getData() { return _data; } - - bool seek(int32 offset, int whence = SEEK_SET); -}; - } // End of namespace Common #endif diff --git a/common/substream.h b/common/substream.h new file mode 100644 index 0000000000..cf794cfa7e --- /dev/null +++ b/common/substream.h @@ -0,0 +1,129 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +#ifndef COMMON_SUBSTREAM_H +#define COMMON_SUBSTREAM_H + +#include "common/stream.h" + +namespace Common { + +/** + * SubReadStream provides access to a ReadStream restricted to the range + * [currentPosition, currentPosition+end). + * + * Manipulating the parent stream directly /will/ mess up a substream. + * Likewise, manipulating two substreams of a parent stream will cause them to + * step on each others toes. + */ +class SubReadStream : virtual public ReadStream { +protected: + ReadStream *_parentStream; + DisposeAfterUse::Flag _disposeParentStream; + uint32 _pos; + uint32 _end; + bool _eos; +public: + SubReadStream(ReadStream *parentStream, uint32 end, DisposeAfterUse::Flag disposeParentStream = DisposeAfterUse::NO) + : _parentStream(parentStream), + _disposeParentStream(disposeParentStream), + _pos(0), + _end(end), + _eos(false) { + assert(parentStream); + } + ~SubReadStream() { + if (_disposeParentStream) + delete _parentStream; + } + + virtual bool eos() const { return _eos; } + virtual bool err() const { return _parentStream->err(); } + virtual void clearErr() { _eos = false; _parentStream->clearErr(); } + virtual uint32 read(void *dataPtr, uint32 dataSize); +}; + +/* + * SeekableSubReadStream provides access to a SeekableReadStream restricted to + * the range [begin, end). + * The same caveats apply to SeekableSubReadStream as do to SeekableReadStream. + * + * Manipulating the parent stream directly /will/ mess up a substream. + * @see SubReadStream + */ +class SeekableSubReadStream : public SubReadStream, public SeekableReadStream { +protected: + SeekableReadStream *_parentStream; + uint32 _begin; +public: + SeekableSubReadStream(SeekableReadStream *parentStream, uint32 begin, uint32 end, DisposeAfterUse::Flag disposeParentStream = DisposeAfterUse::NO); + + virtual int32 pos() const { return _pos - _begin; } + virtual int32 size() const { return _end - _begin; } + + virtual bool seek(int32 offset, int whence = SEEK_SET); +}; + +/** + * This is a wrapper around SeekableSubReadStream, but it adds non-endian + * read methods whose endianness is set on the stream creation. + * + * Manipulating the parent stream directly /will/ mess up a substream. + * @see SubReadStream + */ +class SeekableSubReadStreamEndian : public SeekableSubReadStream { +private: + const bool _bigEndian; + +public: + SeekableSubReadStreamEndian(SeekableReadStream *parentStream, uint32 begin, uint32 end, bool bigEndian = false, DisposeAfterUse::Flag disposeParentStream = DisposeAfterUse::NO) + : SeekableSubReadStream(parentStream, begin, end, disposeParentStream), _bigEndian(bigEndian) { + } + + uint16 readUint16() { + uint16 val; + read(&val, 2); + return (_bigEndian) ? TO_BE_16(val) : TO_LE_16(val); + } + + uint32 readUint32() { + uint32 val; + read(&val, 4); + return (_bigEndian) ? TO_BE_32(val) : TO_LE_32(val); + } + + FORCEINLINE int16 readSint16() { + return (int16)readUint16(); + } + + FORCEINLINE int32 readSint32() { + return (int32)readUint32(); + } +}; + + +} // End of namespace Common + +#endif diff --git a/common/unarj.cpp b/common/unarj.cpp index 050c7e65a2..89acf51cb5 100644 --- a/common/unarj.cpp +++ b/common/unarj.cpp @@ -34,6 +34,8 @@ #include "common/unarj.h" #include "common/file.h" #include "common/hash-str.h" +#include "common/memstream.h" +#include "common/bufferedstream.h" namespace Common { diff --git a/common/unzip.cpp b/common/unzip.cpp index 3f084ad861..da9bb65f43 100644 --- a/common/unzip.cpp +++ b/common/unzip.cpp @@ -106,6 +106,7 @@ typedef struct { #include "common/fs.h" #include "common/unzip.h" #include "common/file.h" +#include "common/memstream.h" #include "common/hashmap.h" #include "common/hash-str.h" diff --git a/common/xmlparser.cpp b/common/xmlparser.cpp index 4dd0e09f53..b53a9a33c2 100644 --- a/common/xmlparser.cpp +++ b/common/xmlparser.cpp @@ -27,7 +27,7 @@ #include "common/util.h" #include "common/archive.h" #include "common/fs.h" -#include "common/stream.h" +#include "common/memstream.h" namespace Common { diff --git a/engines/agi/agi.cpp b/engines/agi/agi.cpp index cfe921a91e..885704b9c6 100644 --- a/engines/agi/agi.cpp +++ b/engines/agi/agi.cpp @@ -27,6 +27,7 @@ #include "common/events.h" #include "common/EventRecorder.h" #include "common/file.h" +#include "common/memstream.h" #include "common/savefile.h" #include "common/config-manager.h" #include "common/debug-channels.h" diff --git a/engines/agi/preagi_winnie.cpp b/engines/agi/preagi_winnie.cpp index 14d90f3211..643cbd86a9 100644 --- a/engines/agi/preagi_winnie.cpp +++ b/engines/agi/preagi_winnie.cpp @@ -30,6 +30,7 @@ #include "graphics/cursorman.h" #include "common/events.h" +#include "common/memstream.h" #include "common/savefile.h" namespace Agi { diff --git a/engines/agi/sound_2gs.cpp b/engines/agi/sound_2gs.cpp index 2748344b36..4ed4fb7bab 100644 --- a/engines/agi/sound_2gs.cpp +++ b/engines/agi/sound_2gs.cpp @@ -26,6 +26,7 @@ #include "common/config-manager.h" #include "common/fs.h" #include "common/md5.h" +#include "common/memstream.h" #include "common/str-array.h" #include "agi/agi.h" @@ -839,7 +840,7 @@ bool SoundGen2GS::loadInstrumentHeaders(const Common::FSNode &exePath, const IIg } // Read the whole executable file into memory - Common::SharedPtr<Common::MemoryReadStream> data(file.readStream(file.size())); + Common::SharedPtr<Common::SeekableReadStream> data(file.readStream(file.size())); file.close(); // Check that we got enough data to be able to parse the instruments @@ -891,7 +892,7 @@ bool SoundGen2GS::loadWaveFile(const Common::FSNode &wavePath, const IIgsExeInfo // Open the wave file and read it into memory file.open(wavePath); - Common::SharedPtr<Common::MemoryReadStream> uint8Wave(file.readStream(file.size())); + Common::SharedPtr<Common::SeekableReadStream> uint8Wave(file.readStream(file.size())); file.close(); // Check that we got the whole wave file diff --git a/engines/agi/sound_midi.cpp b/engines/agi/sound_midi.cpp index f7f38a8d55..9011ecaa86 100644 --- a/engines/agi/sound_midi.cpp +++ b/engines/agi/sound_midi.cpp @@ -47,6 +47,7 @@ #include "sound/midiparser.h" #include "common/config-manager.h" #include "common/file.h" +#include "common/memstream.h" #include "common/stream.h" #include "agi/agi.h" diff --git a/engines/agos/res.cpp b/engines/agos/res.cpp index 5775e71a7a..2d99f7bcef 100644 --- a/engines/agos/res.cpp +++ b/engines/agos/res.cpp @@ -27,6 +27,7 @@ #include "common/file.h" +#include "common/memstream.h" #include "common/util.h" #include "agos/agos.h" diff --git a/engines/agos/res_snd.cpp b/engines/agos/res_snd.cpp index e3c13ffcbd..7f11367d0f 100644 --- a/engines/agos/res_snd.cpp +++ b/engines/agos/res_snd.cpp @@ -25,6 +25,7 @@ #include "common/config-manager.h" #include "common/file.h" +#include "common/memstream.h" #include "agos/intern.h" #include "agos/agos.h" diff --git a/engines/agos/sound.cpp b/engines/agos/sound.cpp index 8914470370..20deb47be8 100644 --- a/engines/agos/sound.cpp +++ b/engines/agos/sound.cpp @@ -24,6 +24,7 @@ */ #include "common/file.h" +#include "common/memstream.h" #include "common/util.h" #include "agos/agos.h" @@ -305,7 +306,7 @@ class CompressedSound : public BaseSound { public: CompressedSound(Audio::Mixer *mixer, Common::File *file, uint32 base) : BaseSound(mixer, file, base, false) {} - Common::MemoryReadStream *loadStream(uint sound) const { + Common::SeekableReadStream *loadStream(uint sound) const { if (_offsets == NULL) return NULL; @@ -334,7 +335,7 @@ class MP3Sound : public CompressedSound { public: MP3Sound(Audio::Mixer *mixer, Common::File *file, uint32 base = 0) : CompressedSound(mixer, file, base) {} Audio::AudioStream *makeAudioStream(uint sound) { - Common::MemoryReadStream *tmp = loadStream(sound); + Common::SeekableReadStream *tmp = loadStream(sound); if (!tmp) return NULL; return Audio::makeMP3Stream(tmp, DisposeAfterUse::YES); @@ -350,7 +351,7 @@ class VorbisSound : public CompressedSound { public: VorbisSound(Audio::Mixer *mixer, Common::File *file, uint32 base = 0) : CompressedSound(mixer, file, base) {} Audio::AudioStream *makeAudioStream(uint sound) { - Common::MemoryReadStream *tmp = loadStream(sound); + Common::SeekableReadStream *tmp = loadStream(sound); if (!tmp) return NULL; return Audio::makeVorbisStream(tmp, DisposeAfterUse::YES); @@ -366,7 +367,7 @@ class FLACSound : public CompressedSound { public: FLACSound(Audio::Mixer *mixer, Common::File *file, uint32 base = 0) : CompressedSound(mixer, file, base) {} Audio::AudioStream *makeAudioStream(uint sound) { - Common::MemoryReadStream *tmp = loadStream(sound); + Common::SeekableReadStream *tmp = loadStream(sound); if (!tmp) return NULL; return Audio::makeFLACStream(tmp, DisposeAfterUse::YES); @@ -775,7 +776,7 @@ void Sound::playVoiceData(byte *soundData, uint sound) { void Sound::playSoundData(Audio::SoundHandle *handle, byte *soundData, uint sound, int pan, int vol, bool loop) { int size = READ_LE_UINT32(soundData + 4) + 8; - Common::MemoryReadStream *stream = new Common::MemoryReadStream(soundData, size); + Common::SeekableReadStream *stream = new Common::MemoryReadStream(soundData, size); Audio::RewindableAudioStream *sndStream = Audio::makeWAVStream(stream, DisposeAfterUse::YES); convertVolume(vol); diff --git a/engines/cine/anim.cpp b/engines/cine/anim.cpp index 747c9221ee..14b8de9e39 100644 --- a/engines/cine/anim.cpp +++ b/engines/cine/anim.cpp @@ -28,7 +28,7 @@ */ #include "common/endian.h" -#include "common/stream.h" +#include "common/memstream.h" #include "cine/cine.h" #include "cine/anim.h" @@ -485,7 +485,7 @@ void convert4BBP(byte *dest, const byte *source, int16 width, int16 height) { * @param[out] animHeader Image header reference * @param readS Input stream open for reading */ -void loadAnimHeader(AnimHeaderStruct &animHeader, Common::MemoryReadStream readS) { +void loadAnimHeader(AnimHeaderStruct &animHeader, Common::SeekableReadStream &readS) { animHeader.field_0 = readS.readByte(); animHeader.field_1 = readS.readByte(); animHeader.field_2 = readS.readByte(); diff --git a/engines/cine/bg.cpp b/engines/cine/bg.cpp index 08722c42e5..449e254021 100644 --- a/engines/cine/bg.cpp +++ b/engines/cine/bg.cpp @@ -25,7 +25,7 @@ #include "common/endian.h" -#include "common/stream.h" +#include "common/memstream.h" #include "cine/cine.h" #include "cine/various.h" diff --git a/engines/cine/object.cpp b/engines/cine/object.cpp index 82dc0a6ef1..2b456ad49d 100644 --- a/engines/cine/object.cpp +++ b/engines/cine/object.cpp @@ -25,7 +25,7 @@ #include "common/endian.h" -#include "common/scummsys.h" +#include "common/memstream.h" #include "common/util.h" #include "cine/cine.h" diff --git a/engines/cine/saveload.cpp b/engines/cine/saveload.cpp index 0f7c50b7e5..fd426be66a 100644 --- a/engines/cine/saveload.cpp +++ b/engines/cine/saveload.cpp @@ -801,7 +801,7 @@ bool CineEngine::makeLoad(char *saveName) { // Hopefully devices with more limited memory can also cope with this memory allocation. saveSize = 256 * 1024; } - Common::SharedPtr<Common::MemoryReadStream> in(saveFile->readStream(saveSize)); + Common::SharedPtr<Common::SeekableReadStream> in(saveFile->readStream(saveSize)); // Try to detect the used savegame format enum CineSaveGameFormat saveGameFormat = detectSaveGameFormat(*in); diff --git a/engines/cine/sound.cpp b/engines/cine/sound.cpp index dd4b4d4ab4..7ba084128b 100644 --- a/engines/cine/sound.cpp +++ b/engines/cine/sound.cpp @@ -25,7 +25,7 @@ #include "common/endian.h" #include "common/file.h" -#include "common/system.h" +#include "common/memstream.h" #include "cine/cine.h" #include "cine/sound.h" diff --git a/engines/cruise/dataLoader.cpp b/engines/cruise/dataLoader.cpp index b48240b30e..03a2117f07 100644 --- a/engines/cruise/dataLoader.cpp +++ b/engines/cruise/dataLoader.cpp @@ -25,6 +25,7 @@ #include "cruise/cruise_main.h" #include "common/endian.h" +#include "common/memstream.h" namespace Cruise { diff --git a/engines/cruise/overlay.cpp b/engines/cruise/overlay.cpp index 01920fa8f1..9a77891deb 100644 --- a/engines/cruise/overlay.cpp +++ b/engines/cruise/overlay.cpp @@ -23,7 +23,7 @@ * */ -#include "common/stream.h" +#include "common/memstream.h" #include "cruise/cruise.h" #include "cruise/cruise_main.h" diff --git a/engines/draci/animation.cpp b/engines/draci/animation.cpp index 2bedbe1801..d7582ec31d 100644 --- a/engines/draci/animation.cpp +++ b/engines/draci/animation.cpp @@ -31,6 +31,8 @@ #include "draci/sound.h" #include "draci/surface.h" +#include "common/memstream.h" + namespace Draci { Animation::Animation(DraciEngine *vm, int id, uint z, bool playing) : _vm(vm) { diff --git a/engines/draci/barchive.cpp b/engines/draci/barchive.cpp index 8f9e836ba3..5307e04250 100644 --- a/engines/draci/barchive.cpp +++ b/engines/draci/barchive.cpp @@ -25,7 +25,7 @@ #include "common/debug.h" #include "common/str.h" -#include "common/stream.h" +#include "common/memstream.h" #include "draci/barchive.h" #include "draci/draci.h" diff --git a/engines/draci/game.cpp b/engines/draci/game.cpp index cb2832552a..eef81d808e 100644 --- a/engines/draci/game.cpp +++ b/engines/draci/game.cpp @@ -25,7 +25,7 @@ #include "common/keyboard.h" #include "common/serializer.h" -#include "common/stream.h" +#include "common/memstream.h" #include "common/system.h" #include "common/util.h" diff --git a/engines/draci/screen.cpp b/engines/draci/screen.cpp index 9e91a14cfc..987bbf2ac1 100644 --- a/engines/draci/screen.cpp +++ b/engines/draci/screen.cpp @@ -23,7 +23,7 @@ * */ -#include "common/stream.h" +#include "common/memstream.h" #include "common/system.h" #include "draci/draci.h" diff --git a/engines/draci/script.cpp b/engines/draci/script.cpp index 583afa736f..2a27541ad9 100644 --- a/engines/draci/script.cpp +++ b/engines/draci/script.cpp @@ -25,7 +25,7 @@ #include "common/array.h" #include "common/debug.h" -#include "common/stream.h" +#include "common/memstream.h" #include "common/stack.h" #include "draci/draci.h" diff --git a/engines/draci/sound.cpp b/engines/draci/sound.cpp index 6828066c3a..af096256ea 100644 --- a/engines/draci/sound.cpp +++ b/engines/draci/sound.cpp @@ -28,7 +28,8 @@ #include "common/debug.h" #include "common/file.h" #include "common/str.h" -#include "common/stream.h" +#include "common/substream.h" +#include "common/memstream.h" #include "common/unzip.h" #include "draci/sound.h" @@ -301,7 +302,7 @@ uint Sound::playSoundBuffer(Audio::SoundHandle *handle, const SoundSample &buffe // only used for dubbing, which is only played from one place in // script.cpp, which blocks until the dubbed sentence has finished // playing. - Common::SeekableReadStream* stream; + Common::SeekableReadStream *stream; const int skip = buffer._format == RAW80 ? 80 : 0; if (buffer._stream) { stream = new Common::SeekableSubReadStream( diff --git a/engines/draci/sprite.cpp b/engines/draci/sprite.cpp index cb3aa58cfa..65c6e21ee4 100644 --- a/engines/draci/sprite.cpp +++ b/engines/draci/sprite.cpp @@ -23,7 +23,7 @@ * */ -#include "common/stream.h" +#include "common/memstream.h" #include "draci/draci.h" #include "draci/font.h" diff --git a/engines/draci/walking.cpp b/engines/draci/walking.cpp index 02612832d2..c6f9a58a85 100644 --- a/engines/draci/walking.cpp +++ b/engines/draci/walking.cpp @@ -23,9 +23,7 @@ * */ -#include <stdlib.h> - -#include "common/stream.h" +#include "common/memstream.h" #include "draci/draci.h" #include "draci/animation.h" diff --git a/engines/gob/dataio.cpp b/engines/gob/dataio.cpp index e409025fc3..b145441b4a 100644 --- a/engines/gob/dataio.cpp +++ b/engines/gob/dataio.cpp @@ -25,7 +25,7 @@ #include "common/endian.h" #include "common/types.h" -#include "common/stream.h" +#include "common/memstream.h" #include "gob/gob.h" #include "gob/dataio.h" diff --git a/engines/gob/demos/demoplayer.cpp b/engines/gob/demos/demoplayer.cpp index 011c524798..9013f600a5 100644 --- a/engines/gob/demos/demoplayer.cpp +++ b/engines/gob/demos/demoplayer.cpp @@ -25,6 +25,7 @@ #include "common/endian.h" #include "common/file.h" +#include "common/memstream.h" #include "gob/gob.h" #include "gob/demos/demoplayer.h" diff --git a/engines/gob/map_v1.cpp b/engines/gob/map_v1.cpp index 3df1cb8512..372f501887 100644 --- a/engines/gob/map_v1.cpp +++ b/engines/gob/map_v1.cpp @@ -23,7 +23,7 @@ * */ -#include "common/stream.h" +#include "common/memstream.h" #include "gob/gob.h" #include "gob/map.h" diff --git a/engines/gob/resources.cpp b/engines/gob/resources.cpp index 9b0cc39215..56941aa4c1 100644 --- a/engines/gob/resources.cpp +++ b/engines/gob/resources.cpp @@ -25,7 +25,7 @@ #include "common/util.h" #include "common/endian.h" -#include "common/stream.h" +#include "common/memstream.h" #include "gob/gob.h" #include "gob/resources.h" diff --git a/engines/gob/save/saveconverter.cpp b/engines/gob/save/saveconverter.cpp index 7bfb2a2da2..59d313138b 100644 --- a/engines/gob/save/saveconverter.cpp +++ b/engines/gob/save/saveconverter.cpp @@ -24,6 +24,7 @@ */ #include "common/endian.h" +#include "common/memstream.h" #include "common/savefile.h" #include "gob/gob.h" diff --git a/engines/gob/save/saveconverter.h b/engines/gob/save/saveconverter.h index 3ae48e1edc..dd5f43875e 100644 --- a/engines/gob/save/saveconverter.h +++ b/engines/gob/save/saveconverter.h @@ -77,7 +77,7 @@ protected: Common::String _fileName; byte *_data; - Common::MemoryReadStream *_stream; + Common::SeekableReadStream *_stream; Common::InSaveFile *openSave() const; diff --git a/engines/gob/save/savefile.cpp b/engines/gob/save/savefile.cpp index 79e931fe30..3869ea2def 100644 --- a/engines/gob/save/savefile.cpp +++ b/engines/gob/save/savefile.cpp @@ -25,6 +25,7 @@ #include "common/util.h" #include "common/endian.h" +#include "common/memstream.h" #include "common/system.h" #include "common/savefile.h" diff --git a/engines/gob/sound/sounddesc.cpp b/engines/gob/sound/sounddesc.cpp index 2efb3e90f2..9df8bbb4bc 100644 --- a/engines/gob/sound/sounddesc.cpp +++ b/engines/gob/sound/sounddesc.cpp @@ -24,7 +24,7 @@ */ #include "common/util.h" -#include "common/stream.h" +#include "common/memstream.h" #include "sound/mixer.h" #include "sound/decoders/raw.h" #include "sound/decoders/wave.h" diff --git a/engines/groovie/music.cpp b/engines/groovie/music.cpp index d21eb019ae..fd2cc2bec8 100644 --- a/engines/groovie/music.cpp +++ b/engines/groovie/music.cpp @@ -30,6 +30,7 @@ #include "backends/audiocd/audiocd.h" #include "common/config-manager.h" #include "common/macresman.h" +#include "common/memstream.h" #include "sound/midiparser.h" namespace Groovie { diff --git a/engines/groovie/resource.cpp b/engines/groovie/resource.cpp index 32cc1735ef..5d4ccf7d91 100644 --- a/engines/groovie/resource.cpp +++ b/engines/groovie/resource.cpp @@ -25,6 +25,7 @@ #include "common/archive.h" #include "common/macresman.h" +#include "common/substream.h" #include "groovie/resource.h" #include "groovie/groovie.h" diff --git a/engines/groovie/saveload.cpp b/engines/groovie/saveload.cpp index 423829c5fe..4e3e4cfcf8 100644 --- a/engines/groovie/saveload.cpp +++ b/engines/groovie/saveload.cpp @@ -26,6 +26,7 @@ #include "groovie/saveload.h" #include "common/system.h" +#include "common/substream.h" #define SUPPORTED_SAVEFILE_VERSION 1 // 0 - Just script variables, compatible with the original diff --git a/engines/kyra/resource_intern.cpp b/engines/kyra/resource_intern.cpp index dff8759d55..f26cb8fb26 100644 --- a/engines/kyra/resource_intern.cpp +++ b/engines/kyra/resource_intern.cpp @@ -26,8 +26,9 @@ #include "kyra/resource_intern.h" #include "kyra/resource.h" -#include "common/stream.h" #include "common/endian.h" +#include "common/memstream.h" +#include "common/substream.h" namespace Kyra { diff --git a/engines/kyra/saveload_hof.cpp b/engines/kyra/saveload_hof.cpp index e957718f95..ced103b7e3 100644 --- a/engines/kyra/saveload_hof.cpp +++ b/engines/kyra/saveload_hof.cpp @@ -25,6 +25,7 @@ #include "common/endian.h" #include "common/savefile.h" +#include "common/substream.h" #include "common/system.h" #include "kyra/kyra_v2.h" diff --git a/engines/kyra/saveload_lol.cpp b/engines/kyra/saveload_lol.cpp index aee24957a0..ee4fbf4dc1 100644 --- a/engines/kyra/saveload_lol.cpp +++ b/engines/kyra/saveload_lol.cpp @@ -31,6 +31,7 @@ #include "common/endian.h" #include "common/savefile.h" +#include "common/substream.h" #include "common/system.h" #include "graphics/scaler.h" diff --git a/engines/kyra/saveload_mr.cpp b/engines/kyra/saveload_mr.cpp index 80c9b2b83c..7c583f95ee 100644 --- a/engines/kyra/saveload_mr.cpp +++ b/engines/kyra/saveload_mr.cpp @@ -25,6 +25,7 @@ #include "common/endian.h" #include "common/savefile.h" +#include "common/substream.h" #include "common/system.h" #include "kyra/kyra_mr.h" diff --git a/engines/kyra/screen.cpp b/engines/kyra/screen.cpp index 8b0a87f0c8..c86e043db7 100644 --- a/engines/kyra/screen.cpp +++ b/engines/kyra/screen.cpp @@ -25,6 +25,7 @@ #include "common/endian.h" +#include "common/memstream.h" #include "common/system.h" #include "engines/util.h" diff --git a/engines/lastexpress/data/animation.cpp b/engines/lastexpress/data/animation.cpp index cc44d6869e..d105a34f8c 100644 --- a/engines/lastexpress/data/animation.cpp +++ b/engines/lastexpress/data/animation.cpp @@ -225,7 +225,7 @@ AnimFrame *Animation::processChunkFrame(Common::SeekableReadStream *in, const Ch assert (c.frame == 0); // Create a temporary chunk buffer - Common::MemoryReadStream *str = in->readStream(c.size); + Common::SeekableReadStream *str = in->readStream(c.size); // Read the frame information FrameInfo i; diff --git a/engines/lastexpress/data/archive.cpp b/engines/lastexpress/data/archive.cpp index 1a5b6905a3..ab95c28b1e 100644 --- a/engines/lastexpress/data/archive.cpp +++ b/engines/lastexpress/data/archive.cpp @@ -32,6 +32,7 @@ #include "common/debug.h" #include "common/file.h" +#include "common/substream.h" namespace LastExpress { diff --git a/engines/lastexpress/data/cursor.cpp b/engines/lastexpress/data/cursor.cpp index 5489fc3d21..3acb8dd4c0 100644 --- a/engines/lastexpress/data/cursor.cpp +++ b/engines/lastexpress/data/cursor.cpp @@ -42,7 +42,7 @@ bool Cursor::load(Common::SeekableReadStream *stream) { return false; // Load the whole file to memory - Common::MemoryReadStream *data = stream->readStream((uint32) stream->size()); + Common::SeekableReadStream *data = stream->readStream((uint32) stream->size()); delete stream; if (!data) return false; diff --git a/engines/lastexpress/data/snd.cpp b/engines/lastexpress/data/snd.cpp index 496bd58772..b98e490215 100644 --- a/engines/lastexpress/data/snd.cpp +++ b/engines/lastexpress/data/snd.cpp @@ -32,6 +32,7 @@ #include "sound/decoders/adpcm.h" #include "sound/audiostream.h" +#include "common/memstream.h" namespace LastExpress { diff --git a/engines/lastexpress/game/savegame.h b/engines/lastexpress/game/savegame.h index d3ba5d13af..5c0e0e9890 100644 --- a/engines/lastexpress/game/savegame.h +++ b/engines/lastexpress/game/savegame.h @@ -78,6 +78,7 @@ #include "common/savefile.h" #include "common/serializer.h" +#include "common/memstream.h" namespace LastExpress { diff --git a/engines/m4/assets.cpp b/engines/m4/assets.cpp index 07cbff5bf1..c4113e00d0 100644 --- a/engines/m4/assets.cpp +++ b/engines/m4/assets.cpp @@ -28,6 +28,8 @@ #include "m4/compression.h" #include "m4/graphics.h" +#include "common/memstream.h" + namespace M4 { BaseAsset::BaseAsset(MadsM4Engine *vm) : _vm(vm) { @@ -382,7 +384,7 @@ void SpriteAsset::loadStreamingFrame(M4Sprite *frame, int frameIndex, int destX, loadFrameHeader(frameHeader); if (frameHeader.w > 0 && frameHeader.h > 0) { - Common::MemoryReadStream *frameData = _stream->readStream(getFrameSize(frameIndex)); + Common::SeekableReadStream *frameData = _stream->readStream(getFrameSize(frameIndex)); if (frameHeader.stream) { frame->loadDeltaRle(frameData, destX - frameHeader.x, destY - frameHeader.y); } else { diff --git a/engines/m4/compression.cpp b/engines/m4/compression.cpp index 2b3f4e1388..9b1416945c 100644 --- a/engines/m4/compression.cpp +++ b/engines/m4/compression.cpp @@ -26,6 +26,8 @@ #include "m4/compression.h" #include "m4/m4.h" +#include "common/memstream.h" + namespace M4 { const char *madsPackString = "MADSPACK"; @@ -90,6 +92,10 @@ void MadsPack::initialise(Common::SeekableReadStream *stream) { _dataOffset = stream->pos(); } +Common::SeekableReadStream *MadsPack::getItemStream(int index) { + return new Common::MemoryReadStream(_items[index].data, _items[index].size, DisposeAfterUse::NO); +} + MadsPack::~MadsPack() { for (int i = 0; i < _count; ++i) delete[] _items[i].data; diff --git a/engines/m4/compression.h b/engines/m4/compression.h index 00e3d1f927..93c7d9af9e 100644 --- a/engines/m4/compression.h +++ b/engines/m4/compression.h @@ -58,9 +58,7 @@ public: int getCount() const { return _count; } MadsPackEntry &getItem(int index) const { return _items[index]; } MadsPackEntry &operator[](int index) const { return _items[index]; } - Common::MemoryReadStream *getItemStream(int index) { - return new Common::MemoryReadStream(_items[index].data, _items[index].size, DisposeAfterUse::NO); - } + Common::SeekableReadStream *getItemStream(int index); int getDataOffset() const { return _dataOffset; } }; diff --git a/engines/m4/converse.cpp b/engines/m4/converse.cpp index 1a0e2e8d3b..70c30d28f2 100644 --- a/engines/m4/converse.cpp +++ b/engines/m4/converse.cpp @@ -25,6 +25,7 @@ #include "common/array.h" #include "common/hashmap.h" +#include "common/substream.h" #include "m4/converse.h" #include "m4/resource.h" diff --git a/engines/m4/graphics.cpp b/engines/m4/graphics.cpp index 6d01db50bd..eb2fc9e4b5 100644 --- a/engines/m4/graphics.cpp +++ b/engines/m4/graphics.cpp @@ -740,7 +740,7 @@ void M4Surface::madsLoadBackground(int roomNumber, RGBList **palData) { void M4Surface::rexLoadBackground(Common::SeekableReadStream *source, RGBList **palData) { MadsPack packData(source); - Common::MemoryReadStream *sourceUnc = packData.getItemStream(0); + Common::SeekableReadStream *sourceUnc = packData.getItemStream(0); int sceneWidth = sourceUnc->readUint16LE(); int sceneHeight = sourceUnc->readUint16LE(); diff --git a/engines/m4/m4.cpp b/engines/m4/m4.cpp index 93490a0821..73dba87e99 100644 --- a/engines/m4/m4.cpp +++ b/engines/m4/m4.cpp @@ -288,7 +288,7 @@ void MadsM4Engine::dumpFile(const char* filename, bool uncompress) { } } else { MadsPack packData(fileS); - Common::MemoryReadStream *sourceUnc; + Common::SeekableReadStream *sourceUnc; for (int i = 0; i < packData.getCount(); i++) { sourceUnc = packData.getItemStream(i); debugCN(kDebugCore, "Dumping compressed chunk %i of %i, size is %i\n", i + 1, packData.getCount(), sourceUnc->size()); diff --git a/engines/m4/midi.cpp b/engines/m4/midi.cpp index 2c767fdf5a..f130ddc3b5 100644 --- a/engines/m4/midi.cpp +++ b/engines/m4/midi.cpp @@ -28,7 +28,7 @@ #include "m4/m4.h" #include "m4/midi.h" -#include "common/stream.h" +#include "common/memstream.h" namespace M4 { diff --git a/engines/m4/resource.cpp b/engines/m4/resource.cpp index fd54d439a6..70abc47960 100644 --- a/engines/m4/resource.cpp +++ b/engines/m4/resource.cpp @@ -27,6 +27,8 @@ #include "m4/resource.h" #include "m4/events.h" +#include "common/substream.h" + namespace M4 { FileSystem::FileSystem(const char *hashFilename) { diff --git a/engines/m4/script.h b/engines/m4/script.h index 2012926330..32b5701419 100644 --- a/engines/m4/script.h +++ b/engines/m4/script.h @@ -223,7 +223,7 @@ public: uint32 readUint32(); protected: ScriptInterpreter *_inter; - Common::MemoryReadStream *_code; + Common::SeekableReadStream *_code; }; struct ScriptFunctionEntry { diff --git a/engines/m4/woodscript.cpp b/engines/m4/woodscript.cpp index ccd3401d3c..4928e0af8d 100644 --- a/engines/m4/woodscript.cpp +++ b/engines/m4/woodscript.cpp @@ -25,6 +25,8 @@ #include "m4/woodscript.h" +#include "common/memstream.h" + namespace M4 { // FIXME: Put in Engine/WoodScript class diff --git a/engines/m4/woodscript.h b/engines/m4/woodscript.h index 0f72935f8d..4b0f457193 100644 --- a/engines/m4/woodscript.h +++ b/engines/m4/woodscript.h @@ -77,7 +77,7 @@ public: uint32 pos() const { return _code->pos() / 4; } protected: WoodScript *_ws; - Common::MemoryReadStream *_code; + Common::SeekableReadStream *_code; Sequence *_sequence; static int32 _dataFormats[]; bool decodeArgument(int32 format, int32 data, long *&arg, long &value); diff --git a/engines/made/database.cpp b/engines/made/database.cpp index 51308cb7e5..2aa378edf5 100644 --- a/engines/made/database.cpp +++ b/engines/made/database.cpp @@ -275,7 +275,7 @@ void GameDatabase::openFromRed(const char *redFilename, const char *filename) { _isRedSource = true; _filename = filename; _redFilename = redFilename; - Common::MemoryReadStream *fileS = RedReader::loadFromRed(redFilename, filename); + Common::SeekableReadStream *fileS = RedReader::loadFromRed(redFilename, filename); if (!fileS) error("GameDatabase::openFromRed() Could not load %s from %s", filename, redFilename); load(*fileS); @@ -289,7 +289,7 @@ void GameDatabase::reload() { error("GameDatabase::reload() Could not open %s", _filename.c_str()); reloadFromStream(fd); } else { - Common::MemoryReadStream *fileS = RedReader::loadFromRed(_redFilename.c_str(), _filename.c_str()); + Common::SeekableReadStream *fileS = RedReader::loadFromRed(_redFilename.c_str(), _filename.c_str()); if (!fileS) error("GameDatabase::openFromRed() Could not load %s from %s", _filename.c_str(), _redFilename.c_str()); reloadFromStream(*fileS); diff --git a/engines/made/redreader.cpp b/engines/made/redreader.cpp index 4ca8d27eab..3d36b69a28 100644 --- a/engines/made/redreader.cpp +++ b/engines/made/redreader.cpp @@ -24,11 +24,11 @@ */ #include "made/redreader.h" +#include "common/memstream.h" namespace Made { - -Common::MemoryReadStream *RedReader::load(const char *redFilename, const char *filename) { +Common::SeekableReadStream *RedReader::load(const char *redFilename, const char *filename) { Common::File fd; FileEntry fileEntry; @@ -49,9 +49,9 @@ Common::MemoryReadStream *RedReader::load(const char *redFilename, const char *f } -Common::MemoryReadStream *RedReader::loadFromRed(const char *redFilename, const char *filename) { +Common::SeekableReadStream *RedReader::loadFromRed(const char *redFilename, const char *filename) { RedReader* red = new RedReader(); - Common::MemoryReadStream* stream = red->load(redFilename, filename); + Common::SeekableReadStream *stream = red->load(redFilename, filename); delete red; return stream; } diff --git a/engines/made/redreader.h b/engines/made/redreader.h index b734ca02e1..a6e72c4e00 100644 --- a/engines/made/redreader.h +++ b/engines/made/redreader.h @@ -34,8 +34,8 @@ namespace Made { class RedReader { public: - Common::MemoryReadStream *load(const char *redFilename, const char *filename); - static Common::MemoryReadStream *loadFromRed(const char *redFilename, const char *filename); + Common::SeekableReadStream *load(const char *redFilename, const char *filename); + static Common::SeekableReadStream *loadFromRed(const char *redFilename, const char *filename); private: struct FileEntry { uint32 compSize, origSize; diff --git a/engines/made/resource.cpp b/engines/made/resource.cpp index ecc2378f15..6140e7e0de 100644 --- a/engines/made/resource.cpp +++ b/engines/made/resource.cpp @@ -24,6 +24,7 @@ */ #include "common/endian.h" +#include "common/memstream.h" #include "sound/mixer.h" #include "sound/decoders/raw.h" diff --git a/engines/mohawk/bitmap.cpp b/engines/mohawk/bitmap.cpp index 0e26e4844b..ec38a4261f 100644 --- a/engines/mohawk/bitmap.cpp +++ b/engines/mohawk/bitmap.cpp @@ -28,6 +28,7 @@ #include "common/debug.h" #include "common/util.h" #include "common/endian.h" +#include "common/memstream.h" #include "common/system.h" namespace Mohawk { diff --git a/engines/mohawk/livingbooks.h b/engines/mohawk/livingbooks.h index 6bd0729bbf..82f6f97adb 100644 --- a/engines/mohawk/livingbooks.h +++ b/engines/mohawk/livingbooks.h @@ -31,6 +31,7 @@ #include "mohawk/graphics.h" #include "common/config-file.h" +#include "common/substream.h" namespace Mohawk { diff --git a/engines/mohawk/resource.cpp b/engines/mohawk/resource.cpp index 74efd6770f..899776245d 100644 --- a/engines/mohawk/resource.cpp +++ b/engines/mohawk/resource.cpp @@ -25,6 +25,7 @@ #include "mohawk/resource.h" +#include "common/substream.h" #include "common/util.h" namespace Mohawk { diff --git a/engines/mohawk/riven_saveload.h b/engines/mohawk/riven_saveload.h index 9cc9bc3737..fbd9f7cb36 100644 --- a/engines/mohawk/riven_saveload.h +++ b/engines/mohawk/riven_saveload.h @@ -28,6 +28,7 @@ #include "common/savefile.h" #include "common/str.h" +#include "common/memstream.h" namespace Mohawk { diff --git a/engines/parallaction/disk_ns.cpp b/engines/parallaction/disk_ns.cpp index 0b893fbe2c..12455af5e7 100644 --- a/engines/parallaction/disk_ns.cpp +++ b/engines/parallaction/disk_ns.cpp @@ -25,6 +25,8 @@ #include "common/config-manager.h" #include "common/fs.h" +#include "common/memstream.h" +#include "common/substream.h" #include "parallaction/parser.h" #include "parallaction/parallaction.h" @@ -1087,4 +1089,4 @@ Common::SeekableReadStream* AmigaDisk_ns::loadSound(const char* name) { return tryOpenFile(path); } -} // namespace Parallaction +} // End of namespace Parallaction diff --git a/engines/parallaction/font.cpp b/engines/parallaction/font.cpp index bf2bf6d419..18f469f0a2 100644 --- a/engines/parallaction/font.cpp +++ b/engines/parallaction/font.cpp @@ -24,7 +24,7 @@ */ #include "common/endian.h" -#include "common/stream.h" +#include "common/memstream.h" #include "parallaction/parallaction.h" @@ -670,7 +670,6 @@ GfxObj* DosDisk_br::createInventoryObjects(Common::SeekableReadStream &stream) { void Parallaction_ns::initFonts() { - if (getPlatform() == Common::kPlatformPC) { _dialogueFont = _disk->loadFont("comic"); _labelFont = _disk->loadFont("topaz"); @@ -683,7 +682,6 @@ void Parallaction_ns::initFonts() { _menuFont = _disk->loadFont("slide"); _introFont = _disk->loadFont("intro"); } - } void Parallaction_br::initFonts() { @@ -701,4 +699,4 @@ void Parallaction_br::initFonts() { } } -} +} // End of namespace Parallaction diff --git a/engines/parallaction/parallaction.cpp b/engines/parallaction/parallaction.cpp index 2de7fe9d64..1c0ab9defd 100644 --- a/engines/parallaction/parallaction.cpp +++ b/engines/parallaction/parallaction.cpp @@ -1004,4 +1004,4 @@ void Parallaction::scheduleLocationSwitch(const char *location) { } -} // namespace Parallaction +} // End of namespace Parallaction diff --git a/engines/parallaction/parallaction.h b/engines/parallaction/parallaction.h index ded1b3bda4..a8a57ed2d8 100644 --- a/engines/parallaction/parallaction.h +++ b/engines/parallaction/parallaction.h @@ -606,7 +606,7 @@ private: extern Parallaction *_vm; -} // namespace Parallaction +} // End of namespace Parallaction #endif diff --git a/engines/parallaction/parser.cpp b/engines/parallaction/parser.cpp index df1e91e8b4..c964b74512 100644 --- a/engines/parallaction/parser.cpp +++ b/engines/parallaction/parser.cpp @@ -257,5 +257,4 @@ void Parser::parseStatement() { (*(*_currentOpcodes)[_lookup])(); } - -} // namespace Parallaction +} // End of namespace Parallaction diff --git a/engines/parallaction/parser.h b/engines/parallaction/parser.h index 5eb26e9fa1..7887b2192f 100644 --- a/engines/parallaction/parser.h +++ b/engines/parallaction/parser.h @@ -409,13 +409,6 @@ public: virtual void parse(Script *script, ProgramPtr program); }; - -} // namespace Parallaction +} // End of namespace Parallaction #endif - - - - - - diff --git a/engines/queen/resource.cpp b/engines/queen/resource.cpp index 1e2eff8458..a70d1f1613 100644 --- a/engines/queen/resource.cpp +++ b/engines/queen/resource.cpp @@ -26,6 +26,7 @@ #include "common/debug.h" #include "common/endian.h" #include "common/config-manager.h" +#include "common/substream.h" #include "queen/resource.h" namespace Queen { diff --git a/engines/queen/sound.cpp b/engines/queen/sound.cpp index 659da2dd97..10ffd61724 100644 --- a/engines/queen/sound.cpp +++ b/engines/queen/sound.cpp @@ -26,7 +26,7 @@ #include "common/config-manager.h" #include "common/endian.h" -#include "common/stream.h" +#include "common/memstream.h" #include "queen/sound.h" #include "queen/input.h" @@ -119,7 +119,7 @@ public: MP3Sound(Audio::Mixer *mixer, QueenEngine *vm) : PCSound(mixer, vm) {} protected: void playSoundData(Common::File *f, uint32 size, Audio::SoundHandle *soundHandle) { - Common::MemoryReadStream *tmp = f->readStream(size); + Common::SeekableReadStream *tmp = f->readStream(size); assert(tmp); _mixer->playStream(Audio::Mixer::kSFXSoundType, soundHandle, new AudioStreamWrapper(Audio::makeMP3Stream(tmp, DisposeAfterUse::YES))); } @@ -132,7 +132,7 @@ public: OGGSound(Audio::Mixer *mixer, QueenEngine *vm) : PCSound(mixer, vm) {} protected: void playSoundData(Common::File *f, uint32 size, Audio::SoundHandle *soundHandle) { - Common::MemoryReadStream *tmp = f->readStream(size); + Common::SeekableReadStream *tmp = f->readStream(size); assert(tmp); _mixer->playStream(Audio::Mixer::kSFXSoundType, soundHandle, new AudioStreamWrapper(Audio::makeVorbisStream(tmp, DisposeAfterUse::YES))); } @@ -145,7 +145,7 @@ public: FLACSound(Audio::Mixer *mixer, QueenEngine *vm) : PCSound(mixer, vm) {} protected: void playSoundData(Common::File *f, uint32 size, Audio::SoundHandle *soundHandle) { - Common::MemoryReadStream *tmp = f->readStream(size); + Common::SeekableReadStream *tmp = f->readStream(size); assert(tmp); _mixer->playStream(Audio::Mixer::kSFXSoundType, soundHandle, new AudioStreamWrapper(Audio::makeFLACStream(tmp, DisposeAfterUse::YES))); } diff --git a/engines/saga/music.cpp b/engines/saga/music.cpp index f1cdcbce46..081fe955fc 100644 --- a/engines/saga/music.cpp +++ b/engines/saga/music.cpp @@ -36,6 +36,7 @@ #include "sound/decoders/raw.h" #include "common/config-manager.h" #include "common/file.h" +#include "common/substream.h" namespace Saga { diff --git a/engines/saga/saga.h b/engines/saga/saga.h index f710a9e8ab..149f1cb580 100644 --- a/engines/saga/saga.h +++ b/engines/saga/saga.h @@ -30,7 +30,7 @@ #include "common/array.h" #include "common/random.h" -#include "common/stream.h" +#include "common/memstream.h" #include "sound/mididrv.h" #include "saga/gfx.h" diff --git a/engines/sci/graphics/maciconbar.cpp b/engines/sci/graphics/maciconbar.cpp index 6f2c9596db..2ce17ab531 100644 --- a/engines/sci/graphics/maciconbar.cpp +++ b/engines/sci/graphics/maciconbar.cpp @@ -30,7 +30,7 @@ #include "sci/graphics/maciconbar.h" #include "sci/graphics/palette.h" -#include "common/stream.h" +#include "common/memstream.h" #include "common/system.h" #include "graphics/pict.h" #include "graphics/surface.h" @@ -54,7 +54,7 @@ void GfxMacIconBar::drawIcons() { if (!res) continue; - Common::MemoryReadStream *stream = new Common::MemoryReadStream(res->data, res->size); + Common::SeekableReadStream *stream = new Common::MemoryReadStream(res->data, res->size); Graphics::Surface *surf = pict->decodeImage(stream, pal); remapColors(surf, pal); diff --git a/engines/sci/sound/audio.cpp b/engines/sci/sound/audio.cpp index aebaaabbd7..829a94d90c 100644 --- a/engines/sci/sound/audio.cpp +++ b/engines/sci/sound/audio.cpp @@ -32,6 +32,7 @@ #include "backends/audiocd/audiocd.h" #include "common/file.h" +#include "common/memstream.h" #include "common/system.h" #include "sound/audiostream.h" @@ -281,7 +282,7 @@ Audio::RewindableAudioStream *AudioPlayer::getAudioStream(uint32 number, uint32 // additional buffer here. MP3/OGG/FLAC decompression works on-the-fly // instead. memcpy(compressedData, audioRes->data, audioRes->size); - Common::MemoryReadStream *compressedStream = new Common::MemoryReadStream(compressedData, audioRes->size, DisposeAfterUse::YES); + Common::SeekableReadStream *compressedStream = new Common::MemoryReadStream(compressedData, audioRes->size, DisposeAfterUse::YES); switch (audioCompressionType) { case MKID_BE('MP3 '): @@ -315,7 +316,7 @@ Audio::RewindableAudioStream *AudioPlayer::getAudioStream(uint32 number, uint32 } } else if (audioRes->size > 4 && READ_BE_UINT32(audioRes->data) == MKID_BE('RIFF')) { // WAVE detected - Common::MemoryReadStream *waveStream = new Common::MemoryReadStream(audioRes->data, audioRes->size, DisposeAfterUse::NO); + Common::SeekableReadStream *waveStream = new Common::MemoryReadStream(audioRes->data, audioRes->size, DisposeAfterUse::NO); // Calculate samplelen from WAVE header int waveSize = 0, waveRate = 0; @@ -327,7 +328,7 @@ Audio::RewindableAudioStream *AudioPlayer::getAudioStream(uint32 number, uint32 audioStream = Audio::makeWAVStream(waveStream, DisposeAfterUse::YES); } else if (audioRes->size > 4 && READ_BE_UINT32(audioRes->data) == MKID_BE('FORM')) { // AIFF detected - Common::MemoryReadStream *waveStream = new Common::MemoryReadStream(audioRes->data, audioRes->size, DisposeAfterUse::NO); + Common::SeekableReadStream *waveStream = new Common::MemoryReadStream(audioRes->data, audioRes->size, DisposeAfterUse::NO); // Calculate samplelen from AIFF header int waveSize = 0, waveRate = 0; @@ -340,7 +341,7 @@ Audio::RewindableAudioStream *AudioPlayer::getAudioStream(uint32 number, uint32 } else if (audioRes->size > 14 && READ_BE_UINT16(audioRes->data) == 1 && READ_BE_UINT16(audioRes->data + 2) == 1 && READ_BE_UINT16(audioRes->data + 4) == 5 && READ_BE_UINT32(audioRes->data + 10) == 0x00018051) { // Mac snd detected - Common::MemoryReadStream *sndStream = new Common::MemoryReadStream(audioRes->data, audioRes->size, DisposeAfterUse::NO); + Common::SeekableReadStream *sndStream = new Common::MemoryReadStream(audioRes->data, audioRes->size, DisposeAfterUse::NO); audioSeekStream = Audio::makeMacSndStream(sndStream, DisposeAfterUse::YES); } else { diff --git a/engines/sci/sound/drivers/amigamac.cpp b/engines/sci/sound/drivers/amigamac.cpp index 07c0582124..7cf798a27e 100644 --- a/engines/sci/sound/drivers/amigamac.cpp +++ b/engines/sci/sound/drivers/amigamac.cpp @@ -29,6 +29,7 @@ #include "common/file.h" #include "common/frac.h" +#include "common/memstream.h" #include "common/util.h" namespace Sci { diff --git a/engines/sci/sound/drivers/midi.cpp b/engines/sci/sound/drivers/midi.cpp index a8f20dc0e2..5a096d2be3 100644 --- a/engines/sci/sound/drivers/midi.cpp +++ b/engines/sci/sound/drivers/midi.cpp @@ -27,6 +27,7 @@ #include "common/config-manager.h" #include "common/file.h" +#include "common/memstream.h" #include "sound/fmopl.h" #include "sound/softsynth/emumidi.h" diff --git a/engines/scumm/file.cpp b/engines/scumm/file.cpp index 08feb7ffd5..95b99d22bd 100644 --- a/engines/scumm/file.cpp +++ b/engines/scumm/file.cpp @@ -27,6 +27,8 @@ #include "scumm/scumm.h" +#include "common/substream.h" + namespace Scumm { #pragma mark - diff --git a/engines/scumm/file.h b/engines/scumm/file.h index c37c2f036e..1dcd3cd7a8 100644 --- a/engines/scumm/file.h +++ b/engines/scumm/file.h @@ -27,6 +27,7 @@ #define SCUMM_FILE_H #include "common/file.h" +#include "common/memstream.h" #include "scumm/detection.h" diff --git a/engines/scumm/file_nes.h b/engines/scumm/file_nes.h index 274ec02ed0..df2528c357 100644 --- a/engines/scumm/file_nes.h +++ b/engines/scumm/file_nes.h @@ -27,6 +27,7 @@ #define SCUMM_FILE_NES_H #include "common/file.h" +#include "common/memstream.h" #include "scumm/file.h" diff --git a/engines/scumm/he/cup_player_he.cpp b/engines/scumm/he/cup_player_he.cpp index 87afe5fd90..fedbdbf377 100644 --- a/engines/scumm/he/cup_player_he.cpp +++ b/engines/scumm/he/cup_player_he.cpp @@ -26,6 +26,7 @@ #ifdef ENABLE_HE #include "common/system.h" +#include "common/memstream.h" #include "sound/audiostream.h" #include "sound/mixer.h" #include "sound/decoders/raw.h" diff --git a/engines/scumm/he/resource_he.cpp b/engines/scumm/he/resource_he.cpp index f7a7d3a567..70663b1b33 100644 --- a/engines/scumm/he/resource_he.cpp +++ b/engines/scumm/he/resource_he.cpp @@ -832,7 +832,7 @@ int Win32ResExtractor::convertIcons(byte *data, int datasize, byte **cursor, int uint32 c, d; int completed; int matched = 0; - MemoryReadStream *in = new MemoryReadStream(data, datasize); + Common::MemoryReadStream *in = new Common::MemoryReadStream(data, datasize); if (!in->read(&dir, sizeof(Win32CursorIconFileDir)- sizeof(Win32CursorIconFileDirEntry))) goto cleanup; diff --git a/engines/scumm/he/resource_he.h b/engines/scumm/he/resource_he.h index 65190ea41c..b3f3479406 100644 --- a/engines/scumm/he/resource_he.h +++ b/engines/scumm/he/resource_he.h @@ -147,9 +147,6 @@ public: bool _arg_raw; Common::String _fileName; CachedCursor _cursorCache[MAX_CACHED_CURSORS]; - - typedef Common::MemoryReadStream MemoryReadStream; - }; class Win32ResExtractor : public ResExtractor { diff --git a/engines/scumm/imuse_digi/dimuse_sndmgr.cpp b/engines/scumm/imuse_digi/dimuse_sndmgr.cpp index 24cac8707b..1d4769a7f5 100644 --- a/engines/scumm/imuse_digi/dimuse_sndmgr.cpp +++ b/engines/scumm/imuse_digi/dimuse_sndmgr.cpp @@ -700,7 +700,7 @@ int32 ImuseDigiSndMgr::getDataFromRegion(SoundDesc *soundDesc, int region, byte assert(len); if (!soundDesc->compressedStream) { - Common::MemoryReadStream *tmp = cmpFile->readStream(len); + Common::SeekableReadStream *tmp = cmpFile->readStream(len); assert(tmp); #ifdef USE_FLAC if (soundMode == 3) diff --git a/engines/scumm/saveload.cpp b/engines/scumm/saveload.cpp index 2d5a84900b..7273f9f871 100644 --- a/engines/scumm/saveload.cpp +++ b/engines/scumm/saveload.cpp @@ -24,6 +24,7 @@ */ #include "common/config-manager.h" +#include "common/memstream.h" #include "common/savefile.h" #include "common/system.h" #include "common/zlib.h" diff --git a/engines/scumm/sound.cpp b/engines/scumm/sound.cpp index 380b52031f..ee8825d946 100644 --- a/engines/scumm/sound.cpp +++ b/engines/scumm/sound.cpp @@ -598,7 +598,7 @@ void Sound::startTalkSound(uint32 offset, uint32 b, int mode, Audio::SoundHandle #ifdef USE_MAD { assert(size > 0); - Common::MemoryReadStream *tmp = _sfxFile->readStream(size); + Common::SeekableReadStream *tmp = _sfxFile->readStream(size); assert(tmp); input = Audio::makeMP3Stream(tmp, DisposeAfterUse::YES); } @@ -608,7 +608,7 @@ void Sound::startTalkSound(uint32 offset, uint32 b, int mode, Audio::SoundHandle #ifdef USE_VORBIS { assert(size > 0); - Common::MemoryReadStream *tmp = _sfxFile->readStream(size); + Common::SeekableReadStream *tmp = _sfxFile->readStream(size); assert(tmp); input = Audio::makeVorbisStream(tmp, DisposeAfterUse::YES); } @@ -618,7 +618,7 @@ void Sound::startTalkSound(uint32 offset, uint32 b, int mode, Audio::SoundHandle #ifdef USE_FLAC { assert(size > 0); - Common::MemoryReadStream *tmp = _sfxFile->readStream(size); + Common::SeekableReadStream *tmp = _sfxFile->readStream(size); assert(tmp); input = Audio::makeFLACStream(tmp, DisposeAfterUse::YES); } diff --git a/engines/sword1/sound.cpp b/engines/sword1/sound.cpp index 55600cfb63..92bed1b624 100644 --- a/engines/sword1/sound.cpp +++ b/engines/sword1/sound.cpp @@ -29,6 +29,7 @@ #include "common/util.h" #include "common/events.h" #include "common/EventRecorder.h" +#include "common/memstream.h" #include "common/system.h" #include "sword1/sound.h" @@ -366,7 +367,7 @@ bool Sound::startSpeech(uint16 roomNo, uint16 localNo) { } } else if (_cowMode == CowPSX && sampleSize != 0xffffffff) { _cowFile.seek(index * 2048); - Common::MemoryReadStream *tmp = _cowFile.readStream(sampleSize); + Common::SeekableReadStream *tmp = _cowFile.readStream(sampleSize); assert(tmp); stream = Audio::makeVagStream(tmp); _mixer->playStream(Audio::Mixer::kSpeechSoundType, &_speechHandle, stream, SOUND_SPEECH_ID, speechVol, speechPan); @@ -379,7 +380,7 @@ bool Sound::startSpeech(uint16 roomNo, uint16 localNo) { #ifdef USE_FLAC else if (_cowMode == CowFLAC) { _cowFile.seek(index); - Common::MemoryReadStream *tmp = _cowFile.readStream(sampleSize); + Common::SeekableReadStream *tmp = _cowFile.readStream(sampleSize); assert(tmp); stream = Audio::makeFLACStream(tmp, DisposeAfterUse::YES); _mixer->playStream(Audio::Mixer::kSpeechSoundType, &_speechHandle, stream, SOUND_SPEECH_ID, speechVol, speechPan); @@ -393,7 +394,7 @@ bool Sound::startSpeech(uint16 roomNo, uint16 localNo) { #ifdef USE_VORBIS else if (_cowMode == CowVorbis) { _cowFile.seek(index); - Common::MemoryReadStream *tmp = _cowFile.readStream(sampleSize); + Common::SeekableReadStream *tmp = _cowFile.readStream(sampleSize); assert(tmp); stream = Audio::makeVorbisStream(tmp, DisposeAfterUse::YES); _mixer->playStream(Audio::Mixer::kSpeechSoundType, &_speechHandle, stream, SOUND_SPEECH_ID, speechVol, speechPan); @@ -407,7 +408,7 @@ bool Sound::startSpeech(uint16 roomNo, uint16 localNo) { #ifdef USE_MAD else if (_cowMode == CowMP3) { _cowFile.seek(index); - Common::MemoryReadStream *tmp = _cowFile.readStream(sampleSize); + Common::SeekableReadStream *tmp = _cowFile.readStream(sampleSize); assert(tmp); stream = Audio::makeMP3Stream(tmp, DisposeAfterUse::YES); _mixer->playStream(Audio::Mixer::kSpeechSoundType, &_speechHandle, stream, SOUND_SPEECH_ID, speechVol, speechPan); diff --git a/engines/sword2/console.cpp b/engines/sword2/console.cpp index 20fd79bc38..6f4665a34c 100644 --- a/engines/sword2/console.cpp +++ b/engines/sword2/console.cpp @@ -26,6 +26,7 @@ */ +#include "common/memstream.h" #include "common/rect.h" #include "common/system.h" diff --git a/engines/sword2/header.cpp b/engines/sword2/header.cpp new file mode 100644 index 0000000000..c930b0c8e7 --- /dev/null +++ b/engines/sword2/header.cpp @@ -0,0 +1,293 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +#include "sword2/header.h" +#include "sword2/screen.h" +#include "sword2/sword2.h" + +#include "common/memstream.h" +#include "common/endian.h" + +namespace Sword2 { + +void ResHeader::read(byte *addr) { + Common::MemoryReadStream readS(addr, size()); + + fileType = readS.readByte(); + compType = readS.readByte(); + compSize = readS.readUint32LE(); + decompSize = readS.readUint32LE(); + readS.read(name, NAME_LEN); +} + +void ResHeader::write(byte *addr) { + Common::MemoryWriteStream writeS(addr, size()); + + writeS.writeByte(fileType); + writeS.writeByte(compType); + writeS.writeUint32LE(compSize); + writeS.writeUint32LE(decompSize); + writeS.write(name, NAME_LEN); +} + +void AnimHeader::read(byte *addr) { + Common::MemoryReadStream readS(addr, size()); + + if (Sword2Engine::isPsx()) { + noAnimFrames = readS.readUint16LE(); + feetStartX = readS.readUint16LE(); + feetStartY = readS.readUint16LE(); + feetEndX = readS.readUint16LE(); + feetEndY = readS.readUint16LE(); + blend = readS.readUint16LE(); + runTimeComp = readS.readByte(); + feetStartDir = readS.readByte(); + feetEndDir = readS.readByte(); + } else { + runTimeComp = readS.readByte(); + noAnimFrames = readS.readUint16LE(); + feetStartX = readS.readUint16LE(); + feetStartY = readS.readUint16LE(); + feetStartDir = readS.readByte(); + feetEndX = readS.readUint16LE(); + feetEndY = readS.readUint16LE(); + feetEndDir = readS.readByte(); + blend = readS.readUint16LE(); + } +} + +void AnimHeader::write(byte *addr) { + Common::MemoryWriteStream writeS(addr, size()); + + writeS.writeByte(runTimeComp); + writeS.writeUint16LE(noAnimFrames); + writeS.writeUint16LE(feetStartX); + writeS.writeUint16LE(feetStartY); + writeS.writeByte(feetStartDir); + writeS.writeUint16LE(feetEndX); + writeS.writeUint16LE(feetEndY); + writeS.writeByte(feetEndDir); + writeS.writeUint16LE(blend); +} + +int CdtEntry::size() { + if (Sword2Engine::isPsx()) + return 12; + else + return 9; +} + +void CdtEntry::read(byte *addr) { + Common::MemoryReadStream readS(addr, size()); + + if (Sword2Engine::isPsx()) { + readS.readByte(); // Skip a byte in psx version + x = readS.readUint16LE(); + y = readS.readUint16LE(); + frameOffset = readS.readUint32LE(); + frameType = readS.readByte(); + } else { + x = readS.readUint16LE(); + y = readS.readUint16LE(); + frameOffset = readS.readUint32LE(); + frameType = readS.readByte(); + } +} + +void CdtEntry::write(byte *addr) { + Common::MemoryWriteStream writeS(addr, size()); + + writeS.writeUint16LE(x); + writeS.writeUint16LE(y); + writeS.writeUint32LE(frameOffset); + writeS.writeByte(frameType); +} + +void FrameHeader::read(byte *addr) { + Common::MemoryReadStream readS(addr, size()); + + compSize = readS.readUint32LE(); + width = readS.readUint16LE(); + height = readS.readUint16LE(); + + if (Sword2Engine::isPsx()) { // In PSX version, frames are half height + height *= 2; + width = (width % 2) ? width + 1 : width; + } +} + +void FrameHeader::write(byte *addr) { + Common::MemoryWriteStream writeS(addr, size()); + + writeS.writeUint32LE(compSize); + writeS.writeUint16LE(width); + writeS.writeUint16LE(height); +} + +void MultiScreenHeader::read(byte *addr) { + Common::MemoryReadStream readS(addr, size()); + + palette = readS.readUint32LE(); + bg_parallax[0] = readS.readUint32LE(); + bg_parallax[1] = readS.readUint32LE(); + screen = readS.readUint32LE(); + fg_parallax[0] = readS.readUint32LE(); + fg_parallax[1] = readS.readUint32LE(); + layers = readS.readUint32LE(); + paletteTable = readS.readUint32LE(); + maskOffset = readS.readUint32LE(); +} + +void MultiScreenHeader::write(byte *addr) { + Common::MemoryWriteStream writeS(addr, size()); + + writeS.writeUint32LE(palette); + writeS.writeUint32LE(bg_parallax[0]); + writeS.writeUint32LE(bg_parallax[1]); + writeS.writeUint32LE(screen); + writeS.writeUint32LE(fg_parallax[0]); + writeS.writeUint32LE(fg_parallax[1]); + writeS.writeUint32LE(layers); + writeS.writeUint32LE(paletteTable); + writeS.writeUint32LE(maskOffset); +} + +void ScreenHeader::read(byte *addr) { + Common::MemoryReadStream readS(addr, size()); + + width = readS.readUint16LE(); + height = readS.readUint16LE(); + noLayers = readS.readUint16LE(); +} + +void ScreenHeader::write(byte *addr) { + Common::MemoryWriteStream writeS(addr, size()); + + writeS.writeUint16LE(width); + writeS.writeUint16LE(height); + writeS.writeUint16LE(noLayers); +} + +void LayerHeader::read(byte *addr) { + Common::MemoryReadStream readS(addr, size()); + + x = readS.readUint16LE(); + y = readS.readUint16LE(); + width = readS.readUint16LE(); + height = readS.readUint16LE(); + maskSize = readS.readUint32LE(); + offset = readS.readUint32LE(); +} + +void LayerHeader::write(byte *addr) { + Common::MemoryWriteStream writeS(addr, size()); + + writeS.writeUint16LE(x); + writeS.writeUint16LE(y); + writeS.writeUint16LE(width); + writeS.writeUint16LE(height); + writeS.writeUint32LE(maskSize); + writeS.writeUint32LE(offset); +} + +void TextHeader::read(byte *addr) { + Common::MemoryReadStream readS(addr, size()); + + noOfLines = readS.readUint32LE(); +} + +void TextHeader::write(byte *addr) { + Common::MemoryWriteStream writeS(addr, size()); + + writeS.writeUint32LE(noOfLines); +} + +void PSXScreensEntry::read(byte *addr) { + Common::MemoryReadStream readS(addr, size()); + + bgPlxXres = readS.readUint16LE(); + bgPlxYres = readS.readUint16LE(); + bgPlxOffset = readS.readUint32LE(); + bgPlxSize = readS.readUint32LE(); + bgXres = readS.readUint16LE(); + bgYres = readS.readUint16LE(); + bgOffset = readS.readUint32LE(); + bgSize = readS.readUint32LE(); + fgPlxXres = readS.readUint16LE(); + fgPlxYres = readS.readUint16LE(); + fgPlxOffset = readS.readUint32LE(); + fgPlxSize = readS.readUint32LE(); +} + +void PSXScreensEntry::write(byte *addr) { + Common::MemoryWriteStream writeS(addr, size()); + + writeS.writeUint16LE(bgPlxXres); + writeS.writeUint16LE(bgPlxYres); + writeS.writeUint32LE(bgPlxOffset); + writeS.writeUint32LE(bgPlxSize); + writeS.writeUint16LE(bgXres); + writeS.writeUint16LE(bgYres); + writeS.writeUint32LE(bgOffset); + writeS.writeUint32LE(bgSize); + writeS.writeUint16LE(fgPlxXres); + writeS.writeUint16LE(fgPlxYres); + writeS.writeUint32LE(fgPlxOffset); + writeS.writeUint32LE(fgPlxSize); +} + +void PSXFontEntry::read(byte *addr) { + Common::MemoryReadStream readS(addr, size()); + + offset = readS.readUint16LE() / 2; + skipLines = readS.readUint16LE(); + charWidth = readS.readUint16LE() / 2; + charHeight = readS.readUint16LE(); +} + +void PSXFontEntry::write(byte *addr) { + Common::MemoryWriteStream writeS(addr, size()); + + writeS.writeUint16LE(offset); + writeS.writeUint16LE(skipLines); + writeS.writeUint16LE(charWidth); + writeS.writeUint16LE(charHeight); +} + +void Parallax::read(byte *addr) { + Common::MemoryReadStream readS(addr, size()); + + w = readS.readUint16LE(); + h = readS.readUint16LE(); +} + +void Parallax::write(byte *addr) { + Common::MemoryWriteStream writeS(addr, size()); + + writeS.writeUint16LE(w); + writeS.writeUint16LE(h); +} + +} // End of namespace Sword2 diff --git a/engines/sword2/header.h b/engines/sword2/header.h index 67cbba35af..3f64152bb9 100644 --- a/engines/sword2/header.h +++ b/engines/sword2/header.h @@ -28,7 +28,6 @@ #ifndef SWORD2_HEADER_H #define SWORD2_HEADER_H -#include "common/stream.h" #include "common/endian.h" namespace Sword2 { @@ -60,25 +59,8 @@ struct ResHeader { return 44; } - void read(byte *addr) { - Common::MemoryReadStream readS(addr, size()); - - fileType = readS.readByte(); - compType = readS.readByte(); - compSize = readS.readUint32LE(); - decompSize = readS.readUint32LE(); - readS.read(name, NAME_LEN); - } - - void write(byte *addr) { - Common::MemoryWriteStream writeS(addr, size()); - - writeS.writeByte(fileType); - writeS.writeByte(compType); - writeS.writeUint32LE(compSize); - writeS.writeUint32LE(decompSize); - writeS.write(name, NAME_LEN); - } + void read(byte *addr); + void write(byte *addr); }; // fileType @@ -156,45 +138,8 @@ struct AnimHeader { return 15; } - void read(byte *addr) { - Common::MemoryReadStream readS(addr, size()); - - if (Sword2Engine::isPsx()) { - noAnimFrames = readS.readUint16LE(); - feetStartX = readS.readUint16LE(); - feetStartY = readS.readUint16LE(); - feetEndX = readS.readUint16LE(); - feetEndY = readS.readUint16LE(); - blend = readS.readUint16LE(); - runTimeComp = readS.readByte(); - feetStartDir = readS.readByte(); - feetEndDir = readS.readByte(); - } else { - runTimeComp = readS.readByte(); - noAnimFrames = readS.readUint16LE(); - feetStartX = readS.readUint16LE(); - feetStartY = readS.readUint16LE(); - feetStartDir = readS.readByte(); - feetEndX = readS.readUint16LE(); - feetEndY = readS.readUint16LE(); - feetEndDir = readS.readByte(); - blend = readS.readUint16LE(); - } - } - - void write(byte *addr) { - Common::MemoryWriteStream writeS(addr, size()); - - writeS.writeByte(runTimeComp); - writeS.writeUint16LE(noAnimFrames); - writeS.writeUint16LE(feetStartX); - writeS.writeUint16LE(feetStartY); - writeS.writeByte(feetStartDir); - writeS.writeUint16LE(feetEndX); - writeS.writeUint16LE(feetEndY); - writeS.writeByte(feetEndDir); - writeS.writeUint16LE(blend); - } + void read(byte *addr); + void write(byte *addr); }; @@ -221,38 +166,10 @@ struct CdtEntry { uint8 frameType; // 0 = print sprite normally with top-left // corner at (x,y), otherwise see below... - static int size() { - if (Sword2Engine::isPsx()) - return 12; - else - return 9; - } - - void read(byte *addr) { - Common::MemoryReadStream readS(addr, size()); - - if (Sword2Engine::isPsx()) { - readS.readByte(); // Skip a byte in psx version - x = readS.readUint16LE(); - y = readS.readUint16LE(); - frameOffset = readS.readUint32LE(); - frameType = readS.readByte(); - } else { - x = readS.readUint16LE(); - y = readS.readUint16LE(); - frameOffset = readS.readUint32LE(); - frameType = readS.readByte(); - } - } + static int size(); - void write(byte *addr) { - Common::MemoryWriteStream writeS(addr, size()); - - writeS.writeUint16LE(x); - writeS.writeUint16LE(y); - writeS.writeUint32LE(frameOffset); - writeS.writeByte(frameType); - } + void read(byte *addr); + void write(byte *addr); }; // 'frameType' bit values @@ -277,26 +194,8 @@ struct FrameHeader { return 8; } - void read(byte *addr) { - Common::MemoryReadStream readS(addr, size()); - - compSize = readS.readUint32LE(); - width = readS.readUint16LE(); - height = readS.readUint16LE(); - - if (Sword2Engine::isPsx()) { // In PSX version, frames are half height - height *= 2; - width = (width % 2) ? width + 1 : width; - } - } - - void write(byte *addr) { - Common::MemoryWriteStream writeS(addr, size()); - - writeS.writeUint32LE(compSize); - writeS.writeUint16LE(width); - writeS.writeUint16LE(height); - } + void read(byte *addr); + void write(byte *addr); }; //---------------------------------------------------------- @@ -331,33 +230,8 @@ struct MultiScreenHeader { return 36; } - void read(byte *addr) { - Common::MemoryReadStream readS(addr, size()); - - palette = readS.readUint32LE(); - bg_parallax[0] = readS.readUint32LE(); - bg_parallax[1] = readS.readUint32LE(); - screen = readS.readUint32LE(); - fg_parallax[0] = readS.readUint32LE(); - fg_parallax[1] = readS.readUint32LE(); - layers = readS.readUint32LE(); - paletteTable = readS.readUint32LE(); - maskOffset = readS.readUint32LE(); - } - - void write(byte *addr) { - Common::MemoryWriteStream writeS(addr, size()); - - writeS.writeUint32LE(palette); - writeS.writeUint32LE(bg_parallax[0]); - writeS.writeUint32LE(bg_parallax[1]); - writeS.writeUint32LE(screen); - writeS.writeUint32LE(fg_parallax[0]); - writeS.writeUint32LE(fg_parallax[1]); - writeS.writeUint32LE(layers); - writeS.writeUint32LE(paletteTable); - writeS.writeUint32LE(maskOffset); - } + void read(byte *addr); + void write(byte *addr); }; // Screen Header @@ -371,21 +245,8 @@ struct ScreenHeader { return 6; } - void read(byte *addr) { - Common::MemoryReadStream readS(addr, size()); - - width = readS.readUint16LE(); - height = readS.readUint16LE(); - noLayers = readS.readUint16LE(); - } - - void write(byte *addr) { - Common::MemoryWriteStream writeS(addr, size()); - - writeS.writeUint16LE(width); - writeS.writeUint16LE(height); - writeS.writeUint16LE(noLayers); - } + void read(byte *addr); + void write(byte *addr); }; // Layer Header @@ -406,27 +267,8 @@ struct LayerHeader { return 16; } - void read(byte *addr) { - Common::MemoryReadStream readS(addr, size()); - - x = readS.readUint16LE(); - y = readS.readUint16LE(); - width = readS.readUint16LE(); - height = readS.readUint16LE(); - maskSize = readS.readUint32LE(); - offset = readS.readUint32LE(); - } - - void write(byte *addr) { - Common::MemoryWriteStream writeS(addr, size()); - - writeS.writeUint16LE(x); - writeS.writeUint16LE(y); - writeS.writeUint16LE(width); - writeS.writeUint16LE(height); - writeS.writeUint32LE(maskSize); - writeS.writeUint32LE(offset); - } + void read(byte *addr); + void write(byte *addr); }; //---------------------------------------------------------- @@ -511,17 +353,8 @@ struct TextHeader { return 4; } - void read(byte *addr) { - Common::MemoryReadStream readS(addr, size()); - - noOfLines = readS.readUint32LE(); - } - - void write(byte *addr) { - Common::MemoryWriteStream writeS(addr, size()); - - writeS.writeUint32LE(noOfLines); - } + void read(byte *addr); + void write(byte *addr); }; // a text file has: @@ -567,39 +400,8 @@ struct PSXScreensEntry { return 36; } - void read(byte *addr) { - Common::MemoryReadStream readS(addr, size()); - - bgPlxXres = readS.readUint16LE(); - bgPlxYres = readS.readUint16LE(); - bgPlxOffset = readS.readUint32LE(); - bgPlxSize = readS.readUint32LE(); - bgXres = readS.readUint16LE(); - bgYres = readS.readUint16LE(); - bgOffset = readS.readUint32LE(); - bgSize = readS.readUint32LE(); - fgPlxXres = readS.readUint16LE(); - fgPlxYres = readS.readUint16LE(); - fgPlxOffset = readS.readUint32LE(); - fgPlxSize = readS.readUint32LE(); - } - - void write(byte *addr) { - Common::MemoryWriteStream writeS(addr, size()); - - writeS.writeUint16LE(bgPlxXres); - writeS.writeUint16LE(bgPlxYres); - writeS.writeUint32LE(bgPlxOffset); - writeS.writeUint32LE(bgPlxSize); - writeS.writeUint16LE(bgXres); - writeS.writeUint16LE(bgYres); - writeS.writeUint32LE(bgOffset); - writeS.writeUint32LE(bgSize); - writeS.writeUint16LE(fgPlxXres); - writeS.writeUint16LE(fgPlxYres); - writeS.writeUint32LE(fgPlxOffset); - writeS.writeUint32LE(fgPlxSize); - } + void read(byte *addr); + void write(byte *addr); }; // PSXFontEntry is present in font resource file, it is used @@ -615,23 +417,8 @@ struct PSXFontEntry { return 8; } - void read(byte *addr) { - Common::MemoryReadStream readS(addr, size()); - - offset = readS.readUint16LE() / 2; - skipLines = readS.readUint16LE(); - charWidth = readS.readUint16LE() / 2; - charHeight = readS.readUint16LE(); - } - - void write(byte *addr) { - Common::MemoryWriteStream writeS(addr, size()); - - writeS.writeUint16LE(offset); - writeS.writeUint16LE(skipLines); - writeS.writeUint16LE(charWidth); - writeS.writeUint16LE(charHeight); - } + void read(byte *addr); + void write(byte *addr); }; } // End of namespace Sword2 diff --git a/engines/sword2/icons.cpp b/engines/sword2/icons.cpp index 4652fc0bc1..b115eb373b 100644 --- a/engines/sword2/icons.cpp +++ b/engines/sword2/icons.cpp @@ -26,7 +26,7 @@ */ -#include "common/stream.h" +#include "common/memstream.h" #include "common/rect.h" #include "sword2/sword2.h" diff --git a/engines/sword2/module.mk b/engines/sword2/module.mk index c675b9561e..bf586aefff 100644 --- a/engines/sword2/module.mk +++ b/engines/sword2/module.mk @@ -8,6 +8,7 @@ MODULE_OBJS := \ debug.o \ events.o \ function.o \ + header.o \ icons.o \ interpreter.o \ layers.o \ diff --git a/engines/sword2/music.cpp b/engines/sword2/music.cpp index 89073fef8e..1519c5d73f 100644 --- a/engines/sword2/music.cpp +++ b/engines/sword2/music.cpp @@ -33,6 +33,8 @@ #include "common/file.h" +#include "common/memstream.h" +#include "common/substream.h" #include "common/system.h" #include "sound/decoders/mp3.h" diff --git a/engines/sword2/object.h b/engines/sword2/object.h index b6b6ca5174..98c9f6863b 100644 --- a/engines/sword2/object.h +++ b/engines/sword2/object.h @@ -28,7 +28,7 @@ #ifndef SWORD2_OBJECT_H #define SWORD2_OBJECT_H -#include "common/stream.h" +#include "common/memstream.h" #include "common/endian.h" namespace Sword2 { diff --git a/engines/sword2/screen.h b/engines/sword2/screen.h index afad64011d..0abaebc5af 100644 --- a/engines/sword2/screen.h +++ b/engines/sword2/screen.h @@ -192,19 +192,8 @@ struct Parallax { return 4; } - void read(byte *addr) { - Common::MemoryReadStream readS(addr, size()); - - w = readS.readUint16LE(); - h = readS.readUint16LE(); - } - - void write(byte *addr) { - Common::MemoryWriteStream writeS(addr, size()); - - writeS.writeUint16LE(w); - writeS.writeUint16LE(h); - } + void read(byte *addr); + void write(byte *addr); }; class Screen { diff --git a/engines/sword2/sound.cpp b/engines/sword2/sound.cpp index b1d0dee81b..abacbd16f0 100644 --- a/engines/sword2/sound.cpp +++ b/engines/sword2/sound.cpp @@ -37,6 +37,7 @@ #include "common/file.h" +#include "common/memstream.h" #include "common/system.h" #include "sword2/sword2.h" diff --git a/engines/sword25/gfx/graphicengine.h b/engines/sword25/gfx/graphicengine.h index 3f3e111f74..ccfa2ed363 100644 --- a/engines/sword25/gfx/graphicengine.h +++ b/engines/sword25/gfx/graphicengine.h @@ -281,8 +281,8 @@ public: Graphics::Surface _frameBuffer; Graphics::Surface *getFrameBuffer() { return &_frameBuffer; } - Common::MemoryReadStream *_thumbnail; - Common::MemoryReadStream *getThumbnail() { return _thumbnail; } + Common::SeekableReadStream *_thumbnail; + Common::SeekableReadStream *getThumbnail() { return _thumbnail; } // Access methods diff --git a/engines/sword25/gfx/image/pngloader.cpp b/engines/sword25/gfx/image/pngloader.cpp index 1b72595a8f..581d5fd917 100644 --- a/engines/sword25/gfx/image/pngloader.cpp +++ b/engines/sword25/gfx/image/pngloader.cpp @@ -35,6 +35,7 @@ // Disable symbol overrides so that we can use png.h #define FORBIDDEN_SYMBOL_ALLOW_ALL +#include "common/memstream.h" #include "sword25/gfx/image/image.h" #include "sword25/gfx/image/pngloader.h" #include <png.h> diff --git a/engines/sword25/gfx/screenshot.cpp b/engines/sword25/gfx/screenshot.cpp index 3dc88237f9..b7bb31c8e4 100644 --- a/engines/sword25/gfx/screenshot.cpp +++ b/engines/sword25/gfx/screenshot.cpp @@ -37,8 +37,7 @@ #define BS_LOG_PREFIX "SCREENSHOT" -#include "common/system.h" -#include "common/savefile.h" +#include "common/memstream.h" #include "sword25/gfx/screenshot.h" #include "sword25/kernel/filesystemutil.h" #include <png.h> @@ -123,7 +122,7 @@ bool Screenshot::saveToFile(Graphics::Surface *data, Common::WriteStream *stream // ----------------------------------------------------------------------------- -Common::MemoryReadStream *Screenshot::createThumbnail(Graphics::Surface *data) { +Common::SeekableReadStream *Screenshot::createThumbnail(Graphics::Surface *data) { // This method takes a screen image with a dimension of 800x600, and creates a screenshot with a dimension of 200x125. // First 50 pixels are cut off the top and bottom (the interface boards in the game). The remaining image of 800x500 // will be on a 16th of its size, reduced by being handed out in 4x4 pixel blocks and the average of each block @@ -177,7 +176,7 @@ Common::MemoryReadStream *Screenshot::createThumbnail(Graphics::Surface *data) { saveToFile(&thumbnail, stream); // Output a MemoryReadStream that encompasses the written data - Common::MemoryReadStream *result = new Common::MemoryReadStream(stream->getData(), stream->size(), + Common::SeekableReadStream *result = new Common::MemoryReadStream(stream->getData(), stream->size(), DisposeAfterUse::YES); return result; } diff --git a/engines/sword25/gfx/screenshot.h b/engines/sword25/gfx/screenshot.h index eefaa1bca6..a0f615f9e6 100644 --- a/engines/sword25/gfx/screenshot.h +++ b/engines/sword25/gfx/screenshot.h @@ -43,7 +43,7 @@ namespace Sword25 { class Screenshot { public: static bool saveToFile(Graphics::Surface *data, Common::WriteStream *stream); - static Common::MemoryReadStream *createThumbnail(Graphics::Surface *data); + static Common::SeekableReadStream *createThumbnail(Graphics::Surface *data); }; } // End of namespace Sword25 diff --git a/engines/sword25/kernel/persistenceservice.cpp b/engines/sword25/kernel/persistenceservice.cpp index 564f031cf3..0508f2be8f 100644 --- a/engines/sword25/kernel/persistenceservice.cpp +++ b/engines/sword25/kernel/persistenceservice.cpp @@ -316,7 +316,7 @@ bool PersistenceService::saveGame(uint slotID, const Common::String &screenshotF } // Get the screenshot - Common::MemoryReadStream *thumbnail = Kernel::getInstance()->getGfx()->getThumbnail(); + Common::SeekableReadStream *thumbnail = Kernel::getInstance()->getGfx()->getThumbnail(); if (thumbnail) { byte *buffer = new Byte[FILE_COPY_BUFFER_SIZE]; diff --git a/engines/teenagent/inventory.cpp b/engines/teenagent/inventory.cpp index 47267dabf0..16a5f20ee6 100644 --- a/engines/teenagent/inventory.cpp +++ b/engines/teenagent/inventory.cpp @@ -22,7 +22,7 @@ * $Id$ */ -#include "common/stream.h" +#include "common/memstream.h" #include "common/ptr.h" #include "teenagent/inventory.h" diff --git a/engines/teenagent/objects.cpp b/engines/teenagent/objects.cpp index f8df4fee77..e6442d3809 100644 --- a/engines/teenagent/objects.cpp +++ b/engines/teenagent/objects.cpp @@ -23,7 +23,7 @@ */ #include "common/debug.h" -#include "common/stream.h" +#include "common/memstream.h" #include "teenagent/objects.h" #include "teenagent/resources.h" diff --git a/engines/teenagent/pack.cpp b/engines/teenagent/pack.cpp index e3b7a33960..8584e05807 100644 --- a/engines/teenagent/pack.cpp +++ b/engines/teenagent/pack.cpp @@ -25,6 +25,8 @@ #include "teenagent/pack.h" #include "common/util.h" #include "common/debug.h" +#include "common/memstream.h" +#include "common/substream.h" namespace TeenAgent { diff --git a/engines/testbed/midi.cpp b/engines/testbed/midi.cpp index 0ec2678d47..499c44e50a 100644 --- a/engines/testbed/midi.cpp +++ b/engines/testbed/midi.cpp @@ -24,6 +24,7 @@ #include "common/archive.h" #include "common/events.h" +#include "common/memstream.h" #include "graphics/cursorman.h" @@ -34,7 +35,7 @@ namespace Testbed { -bool MidiTests::loadMusicInMemory(Common::MemoryWriteStreamDynamic *ws) { +bool MidiTests::loadMusicInMemory(Common::WriteStream *ws) { Common::SeekableReadStream *midiFile = SearchMan.createReadStreamForMember("music.mid"); if (!midiFile) { Testsuite::logPrintf("Error! Can't open Midi music file, check game data directory for file music.mid\n"); diff --git a/engines/testbed/midi.h b/engines/testbed/midi.h index c73d937834..0fb5cf80d5 100644 --- a/engines/testbed/midi.h +++ b/engines/testbed/midi.h @@ -36,7 +36,7 @@ namespace Testbed { namespace MidiTests { // Helper functions for MIDI tests -bool loadMusicInMemory(Common::MemoryWriteStreamDynamic *ws); +bool loadMusicInMemory(Common::WriteStream *ws); void waitForMusicToPlay(MidiParser *parser); // will contain function declarations for MIDI tests diff --git a/engines/tinsel/music.cpp b/engines/tinsel/music.cpp index c20b456711..ad09631260 100644 --- a/engines/tinsel/music.cpp +++ b/engines/tinsel/music.cpp @@ -36,6 +36,7 @@ #include "common/config-manager.h" #include "common/file.h" +#include "common/memstream.h" #include "tinsel/config.h" #include "tinsel/sound.h" @@ -835,7 +836,7 @@ bool PCMMusicPlayer::getNextChunk() { uint32 sampleOffset, sampleLength, sampleCLength; Common::File file; byte *buffer; - Common::MemoryReadStream *sampleStream; + Common::SeekableReadStream *sampleStream; switch (_state) { case S_NEW: diff --git a/engines/tinsel/sound.cpp b/engines/tinsel/sound.cpp index 0a32ab143f..0624409f92 100644 --- a/engines/tinsel/sound.cpp +++ b/engines/tinsel/sound.cpp @@ -37,6 +37,7 @@ #include "common/config-manager.h" #include "common/endian.h" #include "common/file.h" +#include "common/memstream.h" #include "common/system.h" #include "sound/mixer.h" diff --git a/engines/toon/audio.cpp b/engines/toon/audio.cpp index c83375f610..d0e9b168ae 100644 --- a/engines/toon/audio.cpp +++ b/engines/toon/audio.cpp @@ -24,6 +24,8 @@ */ #include "toon/audio.h" +#include "common/memstream.h" +#include "common/substream.h" namespace Toon { diff --git a/engines/toon/resource.cpp b/engines/toon/resource.cpp index 3f879df781..61e3ffb111 100644 --- a/engines/toon/resource.cpp +++ b/engines/toon/resource.cpp @@ -25,6 +25,8 @@ #include "toon/resource.h" #include "common/file.h" +#include "common/memstream.h" +#include "common/substream.h" #include "toon/toon.h" diff --git a/engines/toon/toon.cpp b/engines/toon/toon.cpp index d86beadcd1..61b6e1bfe3 100644 --- a/engines/toon/toon.cpp +++ b/engines/toon/toon.cpp @@ -30,6 +30,8 @@ #include "common/config-manager.h" #include "common/EventRecorder.h" #include "common/savefile.h" +#include "common/memstream.h" + #include "engines/util.h" #include "graphics/surface.h" #include "graphics/thumbnail.h" @@ -1799,6 +1801,10 @@ void ToonEngine::drawInfoLine() { } } +Common::WriteStream *ToonEngine::getSaveBufferStream() { + return _saveBufferStream; +} + const char *ToonEngine::getLocationString(int32 locationId, bool alreadyVisited) { if (alreadyVisited) return _locationDirVisited[locationId]; diff --git a/engines/toon/toon.h b/engines/toon/toon.h index 920ec080aa..05b2bac47c 100644 --- a/engines/toon/toon.h +++ b/engines/toon/toon.h @@ -43,6 +43,10 @@ #include "toon/audio.h" #include "toon/console.h" +namespace Common { +class MemoryWriteStreamDynamic; +} + #define TOON_DAT_VER_MAJ 0 // 1 byte #define TOON_DAT_VER_MIN 3 // 1 byte #define TOON_SAVEGAME_VERSION 4 @@ -308,9 +312,7 @@ public: return _pathFinding; } - Common::WriteStream *getSaveBufferStream() { - return _saveBufferStream; - } + Common::WriteStream *getSaveBufferStream(); bool shouldQuitGame() const { return _shouldQuit; diff --git a/engines/touche/resource.cpp b/engines/touche/resource.cpp index 8a810f09d8..f76084d556 100644 --- a/engines/touche/resource.cpp +++ b/engines/touche/resource.cpp @@ -666,7 +666,7 @@ void ToucheEngine::res_loadSpeechSegment(int num) { return; } _fSpeech[0].seek(offs); - Common::MemoryReadStream *tmp = _fSpeech[0].readStream(size); + Common::SeekableReadStream *tmp = _fSpeech[0].readStream(size); if (tmp) stream = (compressedSpeechFilesTable[_compressedSpeechData].makeStream)(tmp, DisposeAfterUse::YES); } diff --git a/engines/tucker/resource.cpp b/engines/tucker/resource.cpp index 025721e5fc..1d1daf5adc 100644 --- a/engines/tucker/resource.cpp +++ b/engines/tucker/resource.cpp @@ -268,7 +268,7 @@ Audio::RewindableAudioStream *CompressedSound::load(CompressedSoundType type, in int soundSize = _fCompressedSound.readUint32LE(); if (soundSize != 0) { _fCompressedSound.seek(dirOffset + dirSize * 8 + soundOffset); - Common::MemoryReadStream *tmp = _fCompressedSound.readStream(soundSize); + Common::SeekableReadStream *tmp = _fCompressedSound.readStream(soundSize); if (tmp) { stream = (compressedSoundFilesTable[_compressedSoundType].makeStream)(tmp, DisposeAfterUse::YES); } diff --git a/graphics/pict.cpp b/graphics/pict.cpp index ebf643439b..8525897d4c 100644 --- a/graphics/pict.cpp +++ b/graphics/pict.cpp @@ -23,7 +23,7 @@ * */ -#include "common/stream.h" +#include "common/substream.h" #include "graphics/conversion.h" #include "graphics/jpeg.h" diff --git a/graphics/video/coktel_decoder.cpp b/graphics/video/coktel_decoder.cpp index 0247630579..394e96d7ac 100644 --- a/graphics/video/coktel_decoder.cpp +++ b/graphics/video/coktel_decoder.cpp @@ -31,7 +31,7 @@ #include "sound/audiostream.h" #include "sound/decoders/raw.h" -#include "common/stream.h" +#include "common/memstream.h" static const uint32 kVideoCodecIndeo3 = MKID_BE('iv32'); diff --git a/graphics/video/qt_decoder.cpp b/graphics/video/qt_decoder.cpp index f4ecf551d6..879e4d076e 100644 --- a/graphics/video/qt_decoder.cpp +++ b/graphics/video/qt_decoder.cpp @@ -36,6 +36,7 @@ #include "common/debug.h" #include "common/endian.h" #include "common/macresman.h" +#include "common/memstream.h" #include "common/util.h" #include "common/zlib.h" diff --git a/sound/decoders/raw.cpp b/sound/decoders/raw.cpp index 2259cd315c..aedddbf6c4 100644 --- a/sound/decoders/raw.cpp +++ b/sound/decoders/raw.cpp @@ -24,7 +24,7 @@ */ #include "common/endian.h" -#include "common/stream.h" +#include "common/memstream.h" #include "sound/audiostream.h" #include "sound/mixer.h" diff --git a/sound/mods/infogrames.cpp b/sound/mods/infogrames.cpp index c2631dc079..048872d4a0 100644 --- a/sound/mods/infogrames.cpp +++ b/sound/mods/infogrames.cpp @@ -26,6 +26,7 @@ #include "sound/mods/infogrames.h" #include "common/endian.h" #include "common/file.h" +#include "common/memstream.h" namespace Audio { diff --git a/test/common/bufferedreadstream.h b/test/common/bufferedreadstream.h index 4238c1b42e..c10fbf4b1d 100644 --- a/test/common/bufferedreadstream.h +++ b/test/common/bufferedreadstream.h @@ -1,6 +1,7 @@ #include <cxxtest/TestSuite.h> -#include "common/stream.h" +#include "common/memstream.h" +#include "common/bufferedstream.h" class BufferedReadStreamTestSuite : public CxxTest::TestSuite { public: diff --git a/test/common/bufferedseekablereadstream.h b/test/common/bufferedseekablereadstream.h index d9b8e2f6a0..11eb58f3d0 100644 --- a/test/common/bufferedseekablereadstream.h +++ b/test/common/bufferedseekablereadstream.h @@ -1,6 +1,7 @@ #include <cxxtest/TestSuite.h> -#include "common/stream.h" +#include "common/memstream.h" +#include "common/bufferedstream.h" class BufferedSeekableReadStreamTestSuite : public CxxTest::TestSuite { public: diff --git a/test/common/memoryreadstream.h b/test/common/memoryreadstream.h index dab9b34e0c..f7a144d730 100644 --- a/test/common/memoryreadstream.h +++ b/test/common/memoryreadstream.h @@ -1,6 +1,6 @@ #include <cxxtest/TestSuite.h> -#include "common/stream.h" +#include "common/memstream.h" class MemoryReadStreamTestSuite : public CxxTest::TestSuite { public: diff --git a/test/common/seekablesubreadstream.h b/test/common/seekablesubreadstream.h index b6e584e510..0a7f93ca5e 100644 --- a/test/common/seekablesubreadstream.h +++ b/test/common/seekablesubreadstream.h @@ -1,6 +1,7 @@ #include <cxxtest/TestSuite.h> -#include "common/stream.h" +#include "common/memstream.h" +#include "common/substream.h" class SeekableSubReadStreamTestSuite : public CxxTest::TestSuite { public: diff --git a/test/common/stream.h b/test/common/stream.h index 8f989009cd..2bd0599acc 100644 --- a/test/common/stream.h +++ b/test/common/stream.h @@ -1,6 +1,6 @@ #include <cxxtest/TestSuite.h> -#include "common/stream.h" +#include "common/memstream.h" class ReadLineStreamTestSuite : public CxxTest::TestSuite { public: diff --git a/test/common/subreadstream.h b/test/common/subreadstream.h index 15d959892f..463f49e929 100644 --- a/test/common/subreadstream.h +++ b/test/common/subreadstream.h @@ -1,6 +1,7 @@ #include <cxxtest/TestSuite.h> -#include "common/stream.h" +#include "common/memstream.h" +#include "common/substream.h" class SubReadStreamTestSuite : public CxxTest::TestSuite { public: |