From dfe6082a12d27bc0143f6160083907749075a74e Mon Sep 17 00:00:00 2001 From: athrxx Date: Thu, 12 May 2022 01:33:50 +0200 Subject: [PATCH] SCUMM: (v1-3) - fix sound recovery when loading savegames Prevent "stuttering" from starting the music multiple times (which may now happen due to the improved savegame loading for v1-3). Also add some more tweaks to minimize stuttering, like setting volume to 0 during loading. The result now seems to match what I get when using an emulator. --- engines/scumm/saveload.cpp | 13 ++++++------- engines/scumm/scumm.cpp | 21 ++++++++++++++++++++- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/engines/scumm/saveload.cpp b/engines/scumm/saveload.cpp index 903af8499b8..08b6b3325ac 100644 --- a/engines/scumm/saveload.cpp +++ b/engines/scumm/saveload.cpp @@ -396,6 +396,10 @@ bool ScummEngine::loadState(int slot, bool compat, Common::String &filename) { hdr.name[sizeof(hdr.name)-1] = 0; _saveLoadDescription = hdr.name; + // Set to 0 during load to minimize stuttering + if (_musicEngine) + _musicEngine->setMusicVolume(0); + // Unless specifically requested with _saveSound, we do not save the iMUSE // state for temporary state saves - such as certain cutscenes in DOTT, // FOA, Sam and Max, etc. @@ -450,12 +454,6 @@ bool ScummEngine::loadState(int slot, bool compat, Common::String &filename) { saveLoadWithSerializer(ser); delete in; - // Update volume settings - syncSoundSettings(); - - if (_townsPlayer && (hdr.ver >= VER(81))) - _townsPlayer->restoreAfterLoad(); - // Init NES costume data if (_game.platform == Common::kPlatformNES) { if (hdr.ver < VER(47)) @@ -1497,7 +1495,8 @@ void ScummEngine::saveLoadWithSerializer(Common::Serializer &s) { // If we are loading, and the music being loaded was supposed to loop // forever, then resume playing it. This helps a lot when the audio CD // is used to provide ambient music (see bug #1150). - if (s.isLoading() && info.playing && info.numLoops < 0) + // FM-Towns versions handle this in Player_Towns_v1::restoreAfterLoad(). + if (s.isLoading() && info.playing && info.numLoops < 0 && _game.platform != Common::kPlatformFMTowns) _sound->playCDTrackInternal(info.track, info.numLoops, info.start, info.duration); } diff --git a/engines/scumm/scumm.cpp b/engines/scumm/scumm.cpp index 726a7e4f0f4..2ec9e0a5163 100644 --- a/engines/scumm/scumm.cpp +++ b/engines/scumm/scumm.cpp @@ -2342,6 +2342,7 @@ load_game: if (_completeScreenRedraw) { clearCharsetMask(); _charset->_hasMask = false; + bool restoreFMTownsSounds = (_townsPlayer != nullptr); if (_game.id == GID_LOOM) { // HACK as in game save stuff isn't supported exactly as in the original interpreter when using the @@ -2378,6 +2379,17 @@ load_game: VAR(saveLoadVar) = 0; VAR(214) &= ~blockVerbsFlag; endCutscene(); + + if (_game.platform == Common::kPlatformFMTowns && VAR(163)) { + // Sound restore script. Unlike other versions which handle this + // inside the usual entry scripts, FM-Towns calls this from the save script. + memset(args, 0, sizeof(args)); + args[0] = VAR(163); + runScript(38, false, false, args); + } + + restoreFMTownsSounds = false; + } else if (VAR(saveLoadVar) == 2) { // This is our old hack. If verbs should be shown restore them. byte restoreScript = (_game.platform == Common::kPlatformFMTowns) ? 17 : 18; @@ -2392,6 +2404,7 @@ load_game: } else if (_game.version > 3) { for (int i = 0; i < _numVerbs; i++) drawVerb(i, 0); + } else { if (_game.platform != Common::kPlatformNES && _game.platform != Common::kPlatformC64 && _game.platform != Common::kPlatformMacintosh) { // MM and ZAK (v1/2) @@ -2414,12 +2427,18 @@ load_game: beginCutscene(args); startScene(saveLoadRoom, nullptr, 0); endCutscene(); + restoreFMTownsSounds = false; } } - redrawVerbs(); } + // Update volume settings + syncSoundSettings(); + + if (restoreFMTownsSounds) + _townsPlayer->restoreAfterLoad(); + handleMouseOver(false); _completeScreenRedraw = false;