[Scummvm-cvs-logs] SF.net SVN: scummvm:[49815] scummvm/trunk/engines/sci

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Tue Jun 15 14:11:56 CEST 2010


Revision: 49815
          http://scummvm.svn.sourceforge.net/scummvm/?rev=49815&view=rev
Author:   fingolfin
Date:     2010-06-15 12:11:56 +0000 (Tue, 15 Jun 2010)

Log Message:
-----------
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

Modified Paths:
--------------
    scummvm/trunk/engines/sci/resource.cpp
    scummvm/trunk/engines/sci/resource.h
    scummvm/trunk/engines/sci/resource_audio.cpp
    scummvm/trunk/engines/sci/resource_intern.h

Modified: scummvm/trunk/engines/sci/resource.cpp
===================================================================
--- scummvm/trunk/engines/sci/resource.cpp	2010-06-15 12:11:30 UTC (rev 49814)
+++ scummvm/trunk/engines/sci/resource.cpp	2010-06-15 12:11:56 UTC (rev 49815)
@@ -214,8 +214,13 @@
 	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 @@
 
 	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 @@
 	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 @@
 		// 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 @@
 		// 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 @@
 					_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 @@
 				// 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;
 			}
 		}

Modified: scummvm/trunk/engines/sci/resource.h
===================================================================
--- scummvm/trunk/engines/sci/resource.h	2010-06-15 12:11:30 UTC (rev 49814)
+++ scummvm/trunk/engines/sci/resource.h	2010-06-15 12:11:56 UTC (rev 49815)
@@ -312,7 +312,7 @@
 	 */
 	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.

Modified: scummvm/trunk/engines/sci/resource_audio.cpp
===================================================================
--- scummvm/trunk/engines/sci/resource_audio.cpp	2010-06-15 12:11:30 UTC (rev 49814)
+++ scummvm/trunk/engines/sci/resource_audio.cpp	2010-06-15 12:11:56 UTC (rev 49815)
@@ -260,7 +260,7 @@
 		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 @@
 			offset &= 0x0fffffff; // least significant 28 bits
 		}
 
-		ResourceSource *src = getVolume(map, volume_nr);
+		ResourceSource *src = findVolume(map, volume_nr);
 
 		if (src) {
 			if (unload)

Modified: scummvm/trunk/engines/sci/resource_intern.h
===================================================================
--- scummvm/trunk/engines/sci/resource_intern.h	2010-06-15 12:11:30 UTC (rev 49814)
+++ scummvm/trunk/engines/sci/resource_intern.h	2010-06-15 12:11:56 UTC (rev 49815)
@@ -57,9 +57,9 @@
 	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 @@
 
 	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 @@
 		: 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 {


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list