aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorMax Horn2010-06-15 12:11:56 +0000
committerMax Horn2010-06-15 12:11:56 +0000
commit89cf6f7cb1b8336931b46e714b403f9bfe9af128 (patch)
treebf1e3344ed4ff6cd13b57d16840ff85a833dafc7 /engines
parent8c06425ee3cac66469c817ab96cd0ab3688cdae6 (diff)
downloadscummvm-rg350-89cf6f7cb1b8336931b46e714b403f9bfe9af128.tar.gz
scummvm-rg350-89cf6f7cb1b8336931b46e714b403f9bfe9af128.tar.bz2
scummvm-rg350-89cf6f7cb1b8336931b46e714b403f9bfe9af128.zip
SCI: Change ResourceManager::getVolume() to use new classes
* Add new ResourceSource::findVolume() virtual method * Rename ResourceManager::getVolume() to findVolume(), and change it to use the new ResourceSource method * Add some TODO comments pointing to further OOPification possibilities svn-id: r49815
Diffstat (limited to 'engines')
-rw-r--r--engines/sci/resource.cpp29
-rw-r--r--engines/sci/resource.h2
-rw-r--r--engines/sci/resource_audio.cpp4
-rw-r--r--engines/sci/resource_intern.h16
4 files changed, 35 insertions, 16 deletions
diff --git a/engines/sci/resource.cpp b/engines/sci/resource.cpp
index 08ca46f881..44b4525cd2 100644
--- a/engines/sci/resource.cpp
+++ b/engines/sci/resource.cpp
@@ -214,8 +214,13 @@ ResourceSource *ResourceManager::addSource(ResourceSource *newsrc, int number) {
assert(newsrc);
newsrc->volume_number = number;
- if (newsrc->getSourceType() == kSourceAudioVolume)
+ if (newsrc->getSourceType() == kSourceAudioVolume) {
+ // TODO: Move this call into the AudioVolumeResourceSource constructor.
+ // Need to verify if this is safe, though; in particular, whether this
+ // method may be called before the new AudioVolumeResourceSource has been
+ // added to the _sources lists.
checkIfAudioVolumeIsCompressed(newsrc);
+ }
_sources.push_back(newsrc);
return newsrc;
@@ -226,8 +231,13 @@ ResourceSource *ResourceManager::addSource(ResourceSource *newsrc, const Common:
newsrc->resourceFile = resFile;
newsrc->volume_number = number;
- if (newsrc->getSourceType() == kSourceAudioVolume)
+ if (newsrc->getSourceType() == kSourceAudioVolume) {
+ // TODO: Move this call into the AudioVolumeResourceSource constructor.
+ // Need to verify if this is safe, though; in particular, whether this
+ // method may be called before the new AudioVolumeResourceSource has been
+ // added to the _sources lists.
checkIfAudioVolumeIsCompressed(newsrc);
+ }
_sources.push_back(newsrc);
return newsrc;
@@ -240,11 +250,10 @@ ResourceSource *ResourceManager::addPatchDir(const Common::String &dirname) {
return 0;
}
-ResourceSource *ResourceManager::getVolume(ResourceSource *map, int volume_nr) {
+ResourceSource *ResourceManager::findVolume(ResourceSource *map, int volume_nr) {
for (Common::List<ResourceSource *>::iterator it = _sources.begin(); it != _sources.end(); ++it) {
- ResourceSource *src = *it;
- if ((src->getSourceType() == kSourceVolume || src->getSourceType() == kSourceAudioVolume)
- && src->associated_map == map && src->volume_number == volume_nr)
+ ResourceSource *src = (*it)->findVolume(map, volume_nr);
+ if (src)
return src;
}
@@ -908,7 +917,7 @@ ResourceManager::ResVersion ResourceManager::detectMapVersion() {
// check if 0 or 01 - try to read resources in SCI0 format and see if exists
fileStream->seek(0, SEEK_SET);
while (fileStream->read(buff, 6) == 6 && !(buff[0] == 0xFF && buff[1] == 0xFF && buff[2] == 0xFF)) {
- if (getVolume(rsrc, (buff[5] & 0xFC) >> 2) == NULL)
+ if (findVolume(rsrc, (buff[5] & 0xFC) >> 2) == NULL)
return kResVersionSci1Middle;
}
return kResVersionSci0Sci1Early;
@@ -1318,7 +1327,7 @@ int ResourceManager::readResourceMapSCI0(ResourceSource *map) {
// adding a new resource
if (_resMap.contains(resId) == false) {
res = new Resource;
- res->_source = getVolume(map, offset >> bShift);
+ res->_source = findVolume(map, offset >> bShift);
if (!res->_source) {
warning("Could not get volume for resource %d, VolumeID %d", id, offset >> bShift);
if (_mapVersion != _volVersion) {
@@ -1327,7 +1336,7 @@ int ResourceManager::readResourceMapSCI0(ResourceSource *map) {
_mapVersion = _volVersion;
bMask = (_mapVersion == kResVersionSci1Middle) ? 0xF0 : 0xFC;
bShift = (_mapVersion == kResVersionSci1Middle) ? 28 : 26;
- res->_source = getVolume(map, offset >> bShift);
+ res->_source = findVolume(map, offset >> bShift);
}
}
res->_fileOffset = offset & (((~bMask) << 24) | 0xFFFFFF);
@@ -1411,7 +1420,7 @@ int ResourceManager::readResourceMapSCI1(ResourceSource *map) {
// for SCI2.1 and SCI3 maps that are not resmap.000. The resmap.* files' numbers
// need to be used in concurrence with the volume specified in the map to get
// the actual resource file.
- res->_source = getVolume(map, volume_nr + map->volume_number);
+ res->_source = findVolume(map, volume_nr + map->volume_number);
res->_fileOffset = off;
}
}
diff --git a/engines/sci/resource.h b/engines/sci/resource.h
index 67cc4d3c1f..826fbff850 100644
--- a/engines/sci/resource.h
+++ b/engines/sci/resource.h
@@ -312,7 +312,7 @@ protected:
*/
ResourceSource *addPatchDir(const Common::String &path);
- ResourceSource *getVolume(ResourceSource *map, int volume_nr);
+ ResourceSource *findVolume(ResourceSource *map, int volume_nr);
/**
* Adds a source to the resource manager's list of sources.
diff --git a/engines/sci/resource_audio.cpp b/engines/sci/resource_audio.cpp
index 36084087fd..7d716f0f20 100644
--- a/engines/sci/resource_audio.cpp
+++ b/engines/sci/resource_audio.cpp
@@ -260,7 +260,7 @@ int ResourceManager::readAudioMapSCI11(ResourceSource *map) {
return SCI_ERROR_RESMAP_NOT_FOUND;
}
- ResourceSource *src = getVolume(map, 0);
+ ResourceSource *src = findVolume(map, 0);
if (!src)
return SCI_ERROR_NO_RESOURCE_FILES_FOUND;
@@ -380,7 +380,7 @@ int ResourceManager::readAudioMapSCI1(ResourceSource *map, bool unload) {
offset &= 0x0fffffff; // least significant 28 bits
}
- ResourceSource *src = getVolume(map, volume_nr);
+ ResourceSource *src = findVolume(map, volume_nr);
if (src) {
if (unload)
diff --git a/engines/sci/resource_intern.h b/engines/sci/resource_intern.h
index e0d7cdcf87..15fd5c391d 100644
--- a/engines/sci/resource_intern.h
+++ b/engines/sci/resource_intern.h
@@ -57,9 +57,9 @@ public:
const Common::FSNode *resourceFile;
int volume_number;
ResourceSource *associated_map; // TODO: Move to VolumeResourceSource
- uint32 audioCompressionType;
- int32 *audioCompressionOffsetMapping;
- Common::MacResManager *_macResMan;
+ uint32 audioCompressionType; // TODO: Move to AudioVolumeResourceSource
+ int32 *audioCompressionOffsetMapping; // TODO: Move to AudioVolumeResourceSource
+ Common::MacResManager *_macResMan; // TODO: Move to MacResourceForkResourceSource
protected:
ResourceSource(ResSourceType type, const Common::String &name);
@@ -68,6 +68,10 @@ public:
ResSourceType getSourceType() const { return _sourceType; }
const Common::String &getLocationName() const { return _name; }
+
+ virtual ResourceSource *findVolume(ResourceSource *map, int volume_nr) {
+ return NULL;
+ };
};
class DirectoryResourceSource : public ResourceSource {
@@ -86,6 +90,12 @@ public:
: ResourceSource(type, name) {
associated_map = map;
}
+
+ virtual ResourceSource *findVolume(ResourceSource *map, int volume_nr) {
+ if (associated_map == map && volume_number == volume_nr)
+ return this;
+ return NULL;
+ };
};
class ExtMapResourceSource : public ResourceSource {