SCI: Move code from ResourceManager::loadResource to ResourceSource::loadResource
svn-id: r49819
This commit is contained in:
parent
d0f59edd96
commit
d4f16962d0
3 changed files with 46 additions and 25 deletions
|
@ -176,14 +176,18 @@ ResourceSource::ResourceSource(ResSourceType type, const Common::String &name)
|
||||||
associated_map = NULL;
|
associated_map = NULL;
|
||||||
audioCompressionType = 0;
|
audioCompressionType = 0;
|
||||||
audioCompressionOffsetMapping = NULL;
|
audioCompressionOffsetMapping = NULL;
|
||||||
|
_macResMan = NULL;
|
||||||
if (_sourceType == kSourceMacResourceFork)
|
|
||||||
_macResMan = new Common::MacResManager();
|
|
||||||
else
|
|
||||||
_macResMan = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ResourceSource::~ResourceSource() {
|
ResourceSource::~ResourceSource() {
|
||||||
|
}
|
||||||
|
|
||||||
|
MacResourceForkResourceSource::MacResourceForkResourceSource(const Common::String &name)
|
||||||
|
: ResourceSource(kSourceMacResourceFork, name) {
|
||||||
|
_macResMan = new Common::MacResManager();
|
||||||
|
}
|
||||||
|
|
||||||
|
MacResourceForkResourceSource::~MacResourceForkResourceSource() {
|
||||||
delete _macResMan;
|
delete _macResMan;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -344,17 +348,22 @@ Common::SeekableReadStream *ResourceManager::getVolumeFile(ResourceSource *sourc
|
||||||
static uint32 resTypeToMacTag(ResourceType type);
|
static uint32 resTypeToMacTag(ResourceType type);
|
||||||
|
|
||||||
void ResourceManager::loadResource(Resource *res) {
|
void ResourceManager::loadResource(Resource *res) {
|
||||||
if (res->_source->getSourceType() == kSourcePatch && loadFromPatchFile(res))
|
res->_source->loadResource(res, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ResourceSource::loadResource(Resource *res, ResourceManager *resMan) {
|
||||||
|
|
||||||
|
if (getSourceType() == kSourcePatch && resMan->loadFromPatchFile(res))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (res->_source->getSourceType() == kSourceMacResourceFork) {
|
if (getSourceType() == kSourceMacResourceFork) {
|
||||||
assert(res->_source->_macResMan);
|
assert(_macResMan);
|
||||||
Common::SeekableReadStream *stream = res->_source->_macResMan->getResource(resTypeToMacTag(res->_id.type), res->_id.number);
|
Common::SeekableReadStream *stream = _macResMan->getResource(resTypeToMacTag(res->_id.type), res->_id.number);
|
||||||
|
|
||||||
if (!stream)
|
if (!stream)
|
||||||
error("Could not get Mac resource fork resource: %d %d", res->_id.type, res->_id.number);
|
error("Could not get Mac resource fork resource: %d %d", res->_id.type, res->_id.number);
|
||||||
|
|
||||||
int error = decompress(res, stream);
|
int error = resMan->decompress(res, stream);
|
||||||
if (error) {
|
if (error) {
|
||||||
warning("Error %d occured while reading %s from Mac resource file: %s",
|
warning("Error %d occured while reading %s from Mac resource file: %s",
|
||||||
error, res->_id.toString().c_str(), sci_error_types[error]);
|
error, res->_id.toString().c_str(), sci_error_types[error]);
|
||||||
|
@ -363,27 +372,27 @@ void ResourceManager::loadResource(Resource *res) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Common::SeekableReadStream *fileStream = getVolumeFile(res->_source);
|
Common::SeekableReadStream *fileStream = resMan->getVolumeFile(this);
|
||||||
|
|
||||||
if (!fileStream) {
|
if (!fileStream) {
|
||||||
warning("Failed to open %s", res->_source->getLocationName().c_str());
|
warning("Failed to open %s", getLocationName().c_str());
|
||||||
res->unalloc();
|
res->unalloc();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(res->_source->getSourceType()) {
|
switch(getSourceType()) {
|
||||||
case kSourceWave:
|
case kSourceWave:
|
||||||
fileStream->seek(res->_fileOffset, SEEK_SET);
|
fileStream->seek(res->_fileOffset, SEEK_SET);
|
||||||
loadFromWaveFile(res, fileStream);
|
resMan->loadFromWaveFile(res, fileStream);
|
||||||
if (res->_source->_resourceFile)
|
if (_resourceFile)
|
||||||
delete fileStream;
|
delete fileStream;
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case kSourceAudioVolume:
|
case kSourceAudioVolume:
|
||||||
if (res->_source->audioCompressionType) {
|
if (audioCompressionType) {
|
||||||
// this file is compressed, so lookup our offset in the offset-translation table and get the new offset
|
// this file is compressed, so lookup our offset in the offset-translation table and get the new offset
|
||||||
// also calculate the compressed size by using the next offset
|
// also calculate the compressed size by using the next offset
|
||||||
int32 *mappingTable = res->_source->audioCompressionOffsetMapping;
|
int32 *mappingTable = audioCompressionOffsetMapping;
|
||||||
int32 compressedOffset = 0;
|
int32 compressedOffset = 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
@ -413,8 +422,8 @@ void ResourceManager::loadResource(Resource *res) {
|
||||||
case kResourceTypeAudio:
|
case kResourceTypeAudio:
|
||||||
case kResourceTypeAudio36:
|
case kResourceTypeAudio36:
|
||||||
// Directly read the stream, compressed audio wont have resource type id and header size for SCI1.1
|
// Directly read the stream, compressed audio wont have resource type id and header size for SCI1.1
|
||||||
loadFromAudioVolumeSCI1(res, fileStream);
|
resMan->loadFromAudioVolumeSCI1(res, fileStream);
|
||||||
if (res->_source->_resourceFile)
|
if (_resourceFile)
|
||||||
delete fileStream;
|
delete fileStream;
|
||||||
return;
|
return;
|
||||||
default:
|
default:
|
||||||
|
@ -425,19 +434,19 @@ void ResourceManager::loadResource(Resource *res) {
|
||||||
fileStream->seek(res->_fileOffset, SEEK_SET);
|
fileStream->seek(res->_fileOffset, SEEK_SET);
|
||||||
}
|
}
|
||||||
if (getSciVersion() < SCI_VERSION_1_1)
|
if (getSciVersion() < SCI_VERSION_1_1)
|
||||||
loadFromAudioVolumeSCI1(res, fileStream);
|
resMan->loadFromAudioVolumeSCI1(res, fileStream);
|
||||||
else
|
else
|
||||||
loadFromAudioVolumeSCI11(res, fileStream);
|
resMan->loadFromAudioVolumeSCI11(res, fileStream);
|
||||||
|
|
||||||
if (res->_source->_resourceFile)
|
if (_resourceFile)
|
||||||
delete fileStream;
|
delete fileStream;
|
||||||
return;
|
return;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
fileStream->seek(res->_fileOffset, SEEK_SET);
|
fileStream->seek(res->_fileOffset, SEEK_SET);
|
||||||
int error = decompress(res, fileStream);
|
int error = resMan->decompress(res, fileStream);
|
||||||
|
|
||||||
if (res->_source->_resourceFile)
|
if (_resourceFile)
|
||||||
delete fileStream;
|
delete fileStream;
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
|
|
|
@ -166,6 +166,7 @@ class Resource {
|
||||||
|
|
||||||
// FIXME: These 'friend' declarations are meant to be a temporary hack to
|
// FIXME: These 'friend' declarations are meant to be a temporary hack to
|
||||||
// ease transition to the ResourceSource class system.
|
// ease transition to the ResourceSource class system.
|
||||||
|
friend class ResourceSource;
|
||||||
friend class MacResourceForkResourceSource;
|
friend class MacResourceForkResourceSource;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -201,6 +202,7 @@ typedef Common::HashMap<ResourceId, Resource *, ResourceIdHash, ResourceIdEqualT
|
||||||
class ResourceManager {
|
class ResourceManager {
|
||||||
// FIXME: These 'friend' declarations are meant to be a temporary hack to
|
// FIXME: These 'friend' declarations are meant to be a temporary hack to
|
||||||
// ease transition to the ResourceSource class system.
|
// ease transition to the ResourceSource class system.
|
||||||
|
friend class ResourceSource;
|
||||||
friend class DirectoryResourceSource;
|
friend class DirectoryResourceSource;
|
||||||
friend class ExtMapResourceSource;
|
friend class ExtMapResourceSource;
|
||||||
friend class IntMapResourceSource;
|
friend class IntMapResourceSource;
|
||||||
|
|
|
@ -69,6 +69,9 @@ public:
|
||||||
ResSourceType getSourceType() const { return _sourceType; }
|
ResSourceType getSourceType() const { return _sourceType; }
|
||||||
const Common::String &getLocationName() const { return _name; }
|
const Common::String &getLocationName() const { return _name; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO: Document this
|
||||||
|
*/
|
||||||
virtual ResourceSource *findVolume(ResourceSource *map, int volume_nr) {
|
virtual ResourceSource *findVolume(ResourceSource *map, int volume_nr) {
|
||||||
return NULL;
|
return NULL;
|
||||||
};
|
};
|
||||||
|
@ -78,6 +81,12 @@ public:
|
||||||
* TODO: The resMan param for now is just a hack.
|
* TODO: The resMan param for now is just a hack.
|
||||||
*/
|
*/
|
||||||
virtual void scanSource(ResourceManager *resMan) {}
|
virtual void scanSource(ResourceManager *resMan) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load a resource.
|
||||||
|
* TODO: The resMan param for now is just a hack.
|
||||||
|
*/
|
||||||
|
virtual void loadResource(Resource *res, ResourceManager *resMan);
|
||||||
};
|
};
|
||||||
|
|
||||||
class DirectoryResourceSource : public ResourceSource {
|
class DirectoryResourceSource : public ResourceSource {
|
||||||
|
@ -141,7 +150,8 @@ public:
|
||||||
|
|
||||||
class MacResourceForkResourceSource : public ResourceSource {
|
class MacResourceForkResourceSource : public ResourceSource {
|
||||||
public:
|
public:
|
||||||
MacResourceForkResourceSource(const Common::String &name) : ResourceSource(kSourceMacResourceFork, name) {}
|
MacResourceForkResourceSource(const Common::String &name);
|
||||||
|
~MacResourceForkResourceSource();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads the SCI1.1+ resource file from a Mac resource fork.
|
* Reads the SCI1.1+ resource file from a Mac resource fork.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue