aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorMax Horn2010-06-15 12:14:15 +0000
committerMax Horn2010-06-15 12:14:15 +0000
commitbb1336ca415311ed28195b2b7ac574e2244c2cc5 (patch)
tree5b46559a37e1e103207f03c07b3a039d1523f2a8 /engines
parentd032e6481beee01a22302edac5193bc9ebdb8ea9 (diff)
downloadscummvm-rg350-bb1336ca415311ed28195b2b7ac574e2244c2cc5.tar.gz
scummvm-rg350-bb1336ca415311ed28195b2b7ac574e2244c2cc5.tar.bz2
scummvm-rg350-bb1336ca415311ed28195b2b7ac574e2244c2cc5.zip
SCI: Add loadResource impls for WaveResourceSource and AudioVolumeResourceSource
svn-id: r49821
Diffstat (limited to 'engines')
-rw-r--r--engines/sci/resource.cpp142
-rw-r--r--engines/sci/resource.h4
-rw-r--r--engines/sci/resource_intern.h7
3 files changed, 85 insertions, 68 deletions
diff --git a/engines/sci/resource.cpp b/engines/sci/resource.cpp
index 35e0c93d59..45ee9b3d0f 100644
--- a/engines/sci/resource.cpp
+++ b/engines/sci/resource.cpp
@@ -376,89 +376,101 @@ void MacResourceForkResourceSource::loadResource(Resource *res, ResourceManager
}
}
-void ResourceSource::loadResource(Resource *res, ResourceManager *resMan) {
+Common::SeekableReadStream *ResourceSource::getVolumeFile(Resource *res, ResourceManager *resMan) {
Common::SeekableReadStream *fileStream = resMan->getVolumeFile(this);
if (!fileStream) {
warning("Failed to open %s", getLocationName().c_str());
res->unalloc();
- return;
}
- switch(getSourceType()) {
- case kSourceWave:
- fileStream->seek(res->_fileOffset, SEEK_SET);
- resMan->loadFromWaveFile(res, fileStream);
- if (_resourceFile)
- delete fileStream;
+ return fileStream;
+}
+
+void WaveResourceSource::loadResource(Resource *res, ResourceManager *resMan) {
+ Common::SeekableReadStream *fileStream = getVolumeFile(res, resMan);
+ if (!fileStream)
return;
- case kSourceAudioVolume:
- if (audioCompressionType) {
- // this file is compressed, so lookup our offset in the offset-translation table and get the new offset
- // also calculate the compressed size by using the next offset
- int32 *mappingTable = audioCompressionOffsetMapping;
- int32 compressedOffset = 0;
-
- do {
- if (*mappingTable == res->_fileOffset) {
- mappingTable++;
- compressedOffset = *mappingTable;
- // Go to next compressed offset and use that to calculate size of compressed sample
- switch (res->_id.type) {
- case kResourceTypeSync:
- case kResourceTypeSync36:
- // we should already have a (valid) size
- break;
- default:
- mappingTable += 2;
- res->size = *mappingTable - compressedOffset;
- }
+ fileStream->seek(res->_fileOffset, SEEK_SET);
+ resMan->loadFromWaveFile(res, fileStream);
+ if (_resourceFile)
+ delete fileStream;
+}
+
+void AudioVolumeResourceSource::loadResource(Resource *res, ResourceManager *resMan) {
+ Common::SeekableReadStream *fileStream = getVolumeFile(res, resMan);
+ if (!fileStream)
+ return;
+
+ if (audioCompressionType) {
+ // this file is compressed, so lookup our offset in the offset-translation table and get the new offset
+ // also calculate the compressed size by using the next offset
+ int32 *mappingTable = audioCompressionOffsetMapping;
+ int32 compressedOffset = 0;
+
+ do {
+ if (*mappingTable == res->_fileOffset) {
+ mappingTable++;
+ compressedOffset = *mappingTable;
+ // Go to next compressed offset and use that to calculate size of compressed sample
+ switch (res->_id.type) {
+ case kResourceTypeSync:
+ case kResourceTypeSync36:
+ // we should already have a (valid) size
break;
+ default:
+ mappingTable += 2;
+ res->size = *mappingTable - compressedOffset;
}
- mappingTable += 2;
- } while (*mappingTable);
-
- if (!compressedOffset)
- error("could not translate offset to compressed offset in audio volume");
- fileStream->seek(compressedOffset, SEEK_SET);
-
- switch (res->_id.type) {
- 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);
- if (_resourceFile)
- delete fileStream;
- return;
- default:
break;
}
- } else {
- // original file, directly seek to given offset and get SCI1/SCI1.1 audio resource
- fileStream->seek(res->_fileOffset, SEEK_SET);
- }
- if (getSciVersion() < SCI_VERSION_1_1)
+ mappingTable += 2;
+ } while (*mappingTable);
+
+ if (!compressedOffset)
+ error("could not translate offset to compressed offset in audio volume");
+ fileStream->seek(compressedOffset, SEEK_SET);
+
+ switch (res->_id.type) {
+ 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);
- else
- resMan->loadFromAudioVolumeSCI11(res, fileStream);
+ if (_resourceFile)
+ delete fileStream;
+ return;
+ default:
+ break;
+ }
+ } else {
+ // original file, directly seek to given offset and get SCI1/SCI1.1 audio resource
+ fileStream->seek(res->_fileOffset, SEEK_SET);
+ }
+ if (getSciVersion() < SCI_VERSION_1_1)
+ resMan->loadFromAudioVolumeSCI1(res, fileStream);
+ else
+ resMan->loadFromAudioVolumeSCI11(res, fileStream);
- if (_resourceFile)
- delete fileStream;
+ if (_resourceFile)
+ delete fileStream;
+}
+
+void ResourceSource::loadResource(Resource *res, ResourceManager *resMan) {
+ Common::SeekableReadStream *fileStream = getVolumeFile(res, resMan);
+ if (!fileStream)
return;
- default:
- fileStream->seek(res->_fileOffset, SEEK_SET);
- int error = resMan->decompress(res, fileStream);
+ fileStream->seek(res->_fileOffset, SEEK_SET);
+ int error = resMan->decompress(res, fileStream);
- if (_resourceFile)
- delete fileStream;
+ if (_resourceFile)
+ delete fileStream;
- if (error) {
- warning("Error %d occured while reading %s from resource file: %s",
- error, res->_id.toString().c_str(), sci_error_types[error]);
- res->unalloc();
- }
+ if (error) {
+ warning("Error %d occured while reading %s from resource file: %s",
+ error, res->_id.toString().c_str(), sci_error_types[error]);
+ res->unalloc();
}
}
@@ -1541,7 +1553,7 @@ void ResourceManager::addResource(ResourceId resId, ResourceSource *src, uint32
}
int ResourceManager::readResourceInfo(Resource *res, Common::SeekableReadStream *file,
- uint32&szPacked, ResourceCompression &compression) {
+ uint32 &szPacked, ResourceCompression &compression) {
// SCI0 volume format: {wResId wPacked+4 wUnpacked wCompression} = 8 bytes
// SCI1 volume format: {bResType wResNumber wPacked+4 wUnpacked wCompression} = 9 bytes
// SCI1.1 volume format: {bResType wResNumber wPacked wUnpacked wCompression} = 9 bytes
diff --git a/engines/sci/resource.h b/engines/sci/resource.h
index ff848d24b2..6d37455f52 100644
--- a/engines/sci/resource.h
+++ b/engines/sci/resource.h
@@ -167,6 +167,8 @@ class Resource {
// FIXME: These 'friend' declarations are meant to be a temporary hack to
// ease transition to the ResourceSource class system.
friend class ResourceSource;
+ friend class WaveResourceSource;
+ friend class AudioVolumeResourceSource;
friend class MacResourceForkResourceSource;
public:
@@ -393,7 +395,7 @@ protected:
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);
+ int readResourceInfo(Resource *res, Common::SeekableReadStream *file, uint32 &szPacked, ResourceCompression &compression);
void addResource(ResourceId resId, ResourceSource *src, uint32 offset, uint32 size = 0);
void removeAudioResource(ResourceId resId);
diff --git a/engines/sci/resource_intern.h b/engines/sci/resource_intern.h
index 3d51e0ae02..560e99ac80 100644
--- a/engines/sci/resource_intern.h
+++ b/engines/sci/resource_intern.h
@@ -68,6 +68,9 @@ public:
ResSourceType getSourceType() const { return _sourceType; }
const Common::String &getLocationName() const { return _name; }
+ // Auxiliary method, used by loadResource implementations.
+ Common::SeekableReadStream *getVolumeFile(Resource *res, ResourceManager *resMan);
+
/**
* TODO: Document this
*/
@@ -136,7 +139,7 @@ public:
: VolumeResourceSource(name, map, kSourceAudioVolume) {
}
- //virtual void loadResource(Resource *res, ResourceManager *resMan);
+ virtual void loadResource(Resource *res, ResourceManager *resMan);
};
class ExtAudioMapResourceSource : public ResourceSource {
@@ -150,7 +153,7 @@ class WaveResourceSource : public ResourceSource {
public:
WaveResourceSource(const Common::String &name) : ResourceSource(kSourceWave, name) {}
- //virtual void loadResource(Resource *res, ResourceManager *resMan);
+ virtual void loadResource(Resource *res, ResourceManager *resMan);
};
class MacResourceForkResourceSource : public ResourceSource {