Skip to content

Commit

Permalink
Fix pausing when entering system menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Dextinfire committed Sep 28, 2024
1 parent 925de0b commit b9a5e89
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 13 deletions.
4 changes: 4 additions & 0 deletions profiles/common/scriptvars.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 7 additions & 1 deletion src/audio/audiochannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; };
Expand All @@ -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;
};

Expand Down
1 change: 1 addition & 0 deletions src/audio/audiocommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ enum AudioChannelId {
enum AudioChannelState {
ACS_Stopped,
ACS_Playing,
ACS_Paused,
ACS_FadingIn,
ACS_FadingOut
};
Expand Down
15 changes: 15 additions & 0 deletions src/audio/openal/audiochannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions src/audio/openal/audiochannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
20 changes: 13 additions & 7 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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) &&
Expand Down
4 changes: 4 additions & 0 deletions src/scriptvars.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 8 additions & 4 deletions src/vm/inst_sound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/vm/inst_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit b9a5e89

Please sign in to comment.