diff options
Diffstat (limited to 'engines')
-rw-r--r-- | engines/sci/resource.cpp | 25 | ||||
-rw-r--r-- | engines/sci/resource.h | 11 | ||||
-rw-r--r-- | engines/sci/resource_audio.cpp | 16 |
3 files changed, 29 insertions, 23 deletions
diff --git a/engines/sci/resource.cpp b/engines/sci/resource.cpp index a57ae04847..370a135a69 100644 --- a/engines/sci/resource.cpp +++ b/engines/sci/resource.cpp @@ -234,7 +234,9 @@ ResourceSource *ResourceManager::findVolume(ResourceSource *map, int volume_nr) // Resource manager constructors and operations -bool ResourceManager::loadPatch(Resource *res, Common::SeekableReadStream *file) { +bool Resource::loadPatch(Common::SeekableReadStream *file) { + Resource *res = this; + // We assume that the resource type matches res->type // We also assume that the current file position is right at the actual data (behind resourceid/headersize byte) @@ -262,17 +264,17 @@ bool ResourceManager::loadPatch(Resource *res, Common::SeekableReadStream *file) return true; } -bool ResourceManager::loadFromPatchFile(Resource *res) { +bool Resource::loadFromPatchFile() { Common::File file; - const Common::String &filename = res->_source->getLocationName(); + const Common::String &filename = _source->getLocationName(); if (file.open(filename) == false) { warning("Failed to open patch file %s", filename.c_str()); - res->unalloc(); + unalloc(); return false; } // Skip resourceid and header size byte file.seek(2, SEEK_SET); - return loadPatch(res, &file); + return loadPatch(&file); } Common::SeekableReadStream *ResourceManager::getVolumeFile(ResourceSource *source) { @@ -321,8 +323,7 @@ void ResourceManager::loadResource(Resource *res) { void PatchResourceSource::loadResource(Resource *res) { - ResourceManager *resMan = g_sci->getResMan(); - bool result = resMan->loadFromPatchFile(res); + bool result = res->loadFromPatchFile(); if (!result) { // TODO: We used to fallback to the "default" code here if loadFromPatchFile // failed, but I am not sure whether that is really appropriate. @@ -360,19 +361,17 @@ Common::SeekableReadStream *ResourceSource::getVolumeFile(Resource *res) { } void WaveResourceSource::loadResource(Resource *res) { - ResourceManager *resMan = g_sci->getResMan(); Common::SeekableReadStream *fileStream = getVolumeFile(res); if (!fileStream) return; fileStream->seek(res->_fileOffset, SEEK_SET); - resMan->loadFromWaveFile(res, fileStream); + res->loadFromWaveFile(fileStream); if (_resourceFile) delete fileStream; } void AudioVolumeResourceSource::loadResource(Resource *res) { - ResourceManager *resMan = g_sci->getResMan(); Common::SeekableReadStream *fileStream = getVolumeFile(res); if (!fileStream) return; @@ -410,7 +409,7 @@ void AudioVolumeResourceSource::loadResource(Resource *res) { case kResourceTypeAudio: case kResourceTypeAudio36: // Directly read the stream, compressed audio wont have resource type id and header size for SCI1.1 - resMan->loadFromAudioVolumeSCI1(res, fileStream); + res->loadFromAudioVolumeSCI1(fileStream); if (_resourceFile) delete fileStream; return; @@ -422,9 +421,9 @@ void AudioVolumeResourceSource::loadResource(Resource *res) { fileStream->seek(res->_fileOffset, SEEK_SET); } if (getSciVersion() < SCI_VERSION_1_1) - resMan->loadFromAudioVolumeSCI1(res, fileStream); + res->loadFromAudioVolumeSCI1(fileStream); else - resMan->loadFromAudioVolumeSCI11(res, fileStream); + res->loadFromAudioVolumeSCI11(fileStream); if (_resourceFile) delete fileStream; diff --git a/engines/sci/resource.h b/engines/sci/resource.h index 09d87eb9e3..85e03d3a4c 100644 --- a/engines/sci/resource.h +++ b/engines/sci/resource.h @@ -192,6 +192,12 @@ public: void writeToStream(Common::WriteStream *stream) const; uint32 getAudioCompressionType() const; + bool loadPatch(Common::SeekableReadStream *file); + bool loadFromPatchFile(); + bool loadFromWaveFile(Common::SeekableReadStream *file); + bool loadFromAudioVolumeSCI1(Common::SeekableReadStream *file); + bool loadFromAudioVolumeSCI11(Common::SeekableReadStream *file); + protected: int32 _fileOffset; /**< Offset in file */ ResourceStatus _status; @@ -386,11 +392,6 @@ protected: Common::SeekableReadStream *getVolumeFile(ResourceSource *source); void loadResource(Resource *res); - bool loadPatch(Resource *res, Common::SeekableReadStream *file); - bool loadFromPatchFile(Resource *res); - bool loadFromWaveFile(Resource *res, Common::SeekableReadStream *file); - bool loadFromAudioVolumeSCI1(Resource *res, Common::SeekableReadStream *file); - bool loadFromAudioVolumeSCI11(Resource *res, Common::SeekableReadStream *file); void freeOldResources(); int decompress(Resource *res, Common::SeekableReadStream *file); int readResourceInfo(Resource *res, Common::SeekableReadStream *file, uint32 &szPacked, ResourceCompression &compression); diff --git a/engines/sci/resource_audio.cpp b/engines/sci/resource_audio.cpp index 26ea96fb6c..1b90cdfb02 100644 --- a/engines/sci/resource_audio.cpp +++ b/engines/sci/resource_audio.cpp @@ -76,7 +76,9 @@ AudioVolumeResourceSource::AudioVolumeResourceSource(const Common::String &name, delete fileStream; } -bool ResourceManager::loadFromWaveFile(Resource *res, Common::SeekableReadStream *file) { +bool Resource::loadFromWaveFile(Common::SeekableReadStream *file) { + Resource *res = this; + res->data = new byte[res->size]; uint32 really_read = file->read(res->data, res->size); @@ -87,14 +89,16 @@ bool ResourceManager::loadFromWaveFile(Resource *res, Common::SeekableReadStream return true; } -bool ResourceManager::loadFromAudioVolumeSCI11(Resource *res, Common::SeekableReadStream *file) { +bool Resource::loadFromAudioVolumeSCI11(Common::SeekableReadStream *file) { + Resource *res = this; + // Check for WAVE files here uint32 riffTag = file->readUint32BE(); if (riffTag == MKID_BE('RIFF')) { res->_headerSize = 0; res->size = file->readUint32LE(); file->seek(-8, SEEK_CUR); - return loadFromWaveFile(res, file); + return loadFromWaveFile(file); } file->seek(-4, SEEK_CUR); @@ -122,10 +126,12 @@ bool ResourceManager::loadFromAudioVolumeSCI11(Resource *res, Common::SeekableRe file->seek(-11, SEEK_CUR); } - return loadPatch(res, file); + return loadPatch(file); } -bool ResourceManager::loadFromAudioVolumeSCI1(Resource *res, Common::SeekableReadStream *file) { +bool Resource::loadFromAudioVolumeSCI1(Common::SeekableReadStream *file) { + Resource *res = this; + res->data = new byte[res->size]; if (res->data == NULL) { |