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
This commit is contained in:
Max Horn 2010-06-15 12:11:56 +00:00
parent 8c06425ee3
commit 89cf6f7cb1
4 changed files with 35 additions and 16 deletions

View File

@ -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;
}
}

View File

@ -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.

View File

@ -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)

View File

@ -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 {