Skip to content

Commit

Permalink
Fix another specific Practice Mode seek sync problem
Browse files Browse the repository at this point in the history
when seeking forward after pausing and unpausing immediately you get offsync again
just force a resync in this kind of situation
  • Loading branch information
poco0317 committed Nov 5, 2019
1 parent b8ae11a commit 0a60b59
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 25 additions & 2 deletions src/Etterna/Screen/Gameplay/ScreenGameplayPractice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -310,6 +323,15 @@ class LunaScreenGameplayPractice : public Luna<ScreenGameplayPractice>
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);
Expand All @@ -326,6 +348,7 @@ class LunaScreenGameplayPractice : public Luna<ScreenGameplayPractice>
LunaScreenGameplayPractice()
{
ADD_METHOD(SetSongPosition);
ADD_METHOD(SetSongPositionAndUnpause);
ADD_METHOD(AddToRate);
ADD_METHOD(TogglePause);
}
Expand Down
3 changes: 2 additions & 1 deletion src/Etterna/Screen/Gameplay/ScreenGameplayPractice.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 0a60b59

Please sign in to comment.