diff options
Diffstat (limited to 'engines')
-rw-r--r-- | engines/agos/sound.cpp | 14 | ||||
-rw-r--r-- | engines/drascula/drascula.h | 5 | ||||
-rw-r--r-- | engines/drascula/resource.cpp | 8 |
3 files changed, 9 insertions, 18 deletions
diff --git a/engines/agos/sound.cpp b/engines/agos/sound.cpp index 03932aa4de..11a1cd792e 100644 --- a/engines/agos/sound.cpp +++ b/engines/agos/sound.cpp @@ -22,6 +22,7 @@ #include "common/file.h" #include "common/memstream.h" +#include "common/ptr.h" #include "common/textconsole.h" #include "common/util.h" @@ -43,11 +44,10 @@ namespace AGOS { class BaseSound : Common::NonCopyable { protected: - Common::File *_file; + Common::DisposablePtr<Common::File> _file; uint32 *_offsets; Audio::Mixer *_mixer; bool _freeOffsets; - DisposeAfterUse::Flag _disposeFile; public: BaseSound(Audio::Mixer *mixer, Common::File *file, uint32 base, bool bigEndian, DisposeAfterUse::Flag disposeFileAfterUse = DisposeAfterUse::YES); @@ -62,7 +62,7 @@ public: }; BaseSound::BaseSound(Audio::Mixer *mixer, Common::File *file, uint32 base, bool bigEndian, DisposeAfterUse::Flag disposeFileAfterUse) - : _mixer(mixer), _file(file), _disposeFile(disposeFileAfterUse) { + : _mixer(mixer), _file(file, disposeFileAfterUse) { uint res = 0; uint32 size; @@ -96,7 +96,7 @@ BaseSound::BaseSound(Audio::Mixer *mixer, Common::File *file, uint32 base, bool } BaseSound::BaseSound(Audio::Mixer *mixer, Common::File *file, uint32 *offsets, DisposeAfterUse::Flag disposeFileAfterUse) - : _mixer(mixer), _file(file), _disposeFile(disposeFileAfterUse) { + : _mixer(mixer), _file(file, disposeFileAfterUse) { _offsets = offsets; _freeOffsets = false; @@ -105,8 +105,6 @@ BaseSound::BaseSound(Audio::Mixer *mixer, Common::File *file, uint32 *offsets, D BaseSound::~BaseSound() { if (_freeOffsets) free(_offsets); - if (_disposeFile == DisposeAfterUse::YES) - delete _file; } /////////////////////////////////////////////////////////////////////////////// @@ -234,7 +232,7 @@ Audio::AudioStream *WavSound::makeAudioStream(uint sound) { return NULL; _file->seek(_offsets[sound], SEEK_SET); - return Audio::makeWAVStream(_file, DisposeAfterUse::NO); + return Audio::makeWAVStream(_file.get(), DisposeAfterUse::NO); } void WavSound::playSound(uint sound, uint loopSound, Audio::Mixer::SoundType type, Audio::SoundHandle *handle, bool loop, int vol) { @@ -257,7 +255,7 @@ public: Audio::AudioStream *VocSound::makeAudioStream(uint sound) { assert(_offsets); _file->seek(_offsets[sound], SEEK_SET); - return Audio::makeVOCStream(_file, _flags); + return Audio::makeVOCStream(_file.get(), _flags); } void VocSound::playSound(uint sound, uint loopSound, Audio::Mixer::SoundType type, Audio::SoundHandle *handle, bool loop, int vol) { diff --git a/engines/drascula/drascula.h b/engines/drascula/drascula.h index 2b6aa0f291..5ec4684723 100644 --- a/engines/drascula/drascula.h +++ b/engines/drascula/drascula.h @@ -30,6 +30,7 @@ #include "common/file.h" #include "common/hash-str.h" #include "common/keyboard.h" +#include "common/ptr.h" #include "common/random.h" #include "common/savefile.h" #include "common/system.h" @@ -264,15 +265,13 @@ private: }; class TextResourceParser { - Common::SeekableReadStream *_stream; - DisposeAfterUse::Flag _dispose; + Common::DisposablePtr<Common::SeekableReadStream> _stream; int _maxLen; void getLine(char *buf); public: TextResourceParser(Common::SeekableReadStream *stream, DisposeAfterUse::Flag dispose); - ~TextResourceParser(); void parseInt(int &result); void parseString(char *result); diff --git a/engines/drascula/resource.cpp b/engines/drascula/resource.cpp index 61609fb940..95a95e3487 100644 --- a/engines/drascula/resource.cpp +++ b/engines/drascula/resource.cpp @@ -42,7 +42,7 @@ Common::SeekableReadStream *ArchiveMan::open(const Common::String &filename) { } TextResourceParser::TextResourceParser(Common::SeekableReadStream *stream, DisposeAfterUse::Flag dispose) : - _stream(stream), _dispose(dispose) { + _stream(stream, dispose) { // NOTE: strangely enough, the code before this refactoring used the size of // the stream as a fixed maximum length for the parser. Using an updated @@ -50,12 +50,6 @@ TextResourceParser::TextResourceParser(Common::SeekableReadStream *stream, Dispo _maxLen = _stream->size(); } -TextResourceParser::~TextResourceParser() { - if (_dispose == DisposeAfterUse::YES) { - delete _stream; - } -} - void TextResourceParser::getLine(char *buf) { byte c; char *b; |