From 0a60b59029510b877eab273af30ad0054c6c31c7 Mon Sep 17 00:00:00 2001 From: Barinade Date: Mon, 4 Nov 2019 21:51:29 -0600 Subject: [PATCH] Fix another specific Practice Mode seek sync problem when seeking forward after pausing and unpausing immediately you get offsync again just force a resync in this kind of situation --- .../WifeJudgmentSpotting.lua | 2 +- .../Gameplay/ScreenGameplayPractice.cpp | 27 +++++++++++++++++-- .../Screen/Gameplay/ScreenGameplayPractice.h | 3 ++- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/Themes/Til Death/BGAnimations/ScreenGameplay overlay/WifeJudgmentSpotting.lua b/Themes/Til Death/BGAnimations/ScreenGameplay overlay/WifeJudgmentSpotting.lua index 37416e0465..a41fc0ec12 100644 --- a/Themes/Til Death/BGAnimations/ScreenGameplay overlay/WifeJudgmentSpotting.lua +++ b/Themes/Til Death/BGAnimations/ScreenGameplay overlay/WifeJudgmentSpotting.lua @@ -951,7 +951,7 @@ local function duminput(event) elseif event.type == "InputEventType_FirstPress" then if event.DeviceInput.button == "DeviceButton_backspace" then if bookmarkPosition ~= nil then - SCREENMAN:GetTopScreen():SetSongPosition(bookmarkPosition, 1, false) + SCREENMAN:GetTopScreen():SetSongPositionAndUnpause(bookmarkPosition, 1, true) if GAMESTATE:IsPaused() then SCREENMAN:GetTopScreen():TogglePause() end diff --git a/src/Etterna/Screen/Gameplay/ScreenGameplayPractice.cpp b/src/Etterna/Screen/Gameplay/ScreenGameplayPractice.cpp index becffe1d4d..f34f9b03ab 100644 --- a/src/Etterna/Screen/Gameplay/ScreenGameplayPractice.cpp +++ b/src/Etterna/Screen/Gameplay/ScreenGameplayPractice.cpp @@ -215,18 +215,31 @@ ScreenGameplayPractice::TogglePause() void ScreenGameplayPractice::SetSongPosition(float newSongPositionSeconds, float noteDelay, - bool hardSeek) + bool hardSeek, + bool unpause) { bool isPaused = GAMESTATE->GetPaused(); RageSoundParams p = m_pSoundMusic->GetParams(); + + // If paused, we need to move fast so dont use slow seeking + // but if we want to hard seek, we dont care about speed p.m_bAccurateSync = !isPaused || hardSeek; m_pSoundMusic->SetParams(p); + // realign mp3 files by seeking backwards to force a full reseek, then + // seeking forward to finish the job + if (hardSeek && + newSongPositionSeconds > GAMESTATE->m_Position.m_fMusicSeconds) + SOUND->SetSoundPosition(m_pSoundMusic, + GAMESTATE->m_Position.m_fMusicSeconds - 0.01f); + + // Set the final position SOUND->SetSoundPosition(m_pSoundMusic, newSongPositionSeconds - noteDelay); UpdateSongPosition(0); - m_pSoundMusic->Pause(isPaused); + if (unpause && isPaused) + m_pSoundMusic->Pause(false); Steps* pSteps = GAMESTATE->m_pCurSteps; TimingData* pTiming = pSteps->GetTimingData(); @@ -310,6 +323,15 @@ class LunaScreenGameplayPractice : public Luna return 0; } + static int SetSongPositionAndUnpause(T* p, lua_State* L) + { + float position = FArg(1); + float delay = FArg(2); + bool hardseek = BArg(3); + p->SetSongPosition(position, delay, hardseek, true); + return 0; + } + static int AddToRate(T* p, lua_State* L) { float rate = FArg(1); @@ -326,6 +348,7 @@ class LunaScreenGameplayPractice : public Luna LunaScreenGameplayPractice() { ADD_METHOD(SetSongPosition); + ADD_METHOD(SetSongPositionAndUnpause); ADD_METHOD(AddToRate); ADD_METHOD(TogglePause); } diff --git a/src/Etterna/Screen/Gameplay/ScreenGameplayPractice.h b/src/Etterna/Screen/Gameplay/ScreenGameplayPractice.h index 96a3d044b9..6bbcde3337 100644 --- a/src/Etterna/Screen/Gameplay/ScreenGameplayPractice.h +++ b/src/Etterna/Screen/Gameplay/ScreenGameplayPractice.h @@ -30,7 +30,8 @@ class ScreenGameplayPractice : public ScreenGameplay // Move the current position of the song in the middle of gameplay void SetSongPosition(float newSongPositionSeconds, float noteDelay = 0.f, - bool hardSeek = false); + bool hardSeek = false, + bool unpause = false); // Toggle pause void TogglePause();