diff --git a/engines/lure/lure.cpp b/engines/lure/lure.cpp index ab9448c7cd5..10f58adf4c2 100644 --- a/engines/lure/lure.cpp +++ b/engines/lure/lure.cpp @@ -166,6 +166,7 @@ bool LureEngine::saveGame(uint8 slotNumber, Common::String &caption) { Resources::getReference().saveToStream(f); Game::getReference().saveToStream(f); + Sound.saveToStream(f); Room::getReference().saveToStream(f); Fights.saveToStream(f); @@ -207,6 +208,7 @@ bool LureEngine::loadGame(uint8 slotNumber) { // Load in the data Resources::getReference().loadFromStream(f); Game::getReference().loadFromStream(f); + Sound.loadFromStream(f); Room::getReference().loadFromStream(f); Fights.loadFromStream(f); diff --git a/engines/lure/sound.cpp b/engines/lure/sound.cpp index 850b5495190..8a7e0856f4b 100644 --- a/engines/lure/sound.cpp +++ b/engines/lure/sound.cpp @@ -42,6 +42,7 @@ SoundManager::SoundManager() { _descs = Disk::getReference().getEntry(SOUND_DESC_RESOURCE_ID); _numDescs = _descs->size() / sizeof(SoundDescResource); _soundData = NULL; + _paused = false; int midiDriver = MidiDriver::detectMusicDriver(MDT_MIDI | MDT_ADLIB | MDT_PREFER_MIDI); _nativeMT32 = ((midiDriver == MD_MT32) || ConfMan.getBool("native_mt32")); @@ -87,6 +88,36 @@ SoundManager::~SoundManager() { g_system->deleteMutex(_soundMutex); } +void SoundManager::saveToStream(WriteStream *stream) { + debugC(ERROR_BASIC, kLureDebugSounds, "SoundManager::saveToStream"); + ManagedList::iterator i; + + for (i = _activeSounds.begin(); i != _activeSounds.end(); ++i) { + SoundDescResource *rec = *i; + stream->writeByte(rec->soundNumber); + } + stream->writeByte(0xff); +} + +void SoundManager::loadFromStream(ReadStream *stream) { + // Stop any existing sounds playing + killSounds(); + + // Load any playing sounds + uint8 soundNumber; + while ((soundNumber = stream->readByte()) != 0xff) { + uint8 soundIndex = descIndexOf(soundNumber); + if (soundIndex != 0xff) { + // Make sure that the sound is allowed to be restored + SoundDescResource &rec = soundDescs()[soundIndex]; + if ((rec.flags & SF_RESTORE) != 0) + // Requeue the sound for playing + addSound(soundIndex, false); + } + } +} + + void SoundManager::loadSection(uint16 sectionId) { debugC(ERROR_BASIC, kLureDebugSounds, "SoundManager::loadSection = %xh", sectionId); killSounds(); @@ -247,6 +278,17 @@ void SoundManager::setVolume(uint8 volume) { } } +uint8 SoundManager::descIndexOf(uint8 soundNumber) { + SoundDescResource *rec = soundDescs(); + + for (uint8 index = 0; index < _numDescs; ++index, ++rec) { + if (rec->soundNumber == soundNumber) + return index; + } + + return 0xff; // Couldn't find entry +} + SoundDescResource *SoundManager::findSound(uint8 soundNumber) { debugC(ERROR_BASIC, kLureDebugSounds, "SoundManager::findSound soundNumber=%d", soundNumber); ManagedList::iterator i; @@ -499,6 +541,9 @@ void SoundManager::onTimer(void *data) { } void SoundManager::doTimer() { + if (_paused) + return; + g_system->lockMutex(_soundMutex); ManagedList::iterator i; diff --git a/engines/lure/sound.h b/engines/lure/sound.h index c9c5e191c1a..85d889ca4a2 100644 --- a/engines/lure/sound.h +++ b/engines/lure/sound.h @@ -118,6 +118,7 @@ private: bool _isPlaying; bool _nativeMT32; Common::MutexRef _soundMutex; + bool _paused; // Internal support methods void bellsBodge(); @@ -128,6 +129,9 @@ public: SoundManager(); ~SoundManager(); + void saveToStream(WriteStream *stream); + void loadFromStream(ReadStream *stream); + void loadSection(uint16 sectionId); void killSounds(); void addSound(uint8 soundIndex, bool tidyFlag = true); @@ -137,10 +141,14 @@ public: void setVolume(uint8 soundNumber, uint8 volume); void setVolume(uint8 volume); void tidySounds(); + uint8 descIndexOf(uint8 soundNumber); SoundDescResource *findSound(uint8 soundNumber); void removeSounds(); void restoreSounds(); void fadeOut(); + void pause() { _paused = true; } + void resume() { _paused = false; } + bool getPaused() { return _paused; } // The following methods implement the external sound player module void musicInterface_Initialise();