[Scummvm-cvs-logs] SF.net SVN: scummvm:[55678] scummvm/trunk/engines/saga

thebluegr at users.sourceforge.net thebluegr at users.sourceforge.net
Mon Jan 31 12:40:40 CET 2011


Revision: 55678
          http://scummvm.svn.sourceforge.net/scummvm/?rev=55678&view=rev
Author:   thebluegr
Date:     2011-01-31 11:40:40 +0000 (Mon, 31 Jan 2011)

Log Message:
-----------
SAGA: Split the resource patching code into appropriate game-specific resource methods

Modified Paths:
--------------
    scummvm/trunk/engines/saga/resource.cpp
    scummvm/trunk/engines/saga/resource.h
    scummvm/trunk/engines/saga/resource_res.cpp
    scummvm/trunk/engines/saga/resource_rsc.cpp

Modified: scummvm/trunk/engines/saga/resource.cpp
===================================================================
--- scummvm/trunk/engines/saga/resource.cpp	2011-01-31 11:36:14 UTC (rev 55677)
+++ scummvm/trunk/engines/saga/resource.cpp	2011-01-31 11:40:40 UTC (rev 55678)
@@ -95,15 +95,6 @@
 }
 
 bool ResourceContext::load(SagaEngine *vm, Resource *resource) {
-	size_t i;
-	const GamePatchDescription *patchDescription;
-	ResourceData *resourceData;
-	uint16 subjectResourceType;
-	ResourceContext *subjectContext;
-	uint32 subjectResourceId;
-	uint32 patchResourceId;
-	ResourceData *subjectResourceData;
-
 	if (_fileName == NULL) // IHNM special case
 		return true;
 
@@ -134,54 +125,8 @@
 	if (!loadRes(0, _fileSize))
 		return false;
 
-	// Process internal patch files
-	if (_fileType & GAME_PATCHFILE) {
-		subjectResourceType = ~GAME_PATCHFILE & _fileType;
-		subjectContext = resource->getContext((GameFileTypes)subjectResourceType);
-		if (subjectContext == NULL) {
-			error("ResourceContext::load() Subject context not found");
-		}
-		ByteArray tableBuffer;
+	processPatches(resource, vm->getPatchDescriptions());
 
-		resource->loadResource(this, _table.size() - 1, tableBuffer);
-
-		ByteArrayReadStreamEndian readS2(tableBuffer, _isBigEndian);
-		for (i = 0; i < tableBuffer.size() / 8; i++) {
-			subjectResourceId = readS2.readUint32();
-			patchResourceId = readS2.readUint32();
-			subjectResourceData = subjectContext->getResourceData(subjectResourceId);
-			resourceData = getResourceData(patchResourceId);
-			subjectResourceData->patchData = new PatchData(&_file, _fileName);
-			subjectResourceData->offset = resourceData->offset;
-			subjectResourceData->size = resourceData->size;
-		}
-	}
-
-	// Process external patch files
-	for (patchDescription = vm->getPatchDescriptions(); patchDescription && patchDescription->fileName; ++patchDescription) {
-		if ((patchDescription->fileType & _fileType) != 0) {
-			if (patchDescription->resourceId < _table.size()) {
-				resourceData = &_table[patchDescription->resourceId];
-				// Check if we've already found a patch for this resource. One is enough.
-				if (!resourceData->patchData) {
-					resourceData->patchData = new PatchData(patchDescription->fileName);
-					if (resourceData->patchData->_patchFile->open(patchDescription->fileName)) {
-						resourceData->offset = 0;
-						resourceData->size = resourceData->patchData->_patchFile->size();
-						// ITE uses several patch files which are loaded and then not needed
-						// anymore (as they're in memory), so close them here. IHNM uses only
-						// 1 patch file, which is reused, so don't close it
-						if (vm->getGameId() == GID_ITE)
-							resourceData->patchData->_patchFile->close();
-					} else {
-						delete resourceData->patchData;
-						resourceData->patchData = NULL;
-					}
-				}
-			}
-		}
-	}
-
 	// Close the file if it's part of a series of files
 	// This prevents having all voice files open in IHNM for no reason, as each chapter uses
 	// a different voice file

Modified: scummvm/trunk/engines/saga/resource.h
===================================================================
--- scummvm/trunk/engines/saga/resource.h	2011-01-31 11:36:14 UTC (rev 55677)
+++ scummvm/trunk/engines/saga/resource.h	2011-01-31 11:40:40 UTC (rev 55678)
@@ -79,8 +79,7 @@
 	}
 };
 
-class ResourceDataArray : public Common::Array<ResourceData> {
-};
+typedef public Common::Array<ResourceData> ResourceDataArray;
 
 class ResourceContext {
 friend class Resource;
@@ -92,33 +91,15 @@
 		_fileSize(0) {
 	}
 
-	virtual ~ResourceContext() {
-	}
+	virtual ~ResourceContext() { }
 
-	bool isCompressed() const {
-		return _isCompressed;
-	}
+	bool isCompressed() const {	return _isCompressed; }
+	uint16 fileType() const { return _fileType; }
+	int32 fileSize() const { return _fileSize; }
+	int serial() const { return _serial; }
+	bool isBigEndian() const { return _isBigEndian; }
+	const char * fileName() const {	return _fileName; }
 
-	uint16 fileType() const {
-		return _fileType;
-	}
-
-	int32 fileSize() const {
-		return _fileSize;
-	}
-
-	int serial() const {
-		return _serial;
-	}
-
-	bool isBigEndian() const {
-		return _isBigEndian;
-	}
-
-	const char * fileName() const {
-		return _fileName;
-	}
-
 	Common::File *getFile(ResourceData *resourceData) {
 		Common::File *file;
 		const char * fn;
@@ -170,12 +151,12 @@
 	bool load(SagaEngine *_vm, Resource *resource);
 	bool loadResV1(uint32 contextOffset, uint32 contextSize);
 
-	virtual bool loadMacMIDI() = 0;
+	virtual bool loadMacMIDI() { return false; }
 	virtual bool loadRes(uint32 contextOffset, uint32 contextSize) = 0;
+	virtual void processPatches(Resource *resource, const GamePatchDescription *patchFiles) { }
 };
 
-class ResourceContextList : public Common::List<ResourceContext*> {
-};
+typedef Common::List<ResourceContext*> ResourceContextList;
 
 struct MetaResource {
 	int16 sceneIndex;
@@ -212,6 +193,7 @@
 	virtual void loadGlobalResources(int chapter, int actorsEntrance) = 0;
 
 	ResourceContext *getContext(uint16 fileType, int serial = 0);
+	virtual MetaResource* getMetaResource() = 0;
 protected:
 	SagaEngine *_vm;
 	ResourceContextList _contexts;
@@ -221,8 +203,6 @@
 
 	void addContext(const char *fileName, uint16 fileType, bool isCompressed = false, int serial = 0);
 	virtual ResourceContext *createContext() = 0;
-public:
-	virtual MetaResource* getMetaResource() = 0;
 };
 
 // ITE
@@ -232,6 +212,7 @@
 	virtual bool loadRes(uint32 contextOffset, uint32 contextSize) {
 		return loadResV1(contextOffset, contextSize);
 	}
+	virtual void processPatches(Resource *resource, const GamePatchDescription *patchFiles);
 };
 
 class Resource_RSC : public Resource {
@@ -255,16 +236,16 @@
 // IHNM
 class ResourceContext_RES: public ResourceContext {
 protected:
-	virtual bool loadMacMIDI() { return false; }
 	virtual bool loadRes(uint32 contextOffset, uint32 contextSize) {
 		return loadResV1(0, contextSize);
 	}
+
+	virtual void processPatches(Resource *resource, const GamePatchDescription *patchFiles);
 };
 
 // TODO: move load routines from sndres
 class VoiceResourceContext_RES: public ResourceContext {
 protected:
-	virtual bool loadMacMIDI() { return false; }
 	virtual bool loadRes(uint32 contextOffset, uint32 contextSize) {
 		return false;
 	}
@@ -296,7 +277,6 @@
 protected:
 	ResourceDataArray _categories;
 
-	virtual bool loadMacMIDI() { return false; }
 	virtual bool loadRes(uint32 contextOffset, uint32 contextSize) {
 		return loadResV2(contextSize);
 	}

Modified: scummvm/trunk/engines/saga/resource_res.cpp
===================================================================
--- scummvm/trunk/engines/saga/resource_res.cpp	2011-01-31 11:36:14 UTC (rev 55677)
+++ scummvm/trunk/engines/saga/resource_res.cpp	2011-01-31 11:40:40 UTC (rev 55678)
@@ -204,6 +204,39 @@
 	_vm->_spiritualBarometer = 0;
 	_vm->_scene->setChapterNumber(chapter);
 }
+
+void ResourceContext_RES::processPatches(Resource *resource, const GamePatchDescription *patchFiles) {
+	uint16 subjectResourceType;
+	ResourceContext *subjectContext;
+	uint32 subjectResourceId;
+	uint32 patchResourceId;
+	ResourceData *subjectResourceData;
+	ResourceData *resourceData;
+
+	// Process internal patch files
+	if (_fileType & GAME_PATCHFILE) {
+		subjectResourceType = ~GAME_PATCHFILE & _fileType;
+		subjectContext = resource->getContext((GameFileTypes)subjectResourceType);
+		if (subjectContext == NULL) {
+			error("ResourceContext::load() Subject context not found");
+		}
+		ByteArray tableBuffer;
+
+		resource->loadResource(this, _table.size() - 1, tableBuffer);
+
+		ByteArrayReadStreamEndian readS2(tableBuffer, _isBigEndian);
+		for (uint32 i = 0; i < tableBuffer.size() / 8; i++) {
+			subjectResourceId = readS2.readUint32();
+			patchResourceId = readS2.readUint32();
+			subjectResourceData = subjectContext->getResourceData(subjectResourceId);
+			resourceData = getResourceData(patchResourceId);
+			subjectResourceData->patchData = new PatchData(&_file, _fileName);
+			subjectResourceData->offset = resourceData->offset;
+			subjectResourceData->size = resourceData->size;
+		}
+	}
+}
+
 #endif
 
 } // End of namespace Saga

Modified: scummvm/trunk/engines/saga/resource_rsc.cpp
===================================================================
--- scummvm/trunk/engines/saga/resource_rsc.cpp	2011-01-31 11:36:14 UTC (rev 55677)
+++ scummvm/trunk/engines/saga/resource_rsc.cpp	2011-01-31 11:40:40 UTC (rev 55678)
@@ -84,4 +84,31 @@
 	return true;
 }
 
+void ResourceContext_RSC::processPatches(Resource *resource, const GamePatchDescription *patchFiles) {
+	const GamePatchDescription *patchDescription;
+	ResourceData *resourceData;
+
+	// Process external patch files
+	for (patchDescription = patchFiles; patchDescription && patchDescription->fileName; ++patchDescription) {
+		if ((patchDescription->fileType & _fileType) != 0) {
+			if (patchDescription->resourceId < _table.size()) {
+				resourceData = &_table[patchDescription->resourceId];
+				// Check if we've already found a patch for this resource. One is enough.
+				if (!resourceData->patchData) {
+					resourceData->patchData = new PatchData(patchDescription->fileName);
+					if (resourceData->patchData->_patchFile->open(patchDescription->fileName)) {
+						resourceData->offset = 0;
+						resourceData->size = resourceData->patchData->_patchFile->size();
+						// The patched ITE file is in memory, so close the patch file
+						resourceData->patchData->_patchFile->close();
+					} else {
+						delete resourceData->patchData;
+						resourceData->patchData = NULL;
+					}
+				}
+			}
+		}
+	}
+}
+
 } // End of namespace Saga


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