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

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Tue Jun 15 14:19:40 CEST 2010


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

Log Message:
-----------
SCI: Move decompress & readResourceInfo to Resource; more cleanup

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

Modified: scummvm/trunk/engines/sci/resource.cpp
===================================================================
--- scummvm/trunk/engines/sci/resource.cpp	2010-06-15 12:19:14 UTC (rev 49834)
+++ scummvm/trunk/engines/sci/resource.cpp	2010-06-15 12:19:39 UTC (rev 49835)
@@ -338,8 +338,7 @@
 	if (!stream)
 		error("Could not get Mac resource fork resource: %d %d", res->_id.type, res->_id.number);
 
-	ResourceManager *resMan = g_sci->getResMan();
-	int error = resMan->decompress(res, stream);
+	int error = res->decompress(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]);
@@ -436,8 +435,7 @@
 
 	fileStream->seek(res->_fileOffset, SEEK_SET);
 
-	ResourceManager *resMan = g_sci->getResMan();
-	int error = resMan->decompress(res, fileStream);
+	int error = res->decompress(fileStream);
 
 	if (_resourceFile)
 		delete fileStream;
@@ -631,18 +629,18 @@
 
 void DirectoryResourceSource::scanSource() {
 	ResourceManager *resMan = g_sci->getResMan();
-	resMan->readResourcePatches(this);
+	resMan->readResourcePatches();
 
 	// We can't use getSciVersion() at this point, thus using _volVersion
-	if (resMan->_volVersion >= ResourceManager::kResVersionSci11)	// SCI1.1+
-		resMan->readResourcePatchesBase36(this);
+	if (resMan->_volVersion >= kResVersionSci11)	// SCI1.1+
+		resMan->readResourcePatchesBase36();
 
 	resMan->readWaveAudioPatches();
 }
 
 void ExtMapResourceSource::scanSource() {
 	ResourceManager *resMan = g_sci->getResMan();
-	if (resMan->_mapVersion < ResourceManager::kResVersionSci1Late)
+	if (resMan->_mapVersion < kResVersionSci1Late)
 		resMan->readResourceMapSCI0(this);
 	else
 		resMan->readResourceMapSCI1(this);
@@ -881,7 +879,7 @@
 	return "Version not valid";
 }
 
-ResourceManager::ResVersion ResourceManager::detectMapVersion() {
+ResVersion ResourceManager::detectMapVersion() {
 	Common::SeekableReadStream *fileStream = 0;
 	byte buff[6];
 	ResourceSource *rsrc= 0;
@@ -971,7 +969,7 @@
 	return kResVersionUnknown;
 }
 
-ResourceManager::ResVersion ResourceManager::detectVolVersion() {
+ResVersion ResourceManager::detectVolVersion() {
 	Common::SeekableReadStream *fileStream = 0;
 	ResourceSource *rsrc;
 
@@ -1143,7 +1141,7 @@
 	debugC(1, kDebugLevelResMan, "Patching %s - OK", source->getLocationName().c_str());
 }
 
-void ResourceManager::readResourcePatchesBase36(ResourceSource *source) {
+void ResourceManager::readResourcePatchesBase36() {
 	// The base36 encoded audio36 and sync36 resources use a different naming scheme, because they
 	// cannot be described with a single resource number, but are a result of a
 	// <number, noun, verb, cond, seq> tuple. Please don't be confused with the normal audio patches
@@ -1227,7 +1225,7 @@
 	}
 }
 
-void ResourceManager::readResourcePatches(ResourceSource *source) {
+void ResourceManager::readResourcePatches() {
 	// Note: since some SCI1 games(KQ5 floppy, SQ4) might use SCI0 naming scheme for patch files
 	// this function tries to read patch file with any supported naming scheme,
 	// regardless of s_sciVersion value
@@ -1515,7 +1513,7 @@
 	return res;
 }
 
-int ResourceManager::readResourceInfo(Resource *res, Common::SeekableReadStream *file,
+int Resource::readResourceInfo(Common::SeekableReadStream *file,
                                       uint32 &szPacked, ResourceCompression &compression) {
 	// SCI0 volume format:  {wResId wPacked+4 wUnpacked wCompression} = 8 bytes
 	// SCI1 volume format:  {bResType wResNumber wPacked+4 wUnpacked wCompression} = 9 bytes
@@ -1525,7 +1523,8 @@
 	uint32 wCompression, szUnpacked;
 	ResourceType type;
 
-	switch (_volVersion) {
+	ResourceManager *resMan = g_sci->getResMan();
+	switch (resMan->_volVersion) {
 	case kResVersionSci0Sci1Early:
 	case kResVersionSci1Middle:
 		w = file->readUint16LE();
@@ -1552,8 +1551,8 @@
 	case kResVersionSci11Mac:
 		// Doesn't store this data in the resource. Fortunately,
 		// we already have this data.
-		type = res->_id.type;
-		number = res->_id.number;
+		type = _id.type;
+		number = _id.number;
 		szPacked = file->size();
 		szUnpacked = file->size();
 		wCompression = 0;
@@ -1575,8 +1574,8 @@
 	if ((file->eos() || file->err()))
 		return SCI_ERROR_IO_ERROR;
 
-	res->_id = ResourceId(type, number);
-	res->size = szUnpacked;
+	_id = ResourceId(type, number);
+	size = szUnpacked;
 
 	// checking compression method
 	switch (wCompression) {
@@ -1612,13 +1611,13 @@
 	return compression == kCompUnknown ? SCI_ERROR_UNKNOWN_COMPRESSION : 0;
 }
 
-int ResourceManager::decompress(Resource *res, Common::SeekableReadStream *file) {
+int Resource::decompress(Common::SeekableReadStream *file) {
 	int error;
 	uint32 szPacked = 0;
 	ResourceCompression compression = kCompUnknown;
 
 	// fill resource info
-	error = readResourceInfo(res, file, szPacked, compression);
+	error = readResourceInfo(file, szPacked, compression);
 	if (error)
 		return error;
 
@@ -1646,15 +1645,15 @@
 		break;
 #endif
 	default:
-		warning("Resource %s: Compression method %d not supported", res->_id.toString().c_str(), compression);
+		warning("Resource %s: Compression method %d not supported", _id.toString().c_str(), compression);
 		return SCI_ERROR_UNKNOWN_COMPRESSION;
 	}
 
-	res->data = new byte[res->size];
-	res->_status = kResStatusAllocated;
-	error = res->data ? dec->unpack(file, res->data, szPacked, res->size) : SCI_ERROR_RESOURCE_TOO_BIG;
+	data = new byte[size];
+	_status = kResStatusAllocated;
+	error = data ? dec->unpack(file, data, szPacked, size) : SCI_ERROR_RESOURCE_TOO_BIG;
 	if (error)
-		res->unalloc();
+		unalloc();
 
 	delete dec;
 	return error;
@@ -1683,7 +1682,7 @@
 		uint32 szPacked;
 		ResourceCompression compression;
 
-		if (readResourceInfo(res, fileStream, szPacked, compression)) {
+		if (res->readResourceInfo(fileStream, szPacked, compression)) {
 			if (res->_source->_resourceFile)
 				delete fileStream;
 			continue;

Modified: scummvm/trunk/engines/sci/resource.h
===================================================================
--- scummvm/trunk/engines/sci/resource.h	2010-06-15 12:19:14 UTC (rev 49834)
+++ scummvm/trunk/engines/sci/resource.h	2010-06-15 12:19:39 UTC (rev 49835)
@@ -167,6 +167,7 @@
 	// FIXME: These 'friend' declarations are meant to be a temporary hack to
 	// ease transition to the ResourceSource class system.
 	friend class ResourceSource;
+	friend class PatchResourceSource;
 	friend class WaveResourceSource;
 	friend class AudioVolumeResourceSource;
 	friend class MacResourceForkResourceSource;
@@ -192,24 +193,37 @@
 	void writeToStream(Common::WriteStream *stream) const;
 	uint32 getAudioCompressionType() const;
 
+protected:
+	int32 _fileOffset; /**< Offset in file */
+	ResourceStatus _status;
+	uint16 _lockers; /**< Number of places where this resource was locked */
+	ResourceSource *_source;
+
 	bool loadPatch(Common::SeekableReadStream *file);
 	bool loadFromPatchFile();
 	bool loadFromWaveFile(Common::SeekableReadStream *file);
 	bool loadFromAudioVolumeSCI1(Common::SeekableReadStream *file);
 	bool loadFromAudioVolumeSCI11(Common::SeekableReadStream *file);
-
-protected:
-	int32 _fileOffset; /**< Offset in file */
-	ResourceStatus _status;
-	uint16 _lockers; /**< Number of places where this resource was locked */
-	ResourceSource *_source;
+	int decompress(Common::SeekableReadStream *file);
+	int readResourceInfo(Common::SeekableReadStream *file, uint32 &szPacked, ResourceCompression &compression);
 };
 
 typedef Common::HashMap<ResourceId, Resource *, ResourceIdHash, ResourceIdEqualTo> ResourceMap;
 
+enum ResVersion {
+	kResVersionUnknown,
+	kResVersionSci0Sci1Early,
+	kResVersionSci1Middle,
+	kResVersionSci1Late,
+	kResVersionSci11,
+	kResVersionSci11Mac,
+	kResVersionSci32
+};
+
 class ResourceManager {
 	// FIXME: These 'friend' declarations are meant to be a temporary hack to
 	// ease transition to the ResourceSource class system.
+	friend class Resource;	// For _volVersion
 	friend class ResourceSource;
 	friend class DirectoryResourceSource;
 	friend class PatchResourceSource;
@@ -221,16 +235,6 @@
 	friend class MacResourceForkResourceSource;
 
 public:
-	enum ResVersion {
-		kResVersionUnknown,
-		kResVersionSci0Sci1Early,
-		kResVersionSci1Middle,
-		kResVersionSci1Late,
-		kResVersionSci11,
-		kResVersionSci11Mac,
-		kResVersionSci32
-	};
-
 	/**
 	 * Creates a new SCI resource manager.
 	 */
@@ -393,8 +397,6 @@
 	Common::SeekableReadStream *getVolumeFile(ResourceSource *source);
 	void loadResource(Resource *res);
 	void freeOldResources();
-	int decompress(Resource *res, Common::SeekableReadStream *file);
-	int readResourceInfo(Resource *res, Common::SeekableReadStream *file, uint32 &szPacked, ResourceCompression &compression);
 	void addResource(ResourceId resId, ResourceSource *src, uint32 offset, uint32 size = 0);
 	Resource *updateResource(ResourceId resId, ResourceSource *src, uint32 size);
 	void removeAudioResource(ResourceId resId);
@@ -437,8 +439,8 @@
 	/**
 	 * Reads patch files from a local directory.
 	 */
-	void readResourcePatches(ResourceSource *source);
-	void readResourcePatchesBase36(ResourceSource *source);
+	void readResourcePatches();
+	void readResourcePatchesBase36();
 	void processPatch(ResourceSource *source, ResourceType resourceType, uint16 resourceNr, uint32 tuple = 0);
 
 	/**

Modified: scummvm/trunk/engines/sci/resource_audio.cpp
===================================================================
--- scummvm/trunk/engines/sci/resource_audio.cpp	2010-06-15 12:19:14 UTC (rev 49834)
+++ scummvm/trunk/engines/sci/resource_audio.cpp	2010-06-15 12:19:39 UTC (rev 49835)
@@ -319,8 +319,8 @@
 			}
 
 			if (n & 0x40) {
-				// This seems to define the size of raw lipsync data (at least in kq6), may also just be general appended
-				//  data
+				// This seems to define the size of raw lipsync data (at least
+				// in kq6), may also just be general appended data.
 				syncSize += READ_LE_UINT16(ptr);
 				ptr += 2;
 			}


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