diff options
author | Johannes Schickel | 2014-06-04 18:51:15 +0200 |
---|---|---|
committer | Johannes Schickel | 2014-06-04 18:51:15 +0200 |
commit | 4069f63eb0caf668e03636df1c697e3fd0724414 (patch) | |
tree | c864c587b4594271426178d126c62dcc8acd6e81 /engines/scumm/players | |
parent | eeed91c42025329bb06cc99eb08e0ce23ab828e4 (diff) | |
download | scummvm-rg350-4069f63eb0caf668e03636df1c697e3fd0724414.tar.gz scummvm-rg350-4069f63eb0caf668e03636df1c697e3fd0724414.tar.bz2 scummvm-rg350-4069f63eb0caf668e03636df1c697e3fd0724414.zip |
SCUMM: Save/load music/sfx data in AD player.
This makes sure that the currently playing music and sfx are resumed when
loading a save game.
Diffstat (limited to 'engines/scumm/players')
-rw-r--r-- | engines/scumm/players/player_ad.cpp | 47 | ||||
-rw-r--r-- | engines/scumm/players/player_ad.h | 10 |
2 files changed, 50 insertions, 7 deletions
diff --git a/engines/scumm/players/player_ad.cpp b/engines/scumm/players/player_ad.cpp index 08519b42cf..5ed50ab65c 100644 --- a/engines/scumm/players/player_ad.cpp +++ b/engines/scumm/players/player_ad.cpp @@ -185,8 +185,51 @@ void Player_AD::saveLoadWithSerializer(Serializer *ser) { return; } - // TODO: Be nicer than the original and save the data to continue the - // currently played sound resources on load? + if (ser->getVersion() >= VER(96)) { + int32 res[4] = { + _soundPlaying, _sfx[0].resource, _sfx[1].resource, _sfx[2].resource + }; + + // The first thing we save is a list of sound resources being played + // at the moment. + ser->saveLoadArrayOf(res, 4, sizeof(res[0]), sleInt32); + + // If we are loading start the music again at this point. + if (ser->isLoading()) { + if (res[0] != -1) { + startSound(res[0]); + } + } + + uint32 musicOffset = _curOffset; + + static const SaveLoadEntry musicData[] = { + MKLINE(Player_AD, _engineMusicTimer, sleInt32, VER(96)), + MKLINE(Player_AD, _musicTimer, sleUint32, VER(96)), + MKLINE(Player_AD, _internalMusicTimer, sleUint32, VER(96)), + MKLINE(Player_AD, _curOffset, sleUint32, VER(96)), + MKLINE(Player_AD, _nextEventTimer, sleUint32, VER(96)), + MKEND() + }; + + ser->saveLoadEntries(this, musicData); + + // We seek back to the old music position. + if (ser->isLoading()) { + SWAP(musicOffset, _curOffset); + musicSeekTo(musicOffset); + } + + // Finally start up the SFX. This makes sure that they are not + // accidently stopped while seeking to the old music position. + if (ser->isLoading()) { + for (int i = 1; i < ARRAYSIZE(res); ++i) { + if (res[i] != -1) { + startSound(res[i]); + } + } + } + } } int Player_AD::readBuffer(int16 *buffer, const int numSamples) { diff --git a/engines/scumm/players/player_ad.h b/engines/scumm/players/player_ad.h index f5e7ecccbc..63a8503f47 100644 --- a/engines/scumm/players/player_ad.h +++ b/engines/scumm/players/player_ad.h @@ -81,7 +81,7 @@ private: int _samplesTillCallbackRemainder; int _soundPlaying; - int _engineMusicTimer; + int32 _engineMusicTimer; struct SfxSlot; @@ -120,8 +120,8 @@ private: const byte *_musicData; uint _timerLimit; uint _musicTicks; - uint _musicTimer; - uint _internalMusicTimer; + uint32 _musicTimer; + uint32 _internalMusicTimer; bool _loopFlag; uint _musicLoopStart; uint _instrumentOffset[16]; @@ -138,8 +138,8 @@ private: uint _mdvdrState; - uint _curOffset; - uint _nextEventTimer; + uint32 _curOffset; + uint32 _nextEventTimer; static const uint _noteFrequencies[12]; static const uint _mdvdrTable[6]; |