From b9a5e89e09bcad0fd6a7a001cc28c645244587a5 Mon Sep 17 00:00:00 2001 From: Dextinfire <> Date: Sat, 28 Sep 2024 14:52:00 -0700 Subject: [PATCH] Fix pausing when entering system menu --- profiles/common/scriptvars.lua | 4 ++++ src/audio/audiochannel.h | 8 +++++++- src/audio/audiocommon.h | 1 + src/audio/openal/audiochannel.cpp | 15 +++++++++++++++ src/audio/openal/audiochannel.h | 2 ++ src/game.cpp | 20 +++++++++++++------- src/scriptvars.h | 4 ++++ src/vm/inst_sound.cpp | 12 ++++++++---- src/vm/inst_system.cpp | 2 +- 9 files changed, 55 insertions(+), 13 deletions(-) diff --git a/profiles/common/scriptvars.lua b/profiles/common/scriptvars.lua index 43ce9299..ee4e8ef7 100644 --- a/profiles/common/scriptvars.lua +++ b/profiles/common/scriptvars.lua @@ -278,6 +278,10 @@ root.ScriptVars = { SF_TITLEEND=1241, SF_UIHIDDEN=1244, SF_LOADING=1264, + SF_SYSMENUDISABLE=1286, + SF_SYSTEMMENUDISABLE=1221, -- i don't know SYS and SYSTEM exists + SF_SYSTEMMENUDISABLE2=1222, + SF_GAMEPAUSE=1223, SF_ALBUMRELOAD=1310, SF_ALBUMEND=1311, SF_ALBUMCHA1=1312, diff --git a/src/audio/audiochannel.h b/src/audio/audiochannel.h index e67bff5d..5991367d 100644 --- a/src/audio/audiochannel.h +++ b/src/audio/audiochannel.h @@ -26,6 +26,13 @@ class AudioChannel { virtual void FillBuffers(){}; virtual void Stop(float fadeOutDuration){}; + virtual void Pause() { + if (State == ACS_Playing) State = ACS_Paused; + }; + virtual void Resume() { + if (State == ACS_Paused) State = ACS_Playing; + }; + virtual void Update(float dt){}; virtual float PositionInSeconds() const { return 0.0f; }; @@ -43,7 +50,6 @@ class AudioChannel { // Read only - seeking is currently not supported // Actual playhead at start of (graphics) frame, in AudioStream samples int Position = 0; - bool Looping; }; diff --git a/src/audio/audiocommon.h b/src/audio/audiocommon.h index cb21f41b..96272c4b 100644 --- a/src/audio/audiocommon.h +++ b/src/audio/audiocommon.h @@ -22,6 +22,7 @@ enum AudioChannelId { enum AudioChannelState { ACS_Stopped, ACS_Playing, + ACS_Paused, ACS_FadingIn, ACS_FadingOut }; diff --git a/src/audio/openal/audiochannel.cpp b/src/audio/openal/audiochannel.cpp index 496956a6..37ee0af8 100644 --- a/src/audio/openal/audiochannel.cpp +++ b/src/audio/openal/audiochannel.cpp @@ -101,8 +101,23 @@ void AudioChannel::Stop(float fadeOutDuration) { } } +void AudioChannel::Pause() { + if (State == ACS_Playing) { + alSourcePause(Source); + State = ACS_Paused; + } +} + +void AudioChannel::Resume() { + if (State == ACS_Paused) { + alSourcePlay(Source); + State = ACS_Playing; + } +} + void AudioChannel::Update(float dt) { if (!IsInit) return; + if (State == ACS_Paused) return; // Update fade diff --git a/src/audio/openal/audiochannel.h b/src/audio/openal/audiochannel.h index 1b7027eb..a662564b 100644 --- a/src/audio/openal/audiochannel.h +++ b/src/audio/openal/audiochannel.h @@ -17,6 +17,8 @@ class AudioChannel : public Audio::AudioChannel { void Play(AudioStream* stream, bool loop, float fadeInDuration) override; void FillBuffers() override; void Stop(float fadeOutDuration) override; + void Pause() override; + void Resume() override; void Update(float dt) override; diff --git a/src/game.cpp b/src/game.cpp index af487cd3..720aa356 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -226,11 +226,14 @@ void Update(float dt) { SaveIconDisplay::Update(dt); LoadingDisplay::Update(dt); DateDisplay::Update(dt); - TipsNotification::Update(dt); - DelusionTrigger::Update(dt); - UI::MapSystem::Update(dt); - if (CCLCC::YesNoTrigger::YesNoTriggerPtr) - CCLCC::YesNoTrigger::YesNoTriggerPtr->Update(dt); + if (ScrWork[SW_GAMESTATE] & 5 && !GetFlag(SF_GAMEPAUSE) && + !GetFlag(SF_SYSMENUDISABLE)) { + TipsNotification::Update(dt); + DelusionTrigger::Update(dt); + UI::MapSystem::Update(dt); + if (CCLCC::YesNoTrigger::YesNoTriggerPtr) + CCLCC::YesNoTrigger::YesNoTriggerPtr->Update(dt); + } Vm::Update(); } @@ -248,8 +251,11 @@ void Update(float dt) { } if (Profile::GameFeatures & GameFeature::Renderer2D) { - for (int i = 0; i < Profile::Dialogue::PageCount; i++) - DialoguePages[i].Update(dt); + if (ScrWork[SW_GAMESTATE] & 5 && !GetFlag(SF_GAMEPAUSE) && + !GetFlag(SF_SYSMENUDISABLE)) { + for (int i = 0; i < Profile::Dialogue::PageCount; i++) + DialoguePages[i].Update(dt); + } } if ((Profile::GameFeatures & GameFeature::Renderer2D) && diff --git a/src/scriptvars.h b/src/scriptvars.h index 13cd9794..6e488c0c 100644 --- a/src/scriptvars.h +++ b/src/scriptvars.h @@ -276,6 +276,10 @@ V(SF_TITLEMODE) V(SF_TITLEEND) V(SF_UIHIDDEN) V(SF_LOADING) +V(SF_SYSMENUDISABLE) +V(SF_SYSTEMMENUDISABLE) +V(SF_SYSTEMMENUDISABLE2) +V(SF_GAMEPAUSE) V(SF_ALBUMRELOAD) V(SF_ALBUMEND) V(SF_ALBUMCHA1) diff --git a/src/vm/inst_sound.cpp b/src/vm/inst_sound.cpp index a3435ab6..5526920d 100644 --- a/src/vm/inst_sound.cpp +++ b/src/vm/inst_sound.cpp @@ -115,10 +115,8 @@ VmInstruction(InstVoiceStop) { VmInstruction(InstVoiceStopNew) { StartInstruction; PopUint8(channel); - PopExpression(arg1); - ImpLogSlow(LL_Warning, LC_VMStub, - "STUB instruction VoiceStopNew(channel: %i, arg1: %i)\n", channel, - arg1); + PopExpression(fade); + Audio::Channels[Audio::AC_VOICE0 + channel]->Stop(fade); } VmInstruction(InstVoicePlayWait) { StartInstruction; @@ -158,6 +156,12 @@ VmInstruction(InstBGMduelPlay) { VmInstruction(InstSNDpause) { StartInstruction; PopUint8(paused); + + for (int i = 0; i < 6; i++) { + (paused) ? Audio::Channels[Audio::AC_SE0 + i]->Pause() + : Audio::Channels[Audio::AC_SE0 + i]->Resume(); + } + ImpLogSlow(LL_Warning, LC_VMStub, "STUB instruction SNDpause(paused: %i)\n", paused); } diff --git a/src/vm/inst_system.cpp b/src/vm/inst_system.cpp index 70c20640..b0642a91 100644 --- a/src/vm/inst_system.cpp +++ b/src/vm/inst_system.cpp @@ -597,7 +597,7 @@ VmInstruction(InstMSinit) { } if (initType == 0 || initType == 1) { - ScrWork[2113] = 0; + ScrWork[SW_GAMESTATE] = 0; for (int i = 0; i < DialoguePageCount; i++) { DialoguePages[i].Clear(); DialoguePages[i].FadeAnimation.Progress = 0;