From 715e9c6d700e7aad15e7d7b332a351bb1d9fc701 Mon Sep 17 00:00:00 2001 From: neuromancer Date: Fri, 21 May 2021 19:45:47 -0300 Subject: [PATCH] PRIVATE: improved SyncSound implementation --- engines/private/funcs.cpp | 7 +++++++ engines/private/private.cpp | 11 +++++++++++ engines/private/private.h | 2 ++ 3 files changed, 20 insertions(+) diff --git a/engines/private/funcs.cpp b/engines/private/funcs.cpp index b5881f19ba1..e1de7ae0416 100644 --- a/engines/private/funcs.cpp +++ b/engines/private/funcs.cpp @@ -112,6 +112,13 @@ static void fSyncSound(ArgArray args) { if (s != "\"\"") { g_private->playSound(s, 1, true, false); + while (g_private->isSoundActive()) + g_private->ignoreEvents(); + + uint32 i = 100; + while(i--) // one second extra + g_private->ignoreEvents(); + } } diff --git a/engines/private/private.cpp b/engines/private/private.cpp index 51ce14253d0..a6ffba3aa96 100644 --- a/engines/private/private.cpp +++ b/engines/private/private.cpp @@ -299,6 +299,13 @@ Common::Error PrivateEngine::run() { return Common::kNoError; } +void PrivateEngine::ignoreEvents() { + Common::Event event; + g_system->getEventManager()->pollEvent(event); + g_system->updateScreen(); + g_system->delayMillis(10); +} + void PrivateEngine::initFuncs() { for (const Private::FuncTable *fnc = funcTable; fnc->name; fnc++) { Common::String name(fnc->name); @@ -987,6 +994,10 @@ void PrivateEngine::playSound(const Common::String &name, uint loops, bool stopO _mixer->playStream(Audio::Mixer::kSFXSoundType, sh, stream, -1, Audio::Mixer::kMaxChannelVolume); } +bool PrivateEngine::isSoundActive() { + return _mixer->isSoundIDActive(-1); +} + void PrivateEngine::playVideo(const Common::String &name) { debugC(1, kPrivateDebugFunction, "%s(%s)", __FUNCTION__, name.c_str()); //stopSound(true); diff --git a/engines/private/private.h b/engines/private/private.h index efd3ace3484..58a7968dcff 100644 --- a/engines/private/private.h +++ b/engines/private/private.h @@ -186,6 +186,7 @@ public: return true; } + void ignoreEvents(); Common::Error loadGameStream(Common::SeekableReadStream *stream) override; Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave = false) override; void syncGameStream(Common::Serializer &s); @@ -271,6 +272,7 @@ public: // Sounds void playSound(const Common::String &, uint, bool, bool); void stopSound(bool); + bool isSoundActive(); bool _noStopSounds; Common::String getPaperShuffleSound();