rename: MaxRow -> NumRows

fix some off-by-1 row errors
This commit is contained in:
Chris Danford
2004-09-11 03:50:37 +00:00
parent 75a61de900
commit 809dd7dc27
5 changed files with 41 additions and 41 deletions
+21 -21
View File
@@ -127,7 +127,7 @@ void NoteData::CopyAll( const NoteData* pFrom )
bool NoteData::IsRowEmpty( int index ) const 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 this is out of range, we don't have any notes there, so all tracks are empty. */
if( index < 0 || index >= GetMaxRow() ) if( index < 0 || index >= GetNumRows() )
return true; return true;
for( int t=0; t<m_iNumTracks; t++ ) for( int t=0; t<m_iNumTracks; t++ )
@@ -140,8 +140,8 @@ bool NoteData::IsRangeEmpty( int track, int iIndexBegin, int iIndexEnd ) const
{ {
ASSERT( track<m_iNumTracks ); ASSERT( track<m_iNumTracks );
CLAMP( iIndexBegin, 0, GetMaxRow() ); CLAMP( iIndexBegin, 0, GetNumRows()-1 );
CLAMP( iIndexEnd, 0, GetMaxRow() ); CLAMP( iIndexEnd, 0, GetNumRows()-1 );
for( int i=iIndexBegin; i<=iIndexEnd; i++ ) for( int i=iIndexBegin; i<=iIndexEnd; i++ )
if( GetTapNoteX(track,i) != TAP_EMPTY ) if( GetTapNoteX(track,i) != TAP_EMPTY )
@@ -168,7 +168,7 @@ void NoteData::GetTapNonEmptyTracks( int index, set<int>& addTo ) const
int NoteData::GetFirstNonEmptyTrack( int index ) const 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 this is out of range, we don't have any notes there, so all tracks are empty. */
if( index < 0 || index >= GetMaxRow() ) if( index < 0 || index >= GetNumRows() )
return 0; return 0;
for( int t=0; t<m_iNumTracks; t++ ) for( int t=0; t<m_iNumTracks; t++ )
@@ -180,7 +180,7 @@ int NoteData::GetFirstNonEmptyTrack( int index ) const
int NoteData::GetNumTracksWithTap( int index ) const 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 this is out of range, we don't have any notes there, so all tracks are empty. */
if( index < 0 || index >= GetMaxRow() ) if( index < 0 || index >= GetNumRows() )
return 0; return 0;
int iNum = 0; int iNum = 0;
@@ -196,7 +196,7 @@ int NoteData::GetNumTracksWithTap( int index ) const
int NoteData::GetNumTracksWithTapOrHoldHead( int index ) const 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 this is out of range, we don't have any notes there, so all tracks are empty. */
if( index < 0 || index >= GetMaxRow() ) if( index < 0 || index >= GetNumRows() )
return 0; return 0;
int iNum = 0; int iNum = 0;
@@ -212,7 +212,7 @@ int NoteData::GetNumTracksWithTapOrHoldHead( int index ) const
int NoteData::GetFirstTrackWithTap( int index ) const 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 this is out of range, we don't have any notes there, so all tracks are empty. */
if( index < 0 || index >= GetMaxRow() ) if( index < 0 || index >= GetNumRows() )
return -1; return -1;
for( int t=0; t<m_iNumTracks; t++ ) for( int t=0; t<m_iNumTracks; t++ )
@@ -227,7 +227,7 @@ int NoteData::GetFirstTrackWithTap( int index ) const
int NoteData::GetFirstTrackWithTapOrHoldHead( int index ) const 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 this is out of range, we don't have any notes there, so all tracks are empty. */
if( index < 0 || index >= GetMaxRow() ) if( index < 0 || index >= GetNumRows() )
return -1; return -1;
for( int t=0; t<m_iNumTracks; t++ ) for( int t=0; t<m_iNumTracks; t++ )
@@ -328,10 +328,10 @@ void NoteData::PruneUnusedAttacksFromMap()
// Add all used AttackNote values to a map. // Add all used AttackNote values to a map.
map<TapNote,int> mapAttackToNothing; map<TapNote,int> mapAttackToNothing;
int max_row = GetMaxRow(); int num_rows = GetNumRows();
for( int t=0; t<m_iNumTracks; t++ ) for( int t=0; t<m_iNumTracks; t++ )
{ {
for( int r=0; r<=max_row; r++ ) for( int r=0; r<num_rows; r++ )
{ {
TapNote tn = GetTapNote(t, r); TapNote tn = GetTapNote(t, r);
if( IsTapAttack( tn ) ) if( IsTapAttack( tn ) )
@@ -432,14 +432,14 @@ int NoteData::GetNumTapNotes( float fStartBeat, float fEndBeat ) const
int iNumNotes = 0; int iNumNotes = 0;
if( fEndBeat == -1 ) if( fEndBeat == -1 )
fEndBeat = GetMaxBeat(); fEndBeat = GetNumBeats();
int iStartIndex = BeatToNoteRow( fStartBeat ); int iStartIndex = BeatToNoteRow( fStartBeat );
int iEndIndex = BeatToNoteRow( fEndBeat ); int iEndIndex = BeatToNoteRow( fEndBeat );
/* Clamp to known-good ranges. */ /* Clamp to known-good ranges. */
iStartIndex = max( iStartIndex, 0 ); iStartIndex = max( iStartIndex, 0 );
iEndIndex = min( iEndIndex, GetMaxRow()-1 ); iEndIndex = min( iEndIndex, GetNumRows()-1 );
for( int t=0; t<m_iNumTracks; t++ ) for( int t=0; t<m_iNumTracks; t++ )
{ {
@@ -458,7 +458,7 @@ int NoteData::GetNumRowsWithTap( float fStartBeat, float fEndBeat ) const
{ {
int iNumNotes = 0; int iNumNotes = 0;
if(fEndBeat == -1) fEndBeat = GetMaxBeat(); if(fEndBeat == -1) fEndBeat = GetNumBeats();
int iStartIndex = BeatToNoteRow( fStartBeat ); int iStartIndex = BeatToNoteRow( fStartBeat );
int iEndIndex = BeatToNoteRow( fEndBeat ); int iEndIndex = BeatToNoteRow( fEndBeat );
@@ -474,14 +474,14 @@ int NoteData::GetNumMines( float fStartBeat, float fEndBeat ) const
int iNumMines = 0; int iNumMines = 0;
if( fEndBeat == -1 ) if( fEndBeat == -1 )
fEndBeat = GetMaxBeat(); fEndBeat = GetNumBeats();
int iStartIndex = BeatToNoteRow( fStartBeat ); int iStartIndex = BeatToNoteRow( fStartBeat );
int iEndIndex = BeatToNoteRow( fEndBeat ); int iEndIndex = BeatToNoteRow( fEndBeat );
/* Clamp to known-good ranges. */ /* Clamp to known-good ranges. */
iStartIndex = max( iStartIndex, 0 ); iStartIndex = max( iStartIndex, 0 );
iEndIndex = min( iEndIndex, GetMaxRow()-1 ); iEndIndex = min( iEndIndex, GetNumRows()-1 );
for( int t=0; t<m_iNumTracks; t++ ) for( int t=0; t<m_iNumTracks; t++ )
{ {
@@ -497,7 +497,7 @@ int NoteData::GetNumRowsWithTapOrHoldHead( float fStartBeat, float fEndBeat ) co
{ {
int iNumNotes = 0; int iNumNotes = 0;
if(fEndBeat == -1) fEndBeat = GetMaxBeat(); if(fEndBeat == -1) fEndBeat = GetNumBeats();
int iStartIndex = BeatToNoteRow( fStartBeat ); int iStartIndex = BeatToNoteRow( fStartBeat );
int iEndIndex = BeatToNoteRow( fEndBeat ); int iEndIndex = BeatToNoteRow( fEndBeat );
@@ -545,14 +545,14 @@ int NoteData::GetNumHands( float fStartBeat, float fEndBeat ) const
* Otherwise, every row of hold notes counts, so three simultaneous hold * Otherwise, every row of hold notes counts, so three simultaneous hold
* notes will count as hundreds of "hands". */ * notes will count as hundreds of "hands". */
if( fEndBeat == -1 ) if( fEndBeat == -1 )
fEndBeat = GetMaxBeat(); fEndBeat = GetNumBeats();
int iStartIndex = BeatToNoteRow( fStartBeat ); int iStartIndex = BeatToNoteRow( fStartBeat );
int iEndIndex = BeatToNoteRow( fEndBeat ); int iEndIndex = BeatToNoteRow( fEndBeat );
/* Clamp to known-good ranges. */ /* Clamp to known-good ranges. */
iStartIndex = max( iStartIndex, 0 ); iStartIndex = max( iStartIndex, 0 );
iEndIndex = min( iEndIndex, GetMaxRow()-1 ); iEndIndex = min( iEndIndex, GetNumRows()-1 );
int iNum = 0; int iNum = 0;
for( int i=iStartIndex; i<=iEndIndex; i++ ) for( int i=iStartIndex; i<=iEndIndex; i++ )
@@ -569,14 +569,14 @@ int NoteData::GetNumHands( float fStartBeat, float fEndBeat ) const
int NoteData::GetNumN( int MinTaps, float fStartBeat, float fEndBeat ) const int NoteData::GetNumN( int MinTaps, float fStartBeat, float fEndBeat ) const
{ {
if( fEndBeat == -1 ) if( fEndBeat == -1 )
fEndBeat = GetMaxBeat(); fEndBeat = GetNumBeats();
int iStartIndex = BeatToNoteRow( fStartBeat ); int iStartIndex = BeatToNoteRow( fStartBeat );
int iEndIndex = BeatToNoteRow( fEndBeat ); int iEndIndex = BeatToNoteRow( fEndBeat );
/* Clamp to known-good ranges. */ /* Clamp to known-good ranges. */
iStartIndex = max( iStartIndex, 0 ); iStartIndex = max( iStartIndex, 0 );
iEndIndex = min( iEndIndex, GetMaxRow()-1 ); iEndIndex = min( iEndIndex, GetNumRows()-1 );
int iNum = 0; int iNum = 0;
for( int i=iStartIndex; i<=iEndIndex; i++ ) for( int i=iStartIndex; i<=iEndIndex; i++ )
@@ -598,7 +598,7 @@ int NoteData::GetNumN( int MinTaps, float fStartBeat, float fEndBeat ) const
int NoteData::GetNumHoldNotes( float fStartBeat, float fEndBeat ) const int NoteData::GetNumHoldNotes( float fStartBeat, float fEndBeat ) const
{ {
if( fEndBeat == -1 ) if( fEndBeat == -1 )
fEndBeat = GetMaxBeat(); fEndBeat = GetNumBeats();
int iStartIndex = BeatToNoteRow( fStartBeat ); int iStartIndex = BeatToNoteRow( fStartBeat );
int iEndIndex = BeatToNoteRow( fEndBeat ); int iEndIndex = BeatToNoteRow( fEndBeat );
+5 -5
View File
@@ -49,7 +49,7 @@ public:
void ReserveRows( int row ); void ReserveRows( int row );
/* GetTapNote is called a lot. This one doesn't do any bounds checking, /* GetTapNote is called a lot. This one doesn't do any bounds checking,
* which is much faster. Be sure that 0 <= row < GetMaxRow(). */ * which is much faster. Be sure that 0 <= row < GetNumRows(). */
inline TapNote GetTapNoteX(unsigned track, int row) const inline TapNote GetTapNoteX(unsigned track, int row) const
{ {
return m_TapNotes[track][row]; return m_TapNotes[track][row];
@@ -100,10 +100,10 @@ public:
// //
// statistics // statistics
// //
/* Return the highest beat/row that might contain notes. (Use GetLastBeat if you need /* Return the number of beats/rows that might contain notes. Use
* accuracy.) */ * GetLast* if you need to know the location of the last note. */
float GetMaxBeat() const { return NoteRowToBeat(GetMaxRow()); } float GetNumBeats() const { return NoteRowToBeat(GetNumRows()); }
int GetMaxRow() const { return int(m_TapNotes[0].size()); } int GetNumRows() const { return int(m_TapNotes[0].size()); }
float GetFirstBeat() const; // return the beat number of the first note float GetFirstBeat() const; // return the beat number of the first note
int GetFirstRow() const; int GetFirstRow() const;
+6 -6
View File
@@ -346,8 +346,8 @@ void NoteDataUtil::LoadOverlapped( const NoteData &input, NoteData &out, int iNe
const int ShiftThreshold = BeatToNoteRow(1); const int ShiftThreshold = BeatToNoteRow(1);
const int iLastRow = in.GetMaxRow(); const int iNumRows = in.GetNumRows();
for( int row = 0; row < iLastRow; ++row ) for( int row = 0; row < iNumRows; ++row )
{ {
for ( int i = 0; i < in.GetNumTracks(); i++ ) for ( int i = 0; i < in.GetNumTracks(); i++ )
{ {
@@ -393,7 +393,7 @@ void NoteDataUtil::LoadTransformedLights( const NoteData &in, NoteData &out, int
out.Config(in); out.Config(in);
out.SetNumTracks( iNewNumTracks ); out.SetNumTracks( iNewNumTracks );
for( int r=0; r < Original.GetMaxRow(); ++r ) for( int r=0; r < Original.GetNumRows(); ++r )
{ {
if( Original.IsRowEmpty( r ) ) if( Original.IsRowEmpty( r ) )
continue; continue;
@@ -775,14 +775,14 @@ void NoteDataUtil::Turn( NoteData &in, StepsType st, TrackMapping tt, float fSta
GetTrackMapping( st, tt, in.GetNumTracks(), iTakeFromTrack ); GetTrackMapping( st, tt, in.GetNumTracks(), iTakeFromTrack );
if( fEndBeat == -1 ) if( fEndBeat == -1 )
fEndBeat = in.GetMaxBeat(); fEndBeat = in.GetNumBeats();
int iStartIndex = BeatToNoteRow( fStartBeat ); int iStartIndex = BeatToNoteRow( fStartBeat );
int iEndIndex = BeatToNoteRow( fEndBeat ); int iEndIndex = BeatToNoteRow( fEndBeat );
/* Clamp to known-good ranges. */ /* Clamp to known-good ranges. */
iStartIndex = max( iStartIndex, 0 ); iStartIndex = max( iStartIndex, 0 );
iEndIndex = min( iEndIndex, in.GetMaxRow()-1 ); iEndIndex = min( iEndIndex, in.GetNumRows()-1 );
/* XXX: We could do this without an extra temporary NoteData: calculate /* XXX: We could do this without an extra temporary NoteData: calculate
* a list of "swaps". For example, the 4-track mapping 1 0 2 3 is swaps * a list of "swaps". For example, the 4-track mapping 1 0 2 3 is swaps
@@ -1514,7 +1514,7 @@ void NoteDataUtil::FixImpossibleRows( NoteData &in, StepsType st )
return; return;
// each row must pass at least one valid mask // each row must pass at least one valid mask
for( int r=0; r<=in.GetMaxRow(); r++ ) for( int r=0; r<in.GetNumRows(); r++ )
{ {
// only check rows with jumps // only check rows with jumps
if( in.GetNumTapNonEmptyTracks(r) < 2 ) if( in.GetNumTapNonEmptyTracks(r) < 2 )
+8 -8
View File
@@ -24,7 +24,7 @@ int NoteDataWithScoring::GetNumTapNotesWithScore( TapNoteScore tns, const float
int iNumSuccessfulTapNotes = 0; int iNumSuccessfulTapNotes = 0;
if(fEndBeat == -1) if(fEndBeat == -1)
fEndBeat = GetMaxBeat()+1; fEndBeat = GetNumBeats()+1;
unsigned iStartIndex = BeatToNoteRow( fStartBeat ); unsigned iStartIndex = BeatToNoteRow( fStartBeat );
unsigned iEndIndex = BeatToNoteRow( fEndBeat ); unsigned iEndIndex = BeatToNoteRow( fEndBeat );
@@ -44,13 +44,13 @@ int NoteDataWithScoring::GetNumTapNotesWithScore( TapNoteScore tns, const float
int NoteDataWithScoring::GetNumNWithScore( TapNoteScore tns, int MinTaps, const float fStartBeat, float fEndBeat ) const int NoteDataWithScoring::GetNumNWithScore( TapNoteScore tns, int MinTaps, const float fStartBeat, float fEndBeat ) const
{ {
if( fEndBeat == -1 ) if( fEndBeat == -1 )
fEndBeat = GetMaxBeat(); fEndBeat = GetNumBeats();
int iStartIndex = BeatToNoteRow( fStartBeat ); int iStartIndex = BeatToNoteRow( fStartBeat );
int iEndIndex = BeatToNoteRow( fEndBeat ); int iEndIndex = BeatToNoteRow( fEndBeat );
iStartIndex = max( iStartIndex, 0 ); iStartIndex = max( iStartIndex, 0 );
iEndIndex = min( iEndIndex, GetMaxRow()-1 ); iEndIndex = min( iEndIndex, GetNumRows()-1 );
int iNumSuccessfulDoubles = 0; int iNumSuccessfulDoubles = 0;
for( int i=iStartIndex; i<=iEndIndex; i++ ) for( int i=iStartIndex; i<=iEndIndex; i++ )
@@ -80,7 +80,7 @@ int NoteDataWithScoring::GetNumHoldNotesWithScore( HoldNoteScore hns, const floa
int iNumSuccessfulHolds = 0; int iNumSuccessfulHolds = 0;
if(fEndBeat == -1) if(fEndBeat == -1)
fEndBeat = GetMaxBeat(); fEndBeat = GetNumBeats();
int iStartIndex = BeatToNoteRow( fStartBeat ); int iStartIndex = BeatToNoteRow( fStartBeat );
int iEndIndex = BeatToNoteRow( fEndBeat ); int iEndIndex = BeatToNoteRow( fEndBeat );
@@ -99,13 +99,13 @@ int NoteDataWithScoring::GetNumHoldNotesWithScore( HoldNoteScore hns, const floa
int NoteDataWithScoring::GetSuccessfulMines( float fStartBeat, float fEndBeat ) const int NoteDataWithScoring::GetSuccessfulMines( float fStartBeat, float fEndBeat ) const
{ {
if( fEndBeat == -1 ) if( fEndBeat == -1 )
fEndBeat = GetMaxBeat(); fEndBeat = GetNumBeats();
int iStartIndex = BeatToNoteRow( fStartBeat ); int iStartIndex = BeatToNoteRow( fStartBeat );
int iEndIndex = BeatToNoteRow( fEndBeat ); int iEndIndex = BeatToNoteRow( fEndBeat );
iStartIndex = max( iStartIndex, 0 ); iStartIndex = max( iStartIndex, 0 );
iEndIndex = min( iEndIndex, GetMaxRow()-1 ); iEndIndex = min( iEndIndex, GetNumRows()-1 );
int iNumSuccessfulMinesNotes = 0; int iNumSuccessfulMinesNotes = 0;
for( int i=iStartIndex; i<=iEndIndex; i++ ) for( int i=iStartIndex; i<=iEndIndex; i++ )
@@ -124,14 +124,14 @@ int NoteDataWithScoring::GetSuccessfulMines( float fStartBeat, float fEndBeat )
int NoteDataWithScoring::GetSuccessfulHands( float fStartBeat, float fEndBeat ) const int NoteDataWithScoring::GetSuccessfulHands( float fStartBeat, float fEndBeat ) const
{ {
if( fEndBeat == -1 ) if( fEndBeat == -1 )
fEndBeat = GetMaxBeat(); fEndBeat = GetNumBeats();
int iStartIndex = BeatToNoteRow( fStartBeat ); int iStartIndex = BeatToNoteRow( fStartBeat );
int iEndIndex = BeatToNoteRow( fEndBeat ); int iEndIndex = BeatToNoteRow( fEndBeat );
/* Clamp to known-good ranges. */ /* Clamp to known-good ranges. */
iStartIndex = max( iStartIndex, 0 ); iStartIndex = max( iStartIndex, 0 );
iEndIndex = min( iEndIndex, GetMaxRow()-1 ); iEndIndex = min( iEndIndex, GetNumRows()-1 );
int iNum = 0; int iNum = 0;
for( int i=iStartIndex; i<=iEndIndex; i++ ) for( int i=iStartIndex; i<=iEndIndex; i++ )
+1 -1
View File
@@ -473,7 +473,7 @@ void PlayerMinus::ApplyWaitingTransforms()
float fStartBeat, fEndBeat; float fStartBeat, fEndBeat;
mod.GetAttackBeats( GAMESTATE->m_pCurSong, m_PlayerNumber, fStartBeat, fEndBeat ); mod.GetAttackBeats( GAMESTATE->m_pCurSong, m_PlayerNumber, fStartBeat, fEndBeat );
fEndBeat = min( fEndBeat, GetMaxBeat() ); fEndBeat = min( fEndBeat, GetNumBeats() );
LOG->Trace( "Applying transform '%s' from %f to %f to '%s'", mod.sModifier.c_str(), fStartBeat, fEndBeat, LOG->Trace( "Applying transform '%s' from %f to %f to '%s'", mod.sModifier.c_str(), fStartBeat, fEndBeat,
GAMESTATE->m_pCurSong->GetTranslitMainTitle().c_str() ); GAMESTATE->m_pCurSong->GetTranslitMainTitle().c_str() );