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

waltervn at users.sourceforge.net waltervn at users.sourceforge.net
Mon Jun 8 14:20:36 CEST 2009


Revision: 41368
          http://scummvm.svn.sourceforge.net/scummvm/?rev=41368&view=rev
Author:   waltervn
Date:     2009-06-08 12:20:36 +0000 (Mon, 08 Jun 2009)

Log Message:
-----------
SCI: Cleanup

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

Modified: scummvm/trunk/engines/sci/resource.cpp
===================================================================
--- scummvm/trunk/engines/sci/resource.cpp	2009-06-08 11:42:13 UTC (rev 41367)
+++ scummvm/trunk/engines/sci/resource.cpp	2009-06-08 12:20:36 UTC (rev 41368)
@@ -131,56 +131,45 @@
 ResourceSource *ResourceManager::addExternalMap(const char *file_name) {
 	ResourceSource *newsrc = new ResourceSource();
 
-	// Add the new source to the SLL of sources
-	newsrc->next = _sources;
-	_sources = newsrc;
-
 	newsrc->source_type = kSourceExtMap;
 	newsrc->location_name = file_name;
 	newsrc->scanned = false;
 	newsrc->associated_map = NULL;
 
+	_sources.push_back(newsrc);
 	return newsrc;
 }
 
 ResourceSource *ResourceManager::addSource(ResourceSource *map, ResSourceType type, const char *filename, int number) {
 	ResourceSource *newsrc = new ResourceSource();
 
-	// Add the new source to the SLL of sources
-	newsrc->next = _sources;
-	_sources = newsrc;
-
 	newsrc->source_type = type;
 	newsrc->scanned = false;
 	newsrc->location_name = filename;
 	newsrc->volume_number = number;
 	newsrc->associated_map = map;
 
+	_sources.push_back(newsrc);
 	return newsrc;
 }
 
 ResourceSource *ResourceManager::addPatchDir(const char *dirname) {
 	ResourceSource *newsrc = new ResourceSource();
 
-	// Add the new source to the SLL of sources
-	newsrc->next = _sources;
-	_sources = newsrc;
-
 	newsrc->source_type = kSourceDirectory;
 	newsrc->scanned = false;
 	newsrc->location_name = dirname;
 
+	_sources.push_back(newsrc);
 	return 0;
 }
 
 ResourceSource *ResourceManager::getVolume(ResourceSource *map, int volume_nr) {
-	ResourceSource *seeker = _sources;
-
-	while (seeker) {
-		if ((seeker->source_type == kSourceVolume || seeker->source_type == kSourceAudioVolume)
-			&& seeker->associated_map == map && seeker->volume_number == volume_nr)
-			return seeker;
-		seeker = seeker->next;
+	for (Common::List<ResourceSource *>::iterator it = _sources.begin(); it != _sources.end(); ++it) {
+		ResourceSource *src = *it;
+		if ((src->source_type == kSourceVolume || src->source_type == kSourceAudioVolume)
+			&& src->associated_map == map && src->volume_number == volume_nr)
+			return src;
 	}
 
 	return NULL;
@@ -228,21 +217,11 @@
 	return loadPatch(res, file);
 }
 
-bool ResourceManager::loadFromAudioVolume(Resource *res) {
-	Common::File file;
-	const char *filename = res->source->location_name.c_str();
-	if (file.open(filename) == false) {
-		warning("Failed to open audio volume %s", filename);
-		res->unalloc();
-		return false;
-	}
-
-	file.seek(res->file_offset, SEEK_SET);
-
+bool ResourceManager::loadFromAudioVolume(Resource *res, Common::File &file) {
 	ResourceType type = (ResourceType)(file.readByte() & 0x7f);
 	if (((res->id.type == kResourceTypeAudio || res->id.type == kResourceTypeAudio36) && (type != kResourceTypeAudio))
 		|| ((res->id.type == kResourceTypeSync || res->id.type == kResourceTypeSync36) && (type != kResourceTypeSync))) {
-		warning("Resource type mismatch loading %s from %s", res->id.toString().c_str(), filename);
+		warning("Resource type mismatch loading %s from %s", res->id.toString().c_str(), file.getName());
 		res->unalloc();
 		return false;
 	}
@@ -302,10 +281,7 @@
 
 	if (res->source->source_type == kSourcePatch && loadFromPatchFile(res))
 		return;
-	if (res->source->source_type == kSourceAudioVolume) {
-		loadFromAudioVolume(res);
-		return;
-	}
+
 	// Either loading from volume or patch loading failed
 	file = getVolumeFile(res->source->location_name.c_str());
 	if (!file) {
@@ -314,13 +290,17 @@
 		return;
 	}
 	file->seek(res->file_offset, SEEK_SET);
-	int error = decompress(res, file);
-	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 (res->source->source_type == kSourceAudioVolume) {
+		loadFromAudioVolume(res, *file);
+	} else {
+		int error = decompress(res, file);
+		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();
+		}
+	}
 }
 
 Resource *ResourceManager::testResource(ResourceId id) {
@@ -417,7 +397,6 @@
 		addSource(map, kSourceVolume, name.c_str(), number);
 	}
 	addPatchDir(".");
-	// TODO: add RESOURCE.AUD and RESOURCE.SFX for SCI1.1 games
 	if (Common::File::exists("MESSAGE.MAP"))
 		addSource(addExternalMap("MESSAGE.MAP"), kSourceVolume, "RESOURCE.MSG", 0);
 	return 1;
@@ -441,52 +420,37 @@
 	return 1;
 }
 
-int ResourceManager::scanNewSources(ResourceSource *source) {
-	if (!source)
-		return SCI_ERROR_NO_RESOURCE_FILES_FOUND;
+void ResourceManager::scanNewSources() {
+	for (Common::List<ResourceSource *>::iterator it = _sources.begin(); it != _sources.end(); ++it) {
+		ResourceSource *source = *it;
 
-	int resource_error = 0;
-	if (source->next)
-		scanNewSources(source->next);
-
-	if (!source->scanned) {
-		source->scanned = true;
-		switch (source->source_type) {
-		case kSourceDirectory:
-			readResourcePatches(source);
-			break;
-		case kSourceExtMap:
-			if (_mapVersion < SCI_VERSION_1)
-				resource_error = readResourceMapSCI0(source);
-			else
-				resource_error = readResourceMapSCI1(source);
-
-			if (resource_error == SCI_ERROR_RESMAP_NOT_FOUND) {
-				// FIXME: Try reading w/o resource.map
-				resource_error = SCI_ERROR_NO_RESOURCE_FILES_FOUND;
+		if (!source->scanned) {
+			source->scanned = true;
+			switch (source->source_type) {
+			case kSourceDirectory:
+				readResourcePatches(source);
+				break;
+			case kSourceExtMap:
+				if (_mapVersion < SCI_VERSION_1)
+					readResourceMapSCI0(source);
+				else
+					readResourceMapSCI1(source);
+				break;
+			case kSourceIntMap:
+				readMap(source);
+				break;
+			default:
+				break;
 			}
-
-			if (resource_error == SCI_ERROR_NO_RESOURCE_FILES_FOUND) {
-				// Initialize empty resource manager
-				_resMap.clear();
-				resource_error = 0;
-			}
-			break;
-		case kSourceIntMap:
-			resource_error = readMap(source);
-			break;
-		default:
-			break;
 		}
 	}
-	return resource_error;
 }
 
-void ResourceManager::freeResourceSources(ResourceSource *rss) {
-	if (rss) {
-		freeResourceSources(rss->next);
-		delete rss;
-	}
+void ResourceManager::freeResourceSources() {
+	for (Common::List<ResourceSource *>::iterator it = _sources.begin(); it != _sources.end(); ++it)
+		delete *it;
+
+	_sources.clear();
 }
 
 ResourceManager::ResourceManager(int version, int maxMemory) {
@@ -495,7 +459,6 @@
 	_memoryLRU = 0;
 	_LRU.clear();
 	_resMap.clear();
-	_sources = NULL;
 	_sciVersion = version;
 
 	addAppropriateSources();
@@ -510,9 +473,9 @@
 	debug("Using resource map version %d %s", _mapVersion, sci_version_types[_mapVersion]);
 	debug("Using volume version %d %s", _volVersion, sci_version_types[_volVersion]);
 
-	scanNewSources(_sources);
+	scanNewSources();
 	addInternalSources();
-	scanNewSources(_sources);
+	scanNewSources();
 
 	if (version == SCI_VERSION_AUTODETECT)
 		switch (_mapVersion) {
@@ -591,7 +554,7 @@
 		delete itr->_value;
 		itr ++;
 	}
-	freeResourceSources(_sources);
+	freeResourceSources();
 	_resMap.empty();
 
 	Common::List<Common::File *>::iterator it = _volumeFiles.begin();
@@ -738,14 +701,15 @@
 int ResourceManager::detectMapVersion() {
 	Common::File file;
 	byte buff[6];
-	ResourceSource *rsrc = _sources;
-	// looking for extarnal map among sources
-	while (rsrc) {
+	ResourceSource *rsrc;
+
+	for (Common::List<ResourceSource *>::iterator it = _sources.begin(); it != _sources.end(); ++it) {
+		rsrc = *it;
+
 		if (rsrc->source_type == kSourceExtMap) {
 			file.open(rsrc->location_name);
 			break;
 		}
-		rsrc = rsrc->next;
 	}
 	if (file.isOpen() == false) {
 		warning("Failed to open resource map file");
@@ -799,14 +763,14 @@
 
 int ResourceManager::detectVolVersion() {
 	Common::File file;
-	ResourceSource *rsrc = _sources;
-	// looking for a volume among sources
-	while (rsrc) {
+	ResourceSource *rsrc;
+	for (Common::List<ResourceSource *>::iterator it = _sources.begin(); it != _sources.end(); ++it) {
+		rsrc = *it;
+
 		if (rsrc->source_type == kSourceVolume) {
 			file.open(rsrc->location_name);
 			break;
 		}
-		rsrc = rsrc->next;
 	}
 	if (file.isOpen() == false) {
 		warning("Failed to open volume file");

Modified: scummvm/trunk/engines/sci/resource.h
===================================================================
--- scummvm/trunk/engines/sci/resource.h	2009-06-08 11:42:13 UTC (rev 41367)
+++ scummvm/trunk/engines/sci/resource.h	2009-06-08 12:20:36 UTC (rev 41368)
@@ -272,7 +272,7 @@
 
 protected:
 	int _maxMemory; //!< Config option: Maximum total byte number allocated
-	ResourceSource *_sources;
+	Common::List<ResourceSource *> _sources;
 	int _memoryLocked;	//!< Amount of resource bytes in locked memory
 	int _memoryLRU;		//!< Amount of resource bytes under LRU control
 	Common::List<Resource *> _LRU; //!< Last Resource Used list
@@ -316,16 +316,16 @@
 	 *					 used during startup. May be NULL.
 	 * @return One of SCI_ERROR_*.
 	 */
-	int scanNewSources(ResourceSource *source);
+	void scanNewSources();
 	int addAppropriateSources();
 	int addInternalSources();
-	void freeResourceSources(ResourceSource *rss);
+	void freeResourceSources();
 
 	Common::File *getVolumeFile(const char *filename);
 	void loadResource(Resource *res);
 	bool loadPatch(Resource *res, Common::File &file);
 	bool loadFromPatchFile(Resource *res);
-	bool loadFromAudioVolume(Resource *res);
+	bool loadFromAudioVolume(Resource *res, Common::File &file);
 	void freeOldResources(int last_invulnerable);
 	int decompress(Resource *res, Common::File *file);
 	int readResourceInfo(Resource *res, Common::File *file, uint32&szPacked, ResourceCompression &compression);


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