aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Gilbert2007-10-28 03:32:13 +0000
committerPaul Gilbert2007-10-28 03:32:13 +0000
commit5f1ef918209682bb7affb9f0c288b56163d3bc5f (patch)
tree011f7101d91e6a60cd9c0e3c716a80750b224031
parent9d14d74e8d763806afc7019ab5cdda4eab113a44 (diff)
downloadscummvm-rg350-5f1ef918209682bb7affb9f0c288b56163d3bc5f.tar.gz
scummvm-rg350-5f1ef918209682bb7affb9f0c288b56163d3bc5f.tar.bz2
scummvm-rg350-5f1ef918209682bb7affb9f0c288b56163d3bc5f.zip
Added storing of playing sounds to savegame (note: only sounds flagged as restorable are restarted after loading a savegame)
svn-id: r29271
-rw-r--r--engines/lure/lure.cpp2
-rw-r--r--engines/lure/sound.cpp45
-rw-r--r--engines/lure/sound.h8
3 files changed, 55 insertions, 0 deletions
diff --git a/engines/lure/lure.cpp b/engines/lure/lure.cpp
index ab9448c7cd..10f58adf4c 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 850b549519..8a7e0856f4 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<SoundDescResource *>::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<SoundDescResource *>::iterator i;
@@ -499,6 +541,9 @@ void SoundManager::onTimer(void *data) {
}
void SoundManager::doTimer() {
+ if (_paused)
+ return;
+
g_system->lockMutex(_soundMutex);
ManagedList<MidiMusic *>::iterator i;
diff --git a/engines/lure/sound.h b/engines/lure/sound.h
index c9c5e191c1..85d889ca4a 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();