aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFilippos Karapetis2011-01-31 11:40:40 +0000
committerFilippos Karapetis2011-01-31 11:40:40 +0000
commit8bd7ace4d277e68ee0cdf7d6ab275d08d432ddde (patch)
tree41811a073ccb92f5d0837cc283640a76daa59918
parente0314f9ecd22504290ca3fb1d6e6b6db30dd6719 (diff)
downloadscummvm-rg350-8bd7ace4d277e68ee0cdf7d6ab275d08d432ddde.tar.gz
scummvm-rg350-8bd7ace4d277e68ee0cdf7d6ab275d08d432ddde.tar.bz2
scummvm-rg350-8bd7ace4d277e68ee0cdf7d6ab275d08d432ddde.zip
SAGA: Split the resource patching code into appropriate game-specific resource methods
svn-id: r55678
-rw-r--r--engines/saga/resource.cpp57
-rw-r--r--engines/saga/resource.h50
-rw-r--r--engines/saga/resource_res.cpp33
-rw-r--r--engines/saga/resource_rsc.cpp27
4 files changed, 76 insertions, 91 deletions
diff --git a/engines/saga/resource.cpp b/engines/saga/resource.cpp
index 0ef0d438d9..8d73a9b765 100644
--- a/engines/saga/resource.cpp
+++ b/engines/saga/resource.cpp
@@ -95,15 +95,6 @@ bool ResourceContext::loadResV1(uint32 contextOffset, uint32 contextSize) {
}
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,53 +125,7 @@ bool ResourceContext::load(SagaEngine *vm, Resource *resource) {
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;
-
- 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;
- }
- }
- }
- }
- }
+ processPatches(resource, vm->getPatchDescriptions());
// 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
diff --git a/engines/saga/resource.h b/engines/saga/resource.h
index 048ed3933d..777c919ec3 100644
--- a/engines/saga/resource.h
+++ b/engines/saga/resource.h
@@ -79,8 +79,7 @@ struct ResourceData {
}
};
-class ResourceDataArray : public Common::Array<ResourceData> {
-};
+typedef public Common::Array<ResourceData> ResourceDataArray;
class ResourceContext {
friend class Resource;
@@ -92,32 +91,14 @@ public:
_fileSize(0) {
}
- virtual ~ResourceContext() {
- }
-
- 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;
- }
+ virtual ~ResourceContext() { }
- const char * fileName() const {
- return _fileName;
- }
+ 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; }
Common::File *getFile(ResourceData *resourceData) {
Common::File *file;
@@ -170,12 +151,12 @@ protected:
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 @@ public:
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 @@ protected:
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 @@ protected:
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 @@ protected:
// 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 @@ class ResourceContext_HRS: public ResourceContext {
protected:
ResourceDataArray _categories;
- virtual bool loadMacMIDI() { return false; }
virtual bool loadRes(uint32 contextOffset, uint32 contextSize) {
return loadResV2(contextSize);
}
diff --git a/engines/saga/resource_res.cpp b/engines/saga/resource_res.cpp
index 646de8667b..9e4b6a2e63 100644
--- a/engines/saga/resource_res.cpp
+++ b/engines/saga/resource_res.cpp
@@ -204,6 +204,39 @@ void Resource_RES::loadGlobalResources(int chapter, int actorsEntrance) {
_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
diff --git a/engines/saga/resource_rsc.cpp b/engines/saga/resource_rsc.cpp
index 6d9ef70bfe..42c4dc05e8 100644
--- a/engines/saga/resource_rsc.cpp
+++ b/engines/saga/resource_rsc.cpp
@@ -84,4 +84,31 @@ bool ResourceContext_RSC::loadMacMIDI() {
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