SCI: Convert code to use ResourceSource subclasses

svn-id: r49813
This commit is contained in:
Max Horn 2010-06-15 12:11:04 +00:00
parent 24a295f4a3
commit 17a5112162
4 changed files with 38 additions and 37 deletions

View File

@ -210,25 +210,25 @@ ResourceSource *ResourceManager::addExternalMap(const Common::FSNode *mapFile, i
return newsrc;
}
ResourceSource *ResourceManager::addSource(ResourceSource *map, ResSourceType type, const Common::String &filename, int number) {
ResourceSource *newsrc = new ResourceSource(type, filename);
ResourceSource *ResourceManager::addSource(ResourceSource *map, ResourceSource *newsrc, int number) {
assert(newsrc);
newsrc->volume_number = number;
newsrc->associated_map = map;
if (type == kSourceAudioVolume)
if (newsrc->getSourceType() == kSourceAudioVolume)
checkIfAudioVolumeIsCompressed(newsrc);
_sources.push_back(newsrc);
return newsrc;
}
ResourceSource *ResourceManager::addSource(ResourceSource *map, ResSourceType type, const Common::FSNode *resFile, int number) {
ResourceSource *newsrc = new ResourceSource(type, resFile->getName());
ResourceSource *ResourceManager::addSource(ResourceSource *map, ResourceSource *newsrc, const Common::FSNode *resFile, int number) {
assert(newsrc);
newsrc->resourceFile = resFile;
newsrc->volume_number = number;
newsrc->associated_map = map;
if (type == kSourceAudioVolume)
if (newsrc->getSourceType() == kSourceAudioVolume)
checkIfAudioVolumeIsCompressed(newsrc);
_sources.push_back(newsrc);
@ -459,12 +459,12 @@ int ResourceManager::addAppropriateSources() {
const char *dot = strrchr(name.c_str(), '.');
int number = atoi(dot + 1);
addSource(map, kSourceVolume, name, number);
addSource(map, new VolumeResourceSource(name), number);
}
#ifdef ENABLE_SCI32
// GK1CD hires content
if (Common::File::exists("alt.map") && Common::File::exists("resource.alt"))
addSource(addExternalMap("alt.map", 10), kSourceVolume, "resource.alt", 10);
addSource(addExternalMap("alt.map", 10), new VolumeResourceSource("resource.alt"), 10);
#endif
} else if (Common::File::exists("Data1")) {
// Mac SCI1.1+ file naming scheme
@ -472,7 +472,7 @@ int ResourceManager::addAppropriateSources() {
for (Common::ArchiveMemberList::const_iterator x = files.begin(); x != files.end(); ++x) {
Common::String filename = (*x)->getName();
addSource(0, kSourceMacResourceFork, filename, atoi(filename.c_str() + 4));
addSource(0, new MacResourceForkResourceSource(filename), atoi(filename.c_str() + 4));
}
#ifdef ENABLE_SCI32
// Mac SCI32 games have extra folders for patches
@ -484,7 +484,7 @@ int ResourceManager::addAppropriateSources() {
// There can also be a "Patches" resource fork with patches
if (Common::File::exists("Patches"))
addSource(0, kSourceMacResourceFork, "Patches", 100);
addSource(0, new MacResourceForkResourceSource("Patches"), 100);
} else {
// SCI2.1-SCI3 file naming scheme
Common::ArchiveMemberList mapFiles;
@ -504,7 +504,7 @@ int ResourceManager::addAppropriateSources() {
int resNumber = atoi(strrchr(resName.c_str(), '.') + 1);
if (mapNumber == resNumber) {
addSource(addExternalMap(mapName, mapNumber), kSourceVolume, resName, mapNumber);
addSource(addExternalMap(mapName, mapNumber), new VolumeResourceSource(resName), mapNumber);
break;
}
}
@ -513,7 +513,7 @@ int ResourceManager::addAppropriateSources() {
// SCI2.1 resource patches
if (Common::File::exists("resmap.pat") && Common::File::exists("ressci.pat")) {
// We add this resource with a map which surely won't exist
addSource(addExternalMap("resmap.pat", 100), kSourceVolume, "ressci.pat", 100);
addSource(addExternalMap("resmap.pat", 100), new VolumeResourceSource("ressci.pat"), 100);
}
}
#else
@ -523,7 +523,7 @@ int ResourceManager::addAppropriateSources() {
addPatchDir(".");
if (Common::File::exists("message.map"))
addSource(addExternalMap("message.map"), kSourceVolume, "resource.msg", 0);
addSource(addExternalMap("message.map"), new VolumeResourceSource("resource.msg"), 0);
return 1;
}
@ -567,7 +567,7 @@ int ResourceManager::addAppropriateSources(const Common::FSList &fslist) {
#ifdef ENABLE_SCI32
if (sci21PatchMap && sci21PatchRes)
addSource(sci21PatchMap, kSourceVolume, sci21PatchRes, 100);
addSource(sci21PatchMap, new VolumeResourceSource(sci21PatchRes->getName()), sci21PatchRes, 100);
#endif
// Now find all the resource.0?? files
@ -582,7 +582,7 @@ int ResourceManager::addAppropriateSources(const Common::FSList &fslist) {
const char *dot = strrchr(filename.c_str(), '.');
int number = atoi(dot + 1);
addSource(map, kSourceVolume, file, number);
addSource(map, new VolumeResourceSource(file->getName()), file, number);
}
}
@ -597,12 +597,12 @@ int ResourceManager::addInternalSources() {
Common::List<ResourceId>::iterator itr = resources->begin();
while (itr != resources->end()) {
ResourceSource *src = addSource(NULL, kSourceIntMap, "MAP", itr->number);
ResourceSource *src = addSource(NULL, new IntMapResourceSource("MAP"), itr->number);
if ((itr->number == 65535) && Common::File::exists("RESOURCE.SFX"))
addSource(src, kSourceAudioVolume, "RESOURCE.SFX", 0);
addSource(src, new AudioVolumeResourceSource("RESOURCE.SFX"), 0);
else if (Common::File::exists("RESOURCE.AUD"))
addSource(src, kSourceAudioVolume, "RESOURCE.AUD", 0);
addSource(src, new AudioVolumeResourceSource("RESOURCE.AUD"), 0);
++itr;
}

View File

@ -69,18 +69,6 @@ enum {
MAX_OPENED_VOLUMES = 5 ///< Max number of simultaneously opened volumes
};
enum ResSourceType {
kSourceDirectory = 0,
kSourcePatch,
kSourceVolume,
kSourceExtMap,
kSourceIntMap,
kSourceAudioVolume,
kSourceExtAudioMap,
kSourceWave,
kSourceMacResourceFork
};
enum ResourceType {
kResourceTypeView = 0,
kResourceTypePic,
@ -329,14 +317,13 @@ protected:
/**
* Adds a source to the resource manager's list of sources.
* @param map The map associated with this source
* @param type The source type
* @param filename The name of the source to add
* @param source The new source to add
* @return A pointer to the added source structure, or NULL if an error occurred.
*/
ResourceSource *addSource(ResourceSource *map, ResSourceType type, const Common::String &filename,
ResourceSource *addSource(ResourceSource *map, ResourceSource *source,
int number);
ResourceSource *addSource(ResourceSource *map, ResSourceType type,
ResourceSource *addSource(ResourceSource *map, ResourceSource *source,
const Common::FSNode *resFile, int number);
/**

View File

@ -433,7 +433,7 @@ void ResourceManager::setAudioLanguage(int language) {
return;
}
_audioMapSCI1 = addSource(NULL, kSourceExtAudioMap, fullname, language);
_audioMapSCI1 = addSource(NULL, new ExtAudioMapResourceSource(fullname), language);
// Search for audio volumes for this language and add them to the source list
Common::ArchiveMemberList files;
@ -443,7 +443,7 @@ void ResourceManager::setAudioLanguage(int language) {
const char *dot = strrchr(name.c_str(), '.');
int number = atoi(dot + 1);
addSource(_audioMapSCI1, kSourceAudioVolume, name, number);
addSource(_audioMapSCI1, new AudioVolumeResourceSource(name), number);
}
scanNewSources();

View File

@ -34,6 +34,19 @@ namespace Common {
namespace Sci {
enum ResSourceType {
kSourceDirectory = 0,
kSourcePatch,
kSourceVolume,
kSourceExtMap,
kSourceIntMap,
kSourceAudioVolume,
kSourceExtAudioMap,
kSourceWave,
kSourceMacResourceFork
};
class ResourceSource {
protected:
const ResSourceType _sourceType;
@ -48,8 +61,9 @@ public:
int32 *audioCompressionOffsetMapping;
Common::MacResManager *_macResMan;
public:
protected:
ResourceSource(ResSourceType type, const Common::String &name);
public:
virtual ~ResourceSource();
ResSourceType getSourceType() const { return _sourceType; }