Optimize:
ReserveRows, like vector::reserve GetTapNoteX, non-bounds-checking GetTapNote Don't put these large functions in the header; they're probably too big to inline anyway
This commit is contained in:
+134
-14
@@ -127,6 +127,101 @@ void NoteData::CopyAll( const NoteData* pFrom )
|
|||||||
m_AttackMap = pFrom->m_AttackMap;
|
m_AttackMap = pFrom->m_AttackMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool NoteData::IsRowEmpty( int index ) const
|
||||||
|
{
|
||||||
|
/* If this is out of range, we don't have any notes there, so all tracks are empty. */
|
||||||
|
if( index < 0 || index >= GetMaxRow() )
|
||||||
|
return true;
|
||||||
|
|
||||||
|
for( int t=0; t<m_iNumTracks; t++ )
|
||||||
|
if( GetTapNoteX(t, index) != TAP_EMPTY )
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int NoteData::GetNumTapNonEmptyTracks( int index ) const
|
||||||
|
{
|
||||||
|
int iNum = 0;
|
||||||
|
for( int t=0; t<m_iNumTracks; t++ )
|
||||||
|
if( GetTapNote(t, index) != TAP_EMPTY )
|
||||||
|
iNum++;
|
||||||
|
return iNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
int NoteData::GetFirstNonEmptyTrack( int index ) const
|
||||||
|
{
|
||||||
|
/* If this is out of range, we don't have any notes there, so all tracks are empty. */
|
||||||
|
if( index < 0 || index >= GetMaxRow() )
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
for( int t=0; t<m_iNumTracks; t++ )
|
||||||
|
if( GetTapNoteX( t, index ) != TAP_EMPTY )
|
||||||
|
return t;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int NoteData::GetNumTracksWithTap( int index ) const
|
||||||
|
{
|
||||||
|
/* If this is out of range, we don't have any notes there, so all tracks are empty. */
|
||||||
|
if( index < 0 || index >= GetMaxRow() )
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
int iNum = 0;
|
||||||
|
for( int t=0; t<m_iNumTracks; t++ )
|
||||||
|
{
|
||||||
|
TapNote tn = GetTapNoteX( t, index );
|
||||||
|
if( tn == TAP_TAP )
|
||||||
|
iNum++;
|
||||||
|
}
|
||||||
|
return iNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
int NoteData::GetNumTracksWithTapOrHoldHead( int index ) const
|
||||||
|
{
|
||||||
|
/* If this is out of range, we don't have any notes there, so all tracks are empty. */
|
||||||
|
if( index < 0 || index >= GetMaxRow() )
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
int iNum = 0;
|
||||||
|
for( int t=0; t<m_iNumTracks; t++ )
|
||||||
|
{
|
||||||
|
TapNote tn = GetTapNoteX( t, index );
|
||||||
|
if( tn == TAP_TAP || tn == TAP_ADDITION || tn == TAP_HOLD_HEAD )
|
||||||
|
iNum++;
|
||||||
|
}
|
||||||
|
return iNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
int NoteData::GetFirstTrackWithTap( int index ) const
|
||||||
|
{
|
||||||
|
/* If this is out of range, we don't have any notes there, so all tracks are empty. */
|
||||||
|
if( index < 0 || index >= GetMaxRow() )
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
for( int t=0; t<m_iNumTracks; t++ )
|
||||||
|
{
|
||||||
|
TapNote tn = GetTapNoteX( t, index );
|
||||||
|
if( tn == TAP_TAP || tn == TAP_ADDITION )
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int NoteData::GetFirstTrackWithTapOrHoldHead( int index ) const
|
||||||
|
{
|
||||||
|
/* If this is out of range, we don't have any notes there, so all tracks are empty. */
|
||||||
|
if( index < 0 || index >= GetMaxRow() )
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
for( int t=0; t<m_iNumTracks; t++ )
|
||||||
|
{
|
||||||
|
TapNote tn = GetTapNoteX( t, index );
|
||||||
|
if( tn == TAP_TAP || tn == TAP_ADDITION || tn == TAP_HOLD_HEAD )
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
void NoteData::AddHoldNote( HoldNote add )
|
void NoteData::AddHoldNote( HoldNote add )
|
||||||
{
|
{
|
||||||
ASSERT( add.fStartBeat>=0 && add.fEndBeat>=0 );
|
ASSERT( add.fStartBeat>=0 && add.fEndBeat>=0 );
|
||||||
@@ -313,15 +408,22 @@ int NoteData::GetNumTapNotes( float fStartBeat, float fEndBeat ) const
|
|||||||
{
|
{
|
||||||
int iNumNotes = 0;
|
int iNumNotes = 0;
|
||||||
|
|
||||||
if(fEndBeat == -1) fEndBeat = GetMaxBeat();
|
if( fEndBeat == -1 )
|
||||||
|
fEndBeat = GetMaxBeat();
|
||||||
|
|
||||||
int iStartIndex = BeatToNoteRow( fStartBeat );
|
int iStartIndex = BeatToNoteRow( fStartBeat );
|
||||||
int iEndIndex = BeatToNoteRow( fEndBeat );
|
int iEndIndex = BeatToNoteRow( fEndBeat );
|
||||||
|
|
||||||
|
/* Clamp to known-good ranges. */
|
||||||
|
iStartIndex = clamp( iStartIndex, 0, GetMaxRow()-1 );
|
||||||
|
iEndIndex = clamp( iEndIndex, 0, GetMaxRow()-1 );
|
||||||
|
|
||||||
for( int t=0; t<m_iNumTracks; t++ )
|
for( int t=0; t<m_iNumTracks; t++ )
|
||||||
{
|
{
|
||||||
for( int i=iStartIndex; i<=iEndIndex; i++ )
|
for( int i=iStartIndex; i<=iEndIndex; i++ )
|
||||||
{
|
{
|
||||||
if( GetTapNote(t, i) != TAP_EMPTY && GetTapNote(t, i) != TAP_MINE )
|
TapNote tn = GetTapNoteX(t, i);
|
||||||
|
if( tn != TAP_EMPTY && tn != TAP_MINE )
|
||||||
iNumNotes++;
|
iNumNotes++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -348,14 +450,20 @@ int NoteData::GetNumMines( float fStartBeat, float fEndBeat ) const
|
|||||||
{
|
{
|
||||||
int iNumMines = 0;
|
int iNumMines = 0;
|
||||||
|
|
||||||
if(fEndBeat == -1) fEndBeat = GetMaxBeat();
|
if( fEndBeat == -1 )
|
||||||
|
fEndBeat = GetMaxBeat();
|
||||||
|
|
||||||
int iStartIndex = BeatToNoteRow( fStartBeat );
|
int iStartIndex = BeatToNoteRow( fStartBeat );
|
||||||
int iEndIndex = BeatToNoteRow( fEndBeat );
|
int iEndIndex = BeatToNoteRow( fEndBeat );
|
||||||
|
|
||||||
|
/* Clamp to known-good ranges. */
|
||||||
|
iStartIndex = clamp( iStartIndex, 0, GetMaxRow()-1 );
|
||||||
|
iEndIndex = clamp( iEndIndex, 0, GetMaxRow()-1 );
|
||||||
|
|
||||||
for( int t=0; t<m_iNumTracks; t++ )
|
for( int t=0; t<m_iNumTracks; t++ )
|
||||||
{
|
{
|
||||||
for( int i=iStartIndex; i<=iEndIndex; i++ )
|
for( int i=iStartIndex; i<=iEndIndex; i++ )
|
||||||
if( GetTapNote(t, i) == TAP_MINE )
|
if( GetTapNoteX(t, i) == TAP_MINE )
|
||||||
iNumMines++;
|
iNumMines++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -387,8 +495,12 @@ int NoteData::GetNumHands( float fStartBeat, float fEndBeat ) const
|
|||||||
if( fEndBeat == -1 )
|
if( fEndBeat == -1 )
|
||||||
fEndBeat = temp.GetMaxBeat();
|
fEndBeat = temp.GetMaxBeat();
|
||||||
|
|
||||||
const int iStartIndex = BeatToNoteRow( fStartBeat );
|
int iStartIndex = BeatToNoteRow( fStartBeat );
|
||||||
const int iEndIndex = BeatToNoteRow( fEndBeat );
|
int iEndIndex = BeatToNoteRow( fEndBeat );
|
||||||
|
|
||||||
|
/* Clamp to known-good ranges. */
|
||||||
|
iStartIndex = clamp( iStartIndex, 0, temp.GetMaxRow()-1 );
|
||||||
|
iEndIndex = clamp( iEndIndex, 0, temp.GetMaxRow()-1 );
|
||||||
|
|
||||||
int iNum = 0;
|
int iNum = 0;
|
||||||
for( int i=iStartIndex; i<=iEndIndex; i++ )
|
for( int i=iStartIndex; i<=iEndIndex; i++ )
|
||||||
@@ -396,9 +508,8 @@ int NoteData::GetNumHands( float fStartBeat, float fEndBeat ) const
|
|||||||
int iNumNotesThisIndex = 0;
|
int iNumNotesThisIndex = 0;
|
||||||
for( int t=0; t<m_iNumTracks; t++ )
|
for( int t=0; t<m_iNumTracks; t++ )
|
||||||
{
|
{
|
||||||
if( temp.GetTapNote(t, i) == TAP_MINE )
|
TapNote tn = temp.GetTapNoteX(t, i);
|
||||||
continue; // mines don't count
|
if( tn != TAP_MINE && tn != TAP_EMPTY ) // mines don't count
|
||||||
if( temp.GetTapNote(t, i) != TAP_EMPTY )
|
|
||||||
iNumNotesThisIndex++;
|
iNumNotesThisIndex++;
|
||||||
}
|
}
|
||||||
if( iNumNotesThisIndex >= 3 )
|
if( iNumNotesThisIndex >= 3 )
|
||||||
@@ -413,8 +524,12 @@ int NoteData::GetNumN( int MinTaps, float fStartBeat, float fEndBeat ) const
|
|||||||
if( fEndBeat == -1 )
|
if( fEndBeat == -1 )
|
||||||
fEndBeat = GetMaxBeat();
|
fEndBeat = GetMaxBeat();
|
||||||
|
|
||||||
const int iStartIndex = BeatToNoteRow( fStartBeat );
|
int iStartIndex = BeatToNoteRow( fStartBeat );
|
||||||
const int iEndIndex = BeatToNoteRow( fEndBeat );
|
int iEndIndex = BeatToNoteRow( fEndBeat );
|
||||||
|
|
||||||
|
/* Clamp to known-good ranges. */
|
||||||
|
iStartIndex = clamp( iStartIndex, 0, GetMaxRow()-1 );
|
||||||
|
iEndIndex = clamp( iEndIndex, 0, GetMaxRow()-1 );
|
||||||
|
|
||||||
int iNum = 0;
|
int iNum = 0;
|
||||||
for( int i=iStartIndex; i<=iEndIndex; i++ )
|
for( int i=iStartIndex; i<=iEndIndex; i++ )
|
||||||
@@ -422,9 +537,8 @@ int NoteData::GetNumN( int MinTaps, float fStartBeat, float fEndBeat ) const
|
|||||||
int iNumNotesThisIndex = 0;
|
int iNumNotesThisIndex = 0;
|
||||||
for( int t=0; t<m_iNumTracks; t++ )
|
for( int t=0; t<m_iNumTracks; t++ )
|
||||||
{
|
{
|
||||||
if( GetTapNote(t, i) == TAP_MINE )
|
TapNote tn = GetTapNoteX(t, i);
|
||||||
continue; // mines don't count
|
if( tn != TAP_MINE && tn != TAP_EMPTY ) // mines don't count
|
||||||
if( GetTapNote(t, i) != TAP_EMPTY )
|
|
||||||
iNumNotesThisIndex++;
|
iNumNotesThisIndex++;
|
||||||
}
|
}
|
||||||
if( iNumNotesThisIndex >= MinTaps )
|
if( iNumNotesThisIndex >= MinTaps )
|
||||||
@@ -752,6 +866,12 @@ void NoteData::SetTapNote(int track, int row, TapNote t)
|
|||||||
m_TapNotes[track][row]=t;
|
m_TapNotes[track][row]=t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NoteData::ReserveRows( int row )
|
||||||
|
{
|
||||||
|
for(int track = 0; track < m_iNumTracks; ++track)
|
||||||
|
m_TapNotes[track].reserve( row );
|
||||||
|
}
|
||||||
|
|
||||||
void NoteData::EliminateAllButOneTap(int row)
|
void NoteData::EliminateAllButOneTap(int row)
|
||||||
{
|
{
|
||||||
if(row < 0) return;
|
if(row < 0) return;
|
||||||
|
|||||||
+16
-64
@@ -58,6 +58,14 @@ public:
|
|||||||
if(row < 0 || row >= (int) m_TapNotes[track].size()) return TapNote(TAP_EMPTY);
|
if(row < 0 || row >= (int) m_TapNotes[track].size()) return TapNote(TAP_EMPTY);
|
||||||
return m_TapNotes[track][row];
|
return m_TapNotes[track][row];
|
||||||
}
|
}
|
||||||
|
void ReserveRows( int row );
|
||||||
|
|
||||||
|
/* GetTapNote is called a lot. This one doesn't do any bounds checking,
|
||||||
|
* which is much faster. Be sure that 0 <= row < GetMaxRow(). */
|
||||||
|
inline TapNote GetTapNoteX(unsigned track, int row) const
|
||||||
|
{
|
||||||
|
return m_TapNotes[track][row];
|
||||||
|
}
|
||||||
void MoveTapNoteTrack(int dest, int src);
|
void MoveTapNoteTrack(int dest, int src);
|
||||||
void SetTapNote(int track, int row, TapNote t);
|
void SetTapNote(int track, int row, TapNote t);
|
||||||
|
|
||||||
@@ -66,70 +74,14 @@ public:
|
|||||||
void CopyRange( const NoteData* pFrom, int iFromIndexBegin, int iFromIndexEnd, int iToIndexBegin = -1 );
|
void CopyRange( const NoteData* pFrom, int iFromIndexBegin, int iFromIndexEnd, int iToIndexBegin = -1 );
|
||||||
void CopyAll( const NoteData* pFrom );
|
void CopyAll( const NoteData* pFrom );
|
||||||
|
|
||||||
inline bool IsRowEmpty( int index ) const
|
bool IsRowEmpty( int index ) const;
|
||||||
{
|
int GetNumTapNonEmptyTracks( int index ) const;
|
||||||
for( int t=0; t<m_iNumTracks; t++ )
|
int GetFirstNonEmptyTrack( int index ) const;
|
||||||
if( GetTapNote(t, index) != TAP_EMPTY )
|
int GetNumTracksWithTap( int index ) const;
|
||||||
return false;
|
int GetNumTracksWithTapOrHoldHead( int index ) const;
|
||||||
return true;
|
int GetFirstTrackWithTap( int index ) const;
|
||||||
}
|
int GetFirstTrackWithTapOrHoldHead( int index ) const;
|
||||||
inline int GetNumTapNonEmptyTracks( int index ) const
|
|
||||||
{
|
|
||||||
int iNum = 0;
|
|
||||||
for( int t=0; t<m_iNumTracks; t++ )
|
|
||||||
if( GetTapNote(t, index) != TAP_EMPTY )
|
|
||||||
iNum++;
|
|
||||||
return iNum;
|
|
||||||
}
|
|
||||||
inline int GetFirstNonEmptyTrack( int index ) const
|
|
||||||
{
|
|
||||||
for( int t=0; t<m_iNumTracks; t++ )
|
|
||||||
if( GetTapNote(t, index) != TAP_EMPTY )
|
|
||||||
return t;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
inline int GetNumTracksWithTap( int index ) const
|
|
||||||
{
|
|
||||||
int iNum = 0;
|
|
||||||
for( int t=0; t<m_iNumTracks; t++ )
|
|
||||||
{
|
|
||||||
TapNote tn = GetTapNote(t, index);
|
|
||||||
if( tn == TAP_TAP )
|
|
||||||
iNum++;
|
|
||||||
}
|
|
||||||
return iNum;
|
|
||||||
}
|
|
||||||
inline int GetNumTracksWithTapOrHoldHead( int index ) const
|
|
||||||
{
|
|
||||||
int iNum = 0;
|
|
||||||
for( int t=0; t<m_iNumTracks; t++ )
|
|
||||||
{
|
|
||||||
TapNote tn = GetTapNote(t, index);
|
|
||||||
if( tn == TAP_TAP || tn == TAP_ADDITION || tn == TAP_HOLD_HEAD )
|
|
||||||
iNum++;
|
|
||||||
}
|
|
||||||
return iNum;
|
|
||||||
}
|
|
||||||
inline int GetFirstTrackWithTap( int index ) const
|
|
||||||
{
|
|
||||||
for( int t=0; t<m_iNumTracks; t++ )
|
|
||||||
{
|
|
||||||
TapNote tn = GetTapNote(t, index);
|
|
||||||
if( tn == TAP_TAP || tn == TAP_ADDITION )
|
|
||||||
return t;
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
inline int GetFirstTrackWithTapOrHoldHead( int index ) const
|
|
||||||
{
|
|
||||||
for( int t=0; t<m_iNumTracks; t++ )
|
|
||||||
{
|
|
||||||
TapNote tn = GetTapNote(t, index);
|
|
||||||
if( tn == TAP_TAP || tn == TAP_ADDITION || tn == TAP_HOLD_HEAD )
|
|
||||||
return t;
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
inline bool IsThereATapAtRow( int index ) const
|
inline bool IsThereATapAtRow( int index ) const
|
||||||
{
|
{
|
||||||
return GetFirstTrackWithTap( index ) != -1;
|
return GetFirstTrackWithTap( index ) != -1;
|
||||||
|
|||||||
Reference in New Issue
Block a user