aboutsummaryrefslogtreecommitdiff
path: root/engines/sci
diff options
context:
space:
mode:
authorMax Horn2010-06-16 00:24:16 +0000
committerMax Horn2010-06-16 00:24:16 +0000
commite7275161f431d0025a7e2bb47bc2d442670fd155 (patch)
treede44bd2032b708a5b77e20ed23516814da6a0547 /engines/sci
parent81926f106abce4d73a899962a7a1f3fd0307ff40 (diff)
downloadscummvm-rg350-e7275161f431d0025a7e2bb47bc2d442670fd155.tar.gz
scummvm-rg350-e7275161f431d0025a7e2bb47bc2d442670fd155.tar.bz2
scummvm-rg350-e7275161f431d0025a7e2bb47bc2d442670fd155.zip
SCI: Avoid using g_sci in resman (as it might not yet be inited)
svn-id: r49897
Diffstat (limited to 'engines/sci')
-rw-r--r--engines/sci/resource.cpp40
-rw-r--r--engines/sci/resource.h24
-rw-r--r--engines/sci/resource_audio.cpp6
-rw-r--r--engines/sci/resource_intern.h14
4 files changed, 41 insertions, 43 deletions
diff --git a/engines/sci/resource.cpp b/engines/sci/resource.cpp
index e167d50c1a..bda854cfd0 100644
--- a/engines/sci/resource.cpp
+++ b/engines/sci/resource.cpp
@@ -319,11 +319,11 @@ Common::SeekableReadStream *ResourceManager::getVolumeFile(ResourceSource *sourc
static uint32 resTypeToMacTag(ResourceType type);
void ResourceManager::loadResource(Resource *res) {
- res->_source->loadResource(res);
+ res->_source->loadResource(this, res);
}
-void PatchResourceSource::loadResource(Resource *res) {
+void PatchResourceSource::loadResource(ResourceManager *resMan, Resource *res) {
bool result = res->loadFromPatchFile();
if (!result) {
// TODO: We used to fallback to the "default" code here if loadFromPatchFile
@@ -333,13 +333,13 @@ void PatchResourceSource::loadResource(Resource *res) {
}
}
-void MacResourceForkResourceSource::loadResource(Resource *res) {
+void MacResourceForkResourceSource::loadResource(ResourceManager *resMan, Resource *res) {
Common::SeekableReadStream *stream = _macResMan->getResource(resTypeToMacTag(res->getType()), res->getNumber());
if (!stream)
error("Could not get Mac resource fork resource: %d %d", res->getType(), res->getNumber());
- int error = res->decompress(stream);
+ int error = res->decompress(resMan->getVolVersion(), stream);
if (error) {
warning("Error %d occurred while reading %s from Mac resource file: %s",
error, res->_id.toString().c_str(), sci_error_types[error]);
@@ -347,8 +347,7 @@ void MacResourceForkResourceSource::loadResource(Resource *res) {
}
}
-Common::SeekableReadStream *ResourceSource::getVolumeFile(Resource *res) {
- ResourceManager *resMan = g_sci->getResMan();
+Common::SeekableReadStream *ResourceSource::getVolumeFile(ResourceManager *resMan, Resource *res) {
Common::SeekableReadStream *fileStream = resMan->getVolumeFile(this);
if (!fileStream) {
@@ -360,8 +359,8 @@ Common::SeekableReadStream *ResourceSource::getVolumeFile(Resource *res) {
return fileStream;
}
-void WaveResourceSource::loadResource(Resource *res) {
- Common::SeekableReadStream *fileStream = getVolumeFile(res);
+void WaveResourceSource::loadResource(ResourceManager *resMan, Resource *res) {
+ Common::SeekableReadStream *fileStream = getVolumeFile(resMan, res);
if (!fileStream)
return;
@@ -371,8 +370,8 @@ void WaveResourceSource::loadResource(Resource *res) {
delete fileStream;
}
-void AudioVolumeResourceSource::loadResource(Resource *res) {
- Common::SeekableReadStream *fileStream = getVolumeFile(res);
+void AudioVolumeResourceSource::loadResource(ResourceManager *resMan, Resource *res) {
+ Common::SeekableReadStream *fileStream = getVolumeFile(resMan, res);
if (!fileStream)
return;
@@ -429,14 +428,14 @@ void AudioVolumeResourceSource::loadResource(Resource *res) {
delete fileStream;
}
-void ResourceSource::loadResource(Resource *res) {
- Common::SeekableReadStream *fileStream = getVolumeFile(res);
+void ResourceSource::loadResource(ResourceManager *resMan, Resource *res) {
+ Common::SeekableReadStream *fileStream = getVolumeFile(resMan, res);
if (!fileStream)
return;
fileStream->seek(res->_fileOffset, SEEK_SET);
- int error = res->decompress(fileStream);
+ int error = res->decompress(resMan->getVolVersion(), fileStream);
if (error) {
warning("Error %d occurred while reading %s from resource file: %s",
error, res->_id.toString().c_str(), sci_error_types[error]);
@@ -606,9 +605,9 @@ int ResourceManager::addInternalSources() {
ResourceSource *src = addSource(new IntMapResourceSource("MAP", itr->getNumber()));
if ((itr->getNumber() == 65535) && Common::File::exists("RESOURCE.SFX"))
- addSource(new AudioVolumeResourceSource("RESOURCE.SFX", src, 0));
+ addSource(new AudioVolumeResourceSource(this, "RESOURCE.SFX", src, 0));
else if (Common::File::exists("RESOURCE.AUD"))
- addSource(new AudioVolumeResourceSource("RESOURCE.AUD", src, 0));
+ addSource(new AudioVolumeResourceSource(this, "RESOURCE.AUD", src, 0));
++itr;
}
@@ -1506,7 +1505,7 @@ Resource *ResourceManager::updateResource(ResourceId resId, ResourceSource *src,
return res;
}
-int Resource::readResourceInfo(Common::SeekableReadStream *file,
+int Resource::readResourceInfo(ResVersion volVersion, 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
@@ -1516,8 +1515,7 @@ int Resource::readResourceInfo(Common::SeekableReadStream *file,
uint32 wCompression, szUnpacked;
ResourceType type;
- ResourceManager *resMan = g_sci->getResMan();
- switch (resMan->getVolVersion()) {
+ switch (volVersion) {
case kResVersionSci0Sci1Early:
case kResVersionSci1Middle:
w = file->readUint16LE();
@@ -1604,13 +1602,13 @@ int Resource::readResourceInfo(Common::SeekableReadStream *file,
return compression == kCompUnknown ? SCI_ERROR_UNKNOWN_COMPRESSION : 0;
}
-int Resource::decompress(Common::SeekableReadStream *file) {
+int Resource::decompress(ResVersion volVersion, Common::SeekableReadStream *file) {
int error;
uint32 szPacked = 0;
ResourceCompression compression = kCompUnknown;
// fill resource info
- error = readResourceInfo(file, szPacked, compression);
+ error = readResourceInfo(volVersion, file, szPacked, compression);
if (error)
return error;
@@ -1675,7 +1673,7 @@ ResourceCompression ResourceManager::getViewCompression() {
uint32 szPacked;
ResourceCompression compression;
- if (res->readResourceInfo(fileStream, szPacked, compression)) {
+ if (res->readResourceInfo(_volVersion, fileStream, szPacked, compression)) {
if (res->_source->_resourceFile)
delete fileStream;
continue;
diff --git a/engines/sci/resource.h b/engines/sci/resource.h
index 9cf7120ed7..13eb6567ab 100644
--- a/engines/sci/resource.h
+++ b/engines/sci/resource.h
@@ -110,6 +110,16 @@ enum ResourceType {
const char *getResourceTypeName(ResourceType restype);
+enum ResVersion {
+ kResVersionUnknown,
+ kResVersionSci0Sci1Early,
+ kResVersionSci1Middle,
+ kResVersionSci1Late,
+ kResVersionSci11,
+ kResVersionSci11Mac,
+ kResVersionSci32
+};
+
class ResourceManager;
class ResourceSource;
@@ -223,22 +233,12 @@ protected:
bool loadFromWaveFile(Common::SeekableReadStream *file);
bool loadFromAudioVolumeSCI1(Common::SeekableReadStream *file);
bool loadFromAudioVolumeSCI11(Common::SeekableReadStream *file);
- int decompress(Common::SeekableReadStream *file);
- int readResourceInfo(Common::SeekableReadStream *file, uint32 &szPacked, ResourceCompression &compression);
+ int decompress(ResVersion volVersion, Common::SeekableReadStream *file);
+ int readResourceInfo(ResVersion volVersion, Common::SeekableReadStream *file, uint32 &szPacked, ResourceCompression &compression);
};
typedef Common::HashMap<ResourceId, Resource *, ResourceIdHash> 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.
diff --git a/engines/sci/resource_audio.cpp b/engines/sci/resource_audio.cpp
index fc30047e1c..c98b5387be 100644
--- a/engines/sci/resource_audio.cpp
+++ b/engines/sci/resource_audio.cpp
@@ -34,7 +34,7 @@
namespace Sci {
-AudioVolumeResourceSource::AudioVolumeResourceSource(const Common::String &name, ResourceSource *map, int volNum)
+AudioVolumeResourceSource::AudioVolumeResourceSource(ResourceManager *resMan, const Common::String &name, ResourceSource *map, int volNum)
: VolumeResourceSource(name, map, volNum, kSourceAudioVolume) {
_audioCompressionType = 0;
@@ -46,7 +46,7 @@ AudioVolumeResourceSource::AudioVolumeResourceSource(const Common::String &name,
* table for later usage.
*/
- Common::SeekableReadStream *fileStream = getVolumeFile(0);
+ Common::SeekableReadStream *fileStream = getVolumeFile(resMan, 0);
if (!fileStream)
return;
@@ -439,7 +439,7 @@ void ResourceManager::setAudioLanguage(int language) {
const char *dot = strrchr(name.c_str(), '.');
int number = atoi(dot + 1);
- addSource(new AudioVolumeResourceSource(name, _audioMapSCI1, number));
+ addSource(new AudioVolumeResourceSource(this, name, _audioMapSCI1, number));
}
scanNewSources();
diff --git a/engines/sci/resource_intern.h b/engines/sci/resource_intern.h
index 7993fc303e..45421dd722 100644
--- a/engines/sci/resource_intern.h
+++ b/engines/sci/resource_intern.h
@@ -66,7 +66,7 @@ public:
const Common::String &getLocationName() const { return _name; }
// Auxiliary method, used by loadResource implementations.
- Common::SeekableReadStream *getVolumeFile(Resource *res);
+ Common::SeekableReadStream *getVolumeFile(ResourceManager *resMan, Resource *res);
/**
* TODO: Document this
@@ -83,7 +83,7 @@ public:
/**
* Load a resource.
*/
- virtual void loadResource(Resource *res);
+ virtual void loadResource(ResourceManager *resMan, Resource *res);
// FIXME: This audio specific method is a hack. After all, why should a
// ResourceSource or a Resource (which uses this method) have audio
@@ -102,7 +102,7 @@ class PatchResourceSource : public ResourceSource {
public:
PatchResourceSource(const Common::String &name) : ResourceSource(kSourcePatch, name) {}
- virtual void loadResource(Resource *res);
+ virtual void loadResource(ResourceManager *resMan, Resource *res);
};
class VolumeResourceSource : public ResourceSource {
@@ -149,9 +149,9 @@ protected:
int32 *_audioCompressionOffsetMapping;
public:
- AudioVolumeResourceSource(const Common::String &name, ResourceSource *map, int volNum);
+ AudioVolumeResourceSource(ResourceManager *resMan, const Common::String &name, ResourceSource *map, int volNum);
- virtual void loadResource(Resource *res);
+ virtual void loadResource(ResourceManager *resMan, Resource *res);
virtual uint32 getAudioCompressionType() const;
};
@@ -169,7 +169,7 @@ class WaveResourceSource : public ResourceSource {
public:
WaveResourceSource(const Common::String &name) : ResourceSource(kSourceWave, name) {}
- virtual void loadResource(Resource *res);
+ virtual void loadResource(ResourceManager *resMan, Resource *res);
};
/**
@@ -185,7 +185,7 @@ public:
virtual void scanSource(ResourceManager *resMan);
- virtual void loadResource(Resource *res);
+ virtual void loadResource(ResourceManager *resMan, Resource *res);
};
} // End of namespace Sci