aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/sci/resource.cpp57
-rw-r--r--engines/sci/resource.h2
-rw-r--r--engines/sci/resource_intern.h12
3 files changed, 46 insertions, 25 deletions
diff --git a/engines/sci/resource.cpp b/engines/sci/resource.cpp
index 3792d5d9c8..ad4daab005 100644
--- a/engines/sci/resource.cpp
+++ b/engines/sci/resource.cpp
@@ -176,14 +176,18 @@ ResourceSource::ResourceSource(ResSourceType type, const Common::String &name)
associated_map = NULL;
audioCompressionType = 0;
audioCompressionOffsetMapping = NULL;
-
- if (_sourceType == kSourceMacResourceFork)
- _macResMan = new Common::MacResManager();
- else
- _macResMan = NULL;
+ _macResMan = NULL;
}
ResourceSource::~ResourceSource() {
+}
+
+MacResourceForkResourceSource::MacResourceForkResourceSource(const Common::String &name)
+ : ResourceSource(kSourceMacResourceFork, name) {
+ _macResMan = new Common::MacResManager();
+}
+
+MacResourceForkResourceSource::~MacResourceForkResourceSource() {
delete _macResMan;
}
@@ -344,17 +348,22 @@ Common::SeekableReadStream *ResourceManager::getVolumeFile(ResourceSource *sourc
static uint32 resTypeToMacTag(ResourceType type);
void ResourceManager::loadResource(Resource *res) {
- if (res->_source->getSourceType() == kSourcePatch && loadFromPatchFile(res))
+ res->_source->loadResource(res, this);
+}
+
+void ResourceSource::loadResource(Resource *res, ResourceManager *resMan) {
+
+ if (getSourceType() == kSourcePatch && resMan->loadFromPatchFile(res))
return;
- if (res->_source->getSourceType() == kSourceMacResourceFork) {
- assert(res->_source->_macResMan);
- Common::SeekableReadStream *stream = res->_source->_macResMan->getResource(resTypeToMacTag(res->_id.type), res->_id.number);
+ if (getSourceType() == kSourceMacResourceFork) {
+ assert(_macResMan);
+ Common::SeekableReadStream *stream = _macResMan->getResource(resTypeToMacTag(res->_id.type), res->_id.number);
if (!stream)
error("Could not get Mac resource fork resource: %d %d", res->_id.type, res->_id.number);
- int error = decompress(res, stream);
+ int error = resMan->decompress(res, stream);
if (error) {
warning("Error %d occured while reading %s from Mac resource file: %s",
error, res->_id.toString().c_str(), sci_error_types[error]);
@@ -363,27 +372,27 @@ void ResourceManager::loadResource(Resource *res) {
return;
}
- Common::SeekableReadStream *fileStream = getVolumeFile(res->_source);
+ Common::SeekableReadStream *fileStream = resMan->getVolumeFile(this);
if (!fileStream) {
- warning("Failed to open %s", res->_source->getLocationName().c_str());
+ warning("Failed to open %s", getLocationName().c_str());
res->unalloc();
return;
}
- switch(res->_source->getSourceType()) {
+ switch(getSourceType()) {
case kSourceWave:
fileStream->seek(res->_fileOffset, SEEK_SET);
- loadFromWaveFile(res, fileStream);
- if (res->_source->_resourceFile)
+ resMan->loadFromWaveFile(res, fileStream);
+ if (_resourceFile)
delete fileStream;
return;
case kSourceAudioVolume:
- if (res->_source->audioCompressionType) {
+ 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 = res->_source->audioCompressionOffsetMapping;
+ int32 *mappingTable = audioCompressionOffsetMapping;
int32 compressedOffset = 0;
do {
@@ -413,8 +422,8 @@ void ResourceManager::loadResource(Resource *res) {
case kResourceTypeAudio:
case kResourceTypeAudio36:
// Directly read the stream, compressed audio wont have resource type id and header size for SCI1.1
- loadFromAudioVolumeSCI1(res, fileStream);
- if (res->_source->_resourceFile)
+ resMan->loadFromAudioVolumeSCI1(res, fileStream);
+ if (_resourceFile)
delete fileStream;
return;
default:
@@ -425,19 +434,19 @@ void ResourceManager::loadResource(Resource *res) {
fileStream->seek(res->_fileOffset, SEEK_SET);
}
if (getSciVersion() < SCI_VERSION_1_1)
- loadFromAudioVolumeSCI1(res, fileStream);
+ resMan->loadFromAudioVolumeSCI1(res, fileStream);
else
- loadFromAudioVolumeSCI11(res, fileStream);
+ resMan->loadFromAudioVolumeSCI11(res, fileStream);
- if (res->_source->_resourceFile)
+ if (_resourceFile)
delete fileStream;
return;
default:
fileStream->seek(res->_fileOffset, SEEK_SET);
- int error = decompress(res, fileStream);
+ int error = resMan->decompress(res, fileStream);
- if (res->_source->_resourceFile)
+ if (_resourceFile)
delete fileStream;
if (error) {
diff --git a/engines/sci/resource.h b/engines/sci/resource.h
index fa5d757def..89af97df7e 100644
--- a/engines/sci/resource.h
+++ b/engines/sci/resource.h
@@ -166,6 +166,7 @@ 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 MacResourceForkResourceSource;
public:
@@ -201,6 +202,7 @@ typedef Common::HashMap<ResourceId, Resource *, ResourceIdHash, ResourceIdEqualT
class ResourceManager {
// FIXME: These 'friend' declarations are meant to be a temporary hack to
// ease transition to the ResourceSource class system.
+ friend class ResourceSource;
friend class DirectoryResourceSource;
friend class ExtMapResourceSource;
friend class IntMapResourceSource;
diff --git a/engines/sci/resource_intern.h b/engines/sci/resource_intern.h
index c492602187..5c63436b1b 100644
--- a/engines/sci/resource_intern.h
+++ b/engines/sci/resource_intern.h
@@ -69,6 +69,9 @@ public:
ResSourceType getSourceType() const { return _sourceType; }
const Common::String &getLocationName() const { return _name; }
+ /**
+ * TODO: Document this
+ */
virtual ResourceSource *findVolume(ResourceSource *map, int volume_nr) {
return NULL;
};
@@ -78,6 +81,12 @@ public:
* TODO: The resMan param for now is just a hack.
*/
virtual void scanSource(ResourceManager *resMan) {}
+
+ /**
+ * Load a resource.
+ * TODO: The resMan param for now is just a hack.
+ */
+ virtual void loadResource(Resource *res, ResourceManager *resMan);
};
class DirectoryResourceSource : public ResourceSource {
@@ -141,7 +150,8 @@ public:
class MacResourceForkResourceSource : public ResourceSource {
public:
- MacResourceForkResourceSource(const Common::String &name) : ResourceSource(kSourceMacResourceFork, name) {}
+ MacResourceForkResourceSource(const Common::String &name);
+ ~MacResourceForkResourceSource();
/**
* Reads the SCI1.1+ resource file from a Mac resource fork.