Introduced new type Common::DisposeAfterUse::Flag
svn-id: r45233
This commit is contained in:
parent
64861f1e40
commit
2bbf708dea
28 changed files with 68 additions and 61 deletions
|
@ -37,7 +37,7 @@ MemoryReadStream *ReadStream::readStream(uint32 dataSize) {
|
||||||
void *buf = malloc(dataSize);
|
void *buf = malloc(dataSize);
|
||||||
dataSize = read(buf, dataSize);
|
dataSize = read(buf, dataSize);
|
||||||
assert(dataSize > 0);
|
assert(dataSize > 0);
|
||||||
return new MemoryReadStream((byte *)buf, dataSize, true);
|
return new MemoryReadStream((byte *)buf, dataSize, DisposeAfterUse::YES);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -188,7 +188,7 @@ uint32 SubReadStream::read(void *dataPtr, uint32 dataSize) {
|
||||||
return dataSize;
|
return dataSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
SeekableSubReadStream::SeekableSubReadStream(SeekableReadStream *parentStream, uint32 begin, uint32 end, bool disposeParentStream)
|
SeekableSubReadStream::SeekableSubReadStream(SeekableReadStream *parentStream, uint32 begin, uint32 end, DisposeAfterUse::Flag disposeParentStream)
|
||||||
: SubReadStream(parentStream, end, disposeParentStream),
|
: SubReadStream(parentStream, end, disposeParentStream),
|
||||||
_parentStream(parentStream),
|
_parentStream(parentStream),
|
||||||
_begin(begin) {
|
_begin(begin) {
|
||||||
|
@ -222,7 +222,7 @@ bool SeekableSubReadStream::seek(int32 offset, int whence) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
BufferedReadStream::BufferedReadStream(ReadStream *parentStream, uint32 bufSize, bool disposeParentStream)
|
BufferedReadStream::BufferedReadStream(ReadStream *parentStream, uint32 bufSize, DisposeAfterUse::Flag disposeParentStream)
|
||||||
: _parentStream(parentStream),
|
: _parentStream(parentStream),
|
||||||
_disposeParentStream(disposeParentStream),
|
_disposeParentStream(disposeParentStream),
|
||||||
_pos(0),
|
_pos(0),
|
||||||
|
@ -279,7 +279,7 @@ uint32 BufferedReadStream::read(void *dataPtr, uint32 dataSize) {
|
||||||
return alreadyRead + dataSize;
|
return alreadyRead + dataSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
BufferedSeekableReadStream::BufferedSeekableReadStream(SeekableReadStream *parentStream, uint32 bufSize, bool disposeParentStream)
|
BufferedSeekableReadStream::BufferedSeekableReadStream(SeekableReadStream *parentStream, uint32 bufSize, DisposeAfterUse::Flag disposeParentStream)
|
||||||
: BufferedReadStream(parentStream, bufSize, disposeParentStream),
|
: BufferedReadStream(parentStream, bufSize, disposeParentStream),
|
||||||
_parentStream(parentStream) {
|
_parentStream(parentStream) {
|
||||||
}
|
}
|
||||||
|
|
|
@ -396,6 +396,11 @@ public:
|
||||||
virtual String readLine();
|
virtual String readLine();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
namespace DisposeAfterUse {
|
||||||
|
enum Flag { NO, YES };
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SubReadStream provides access to a ReadStream restricted to the range
|
* SubReadStream provides access to a ReadStream restricted to the range
|
||||||
* [currentPosition, currentPosition+end).
|
* [currentPosition, currentPosition+end).
|
||||||
|
@ -407,12 +412,12 @@ public:
|
||||||
class SubReadStream : virtual public ReadStream {
|
class SubReadStream : virtual public ReadStream {
|
||||||
protected:
|
protected:
|
||||||
ReadStream *_parentStream;
|
ReadStream *_parentStream;
|
||||||
bool _disposeParentStream;
|
DisposeAfterUse::Flag _disposeParentStream;
|
||||||
uint32 _pos;
|
uint32 _pos;
|
||||||
uint32 _end;
|
uint32 _end;
|
||||||
bool _eos;
|
bool _eos;
|
||||||
public:
|
public:
|
||||||
SubReadStream(ReadStream *parentStream, uint32 end, bool disposeParentStream = false)
|
SubReadStream(ReadStream *parentStream, uint32 end, DisposeAfterUse::Flag disposeParentStream = DisposeAfterUse::NO)
|
||||||
: _parentStream(parentStream),
|
: _parentStream(parentStream),
|
||||||
_disposeParentStream(disposeParentStream),
|
_disposeParentStream(disposeParentStream),
|
||||||
_pos(0),
|
_pos(0),
|
||||||
|
@ -421,7 +426,8 @@ public:
|
||||||
assert(parentStream);
|
assert(parentStream);
|
||||||
}
|
}
|
||||||
~SubReadStream() {
|
~SubReadStream() {
|
||||||
if (_disposeParentStream) delete _parentStream;
|
if (_disposeParentStream)
|
||||||
|
delete _parentStream;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool eos() const { return _eos; }
|
virtual bool eos() const { return _eos; }
|
||||||
|
@ -443,7 +449,7 @@ protected:
|
||||||
SeekableReadStream *_parentStream;
|
SeekableReadStream *_parentStream;
|
||||||
uint32 _begin;
|
uint32 _begin;
|
||||||
public:
|
public:
|
||||||
SeekableSubReadStream(SeekableReadStream *parentStream, uint32 begin, uint32 end, bool disposeParentStream = false);
|
SeekableSubReadStream(SeekableReadStream *parentStream, uint32 begin, uint32 end, DisposeAfterUse::Flag disposeParentStream = DisposeAfterUse::NO);
|
||||||
|
|
||||||
virtual int32 pos() const { return _pos - _begin; }
|
virtual int32 pos() const { return _pos - _begin; }
|
||||||
virtual int32 size() const { return _end - _begin; }
|
virtual int32 size() const { return _end - _begin; }
|
||||||
|
@ -463,7 +469,7 @@ private:
|
||||||
const bool _bigEndian;
|
const bool _bigEndian;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SeekableSubReadStreamEndian(SeekableReadStream *parentStream, uint32 begin, uint32 end, bool bigEndian = false, bool disposeParentStream = false)
|
SeekableSubReadStreamEndian(SeekableReadStream *parentStream, uint32 begin, uint32 end, bool bigEndian = false, DisposeAfterUse::Flag disposeParentStream = DisposeAfterUse::NO)
|
||||||
: SeekableSubReadStream(parentStream, begin, end, disposeParentStream), _bigEndian(bigEndian) {
|
: SeekableSubReadStream(parentStream, begin, end, disposeParentStream), _bigEndian(bigEndian) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -496,14 +502,14 @@ public:
|
||||||
class BufferedReadStream : virtual public ReadStream {
|
class BufferedReadStream : virtual public ReadStream {
|
||||||
protected:
|
protected:
|
||||||
ReadStream *_parentStream;
|
ReadStream *_parentStream;
|
||||||
bool _disposeParentStream;
|
DisposeAfterUse::Flag _disposeParentStream;
|
||||||
byte *_buf;
|
byte *_buf;
|
||||||
uint32 _pos;
|
uint32 _pos;
|
||||||
uint32 _bufSize;
|
uint32 _bufSize;
|
||||||
uint32 _realBufSize;
|
uint32 _realBufSize;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BufferedReadStream(ReadStream *parentStream, uint32 bufSize, bool disposeParentStream = false);
|
BufferedReadStream(ReadStream *parentStream, uint32 bufSize, DisposeAfterUse::Flag disposeParentStream = DisposeAfterUse::NO);
|
||||||
~BufferedReadStream();
|
~BufferedReadStream();
|
||||||
|
|
||||||
virtual bool eos() const { return (_pos == _bufSize) && _parentStream->eos(); }
|
virtual bool eos() const { return (_pos == _bufSize) && _parentStream->eos(); }
|
||||||
|
@ -521,7 +527,7 @@ class BufferedSeekableReadStream : public BufferedReadStream, public SeekableRea
|
||||||
protected:
|
protected:
|
||||||
SeekableReadStream *_parentStream;
|
SeekableReadStream *_parentStream;
|
||||||
public:
|
public:
|
||||||
BufferedSeekableReadStream(SeekableReadStream *parentStream, uint32 bufSize, bool disposeParentStream = false);
|
BufferedSeekableReadStream(SeekableReadStream *parentStream, uint32 bufSize, DisposeAfterUse::Flag disposeParentStream = DisposeAfterUse::NO);
|
||||||
|
|
||||||
virtual int32 pos() const { return _parentStream->pos() - (_bufSize - _pos); }
|
virtual int32 pos() const { return _parentStream->pos() - (_bufSize - _pos); }
|
||||||
virtual int32 size() const { return _parentStream->size(); }
|
virtual int32 size() const { return _parentStream->size(); }
|
||||||
|
@ -542,7 +548,7 @@ private:
|
||||||
const uint32 _size;
|
const uint32 _size;
|
||||||
uint32 _pos;
|
uint32 _pos;
|
||||||
byte _encbyte;
|
byte _encbyte;
|
||||||
bool _disposeMemory;
|
DisposeAfterUse::Flag _disposeMemory;
|
||||||
bool _eos;
|
bool _eos;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -552,7 +558,7 @@ public:
|
||||||
* wraps it. If disposeMemory is true, the MemoryReadStream takes ownership
|
* wraps it. If disposeMemory is true, the MemoryReadStream takes ownership
|
||||||
* of the buffer and hence free's it when destructed.
|
* of the buffer and hence free's it when destructed.
|
||||||
*/
|
*/
|
||||||
MemoryReadStream(const byte *dataPtr, uint32 dataSize, bool disposeMemory = false) :
|
MemoryReadStream(const byte *dataPtr, uint32 dataSize, DisposeAfterUse::Flag disposeMemory = DisposeAfterUse::NO) :
|
||||||
_ptrOrig(dataPtr),
|
_ptrOrig(dataPtr),
|
||||||
_ptr(dataPtr),
|
_ptr(dataPtr),
|
||||||
_size(dataSize),
|
_size(dataSize),
|
||||||
|
@ -649,7 +655,7 @@ private:
|
||||||
byte *_ptr;
|
byte *_ptr;
|
||||||
byte *_data;
|
byte *_data;
|
||||||
uint32 _pos;
|
uint32 _pos;
|
||||||
bool _disposeMemory;
|
DisposeAfterUse::Flag _disposeMemory;
|
||||||
|
|
||||||
void ensureCapacity(uint32 new_len) {
|
void ensureCapacity(uint32 new_len) {
|
||||||
if (new_len <= _capacity)
|
if (new_len <= _capacity)
|
||||||
|
@ -670,7 +676,7 @@ private:
|
||||||
_size = new_len;
|
_size = new_len;
|
||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
MemoryWriteStreamDynamic(bool disposeMemory = false) : _capacity(0), _size(0), _ptr(0), _data(0), _pos(0), _disposeMemory(disposeMemory) {}
|
MemoryWriteStreamDynamic(DisposeAfterUse::Flag disposeMemory = DisposeAfterUse::NO) : _capacity(0), _size(0), _ptr(0), _data(0), _pos(0), _disposeMemory(disposeMemory) {}
|
||||||
|
|
||||||
~MemoryWriteStreamDynamic() {
|
~MemoryWriteStreamDynamic() {
|
||||||
if (_disposeMemory)
|
if (_disposeMemory)
|
||||||
|
|
|
@ -379,7 +379,7 @@ bool ArjFile::open(const Common::String &filename) {
|
||||||
// If reading from archiveFile directly is too slow to be usable,
|
// If reading from archiveFile directly is too slow to be usable,
|
||||||
// maybe the filesystem code should instead wrap its files
|
// maybe the filesystem code should instead wrap its files
|
||||||
// in a BufferedReadStream.
|
// in a BufferedReadStream.
|
||||||
decoder->_compressed = new BufferedReadStream(&archiveFile, 4096, false);
|
decoder->_compressed = new BufferedReadStream(&archiveFile, 4096);
|
||||||
decoder->_outstream = new MemoryWriteStream(uncompressedData, hdr->origSize);
|
decoder->_outstream = new MemoryWriteStream(uncompressedData, hdr->origSize);
|
||||||
|
|
||||||
if (hdr->method == 1 || hdr->method == 2 || hdr->method == 3)
|
if (hdr->method == 1 || hdr->method == 2 || hdr->method == 3)
|
||||||
|
@ -391,7 +391,7 @@ bool ArjFile::open(const Common::String &filename) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
_uncompressed = new MemoryReadStream(uncompressedData, hdr->origSize, true);
|
_uncompressed = new MemoryReadStream(uncompressedData, hdr->origSize, DisposeAfterUse::YES);
|
||||||
assert(_uncompressed);
|
assert(_uncompressed);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -1442,7 +1442,7 @@ Common::SeekableReadStream *ZipArchive::createReadStreamForMember(const Common::
|
||||||
assert(buffer);
|
assert(buffer);
|
||||||
unzReadCurrentFile(_zipFile, buffer, fileInfo.uncompressed_size);
|
unzReadCurrentFile(_zipFile, buffer, fileInfo.uncompressed_size);
|
||||||
unzCloseCurrentFile(_zipFile);
|
unzCloseCurrentFile(_zipFile);
|
||||||
return new Common::MemoryReadStream(buffer, fileInfo.uncompressed_size+1, true);
|
return new Common::MemoryReadStream(buffer, fileInfo.uncompressed_size+1, DisposeAfterUse::YES);
|
||||||
|
|
||||||
// FIXME: instead of reading all into a memory stream, we could
|
// FIXME: instead of reading all into a memory stream, we could
|
||||||
// instead create a new ZipStream class. But then we have to be
|
// instead create a new ZipStream class. But then we have to be
|
||||||
|
|
|
@ -48,7 +48,7 @@ bool XMLParser::loadFile(const FSNode &node) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool XMLParser::loadBuffer(const byte *buffer, uint32 size, bool disposable) {
|
bool XMLParser::loadBuffer(const byte *buffer, uint32 size, DisposeAfterUse::Flag disposable) {
|
||||||
_stream = new MemoryReadStream(buffer, size, disposable);
|
_stream = new MemoryReadStream(buffer, size, disposable);
|
||||||
_fileName = "Memory Stream";
|
_fileName = "Memory Stream";
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -198,7 +198,7 @@ public:
|
||||||
* i.e. if it can be freed safely after it's
|
* i.e. if it can be freed safely after it's
|
||||||
* no longer needed by the parser.
|
* no longer needed by the parser.
|
||||||
*/
|
*/
|
||||||
bool loadBuffer(const byte *buffer, uint32 size, bool disposable = false);
|
bool loadBuffer(const byte *buffer, uint32 size, DisposeAfterUse::Flag disposable = DisposeAfterUse::NO);
|
||||||
|
|
||||||
bool loadStream(Common::SeekableReadStream *stream);
|
bool loadStream(Common::SeekableReadStream *stream);
|
||||||
|
|
||||||
|
|
|
@ -89,7 +89,7 @@ const uint8 *PCjrSound::getVoicePointer(uint voiceNum) {
|
||||||
}
|
}
|
||||||
|
|
||||||
IIgsSample::IIgsSample(uint8 *data, uint32 len, int resnum, SoundMgr &manager) : AgiSound(manager) {
|
IIgsSample::IIgsSample(uint8 *data, uint32 len, int resnum, SoundMgr &manager) : AgiSound(manager) {
|
||||||
Common::MemoryReadStream stream(data, len, true);
|
Common::MemoryReadStream stream(data, len, Common::DisposeAfterUse::YES);
|
||||||
|
|
||||||
// Check that the header was read ok and that it's of the correct type
|
// Check that the header was read ok and that it's of the correct type
|
||||||
if (_header.read(stream) && _header.type == AGI_SOUND_SAMPLE) { // An Apple IIGS AGI sample resource
|
if (_header.read(stream) && _header.type == AGI_SOUND_SAMPLE) { // An Apple IIGS AGI sample resource
|
||||||
|
|
|
@ -209,7 +209,7 @@ int loadOverlay(const char *scriptName) {
|
||||||
|
|
||||||
debug(1, "OVL loading done...");
|
debug(1, "OVL loading done...");
|
||||||
|
|
||||||
Common::MemoryReadStream s(unpackedBuffer, unpackedSize, true);
|
Common::MemoryReadStream s(unpackedBuffer, unpackedSize, Common::DisposeAfterUse::YES);
|
||||||
unpackedBuffer = NULL;
|
unpackedBuffer = NULL;
|
||||||
|
|
||||||
ovlData = overlayTable[scriptIdx].ovlData;
|
ovlData = overlayTable[scriptIdx].ovlData;
|
||||||
|
@ -590,7 +590,7 @@ int loadOverlay(const char *scriptName) {
|
||||||
loadPackedFileToMem(fileIdx, (uint8 *) unpackedBuffer);
|
loadPackedFileToMem(fileIdx, (uint8 *) unpackedBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
Common::MemoryReadStream s2(unpackedBuffer, unpackedSize, true);
|
Common::MemoryReadStream s2(unpackedBuffer, unpackedSize, Common::DisposeAfterUse::YES);
|
||||||
unpackedBuffer = NULL;
|
unpackedBuffer = NULL;
|
||||||
|
|
||||||
ovlData->specialString1Length = s2.readUint16BE();
|
ovlData->specialString1Length = s2.readUint16BE();
|
||||||
|
|
|
@ -65,7 +65,7 @@ Common::SeekableReadStream *ResMan::open(uint32 fileRef) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returning the resource substream
|
// Returning the resource substream
|
||||||
return new Common::SeekableSubReadStream(gjdFile, resInfo.offset, resInfo.offset + resInfo.size, true);
|
return new Common::SeekableSubReadStream(gjdFile, resInfo.offset, resInfo.offset + resInfo.size, Common::DisposeAfterUse::YES);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -138,7 +138,7 @@ Common::InSaveFile *SaveLoad::openForLoading(const Common::String &target, int s
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return a substream, skipping the metadata
|
// Return a substream, skipping the metadata
|
||||||
Common::SeekableSubReadStream *sub = new Common::SeekableSubReadStream(savefile, metaDataSize, savefile->size(), true);
|
Common::SeekableSubReadStream *sub = new Common::SeekableSubReadStream(savefile, metaDataSize, savefile->size(), Common::DisposeAfterUse::YES);
|
||||||
|
|
||||||
// Move to the beginning of the substream
|
// Move to the beginning of the substream
|
||||||
sub->seek(0, SEEK_SET);
|
sub->seek(0, SEEK_SET);
|
||||||
|
|
|
@ -78,7 +78,7 @@ Common::SeekableReadStream *PlainArchive::createReadStreamForMember(const Common
|
||||||
if (!parent)
|
if (!parent)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return new Common::SeekableSubReadStream(parent, fDesc->_value.offset, fDesc->_value.offset + fDesc->_value.size, true);
|
return new Common::SeekableSubReadStream(parent, fDesc->_value.offset, fDesc->_value.offset + fDesc->_value.size, Common::DisposeAfterUse::YES);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -> CachedArchive implementation
|
// -> CachedArchive implementation
|
||||||
|
@ -130,7 +130,7 @@ Common::SeekableReadStream *CachedArchive::createReadStreamForMember(const Commo
|
||||||
if (fDesc == _files.end())
|
if (fDesc == _files.end())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return new Common::MemoryReadStream(fDesc->_value.data, fDesc->_value.size, false);
|
return new Common::MemoryReadStream(fDesc->_value.data, fDesc->_value.size, Common::DisposeAfterUse::NO);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResFileLoader implementations
|
// ResFileLoader implementations
|
||||||
|
|
|
@ -152,7 +152,7 @@ Common::Error KyraEngine_HoF::loadGameState(int slot) {
|
||||||
|
|
||||||
int loadedZTable = _characterShapeFile;
|
int loadedZTable = _characterShapeFile;
|
||||||
|
|
||||||
Common::SeekableSubReadStreamEndian in(saveFile, saveFile->pos(), saveFile->size(), !header.originalSave, true);
|
Common::SeekableSubReadStreamEndian in(saveFile, saveFile->pos(), saveFile->size(), !header.originalSave, Common::DisposeAfterUse::YES);
|
||||||
|
|
||||||
_screen->hideMouse();
|
_screen->hideMouse();
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ Common::Error LoLEngine::loadGameState(int slot) {
|
||||||
_screen->fillRect(112, 0, 287, 119, 0, 0);
|
_screen->fillRect(112, 0, 287, 119, 0, 0);
|
||||||
_screen->updateScreen();
|
_screen->updateScreen();
|
||||||
|
|
||||||
Common::SeekableSubReadStreamEndian in(saveFile, saveFile->pos(), saveFile->size(), !header.originalSave, true);
|
Common::SeekableSubReadStreamEndian in(saveFile, saveFile->pos(), saveFile->size(), !header.originalSave, Common::DisposeAfterUse::YES);
|
||||||
|
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
LoLCharacter *c = &_characters[i];
|
LoLCharacter *c = &_characters[i];
|
||||||
|
|
|
@ -150,7 +150,7 @@ Common::Error KyraEngine_MR::loadGameState(int slot) {
|
||||||
|
|
||||||
int curShapes = _characterShapeFile;
|
int curShapes = _characterShapeFile;
|
||||||
|
|
||||||
Common::SeekableSubReadStreamEndian in(saveFile, saveFile->pos(), saveFile->size(), !header.originalSave, true);
|
Common::SeekableSubReadStreamEndian in(saveFile, saveFile->pos(), saveFile->size(), !header.originalSave, Common::DisposeAfterUse::YES);
|
||||||
|
|
||||||
_screen->hideMouse();
|
_screen->hideMouse();
|
||||||
|
|
||||||
|
|
|
@ -2969,7 +2969,7 @@ bool Screen::loadPaletteTable(const char *filename, int firstPalette) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Screen::loadPalette(const byte *data, Palette &pal, int bytes) {
|
void Screen::loadPalette(const byte *data, Palette &pal, int bytes) {
|
||||||
Common::MemoryReadStream stream(data, bytes, false);
|
Common::MemoryReadStream stream(data, bytes, Common::DisposeAfterUse::NO);
|
||||||
|
|
||||||
if (_isAmiga)
|
if (_isAmiga)
|
||||||
pal.loadAmigaPalette(stream, 0, stream.size() / Palette::kAmigaBytesPerColor);
|
pal.loadAmigaPalette(stream, 0, stream.size() / Palette::kAmigaBytesPerColor);
|
||||||
|
|
|
@ -59,7 +59,7 @@ public:
|
||||||
MadsPackEntry &getItem(int index) const { return _items[index]; }
|
MadsPackEntry &getItem(int index) const { return _items[index]; }
|
||||||
MadsPackEntry &operator[](int index) const { return _items[index]; }
|
MadsPackEntry &operator[](int index) const { return _items[index]; }
|
||||||
Common::MemoryReadStream *getItemStream(int index) {
|
Common::MemoryReadStream *getItemStream(int index) {
|
||||||
return new Common::MemoryReadStream(_items[index].data, _items[index].size, false);
|
return new Common::MemoryReadStream(_items[index].data, _items[index].size, Common::DisposeAfterUse::NO);
|
||||||
}
|
}
|
||||||
int getDataOffset() const { return _dataOffset; }
|
int getDataOffset() const { return _dataOffset; }
|
||||||
};
|
};
|
||||||
|
|
|
@ -45,7 +45,7 @@ Common::MemoryReadStream *RedReader::load(const char *redFilename, const char *f
|
||||||
lzhDec->decompress(fd, fileBuf, fileEntry.compSize, fileEntry.origSize);
|
lzhDec->decompress(fd, fileBuf, fileEntry.compSize, fileEntry.origSize);
|
||||||
delete lzhDec;
|
delete lzhDec;
|
||||||
|
|
||||||
return new Common::MemoryReadStream(fileBuf, fileEntry.origSize, true);
|
return new Common::MemoryReadStream(fileBuf, fileEntry.origSize, Common::DisposeAfterUse::YES);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -133,7 +133,7 @@ Common::SeekableReadStream *NSArchive::createReadStreamForMember(const Common::S
|
||||||
|
|
||||||
int offset = _archiveOffsets[index];
|
int offset = _archiveOffsets[index];
|
||||||
int endOffset = _archiveOffsets[index] + _archiveLenghts[index];
|
int endOffset = _archiveOffsets[index] + _archiveLenghts[index];
|
||||||
return new Common::SeekableSubReadStream(_stream, offset, endOffset, false);
|
return new Common::SeekableSubReadStream(_stream, offset, endOffset, Common::DisposeAfterUse::NO);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NSArchive::hasFile(const Common::String &name) {
|
bool NSArchive::hasFile(const Common::String &name) {
|
||||||
|
@ -670,7 +670,7 @@ public:
|
||||||
ppDecrunchBuffer(src, dest, crlen-8, decrlen);
|
ppDecrunchBuffer(src, dest, crlen-8, decrlen);
|
||||||
|
|
||||||
free(src);
|
free(src);
|
||||||
_stream = new Common::MemoryReadStream(dest, decrlen, true);
|
_stream = new Common::MemoryReadStream(dest, decrlen, Common::DisposeAfterUse::YES);
|
||||||
_dispose = true;
|
_dispose = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -678,7 +678,7 @@ void Parallaction_ns::initFonts() {
|
||||||
_introFont = _disk->loadFont("slide");
|
_introFont = _disk->loadFont("slide");
|
||||||
} else {
|
} else {
|
||||||
_dialogueFont = _disk->loadFont("comic");
|
_dialogueFont = _disk->loadFont("comic");
|
||||||
Common::MemoryReadStream stream(_amigaTopazFont, 2600, false);
|
Common::MemoryReadStream stream(_amigaTopazFont, 2600, Common::DisposeAfterUse::NO);
|
||||||
_labelFont = new AmigaFont(stream);
|
_labelFont = new AmigaFont(stream);
|
||||||
_menuFont = _disk->loadFont("slide");
|
_menuFont = _disk->loadFont("slide");
|
||||||
_introFont = _disk->loadFont("intro");
|
_introFont = _disk->loadFont("intro");
|
||||||
|
|
|
@ -83,17 +83,17 @@ void Sound::playSoundBuffer(Audio::SoundHandle *handle, SoundBuffer &buffer, int
|
||||||
switch (buffer.soundType) {
|
switch (buffer.soundType) {
|
||||||
#ifdef USE_MAD
|
#ifdef USE_MAD
|
||||||
case kSoundMP3:
|
case kSoundMP3:
|
||||||
stream = Audio::makeMP3Stream(new Common::MemoryReadStream(buffer.buffer, buffer.size, true), true);
|
stream = Audio::makeMP3Stream(new Common::MemoryReadStream(buffer.buffer, buffer.size, Common::DisposeAfterUse::YES), true);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_VORBIS
|
#ifdef USE_VORBIS
|
||||||
case kSoundOGG:
|
case kSoundOGG:
|
||||||
stream = Audio::makeVorbisStream(new Common::MemoryReadStream(buffer.buffer, buffer.size, true), true);
|
stream = Audio::makeVorbisStream(new Common::MemoryReadStream(buffer.buffer, buffer.size, Common::DisposeAfterUse::YES), true);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_FLAC
|
#ifdef USE_FLAC
|
||||||
case kSoundFLAC:
|
case kSoundFLAC:
|
||||||
stream = Audio::makeFlacStream(new Common::MemoryReadStream(buffer.buffer, buffer.size, true), true);
|
stream = Audio::makeFlacStream(new Common::MemoryReadStream(buffer.buffer, buffer.size, Common::DisposeAfterUse::YES), true);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -1156,10 +1156,10 @@ Audio::AudioStream* SfxState::getAudioStream(uint32 number, uint32 volume, int *
|
||||||
|
|
||||||
if (audioRes->headerSize > 0) {
|
if (audioRes->headerSize > 0) {
|
||||||
// SCI1.1
|
// SCI1.1
|
||||||
Common::MemoryReadStream headerStream(audioRes->header, audioRes->headerSize, false);
|
Common::MemoryReadStream headerStream(audioRes->header, audioRes->headerSize, Common::DisposeAfterUse::NO);
|
||||||
|
|
||||||
if (readSOLHeader(&headerStream, audioRes->headerSize, size, _audioRate, audioFlags)) {
|
if (readSOLHeader(&headerStream, audioRes->headerSize, size, _audioRate, audioFlags)) {
|
||||||
Common::MemoryReadStream dataStream(audioRes->data, audioRes->size, false);
|
Common::MemoryReadStream dataStream(audioRes->data, audioRes->size, Common::DisposeAfterUse::NO);
|
||||||
data = readSOLAudio(&dataStream, size, audioFlags, flags);
|
data = readSOLAudio(&dataStream, size, audioFlags, flags);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -223,7 +223,7 @@ void ScummEngine_v4::prepareSavegame() {
|
||||||
if (!writeStream->err()) {
|
if (!writeStream->err()) {
|
||||||
// wrap uncompressing MemoryReadStream around the savegame data
|
// wrap uncompressing MemoryReadStream around the savegame data
|
||||||
_savePreparedSavegame = Common::wrapCompressedReadStream(
|
_savePreparedSavegame = Common::wrapCompressedReadStream(
|
||||||
new Common::MemoryReadStream(memStream->getData(), memStream->size(), true));
|
new Common::MemoryReadStream(memStream->getData(), memStream->size(), Common::DisposeAfterUse::YES));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// free the CompressedWriteStream and MemoryWriteStreamDynamic
|
// free the CompressedWriteStream and MemoryWriteStreamDynamic
|
||||||
|
|
|
@ -50,22 +50,23 @@
|
||||||
|
|
||||||
namespace Sword2 {
|
namespace Sword2 {
|
||||||
|
|
||||||
// This class behaves like SeekableSubReadStream, except it remembers where the
|
/**
|
||||||
// previous read() or seek() took it, so that it can continue from that point
|
* This class behaves like SeekableSubReadStream, except it remembers where the
|
||||||
// the next time. This is because we're frequently streaming two pieces of
|
* previous read() or seek() took it, so that it can continue from that point
|
||||||
// music from the same file.
|
* the next time. This is because we're frequently streaming two pieces of
|
||||||
|
* music from the same file.
|
||||||
|
*/
|
||||||
class SafeSubReadStream : public Common::SeekableSubReadStream {
|
class SafeSubReadStream : public Common::SeekableSubReadStream {
|
||||||
protected:
|
protected:
|
||||||
uint32 _previousPos;
|
uint32 _previousPos;
|
||||||
public:
|
public:
|
||||||
SafeSubReadStream(SeekableReadStream *parentStream, uint32 begin, uint32 end, bool disposeParentStream);
|
SafeSubReadStream(SeekableReadStream *parentStream, uint32 begin, uint32 end);
|
||||||
virtual uint32 read(void *dataPtr, uint32 dataSize);
|
virtual uint32 read(void *dataPtr, uint32 dataSize);
|
||||||
virtual bool seek(int32 offset, int whence = SEEK_SET);
|
virtual bool seek(int32 offset, int whence = SEEK_SET);
|
||||||
};
|
};
|
||||||
|
|
||||||
SafeSubReadStream::SafeSubReadStream(SeekableReadStream *parentStream, uint32 begin, uint32 end, bool disposeParentStream)
|
SafeSubReadStream::SafeSubReadStream(SeekableReadStream *parentStream, uint32 begin, uint32 end)
|
||||||
: SeekableSubReadStream(parentStream, begin, end, disposeParentStream) {
|
: SeekableSubReadStream(parentStream, begin, end, Common::DisposeAfterUse::NO) {
|
||||||
_previousPos = 0;
|
_previousPos = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,17 +198,17 @@ static Audio::AudioStream *getAudioStream(SoundFileHandle *fh, const char *base,
|
||||||
return makeCLUStream(&fh->file, enc_len);
|
return makeCLUStream(&fh->file, enc_len);
|
||||||
#ifdef USE_MAD
|
#ifdef USE_MAD
|
||||||
case kMP3Mode:
|
case kMP3Mode:
|
||||||
tmp = new SafeSubReadStream(&fh->file, pos, pos + enc_len, false);
|
tmp = new SafeSubReadStream(&fh->file, pos, pos + enc_len);
|
||||||
return Audio::makeMP3Stream(tmp, true);
|
return Audio::makeMP3Stream(tmp, true);
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_VORBIS
|
#ifdef USE_VORBIS
|
||||||
case kVorbisMode:
|
case kVorbisMode:
|
||||||
tmp = new SafeSubReadStream(&fh->file, pos, pos + enc_len, false);
|
tmp = new SafeSubReadStream(&fh->file, pos, pos + enc_len);
|
||||||
return Audio::makeVorbisStream(tmp, true);
|
return Audio::makeVorbisStream(tmp, true);
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_FLAC
|
#ifdef USE_FLAC
|
||||||
case kFlacMode:
|
case kFlacMode:
|
||||||
tmp = new SafeSubReadStream(&fh->file, pos, pos + enc_len, false);
|
tmp = new SafeSubReadStream(&fh->file, pos, pos + enc_len);
|
||||||
return Audio::makeFlacStream(tmp, true);
|
return Audio::makeFlacStream(tmp, true);
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
|
@ -301,7 +302,7 @@ Audio::AudioStream *makePSXCLUStream(Common::File *file, int size) {
|
||||||
|
|
||||||
byte *buffer = (byte *)malloc(size);
|
byte *buffer = (byte *)malloc(size);
|
||||||
file->read(buffer, size);
|
file->read(buffer, size);
|
||||||
return new Audio::VagStream(new Common::MemoryReadStream(buffer, size, true));
|
return new Audio::VagStream(new Common::MemoryReadStream(buffer, size, Common::DisposeAfterUse::YES));
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
|
@ -78,7 +78,7 @@ Common::SeekableReadStream *Pack::getStream(uint32 id) const {
|
||||||
if (id < 1 || id > count)
|
if (id < 1 || id > count)
|
||||||
return 0;
|
return 0;
|
||||||
debug(0, "stream: %04x-%04x", offsets[id - 1], offsets[id]);
|
debug(0, "stream: %04x-%04x", offsets[id - 1], offsets[id]);
|
||||||
return new Common::SeekableSubReadStream(&file, offsets[id - 1], offsets[id], false);
|
return new Common::SeekableSubReadStream(&file, offsets[id - 1], offsets[id], Common::DisposeAfterUse::NO);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // End of namespace TeenAgent
|
} // End of namespace TeenAgent
|
||||||
|
|
|
@ -874,7 +874,7 @@ bool PCMMusicPlayer::getNextChunk() {
|
||||||
"offset %d (script %d.%d)", sampleCLength, sampleOffset,
|
"offset %d (script %d.%d)", sampleCLength, sampleOffset,
|
||||||
_scriptNum, _scriptIndex - 1);
|
_scriptNum, _scriptIndex - 1);
|
||||||
|
|
||||||
sampleStream = new Common::MemoryReadStream(buffer, sampleCLength, true);
|
sampleStream = new Common::MemoryReadStream(buffer, sampleCLength, Common::DisposeAfterUse::YES);
|
||||||
|
|
||||||
delete _curChunk;
|
delete _curChunk;
|
||||||
_curChunk = makeADPCMStream(sampleStream, true, sampleCLength,
|
_curChunk = makeADPCMStream(sampleStream, true, sampleCLength,
|
||||||
|
|
|
@ -133,7 +133,7 @@ bool SoundManager::playSample(int id, Audio::Mixer::SoundType type, Audio::Sound
|
||||||
_vm->_mixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType, volVoice);
|
_vm->_mixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType, volVoice);
|
||||||
|
|
||||||
Common::MemoryReadStream *compressedStream =
|
Common::MemoryReadStream *compressedStream =
|
||||||
new Common::MemoryReadStream(sampleBuf, sampleLen, true);
|
new Common::MemoryReadStream(sampleBuf, sampleLen, Common::DisposeAfterUse::YES);
|
||||||
Audio::AudioStream *sampleStream = 0;
|
Audio::AudioStream *sampleStream = 0;
|
||||||
|
|
||||||
// play it
|
// play it
|
||||||
|
@ -284,7 +284,7 @@ bool SoundManager::playSample(int id, int sub, bool bLooped, int x, int y, int p
|
||||||
error(FILE_IS_CORRUPT, _vm->getSampleFile(sampleLanguage));
|
error(FILE_IS_CORRUPT, _vm->getSampleFile(sampleLanguage));
|
||||||
|
|
||||||
Common::MemoryReadStream *compressedStream =
|
Common::MemoryReadStream *compressedStream =
|
||||||
new Common::MemoryReadStream(sampleBuf, sampleLen, true);
|
new Common::MemoryReadStream(sampleBuf, sampleLen, Common::DisposeAfterUse::YES);
|
||||||
Audio::AudioStream *sampleStream = 0;
|
Audio::AudioStream *sampleStream = 0;
|
||||||
|
|
||||||
switch (_soundMode) {
|
switch (_soundMode) {
|
||||||
|
|
|
@ -2311,7 +2311,7 @@ Common::MemoryReadStream *Vmd::getExtraData(const char *fileName) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Common::MemoryReadStream *stream =
|
Common::MemoryReadStream *stream =
|
||||||
new Common::MemoryReadStream(data, _extraData[i].realSize, true);
|
new Common::MemoryReadStream(data, _extraData[i].realSize, Common::DisposeAfterUse::YES);
|
||||||
|
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
|
|
|
@ -696,7 +696,7 @@ bool ThemeEngine::loadDefaultXML() {
|
||||||
#include "themes/default.inc"
|
#include "themes/default.inc"
|
||||||
;
|
;
|
||||||
|
|
||||||
if (!_parser->loadBuffer((const byte*)defaultXML, strlen(defaultXML), false))
|
if (!_parser->loadBuffer((const byte*)defaultXML, strlen(defaultXML)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
_themeName = "ScummVM Classic Theme (Builtin Version)";
|
_themeName = "ScummVM Classic Theme (Builtin Version)";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue