From a76612ec5a91847e7e23652614d5e572af2c4aab Mon Sep 17 00:00:00 2001 From: johndoe123 Date: Thu, 17 May 2018 06:22:13 +1000 Subject: ILLUSIONS: Implement voice pausing/unpausing (cherry picked from commit a70cf1d) --- engines/illusions/sound.cpp | 32 +++++++++++++++++------- engines/illusions/sound.h | 8 ++++-- engines/illusions/threads/talkthread.cpp | 4 +-- engines/illusions/threads/talkthread_duckman.cpp | 4 +-- 4 files changed, 33 insertions(+), 15 deletions(-) (limited to 'engines/illusions') diff --git a/engines/illusions/sound.cpp b/engines/illusions/sound.cpp index 1e8ca49f88..d8b03169ea 100644 --- a/engines/illusions/sound.cpp +++ b/engines/illusions/sound.cpp @@ -229,7 +229,7 @@ void MidiPlayer::endOfTrack() { // VoicePlayer -VoicePlayer::VoicePlayer() { +VoicePlayer::VoicePlayer() : _wasPlaying(false), _isPaused(false) { } VoicePlayer::~VoicePlayer() { @@ -267,6 +267,22 @@ void VoicePlayer::stop() { _voiceName.clear(); } +void VoicePlayer::pause() { + if (!_isPaused) { + _isPaused = true; + _wasPlaying = isPlaying(); + g_system->getMixer()->pauseHandle(_soundHandle, true); + } +} + +void VoicePlayer::unpause() { + if (_isPaused) { + _isPaused = false; + if (_wasPlaying) + g_system->getMixer()->pauseHandle(_soundHandle, false); + } +} + bool VoicePlayer::isPlaying() { return g_system->getMixer()->isSoundHandleActive(_soundHandle); } @@ -280,12 +296,6 @@ bool VoicePlayer::isCued() { return _voiceStatus == 2; } -void VoicePlayer::pause(bool paused) { - if (isPlaying()) { - g_system->getMixer()->pauseHandle(_soundHandle, paused); - } -} - // Sound Sound::Sound(uint32 soundEffectId, uint32 soundGroupId, bool looping) @@ -394,8 +404,12 @@ void SoundMan::stopVoice() { _voicePlayer->stop(); } -void SoundMan::pauseVoice(bool paused) { - _voicePlayer->pause(paused); +void SoundMan::pauseVoice() { + _voicePlayer->pause(); +} + +void SoundMan::unpauseVoice() { + _voicePlayer->unpause(); } bool SoundMan::isVoicePlaying() { diff --git a/engines/illusions/sound.h b/engines/illusions/sound.h index 8d5f21eed9..2669102b69 100644 --- a/engines/illusions/sound.h +++ b/engines/illusions/sound.h @@ -80,8 +80,9 @@ public: bool cue(const char *voiceName); void stopCueing(); void start(int16 volume, int16 pan); - void pause(bool paused); void stop(); + void pause(); + void unpause(); bool isPlaying(); bool isEnabled(); bool isCued(); @@ -89,6 +90,8 @@ protected: Audio::SoundHandle _soundHandle; Common::String _voiceName; uint _voiceStatus; + bool _wasPlaying; + bool _isPaused; }; class Sound { @@ -134,7 +137,8 @@ public: void stopCueingVoice(); void startVoice(int16 volume, int16 pan); void stopVoice(); - void pauseVoice(bool paused); + void pauseVoice(); + void unpauseVoice(); bool isVoicePlaying(); bool isVoiceEnabled(); bool isVoiceCued(); diff --git a/engines/illusions/threads/talkthread.cpp b/engines/illusions/threads/talkthread.cpp index 7c2e01276e..c7f7a67b0e 100644 --- a/engines/illusions/threads/talkthread.cpp +++ b/engines/illusions/threads/talkthread.cpp @@ -282,7 +282,7 @@ void TalkThread::onPause() { case 6: case 7: if (!(_flags & 4)) { - // TODO audvocPauseVoice(); + _vm->_soundMan->pauseVoice(); } if (!(_flags & 8)) { _textDurationElapsed = getDurationElapsed(_textStartTime, _textEndTime); @@ -313,7 +313,7 @@ void TalkThread::onUnpause() { break; case 6: if (!(_flags & 4)) { - // TODO audvocUnpauseVoice(); + _vm->_soundMan->unpauseVoice(); } if (!(_flags & 8)) { _textStartTime = getCurrentTime(); diff --git a/engines/illusions/threads/talkthread_duckman.cpp b/engines/illusions/threads/talkthread_duckman.cpp index 36911597ff..2b1294c846 100644 --- a/engines/illusions/threads/talkthread_duckman.cpp +++ b/engines/illusions/threads/talkthread_duckman.cpp @@ -206,7 +206,7 @@ int TalkThread_Duckman::onUpdate() { void TalkThread_Duckman::onPause() { if (_status == 5) { if (!(_flags & 4)) { - _vm->_soundMan->pauseVoice(true); + _vm->_soundMan->pauseVoice(); } if (!(_flags & 8)) _textDurationElapsed = getDurationElapsed(_textStartTime, _textEndTime); @@ -220,7 +220,7 @@ void TalkThread_Duckman::onUnpause() { _vm->_soundMan->cueVoice((char*)talkEntry->_voiceName); } else if (_status == 5) { if (!(_flags & 4)) { - _vm->_soundMan->pauseVoice(false); + _vm->_soundMan->unpauseVoice(); } if (!(_flags & 8)) { _textStartTime = getCurrentTime(); -- cgit v1.2.3