SCI: Improve audio volume & settings sync code
This patch includes enhancements to the ScummVM integration with
SCI engine, with particular focus on SCI32 support.
1. Fixes audio volumes syncing erroneously to ScummVM in games
that modify the audio volume without user action (e.g. SCI1.1
talkies that reduce music volume during speech playback). Now,
volumes will only be synchronised when the user interacts with
the game's audio settings. This mechanism works by looking for
a known volume control object in the stack, and only syncing
when the control object is present. (Ports and planes were
researched and found unreliable.)
2. Fixes audio syncing in SCI32 games that do not set game
volumes through kDoSoundMasterVolume/kDoAudioVolume, like GK1,
GK2, Phant1, and Torin.
3. Fixes speech/subtitles syncing in SCI32 games that do not use
global 90, like LSL6hires.
4. Fixes in-game volume controls in SCI32 games reflecting
outdated audio volumes when a change is made during the game
from the ScummVM launcher.
5. Fixes SCI32 games that would restore volumes from save games
or reset volumes on startup, which caused game volumes to be
out-of-sync with ScummVM when started.
6. ScummVM integration code for audio sync has been abstracted
into a new GuestAdditions class. This keeps the ScummVM-
specific code all in one place, with only small hooks into the
engine code. ScummVM integrated save/load code should probably
also go here in the future.
Fixes Trac#9700.
2017-01-26 13:18:41 -06:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SCI_ENGINE_GUEST_ADDITIONS_H
|
|
|
|
#define SCI_ENGINE_GUEST_ADDITIONS_H
|
|
|
|
|
|
|
|
#include "sci/engine/vm_types.h"
|
|
|
|
|
|
|
|
namespace Sci {
|
|
|
|
|
|
|
|
struct EngineState;
|
|
|
|
class GameFeatures;
|
2017-04-22 12:27:57 -05:00
|
|
|
class Kernel;
|
|
|
|
class Script;
|
SCI: Improve audio volume & settings sync code
This patch includes enhancements to the ScummVM integration with
SCI engine, with particular focus on SCI32 support.
1. Fixes audio volumes syncing erroneously to ScummVM in games
that modify the audio volume without user action (e.g. SCI1.1
talkies that reduce music volume during speech playback). Now,
volumes will only be synchronised when the user interacts with
the game's audio settings. This mechanism works by looking for
a known volume control object in the stack, and only syncing
when the control object is present. (Ports and planes were
researched and found unreliable.)
2. Fixes audio syncing in SCI32 games that do not set game
volumes through kDoSoundMasterVolume/kDoAudioVolume, like GK1,
GK2, Phant1, and Torin.
3. Fixes speech/subtitles syncing in SCI32 games that do not use
global 90, like LSL6hires.
4. Fixes in-game volume controls in SCI32 games reflecting
outdated audio volumes when a change is made during the game
from the ScummVM launcher.
5. Fixes SCI32 games that would restore volumes from save games
or reset volumes on startup, which caused game volumes to be
out-of-sync with ScummVM when started.
6. ScummVM integration code for audio sync has been abstracted
into a new GuestAdditions class. This keeps the ScummVM-
specific code all in one place, with only small hooks into the
engine code. ScummVM integrated save/load code should probably
also go here in the future.
Fixes Trac#9700.
2017-01-26 13:18:41 -06:00
|
|
|
class SegManager;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The GuestAdditions class hooks into the SCI virtual machine to provide
|
|
|
|
* enhanced interactions between the ScummVM GUI and the game engine. Currently,
|
|
|
|
* this enhanced functionality encompasses synchronisation of audio volumes and
|
|
|
|
* other audio-related settings.
|
|
|
|
*
|
|
|
|
* Some parts of the audio sync are applied as script patches using the normal
|
|
|
|
* ScriptPatcher mechanism. These patches are designed to prevent the game from
|
|
|
|
* resetting to a default volume when starting up or loading a save.
|
|
|
|
*/
|
|
|
|
class GuestAdditions {
|
|
|
|
public:
|
2017-04-22 12:27:57 -05:00
|
|
|
GuestAdditions(EngineState *state, GameFeatures *features, Kernel *kernel);
|
|
|
|
|
|
|
|
#pragma mark -
|
SCI: Improve audio volume & settings sync code
This patch includes enhancements to the ScummVM integration with
SCI engine, with particular focus on SCI32 support.
1. Fixes audio volumes syncing erroneously to ScummVM in games
that modify the audio volume without user action (e.g. SCI1.1
talkies that reduce music volume during speech playback). Now,
volumes will only be synchronised when the user interacts with
the game's audio settings. This mechanism works by looking for
a known volume control object in the stack, and only syncing
when the control object is present. (Ports and planes were
researched and found unreliable.)
2. Fixes audio syncing in SCI32 games that do not set game
volumes through kDoSoundMasterVolume/kDoAudioVolume, like GK1,
GK2, Phant1, and Torin.
3. Fixes speech/subtitles syncing in SCI32 games that do not use
global 90, like LSL6hires.
4. Fixes in-game volume controls in SCI32 games reflecting
outdated audio volumes when a change is made during the game
from the ScummVM launcher.
5. Fixes SCI32 games that would restore volumes from save games
or reset volumes on startup, which caused game volumes to be
out-of-sync with ScummVM when started.
6. ScummVM integration code for audio sync has been abstracted
into a new GuestAdditions class. This keeps the ScummVM-
specific code all in one place, with only small hooks into the
engine code. ScummVM integrated save/load code should probably
also go here in the future.
Fixes Trac#9700.
2017-01-26 13:18:41 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Synchronises audio volume settings from ScummVM to the game. Called
|
|
|
|
* whenever the ScummVM launcher is dismissed.
|
|
|
|
*/
|
|
|
|
void syncSoundSettings() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Synchronises all audio settings from ScummVM to the game. Called when the
|
|
|
|
* game is first started, and when save games are loaded.
|
|
|
|
*/
|
|
|
|
void syncAudioOptionsFromScummVM() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clears audio settings synchronisation state.
|
|
|
|
*/
|
|
|
|
void reset();
|
|
|
|
|
|
|
|
private:
|
|
|
|
EngineState *_state;
|
|
|
|
GameFeatures *_features;
|
2017-04-22 12:27:57 -05:00
|
|
|
Kernel *_kernel;
|
SCI: Improve audio volume & settings sync code
This patch includes enhancements to the ScummVM integration with
SCI engine, with particular focus on SCI32 support.
1. Fixes audio volumes syncing erroneously to ScummVM in games
that modify the audio volume without user action (e.g. SCI1.1
talkies that reduce music volume during speech playback). Now,
volumes will only be synchronised when the user interacts with
the game's audio settings. This mechanism works by looking for
a known volume control object in the stack, and only syncing
when the control object is present. (Ports and planes were
researched and found unreliable.)
2. Fixes audio syncing in SCI32 games that do not set game
volumes through kDoSoundMasterVolume/kDoAudioVolume, like GK1,
GK2, Phant1, and Torin.
3. Fixes speech/subtitles syncing in SCI32 games that do not use
global 90, like LSL6hires.
4. Fixes in-game volume controls in SCI32 games reflecting
outdated audio volumes when a change is made during the game
from the ScummVM launcher.
5. Fixes SCI32 games that would restore volumes from save games
or reset volumes on startup, which caused game volumes to be
out-of-sync with ScummVM when started.
6. ScummVM integration code for audio sync has been abstracted
into a new GuestAdditions class. This keeps the ScummVM-
specific code all in one place, with only small hooks into the
engine code. ScummVM integrated save/load code should probably
also go here in the future.
Fixes Trac#9700.
2017-01-26 13:18:41 -06:00
|
|
|
SegManager *_segMan;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convenience function for invoking selectors that reduces boilerplate code
|
|
|
|
* required by Sci::invokeSelector.
|
|
|
|
*/
|
|
|
|
void invokeSelector(const reg_t objId, const Selector selector, const int argc = 0, const StackPtr argv = nullptr) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines whether the current stack contains calls from audio controls
|
|
|
|
* that indicate a user-initiated change of audio settings.
|
|
|
|
*/
|
|
|
|
bool shouldSyncAudio() const;
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
#pragma mark Hooks
|
|
|
|
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Guest additions hook for SciEngine::runGame.
|
|
|
|
*/
|
|
|
|
void sciEngineRunGameHook();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Guest additions hook for write_var.
|
|
|
|
*/
|
|
|
|
void writeVarHook(const int type, const int index, const reg_t value);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Guest additions hook for kDoSoundMasterVolume.
|
|
|
|
*
|
|
|
|
* @returns true if the default action should be prevented
|
|
|
|
*/
|
|
|
|
bool kDoSoundMasterVolumeHook(const int volume) const;
|
|
|
|
|
|
|
|
#ifdef ENABLE_SCI32
|
|
|
|
/**
|
|
|
|
* Guest additions hook for send_selector.
|
|
|
|
*/
|
|
|
|
void sendSelectorHook(const reg_t sendObj, Selector &selector, reg_t *argp);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Guest additions hook for Audio32::setVolume.
|
|
|
|
*
|
|
|
|
* @returns true if the default action should be prevented
|
|
|
|
*/
|
|
|
|
bool audio32SetVolumeHook(const int16 channelIndex, const int16 volume) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Guest additions hook for kDoSoundSetVolume.
|
|
|
|
*/
|
|
|
|
void kDoSoundSetVolumeHook(const reg_t soundObj, const int16 volume) const;
|
2017-04-22 12:27:57 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Guest additions hook for SegManager::instantiateScript.
|
|
|
|
*/
|
|
|
|
void instantiateScriptHook(Script &script) const;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
#pragma mark Save & restore
|
|
|
|
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Patches game scripts to hook into the ScummVM launcher UI when a user
|
|
|
|
* tries to save or restore a game from inside the game.
|
|
|
|
*/
|
|
|
|
void patchGameSaveRestore() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void patchGameSaveRestoreSCI16() const;
|
|
|
|
|
|
|
|
#ifdef ENABLE_SCI32
|
|
|
|
public:
|
|
|
|
reg_t kScummVMSaveLoad(EngineState *s, int argc, reg_t *argv) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void patchGameSaveRestoreSCI32(Script &script) const;
|
SCI: Improve audio volume & settings sync code
This patch includes enhancements to the ScummVM integration with
SCI engine, with particular focus on SCI32 support.
1. Fixes audio volumes syncing erroneously to ScummVM in games
that modify the audio volume without user action (e.g. SCI1.1
talkies that reduce music volume during speech playback). Now,
volumes will only be synchronised when the user interacts with
the game's audio settings. This mechanism works by looking for
a known volume control object in the stack, and only syncing
when the control object is present. (Ports and planes were
researched and found unreliable.)
2. Fixes audio syncing in SCI32 games that do not set game
volumes through kDoSoundMasterVolume/kDoAudioVolume, like GK1,
GK2, Phant1, and Torin.
3. Fixes speech/subtitles syncing in SCI32 games that do not use
global 90, like LSL6hires.
4. Fixes in-game volume controls in SCI32 games reflecting
outdated audio volumes when a change is made during the game
from the ScummVM launcher.
5. Fixes SCI32 games that would restore volumes from save games
or reset volumes on startup, which caused game volumes to be
out-of-sync with ScummVM when started.
6. ScummVM integration code for audio sync has been abstracted
into a new GuestAdditions class. This keeps the ScummVM-
specific code all in one place, with only small hooks into the
engine code. ScummVM integrated save/load code should probably
also go here in the future.
Fixes Trac#9700.
2017-01-26 13:18:41 -06:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
#pragma mark Message type sync
|
|
|
|
|
|
|
|
private:
|
|
|
|
/**
|
|
|
|
* true if the message type (text/speech/text+speech) has been synchronised
|
|
|
|
* from ScummVM to the game.
|
|
|
|
*/
|
|
|
|
bool _messageTypeSynced;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Synchronises the message type (speech/text/speech+text) from a ScummVM to
|
|
|
|
* a game.
|
|
|
|
*/
|
|
|
|
void syncMessageTypeFromScummVM() const;
|
|
|
|
|
|
|
|
void syncMessageTypeFromScummVMUsingDefaultStrategy() const;
|
|
|
|
#ifdef ENABLE_SCI32
|
|
|
|
void syncMessageTypeFromScummVMUsingShiversStrategy() const;
|
|
|
|
void syncMessageTypeFromScummVMUsingLSL6HiresStrategy() const;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Synchronises the message type (speech/text/speech+text) from a game to
|
|
|
|
* ScummVM.
|
|
|
|
*/
|
|
|
|
void syncMessageTypeToScummVM(const int index, const reg_t value);
|
|
|
|
|
|
|
|
void syncMessageTypeToScummVMUsingDefaultStrategy(const int index, const reg_t value);
|
|
|
|
#ifdef ENABLE_SCI32
|
|
|
|
void syncMessageTypeToScummVMUsingShiversStrategy(const int index, const reg_t value);
|
|
|
|
void syncMessageTypeToScummVMUsingLSL6HiresStrategy(const reg_t sendObj, Selector &selector, reg_t *argp);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
#pragma mark Master volume sync
|
|
|
|
|
|
|
|
private:
|
|
|
|
/**
|
|
|
|
* Synchronises audio volume settings from ScummVM to the game, for games
|
|
|
|
* that do not store volume themselves and just call to the kernel.
|
|
|
|
*/
|
|
|
|
void syncMasterVolumeFromScummVM() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Synchronises audio volume settings from the game to ScummVM, for games
|
|
|
|
* that do not store volume themselves and just call to the kernel.
|
|
|
|
*/
|
|
|
|
void syncMasterVolumeToScummVM(const int16 masterVolume) const;
|
|
|
|
|
|
|
|
#ifdef ENABLE_SCI32
|
|
|
|
#pragma mark -
|
|
|
|
#pragma mark Globals volume sync
|
|
|
|
|
|
|
|
private:
|
|
|
|
/**
|
|
|
|
* Synchronises audio volume settings from ScummVM to the game, for games
|
|
|
|
* that store volumes in globals.
|
|
|
|
*/
|
|
|
|
void syncAudioVolumeGlobalsFromScummVM() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Synchronises audio volume settings from ScummVM to GK1 at game startup
|
|
|
|
* time.
|
|
|
|
*/
|
|
|
|
void syncGK1StartupVolumeFromScummVM(const int index, const reg_t value) const;
|
|
|
|
|
|
|
|
void syncGK1VolumeFromScummVM(const int16 musicVolume, const int16 dacVolume) const;
|
|
|
|
void syncGK2VolumeFromScummVM(const int16 musicVolume) const;
|
|
|
|
void syncLSL6HiresVolumeFromScummVM(const int16 musicVolume) const;
|
|
|
|
void syncTorinVolumeFromScummVM(const int16 musicVolume, const int16 sfxVolume, const int16 speechVolume) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Synchronises audio volume settings from a game to ScummVM, for games
|
|
|
|
* that store volumes in globals.
|
|
|
|
*/
|
|
|
|
void syncAudioVolumeGlobalsToScummVM(const int index, const reg_t value) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Synchronises audio volume settings from GK1 to ScummVM.
|
|
|
|
*/
|
|
|
|
void syncGK1AudioVolumeToScummVM(const reg_t soundObj, const int16 volume) const;
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
#pragma mark Audio UI sync
|
|
|
|
|
|
|
|
private:
|
|
|
|
/**
|
|
|
|
* Synchronises the in-game control panel UI in response to a change of
|
|
|
|
* volume from the ScummVM GUI. The values of the volume parameters passed
|
|
|
|
* to this function are game-specific.
|
|
|
|
*/
|
|
|
|
void syncInGameUI(const int16 musicVolume, const int16 sfxVolume) const;
|
|
|
|
|
|
|
|
void syncGK1UI() const;
|
|
|
|
void syncGK2UI() const;
|
|
|
|
void syncLSL6HiresUI(const int16 musicVolume) const;
|
|
|
|
void syncPhant1UI(const int16 oldMusicVolume, const int16 musicVolume, reg_t &musicGlobal, const int16 oldDacVolume, const int16 dacVolume, reg_t &dacGlobal) const;
|
|
|
|
void syncPQ4UI(const int16 musicVolume) const;
|
|
|
|
void syncPQSWATUI() const;
|
|
|
|
void syncQFG4UI(const int16 musicVolume) const;
|
|
|
|
void syncShivers1UI(const int16 dacVolume) const;
|
|
|
|
void syncSQ6UI() const;
|
|
|
|
void syncTorinUI(const int16 musicVolume, const int16 sfxVolume, const int16 speechVolume) const;
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
#pragma mark Talk speed sync
|
|
|
|
|
|
|
|
private:
|
|
|
|
/**
|
|
|
|
* Synchronises text speed settings from ScummVM to a game.
|
|
|
|
*/
|
|
|
|
void syncTextSpeedFromScummVM() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Synchronises text speed settings from a game to ScummVM.
|
|
|
|
*/
|
|
|
|
void syncTextSpeedToScummVM(const int index, const reg_t value) const;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
} // End of namespace Sci
|
|
|
|
|
|
|
|
#endif // SCI_ENGINE_GUEST_ADDITIONS_H
|