diff options
Diffstat (limited to 'engines/sci/resource_audio.cpp')
-rw-r--r-- | engines/sci/resource_audio.cpp | 62 |
1 files changed, 40 insertions, 22 deletions
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 |