diff options
author | Matthew Stewart | 2018-08-02 05:28:38 -0400 |
---|---|---|
committer | Eugene Sandulenko | 2018-08-09 08:37:30 +0200 |
commit | ad6a2bb0bb02ddbcffeaf2da14919fd9a73a786e (patch) | |
tree | e2c6078c99da52c1d480e2339bde35c661a916ca /engines | |
parent | e5e54b8a1f937e2df1dfd141de9d4444257f9540 (diff) | |
download | scummvm-rg350-ad6a2bb0bb02ddbcffeaf2da14919fd9a73a786e.tar.gz scummvm-rg350-ad6a2bb0bb02ddbcffeaf2da14919fd9a73a786e.tar.bz2 scummvm-rg350-ad6a2bb0bb02ddbcffeaf2da14919fd9a73a786e.zip |
STARTREK: Make FileStream extend MemoryReadStream
Diffstat (limited to 'engines')
-rw-r--r-- | engines/startrek/filestream.cpp | 73 | ||||
-rw-r--r-- | engines/startrek/filestream.h | 27 | ||||
-rw-r--r-- | engines/startrek/startrek.cpp | 14 |
3 files changed, 17 insertions, 97 deletions
diff --git a/engines/startrek/filestream.cpp b/engines/startrek/filestream.cpp index b4fa2d27e5..b4b864416a 100644 --- a/engines/startrek/filestream.cpp +++ b/engines/startrek/filestream.cpp @@ -24,79 +24,12 @@ namespace StarTrek { -FileStream::FileStream(Common::SeekableReadStream *stream, bool bigEndian) { - _bigEndian = bigEndian; - - _pos = 0; - _size = stream->size(); - _data = new byte[_size]; - stream->read(_data, _size); - delete stream; +FileStream::FileStream(byte *data, uint32 len, bool bigEndian) : Common::MemoryReadStreamEndian(data, len, bigEndian) { + _data = data; } FileStream::~FileStream() { - delete[] _data; -} - -// ReadStream functions - -uint32 FileStream::read(void *dataPtr, uint32 dataSize) { - if (_pos + dataSize > (uint32)size()) - dataSize = size() - _pos; - memcpy(dataPtr, _data + _pos, dataSize); - _pos += dataSize; - return dataSize; -} - -byte FileStream::readByte() { - assert(_pos + 1 <= size()); - return _data[_pos++]; -} - -uint16 FileStream::readUint16() { - assert(_pos + 2 <= size()); - uint16 w; - if (_bigEndian) - w = READ_BE_UINT16(_data + _pos); - else - w = READ_LE_UINT16(_data + _pos); - _pos += 2; - return w; -} - -uint32 FileStream::readUint32() { - assert(_pos + 4 <= size()); - uint32 w; - if (_bigEndian) - w = READ_BE_UINT32(_data + _pos); - else - w = READ_LE_UINT32(_data + _pos); - _pos += 4; - return w; -} - -int16 FileStream::readSint16() { - return (int16)readUint16(); -} - -int32 FileStream::readSint32() { - return (int32)readUint32(); -} - -// SeekableReadStream functions - -int32 FileStream::pos() const { - return _pos; -} - -int32 FileStream::size() const { - return _size; -} - -bool FileStream::seek(int32 offset, int whence) { - assert(whence == SEEK_SET); - _pos = offset; - return true; + free(_data); } } // End of namespace StarTrek diff --git a/engines/startrek/filestream.h b/engines/startrek/filestream.h index ddef496b2d..9f69d62686 100644 --- a/engines/startrek/filestream.h +++ b/engines/startrek/filestream.h @@ -23,37 +23,16 @@ #define STARTREK_FILESTREAM_H #include "common/stream.h" +#include "common/memstream.h" namespace StarTrek { -class FileStream { +class FileStream : public Common::MemoryReadStreamEndian { public: - FileStream(Common::SeekableReadStream *stream, bool bigEndian); + FileStream(byte *data, uint32 len, bool bigEndian); ~FileStream(); byte *_data; - -private: - bool _bigEndian; - int32 _pos; - int32 _size; - -public: - // ReadStream functions - bool eos() const; - uint32 read(void *dataPtr, uint32 dataSize); - - byte readByte(); - uint16 readUint16(); - uint32 readUint32(); - int16 readSint16(); - int32 readSint32(); - - // SeekableReadStream functions - int32 pos() const; - int32 size() const; - bool seek(int32 offset, int whence); - }; } // End of namespace StarTrek diff --git a/engines/startrek/startrek.cpp b/engines/startrek/startrek.cpp index cea59a48fd..e0aef012ea 100644 --- a/engines/startrek/startrek.cpp +++ b/engines/startrek/startrek.cpp @@ -420,7 +420,9 @@ SharedPtr<FileStream> StarTrekEngine::loadFile(Common::String filename, int file Common::File *file = new Common::File(); if (!file->open(filename.c_str())) error("Could not find file \'%s\'", filename.c_str()); - return SharedPtr<FileStream>(new FileStream(file, bigEndian)); + byte *data = (byte *)malloc(file->size()); + file->read(data, file->size()); + return SharedPtr<FileStream>(new FileStream(data, file->size(), bigEndian)); } Common::SeekableReadStream *indexFile = 0; @@ -523,7 +525,10 @@ SharedPtr<FileStream> StarTrekEngine::loadFile(Common::String filename, int file Common::SeekableReadStream *stream = dataFile->readStream(uncompressedSize); delete dataFile; delete dataRunFile; - return SharedPtr<FileStream>(new FileStream(stream, bigEndian)); + + byte *data = (byte *)malloc(stream->size()); + stream->read(data, stream->size()); + return SharedPtr<FileStream>(new FileStream(data, stream->size(), bigEndian)); } else { if (fileCount != 1) { dataRunFile->seek(indexOffset); @@ -545,7 +550,10 @@ SharedPtr<FileStream> StarTrekEngine::loadFile(Common::String filename, int file delete dataFile; delete dataRunFile; - return SharedPtr<FileStream>(new FileStream(stream, bigEndian)); + + byte *data = (byte *)malloc(stream->size()); + stream->read(data, stream->size()); + return SharedPtr<FileStream>(new FileStream(data, stream->size(), bigEndian)); } // We should not get to this point... |