diff options
author | Torbjörn Andersson | 2003-09-27 16:10:43 +0000 |
---|---|---|
committer | Torbjörn Andersson | 2003-09-27 16:10:43 +0000 |
commit | e19e7c879a1fc88458a3e26715875e60512d755b (patch) | |
tree | d0e41c77c7c6cd96b4aee66c4344e2160b5ac3bb | |
parent | 796fcfff7e70a4d1951d42ad8b8f39f45914a24e (diff) | |
download | scummvm-rg350-e19e7c879a1fc88458a3e26715875e60512d755b.tar.gz scummvm-rg350-e19e7c879a1fc88458a3e26715875e60512d755b.tar.bz2 scummvm-rg350-e19e7c879a1fc88458a3e26715875e60512d755b.zip |
Save enough information about the currently playing music before the
credits so that it can be properly resumed afterwards.
svn-id: r10429
-rw-r--r-- | sword2/driver/d_sound.cpp | 56 | ||||
-rw-r--r-- | sword2/driver/d_sound.h | 4 | ||||
-rw-r--r-- | sword2/function.cpp | 13 |
3 files changed, 62 insertions, 11 deletions
diff --git a/sword2/driver/d_sound.cpp b/sword2/driver/d_sound.cpp index 6dabc572ac..e4020b370b 100644 --- a/sword2/driver/d_sound.cpp +++ b/sword2/driver/d_sound.cpp @@ -308,6 +308,62 @@ int32 Sword2Sound::ReverseStereo(void) { return RD_OK; } +// Save/Restore information about current music so that we can restore it +// after the credits. + +void Sword2Sound::saveMusicState() { + StackLock lock(_mutex); + + int saveStream; + + if (music[0]._streaming && !music[0]._fading) { + saveStream = 0; + } else if (music[1]._streaming && !music[0]._fading) { + saveStream = 1; + } else { + music[2]._streaming = false; + return; + } + + music[2]._streaming = true; + music[2]._fading = 0; + music[2]._looping = music[saveStream]._looping; + music[2]._fileStart = music[saveStream]._fileStart; + music[2]._filePos = music[saveStream]._filePos; + music[2]._fileEnd = music[saveStream]._fileEnd; + music[2]._lastSample = music[saveStream]._lastSample; +} + +void Sword2Sound::restoreMusicState() { + StackLock lock(_mutex); + + int restoreStream; + + if (!music[2]._streaming) + return; + + // Fade out any music that happens to be playing + + for (int i = 0; i < MAXMUS; i++) { + if (music[i]._streaming && !music[i]._fading) + music[i]._fading = FADE_SAMPLES; + } + + if (!music[0]._streaming && !music[0]._fading) { + restoreStream = 0; + } else { + restoreStream = 1; + } + + music[restoreStream]._streaming = true; + music[restoreStream]._fading = 0; + music[restoreStream]._looping = music[2]._looping; + music[restoreStream]._fileStart = music[2]._fileStart; + music[restoreStream]._filePos = music[2]._filePos; + music[restoreStream]._fileEnd = music[2]._fileEnd; + music[restoreStream]._lastSample = music[2]._lastSample; +} + // -------------------------------------------------------------------------- // This function returns the index of the sound effect with the ID passed in. // -------------------------------------------------------------------------- diff --git a/sword2/driver/d_sound.h b/sword2/driver/d_sound.h index 2d59a1d625..520a320446 100644 --- a/sword2/driver/d_sound.h +++ b/sword2/driver/d_sound.h @@ -100,6 +100,8 @@ class Sword2Sound { int32 PauseMusic(void); int32 UnpauseMusic(void); int32 StreamCompMusic(const char *filename, uint32 musicId, bool looping); + void saveMusicState(); + void restoreMusicState(); int32 MusicTimeRemaining(); int32 ReverseStereo(void); uint8 GetFxVolume(void); @@ -129,7 +131,7 @@ class Sword2Sound { RateConverter *_converter; FxHandle fx[MAXFX]; - MusicHandle music[MAXMUS]; + MusicHandle music[MAXMUS + 1]; // We used to have two music volumes - one for each channel - // but they were always set to the same value. diff --git a/sword2/function.cpp b/sword2/function.cpp index aa265ca8de..b2aae47b38 100644 --- a/sword2/function.cpp +++ b/sword2/function.cpp @@ -391,13 +391,12 @@ int32 FN_play_credits(int32 *params) { uint8 oldPal[1024]; uint8 tmpPal[1024]; int32 music_length; - uint32 safe_looping_music_id; int32 pars[2]; // FIXME: We need a better method for saving/restoring the // music state as this one only restarts looping music. - safe_looping_music_id = looping_music_id; + g_sound->saveMusicState(); g_sound->MuteFx(1); g_sound->MuteSpeech(1); @@ -446,14 +445,8 @@ int32 FN_play_credits(int32 *params) { g_system->delay_msecs(30); } - looping_music_id = safe_looping_music_id; - - if (looping_music_id) { - pars[0] = looping_music_id; - pars[1] = FX_LOOP; - FN_play_music(pars); - } else - FN_stop_music(NULL); + FN_stop_music(NULL); + g_sound->restoreMusicState(); BS2_SetPalette(0, 256, oldPal, RDPAL_FADE); FadeUp(0.75); |