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.
This commit is contained in:
athrxx 2022-05-12 01:33:50 +02:00
parent ed8e1c4870
commit dfe6082a12
2 changed files with 26 additions and 8 deletions

View file

@ -396,6 +396,10 @@ bool ScummEngine::loadState(int slot, bool compat, Common::String &filename) {
hdr.name[sizeof(hdr.name)-1] = 0; hdr.name[sizeof(hdr.name)-1] = 0;
_saveLoadDescription = hdr.name; _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 // Unless specifically requested with _saveSound, we do not save the iMUSE
// state for temporary state saves - such as certain cutscenes in DOTT, // state for temporary state saves - such as certain cutscenes in DOTT,
// FOA, Sam and Max, etc. // FOA, Sam and Max, etc.
@ -450,12 +454,6 @@ bool ScummEngine::loadState(int slot, bool compat, Common::String &filename) {
saveLoadWithSerializer(ser); saveLoadWithSerializer(ser);
delete in; delete in;
// Update volume settings
syncSoundSettings();
if (_townsPlayer && (hdr.ver >= VER(81)))
_townsPlayer->restoreAfterLoad();
// Init NES costume data // Init NES costume data
if (_game.platform == Common::kPlatformNES) { if (_game.platform == Common::kPlatformNES) {
if (hdr.ver < VER(47)) 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 // 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 // forever, then resume playing it. This helps a lot when the audio CD
// is used to provide ambient music (see bug #1150). // 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); _sound->playCDTrackInternal(info.track, info.numLoops, info.start, info.duration);
} }

View file

@ -2342,6 +2342,7 @@ load_game:
if (_completeScreenRedraw) { if (_completeScreenRedraw) {
clearCharsetMask(); clearCharsetMask();
_charset->_hasMask = false; _charset->_hasMask = false;
bool restoreFMTownsSounds = (_townsPlayer != nullptr);
if (_game.id == GID_LOOM) { if (_game.id == GID_LOOM) {
// HACK as in game save stuff isn't supported exactly as in the original interpreter when using the // 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(saveLoadVar) = 0;
VAR(214) &= ~blockVerbsFlag; VAR(214) &= ~blockVerbsFlag;
endCutscene(); 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) { } else if (VAR(saveLoadVar) == 2) {
// This is our old hack. If verbs should be shown restore them. // This is our old hack. If verbs should be shown restore them.
byte restoreScript = (_game.platform == Common::kPlatformFMTowns) ? 17 : 18; byte restoreScript = (_game.platform == Common::kPlatformFMTowns) ? 17 : 18;
@ -2392,6 +2404,7 @@ load_game:
} else if (_game.version > 3) { } else if (_game.version > 3) {
for (int i = 0; i < _numVerbs; i++) for (int i = 0; i < _numVerbs; i++)
drawVerb(i, 0); drawVerb(i, 0);
} else { } else {
if (_game.platform != Common::kPlatformNES && _game.platform != Common::kPlatformC64 && _game.platform != Common::kPlatformMacintosh) { if (_game.platform != Common::kPlatformNES && _game.platform != Common::kPlatformC64 && _game.platform != Common::kPlatformMacintosh) {
// MM and ZAK (v1/2) // MM and ZAK (v1/2)
@ -2414,12 +2427,18 @@ load_game:
beginCutscene(args); beginCutscene(args);
startScene(saveLoadRoom, nullptr, 0); startScene(saveLoadRoom, nullptr, 0);
endCutscene(); endCutscene();
restoreFMTownsSounds = false;
} }
} }
redrawVerbs(); redrawVerbs();
} }
// Update volume settings
syncSoundSettings();
if (restoreFMTownsSounds)
_townsPlayer->restoreAfterLoad();
handleMouseOver(false); handleMouseOver(false);
_completeScreenRedraw = false; _completeScreenRedraw = false;