Skip to content

Commit

Permalink
Replace a bunch of GetElapsedTimeFromBeat calls with our vector lookup.
Browse files Browse the repository at this point in the history
  • Loading branch information
xwidghet committed Nov 19, 2016
1 parent 89eda0d commit de1ebe0
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/Attack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/AutoKeysounds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Background.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Foreground.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down
8 changes: 4 additions & 4 deletions src/GameSoundManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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. */
Expand Down Expand Up @@ -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 );

Expand Down
2 changes: 1 addition & 1 deletion src/GameState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
4 changes: 2 additions & 2 deletions src/GameplayAssist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down Expand Up @@ -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 */

Expand Down
8 changes: 4 additions & 4 deletions src/Song.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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()));
}
}

Expand Down
24 changes: 22 additions & 2 deletions src/TimingData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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() );
}

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

0 comments on commit de1ebe0

Please sign in to comment.