diff --git a/src/Attack.cpp b/src/Attack.cpp index 7062b303cf..01021035c4 100644 --- a/src/Attack.cpp +++ b/src/Attack.cpp @@ -37,7 +37,7 @@ void Attack::GetRealtimeAttackBeats( const Song *pSong, const PlayerState* pPlay fStartBeat = truncf(fStartBeat)+1; const TimingData &timing = pSong->m_SongTiming; - const float lStartSecond = timing.GetElapsedTimeFromBeat( fStartBeat ); + const float lStartSecond = timing.WhereUAtBro( fStartBeat ); const float fEndSecond = lStartSecond + fSecsRemaining; fEndBeat = timing.GetBeatFromElapsedTime( fEndSecond ); fEndBeat = truncf(fEndBeat)+1; diff --git a/src/AutoKeysounds.cpp b/src/AutoKeysounds.cpp index a8a0871b8a..2b6ef3a0e1 100644 --- a/src/AutoKeysounds.cpp +++ b/src/AutoKeysounds.cpp @@ -87,7 +87,7 @@ void AutoKeysounds::LoadAutoplaySoundsInto( RageSoundReader_Chain *pChain ) if( tn[pn].iKeysoundIndex >= 0 ) { RString sKeysoundFilePath = sSongDir + pSong->m_vsKeysoundFile[tn[pn].iKeysoundIndex]; - float fSeconds = GAMESTATE->m_pCurSteps[pn]->GetTimingData()->GetElapsedTimeFromBeatNoOffset( NoteRowToBeat(iRow) ) + SOUNDMAN->GetPlayLatency(); + float fSeconds = GAMESTATE->m_pCurSteps[pn]->GetTimingData()->WhereUAtBroNoOffset( NoteRowToBeat(iRow) ) + SOUNDMAN->GetPlayLatency(); float fPan = 0; // If two players are playing, pan the keysounds to each player's respective side diff --git a/src/Background.cpp b/src/Background.cpp index 2585507947..cda28962c0 100644 --- a/src/Background.cpp +++ b/src/Background.cpp @@ -798,7 +798,7 @@ void BackgroundImpl::Layer::UpdateCurBGChange( const Song *pSong, float fLastMus m_pCurrentBGA->PlayCommand( "GainFocus" ); /* How much time of this BGA have we skipped? (This happens with SetSeconds.) */ - const float fStartSecond = pSong->m_SongTiming.GetElapsedTimeFromBeat( change.m_fStartBeat ); + const float fStartSecond = pSong->m_SongTiming.WhereUAtBro( change.m_fStartBeat ); /* This is affected by the music rate. */ fDeltaTime = fCurrentTime - fStartSecond; diff --git a/src/Foreground.cpp b/src/Foreground.cpp index 4654d72e2c..807565ff99 100644 --- a/src/Foreground.cpp +++ b/src/Foreground.cpp @@ -101,7 +101,7 @@ void Foreground::Update( float fDeltaTime ) bga.m_bga->SetVisible( true ); bga.m_bga->PlayCommand( "On" ); - const float fStartSecond = m_pSong->m_SongTiming.GetElapsedTimeFromBeat( bga.m_fStartBeat ); + const float fStartSecond = m_pSong->m_SongTiming.WhereUAtBro( bga.m_fStartBeat ); const float fStopSecond = fStartSecond + bga.m_bga->GetTweenTimeLeft(); bga.m_fStopBeat = m_pSong->m_SongTiming.GetBeatFromElapsedTime( fStopSecond ); diff --git a/src/GameSoundManager.cpp b/src/GameSoundManager.cpp index a0a0feb8db..83269ad2b8 100644 --- a/src/GameSoundManager.cpp +++ b/src/GameSoundManager.cpp @@ -179,9 +179,9 @@ static void StartMusic( MusicToPlay &ToPlay ) /* Extend the loop period so it always starts and ends on the same fractional * beat. That is, if it starts on beat 1.5, and ends on beat 10.2, extend it * to end on beat 10.5. This way, effects always loop cleanly. */ - float fStartBeat = NewMusic->m_NewTiming.GetBeatFromElapsedTimeNoOffset( ToPlay.fStartSecond ); + float fStartBeat = NewMusic->m_NewTiming.WhereUAtBroNoOffset( ToPlay.fStartSecond ); float fEndSec = ToPlay.fStartSecond + ToPlay.fLengthSeconds; - float fEndBeat = NewMusic->m_NewTiming.GetBeatFromElapsedTimeNoOffset( fEndSec ); + float fEndBeat = NewMusic->m_NewTiming.WhereUAtBroNoOffset( fEndSec ); const float fStartBeatFraction = fmodfp( fStartBeat, 1 ); const float fEndBeatFraction = fmodfp( fEndBeat, 1 ); @@ -192,7 +192,7 @@ static void StartMusic( MusicToPlay &ToPlay ) fEndBeat += fBeatDifference; - const float fRealEndSec = NewMusic->m_NewTiming.GetElapsedTimeFromBeatNoOffset( fEndBeat ); + const float fRealEndSec = NewMusic->m_NewTiming.WhereUAtBroNoOffset( fEndBeat ); const float fNewLengthSec = fRealEndSec - ToPlay.fStartSecond; /* Extend fFadeOutLengthSeconds, so the added time is faded out. */ @@ -238,7 +238,7 @@ static void StartMusic( MusicToPlay &ToPlay ) if( fCurBeatToStartOn < fCurBeat ) fCurBeatToStartOn += 1.0f; - const float fSecondToStartOn = g_Playing->m_Timing.GetElapsedTimeFromBeatNoOffset( fCurBeatToStartOn ); + const float fSecondToStartOn = g_Playing->m_Timing.WhereUAtBroNoOffset( fCurBeatToStartOn ); const float fMaximumDistance = 2; const float fDistance = min( fSecondToStartOn - GAMESTATE->m_Position.m_fMusicSeconds, fMaximumDistance ); diff --git a/src/GameState.cpp b/src/GameState.cpp index 3910090637..4788be2348 100644 --- a/src/GameState.cpp +++ b/src/GameState.cpp @@ -1289,7 +1289,7 @@ update player position code goes here float GameState::GetSongPercent( float beat ) const { // 0 = first step; 1 = last step - float curTime = this->m_pCurSong->m_SongTiming.GetElapsedTimeFromBeat(beat); + float curTime = this->m_pCurSong->m_SongTiming.WhereUAtBro(beat); return (curTime - m_pCurSong->GetFirstSecond()) / m_pCurSong->GetLastSecond(); } diff --git a/src/GameplayAssist.cpp b/src/GameplayAssist.cpp index 588a6067e7..c7926db9ff 100644 --- a/src/GameplayAssist.cpp +++ b/src/GameplayAssist.cpp @@ -53,7 +53,7 @@ void GameplayAssist::PlayTicks( const NoteData &nd, const PlayerState *ps ) if( iClapRow != -1 && timing.IsJudgableAtRow(iClapRow)) { const float fTickBeat = NoteRowToBeat( iClapRow ); - const float fTickSecond = timing.GetElapsedTimeFromBeatNoOffset( fTickBeat ); + const float fTickSecond = timing.WhereUAtBroNoOffset( fTickBeat ); float fSecondsUntil = fTickSecond - position.m_fMusicSeconds; fSecondsUntil /= GAMESTATE->m_SongOptions.GetCurrent().m_fMusicRate; /* 2x music rate means the time until the tick is halved */ @@ -89,7 +89,7 @@ void GameplayAssist::PlayTicks( const NoteData &nd, const PlayerState *ps ) if( iMetronomeRow != -1 ) { const float fTickBeat = NoteRowToBeat( iMetronomeRow ); - const float fTickSecond = timing.GetElapsedTimeFromBeatNoOffset( fTickBeat ); + const float fTickSecond = timing.WhereUAtBroNoOffset( fTickBeat ); float fSecondsUntil = fTickSecond - position.m_fMusicSeconds; fSecondsUntil /= GAMESTATE->m_SongOptions.GetCurrent().m_fMusicRate; /* 2x music rate means the time until the tick is halved */ diff --git a/src/Song.cpp b/src/Song.cpp index 113202e0a5..d235a74ecd 100644 --- a/src/Song.cpp +++ b/src/Song.cpp @@ -779,14 +779,14 @@ void Song::TidyUpData( bool from_cache, bool /* duringCache */ ) m_fMusicSampleStartSeconds+m_fMusicSampleLengthSeconds > this->m_fMusicLengthSeconds) { const TimingData &timing = this->m_SongTiming; - m_fMusicSampleStartSeconds = timing.GetElapsedTimeFromBeat(100); + m_fMusicSampleStartSeconds = timing.WhereUAtBro(100); if(m_fMusicSampleStartSeconds+m_fMusicSampleLengthSeconds > this->m_fMusicLengthSeconds) { // Attempt to get a reasonable default. int iBeat = lround(this->m_SongTiming.GetBeatFromElapsedTime(this->GetLastSecond())/2); iBeat -= iBeat%4; - m_fMusicSampleStartSeconds = timing.GetElapsedTimeFromBeat((float)iBeat); + m_fMusicSampleStartSeconds = timing.WhereUAtBro((float)iBeat); } } @@ -1102,9 +1102,9 @@ void Song::ReCalculateRadarValuesAndLastSecond(bool fromCache, bool duringCache) if( tempNoteData.GetLastRow() != 0 ) { localFirst = min(localFirst, - pSteps->GetTimingData()->GetElapsedTimeFromBeat(tempNoteData.GetFirstBeat())); + pSteps->GetTimingData()->WhereUAtBro(tempNoteData.GetFirstBeat())); localLast = max(localLast, - pSteps->GetTimingData()->GetElapsedTimeFromBeat(tempNoteData.GetLastBeat())); + pSteps->GetTimingData()->WhereUAtBro(tempNoteData.GetLastBeat())); } } diff --git a/src/TimingData.cpp b/src/TimingData.cpp index 473dd0da57..e4fb180787 100644 --- a/src/TimingData.cpp +++ b/src/TimingData.cpp @@ -1169,7 +1169,7 @@ float TimingData::GetDisplayedSpeedPercent( float fSongBeat, float fMusicSeconds const SpeedSegment *seg = ToSpeed(speeds[index]); float fStartBeat = seg->GetBeat(); - float fStartTime = GetElapsedTimeFromBeat( fStartBeat ) - GetDelayAtBeat( fStartBeat ); + float fStartTime = WhereUAtBro( fStartBeat ) - GetDelayAtBeat( fStartBeat ); float fEndTime; float fCurTime = fMusicSeconds; @@ -1179,7 +1179,7 @@ float TimingData::GetDisplayedSpeedPercent( float fSongBeat, float fMusicSeconds } else { - fEndTime = GetElapsedTimeFromBeat( fStartBeat + seg->GetDelay() ) + fEndTime = WhereUAtBro( fStartBeat + seg->GetDelay() ) - GetDelayAtBeat( fStartBeat + seg->GetDelay() ); } @@ -1392,6 +1392,26 @@ float TimingData::WhereUAtBro(int row) { return GetElapsedTimeFromBeat(NoteRowToBeat(row)); } +float TimingData::WhereUAtBroNoOffset(float beat) { + if (beat < 0) return 0; + size_t row = BeatToNoteRow(beat); + + if (ValidSequentialAssumption && row < ElapsedTimesAtAllRows.size()) + return ElapsedTimesAtAllRows[row]; + + return GetElapsedTimeFromBeatNoOffset(beat); +} + +float TimingData::WhereUAtBroNoOffset(float beat) const { + if (beat < 0) return 0; + size_t row = BeatToNoteRow(beat); + + if (ValidSequentialAssumption && row < ElapsedTimesAtAllRows.size()) + return ElapsedTimesAtAllRows[row]; + + return GetElapsedTimeFromBeatNoOffset(beat); +} + /** @brief Allow Lua to have access to the TimingData. */ class LunaTimingData: public Luna { diff --git a/src/TimingData.h b/src/TimingData.h index 105981d1bf..4c35f33a98 100644 --- a/src/TimingData.h +++ b/src/TimingData.h @@ -475,6 +475,8 @@ class TimingData float WhereUAtBro(float beat) const; float WhereUAtBro(float beat); + float WhereUAtBroNoOffset(float beat) const; + float WhereUAtBroNoOffset(float beat); float WhereUAtBro(int row); bool ValidSequentialAssumption = true;