Skip to content

Commit

Permalink
Don't use slow lrintf function for getting BeatToNoteRow, and comment…
Browse files Browse the repository at this point in the history
… that the supposedly accurate version actually rounds up.
  • Loading branch information
xwidghet committed Aug 24, 2016
1 parent fa53caf commit eed2f6e
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/AutoKeysounds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ void AutoKeysounds::Update( float fDelta )
float fPositionSeconds = GAMESTATE->m_fMusicSeconds;
float fSongBeat = GAMESTATE->m_pCurSong->GetBeatFromElapsedTime( fPositionSeconds );
int iRowNow = BeatToNoteRowNotRounded( fSongBeat );
int iRowNow = BeatToNoteRow( fSongBeat );
iRowNow = max( 0, iRowNow );
static int iRowLastCrossed = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/BeginnerHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ void BeginnerHelper::Update( float fDeltaTime )
return;

// the row we want to check on this update
int iCurRow = BeatToNoteRowNotRounded( GAMESTATE->m_Position.m_fSongBeat + 0.4f );
int iCurRow = BeatToNoteRow( GAMESTATE->m_Position.m_fSongBeat + 0.4f );
FOREACH_EnabledPlayer( pn )
{
for( int iRow=m_iLastRowChecked; iRow<iCurRow; iRow++ )
Expand Down
4 changes: 2 additions & 2 deletions src/GameSoundManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ void GameSoundManager::Update( float fDeltaTime )

float fSongBeat = GAMESTATE->m_Position.m_fSongBeat;

int iRowNow = BeatToNoteRowNotRounded( fSongBeat );
int iRowNow = BeatToNoteRow( fSongBeat );
iRowNow = max( 0, iRowNow );

int iBeatNow = iRowNow / ROWS_PER_BEAT;
Expand All @@ -633,7 +633,7 @@ void GameSoundManager::Update( float fDeltaTime )
if( lights.GetNumTracks() > 0 ) // lights data was loaded
{
const float fSongBeat = GAMESTATE->m_Position.m_fLightSongBeat;
const int iSongRow = BeatToNoteRowNotRounded( fSongBeat );
const int iSongRow = BeatToNoteRow( fSongBeat );

static int iRowLastCrossed = 0;

Expand Down
2 changes: 1 addition & 1 deletion src/GameplayAssist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void GameplayAssist::PlayTicks( const NoteData &nd, const PlayerState *ps )
const TimingData &timing = *GAMESTATE->m_pCurSteps[ps->m_PlayerNumber]->GetTimingData();
const float fSongBeat = timing.GetBeatFromElapsedTimeNoOffset( fPositionSeconds );

const int iSongRow = max( 0, BeatToNoteRowNotRounded( fSongBeat ) );
const int iSongRow = max( 0, BeatToNoteRow( fSongBeat ) );
static int iRowLastCrossed = -1;
if( iSongRow < iRowLastCrossed )
iRowLastCrossed = iSongRow;
Expand Down
13 changes: 5 additions & 8 deletions src/NoteTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,25 +273,22 @@ bool IsNoteOfType( int row, NoteType t );

/* This is more accurate: by computing the integer and fractional parts separately, we
* can avoid storing very large numbers in a float and possibly losing precision. It's
* slower; use this once less stuff uses BeatToNoteRow. */
/*
* slower; use this once less stuff uses BeatToNoteRow.
*
* This function rounds up.
inline int BeatToNoteRow( float fBeatNum )
{
float fraction = fBeatNum - truncf(fBeatNum);
int integer = int(fBeatNum) * ROWS_PER_BEAT;
return integer + lrintf(fraction * ROWS_PER_BEAT);
}
*/

/**
* @brief Convert the beat into a note row.
* @param fBeatNum the beat to convert.
* @return the note row. */
inline int BeatToNoteRow( float fBeatNum ) { return lrintf( fBeatNum * ROWS_PER_BEAT ); } // round
/**
* @brief Convert the beat into a note row without rounding.
* @param fBeatNum the beat to convert.
* @return the note row. */
inline int BeatToNoteRowNotRounded( float fBeatNum ) { return (int)( fBeatNum * ROWS_PER_BEAT ); }
inline int BeatToNoteRow( float fBeatNum ) { return (int)( fBeatNum * ROWS_PER_BEAT ); }
/**
* @brief Convert the note row to a beat.
* @param iRow the row to convert.
Expand Down
8 changes: 2 additions & 6 deletions src/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ void Player::Load()

m_LastTapNoteScore = TNS_None;
// The editor can start playing in the middle of the song.
const int iNoteRow = BeatToNoteRowNotRounded( m_pPlayerState->m_Position.m_fSongBeat );
const int iNoteRow = BeatToNoteRow( m_pPlayerState->m_Position.m_fSongBeat );
m_iFirstUncrossedRow = iNoteRow - 1;
m_pJudgedRows->Reset( iNoteRow );

Expand Down Expand Up @@ -1050,11 +1050,7 @@ void Player::Update( float fDeltaTime )
}

{
// Why was this originally "BeatToNoteRowNotRounded"? It should be rounded. -Chris
/* We want to send the crossed row message exactly when we cross the row--not
* .5 before the row. Use a very slow song (around 2 BPM) as a test case: without
* rounding, autoplay steps early. -glenn */
const int iRowNow = BeatToNoteRowNotRounded( m_pPlayerState->m_Position.m_fSongBeat );
const int iRowNow = BeatToNoteRow( m_pPlayerState->m_Position.m_fSongBeat );
if( iRowNow >= 0 )
{
if( GAMESTATE->IsPlayerEnabled(m_pPlayerState) )
Expand Down
6 changes: 3 additions & 3 deletions src/ScreenGameplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2187,7 +2187,7 @@ void ScreenGameplay::UpdateLights()
ZERO( bBlinkGameButton );
{
const float fSongBeat = GAMESTATE->m_Position.m_fLightSongBeat;
const int iSongRow = BeatToNoteRowNotRounded( fSongBeat );
const int iSongRow = BeatToNoteRow( fSongBeat );

static int iRowLastCrossed = 0;

Expand Down Expand Up @@ -2270,7 +2270,7 @@ void ScreenGameplay::SendCrossedMessages()
float fPositionSeconds = GAMESTATE->m_Position.m_fMusicSeconds;
float fSongBeat = GAMESTATE->m_pCurSong->m_SongTiming.GetBeatFromElapsedTime( fPositionSeconds );

int iRowNow = BeatToNoteRowNotRounded( fSongBeat );
int iRowNow = BeatToNoteRow( fSongBeat );
iRowNow = max( 0, iRowNow );

for( int r=iRowLastCrossed+1; r<=iRowNow; r++ )
Expand Down Expand Up @@ -2308,7 +2308,7 @@ void ScreenGameplay::SendCrossedMessages()
float fPositionSeconds = GAMESTATE->m_Position.m_fMusicSeconds + fNoteWillCrossInSeconds;
float fSongBeat = GAMESTATE->m_pCurSong->m_SongTiming.GetBeatFromElapsedTime( fPositionSeconds );

int iRowNow = BeatToNoteRowNotRounded( fSongBeat );
int iRowNow = BeatToNoteRow( fSongBeat );
iRowNow = max( 0, iRowNow );
int &iRowLastCrossed = iRowLastCrossedAll[i];

Expand Down
4 changes: 2 additions & 2 deletions src/ScreenHowToPlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ void ScreenHowToPlay::Step()
#define ST_JUMPUD (ST_UP | ST_DOWN)

int iStep = 0;
const int iNoteRow = BeatToNoteRowNotRounded( GAMESTATE->m_Position.m_fSongBeat + 0.6f );
const int iNoteRow = BeatToNoteRow( GAMESTATE->m_Position.m_fSongBeat + 0.6f );
// if we want to miss from here on out, don't process steps.
if( m_iW2s < m_iNumW2s && m_NoteData.IsThereATapAtRow( iNoteRow ) )
{
Expand Down Expand Up @@ -251,7 +251,7 @@ void ScreenHowToPlay::Update( float fDelta )
m_fFakeSecondsIntoSong += fDelta;

static int iLastNoteRowCounted = 0;
int iCurNoteRow = BeatToNoteRowNotRounded( GAMESTATE->m_Position.m_fSongBeat );
int iCurNoteRow = BeatToNoteRow( GAMESTATE->m_Position.m_fSongBeat );

if( iCurNoteRow != iLastNoteRowCounted &&m_NoteData.IsThereATapAtRow(iCurNoteRow) )
{
Expand Down
8 changes: 4 additions & 4 deletions src/TimingData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -778,9 +778,9 @@ void FindEvent(int& event_row, int& event_type,
const vector<TimingSegment*>& bpms, const vector<TimingSegment*>& warps,
const vector<TimingSegment*>& stops, const vector<TimingSegment*>& delays)
{
if(start.is_warping && BeatToNoteRowNotRounded(start.warp_destination) < event_row)
if(start.is_warping && BeatToNoteRow(start.warp_destination) < event_row)
{
event_row= BeatToNoteRowNotRounded(start.warp_destination);
event_row= BeatToNoteRow(start.warp_destination);
event_type= FOUND_WARP_DESTINATION;
}
if(start.bpm < bpms.size() && bpms[start.bpm]->GetRow() < event_row)
Expand All @@ -793,9 +793,9 @@ void FindEvent(int& event_row, int& event_type,
event_row= delays[start.delay]->GetRow();
event_type= FOUND_DELAY;
}
if(find_marker && BeatToNoteRowNotRounded(beat) < event_row)
if(find_marker && BeatToNoteRow(beat) < event_row)
{
event_row= BeatToNoteRowNotRounded(beat);
event_row= BeatToNoteRow(beat);
event_type= FOUND_MARKER;
}
if(start.stop < stops.size() && stops[start.stop]->GetRow() < event_row)
Expand Down

0 comments on commit eed2f6e

Please sign in to comment.