aboutsummaryrefslogtreecommitdiff
path: root/engines/sci
diff options
context:
space:
mode:
Diffstat (limited to 'engines/sci')
-rw-r--r--engines/sci/engine/ksound.cpp4
-rw-r--r--engines/sci/resource.h2
-rw-r--r--engines/sci/resource_audio.cpp62
3 files changed, 42 insertions, 26 deletions
diff --git a/engines/sci/engine/ksound.cpp b/engines/sci/engine/ksound.cpp
index ed53b8d52f..4a5e4f3df6 100644
--- a/engines/sci/engine/ksound.cpp
+++ b/engines/sci/engine/ksound.cpp
@@ -493,10 +493,8 @@ reg_t kSetLanguage(EngineState *s, int argc, reg_t *argv) {
// Basically, it instructs the interpreter to switch the audio resources
// (resource.aud and associated map files) and load them from the "Spanish"
// subdirectory instead.
- Common::String audioDirectory = s->_segMan->getString(argv[0]);
- //warning("SetLanguage: set audio resource directory to '%s'", audioDirectory.c_str());
+ const Common::String audioDirectory = s->_segMan->getString(argv[0]);
g_sci->getResMan()->changeAudioDirectory(audioDirectory);
-
return s->r_acc;
}
diff --git a/engines/sci/resource.h b/engines/sci/resource.h
index e601a1c434..5589129553 100644
--- a/engines/sci/resource.h
+++ b/engines/sci/resource.h
@@ -372,7 +372,7 @@ public:
void setAudioLanguage(int language);
int getAudioLanguage() const;
- void changeAudioDirectory(Common::String path);
+ void changeAudioDirectory(const Common::String &path);
bool isGMTrackIncluded();
bool isSci11Mac() const { return _volVersion == kResVersionSci11Mac; }
ViewType getViewType() const { return _viewType; }
diff --git a/engines/sci/resource_audio.cpp b/engines/sci/resource_audio.cpp
index 7757445bc1..bd6eee3cca 100644
--- a/engines/sci/resource_audio.cpp
+++ b/engines/sci/resource_audio.cpp
@@ -964,33 +964,53 @@ bool ResourceManager::addAudioSources() {
return true;
}
-void ResourceManager::changeAudioDirectory(Common::String path) {
- // TODO: This implementation is broken.
- return;
-
-#if 0
- // Remove all of the audio map resource sources, as well as the audio resource sources
- for (Common::List<ResourceSource *>::iterator it = _sources.begin(); it != _sources.end();) {
- ResourceSource *source = *it;
- ResSourceType sourceType = source->getSourceType();
-
- // Remove the resource source, if it's an audio map or an audio file
- if (sourceType == kSourceIntMap || sourceType == kSourceAudioVolume) {
- // Don't remove 65535.map (the SFX map) or resource.sfx
- if (source->_volumeNumber == 65535 || source->getLocationName() == "RESOURCE.SFX") {
- ++it;
+void ResourceManager::changeAudioDirectory(const Common::String &path) {
+ // Resources must be cleared before ResourceSources because the destructor
+ // of a Resource accesses its own ResourceSource
+ ResourceMap::iterator resIt = _resMap.begin();
+ while (resIt != _resMap.end()) {
+ Resource *resource = resIt->_value;
+ ResourceType type = resource->getType();
+ if (type == kResourceTypeMap ||
+ type == kResourceTypeAudio36 ||
+ type == kResourceTypeSync36) {
+
+ if (type == kResourceTypeMap && resource->getNumber() == 65535) {
+ ++resIt;
continue;
}
- // erase() will move the iterator to the next element
- it = _sources.erase(it);
+ if (resource->_status == kResStatusLocked) {
+ resource->_lockers = 1;
+ unlockResource(resource);
+ }
+ if (resource->_status == kResStatusEnqueued) {
+ removeFromLRU(resource);
+ }
+ if (resource->_status != kResStatusNoMalloc) {
+ resource->unalloc();
+ }
+ delete resource;
+ _resMap.erase(resIt);
+ }
+
+ ++resIt;
+ }
+
+ Common::List<ResourceSource *>::iterator sourceIt = _sources.begin();
+ while (sourceIt != _sources.end()) {
+ ResourceSource *source = *sourceIt;
+ ResSourceType sourceType = source->getSourceType();
+ if ((sourceType == kSourceIntMap && source->_volumeNumber != 65535) ||
+ (sourceType == kSourceAudioVolume && source->getLocationName() != "RESOURCE.SFX")) {
+
+ sourceIt = _sources.erase(sourceIt);
delete source;
} else {
- ++it;
+ ++sourceIt;
}
}
- // Now, readd the audio resource sources
Common::String mapName = "MAP";
Common::String audioResourceName = "RESOURCE.AUD";
if (!path.empty()) {
@@ -1002,16 +1022,14 @@ void ResourceManager::changeAudioDirectory(Common::String path) {
Common::List<ResourceId>::iterator it;
for (it = resources.begin(); it != resources.end(); ++it) {
// Don't readd 65535.map or resource.sfx
- if ((it->getNumber() == 65535))
+ if (it->getNumber() == 65535)
continue;
ResourceSource *src = addSource(new IntMapResourceSource(mapName, 0, it->getNumber()));
addSource(new AudioVolumeResourceSource(this, audioResourceName, src, 0));
}
- // Rescan the newly added resources
scanNewSources();
-#endif
}
} // End of namespace Sci