Use a associative arrays instead of normal vectors to hold TapNotes.

More places NoteDataUtil, NoteDataWithScoring need to be converted to use the new row iteration macros.
This commit is contained in:
Chris Danford
2004-09-29 06:43:57 +00:00
parent f22ec944d4
commit 0f6ed81faf
7 changed files with 233 additions and 189 deletions
+138 -125
View File
@@ -36,14 +36,6 @@ void NoteData::SetNumTracks( int iNewNumTracks )
m_TapNotes.resize( iNewNumTracks );
// Enforce that all track vectors have the same length.
unsigned uNumRows = m_TapNotes[0].size();
for( unsigned t=0; t<m_TapNotes.size(); t++ )
{
m_TapNotes[t].resize( uNumRows, TAP_EMPTY );
}
/* Remove all hold notes that are out of bounds. */
// Iterate backwards so that we can delete.
for( int h = m_HoldNotes.size()-1; h >= 0; --h )
@@ -56,9 +48,9 @@ void NoteData::SetNumTracks( int iNewNumTracks )
void NoteData::ClearRange( int iNoteIndexBegin, int iNoteIndexEnd )
{
this->ConvertHoldNotesTo4s();
for( unsigned t=0; t<m_TapNotes.size(); t++ )
for( unsigned t=0; t<GetNumTracks(); t++ )
{
for( int i=iNoteIndexBegin; i <= iNoteIndexEnd; i++ )
FOREACH_NONEMPTY_ROW_IN_TRACK_RANGE( *this, t, i, iNoteIndexBegin, iNoteIndexEnd )
SetTapNote(t, i, TAP_EMPTY);
}
this->Convert4sToHoldNotes();
@@ -66,7 +58,7 @@ void NoteData::ClearRange( int iNoteIndexBegin, int iNoteIndexEnd )
void NoteData::ClearAll()
{
for( unsigned t=0; t<m_TapNotes.size(); t++ )
for( unsigned t=0; t<GetNumTracks(); t++ )
m_TapNotes[t].clear();
m_HoldNotes.clear();
}
@@ -82,25 +74,24 @@ void NoteData::CopyRange( const NoteData* pFrom, int iFromIndexBegin, int iFromI
To.To4s( *this );
// copy recorded TapNotes
int f = iFromIndexBegin, t = iToIndexBegin;
while( f<=iFromIndexEnd )
for( int t=0; t<GetNumTracks(); t++ )
{
for( int c=0; c<GetNumTracks(); c++ )
FOREACH_NONEMPTY_ROW_IN_TRACK_RANGE( From, t, from, iFromIndexBegin, iFromIndexEnd )
{
TapNote tn = From.GetTapNote( c, f );
int to = iToIndexBegin + from - iFromIndexBegin;
TapNote tn = From.GetTapNote( t, from );
if( tn.type == TapNote::attack )
{
Attack attack = From.GetAttackAt( c, f );
To.SetTapAttackNote( c, t, attack );
Attack attack = From.GetAttackAt( t, from );
To.SetTapAttackNote( t, to, attack );
}
else
{
To.SetTapNote( c, t, tn );
To.SetTapNote( t, to, tn );
}
}
f++;
t++;
}
this->From4s( To );
@@ -124,10 +115,6 @@ void NoteData::CopyAll( const NoteData* pFrom )
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 >= GetNumRows() )
return true;
for( int t=0; t<GetNumTracks(); t++ )
if( GetTapNoteX(t, index).type != TapNote::empty )
return false;
@@ -137,11 +124,8 @@ bool NoteData::IsRowEmpty( int index ) const
bool NoteData::IsRangeEmpty( int track, int iIndexBegin, int iIndexEnd ) const
{
ASSERT( track < GetNumTracks() );
CLAMP( iIndexBegin, 0, GetNumRows()-1 );
CLAMP( iIndexEnd, 0, GetNumRows()-1 );
for( int i=iIndexBegin; i<=iIndexEnd; i++ )
FOREACH_NONEMPTY_ROW_IN_TRACK_RANGE( *this, track, i, iIndexBegin, iIndexEnd )
if( GetTapNoteX(track,i).type != TapNote::empty )
return false;
return true;
@@ -165,10 +149,6 @@ void NoteData::GetTapNonEmptyTracks( int index, set<int>& addTo ) 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( index < 0 || index >= GetNumRows() )
return 0;
for( int t=0; t<GetNumTracks(); t++ )
if( GetTapNoteX( t, index ).type != TapNote::empty )
return t;
@@ -177,10 +157,6 @@ int NoteData::GetFirstNonEmptyTrack( 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( index < 0 || index >= GetNumRows() )
return 0;
int iNum = 0;
for( int t=0; t<GetNumTracks(); t++ )
{
@@ -193,10 +169,6 @@ int NoteData::GetNumTracksWithTap( 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( index < 0 || index >= GetNumRows() )
return 0;
int iNum = 0;
for( int t=0; t<GetNumTracks(); t++ )
{
@@ -209,10 +181,6 @@ int NoteData::GetNumTracksWithTapOrHoldHead( 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( index < 0 || index >= GetNumRows() )
return -1;
for( int t=0; t<GetNumTracks(); t++ )
{
TapNote tn = GetTapNoteX( t, index );
@@ -224,10 +192,6 @@ int NoteData::GetFirstTrackWithTap( 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( index < 0 || index >= GetNumRows() )
return -1;
for( int t=0; t<GetNumTracks(); t++ )
{
TapNote tn = GetTapNoteX( t, index );
@@ -263,7 +227,7 @@ void NoteData::AddHoldNote( HoldNote add )
int iAddEndIndex = add.iEndRow;
// delete TapNotes under this HoldNote
for( int i=iAddStartIndex+1; i<=iAddEndIndex; i++ )
FOREACH_NONEMPTY_ROW_IN_TRACK_RANGE( *this, add.iTrack, i, iAddStartIndex+1, iAddEndIndex )
SetTapNote( add.iTrack, i, TAP_EMPTY );
// add a tap note at the start of this hold
@@ -325,10 +289,9 @@ void NoteData::PruneUnusedAttacksFromMap()
// Add all used AttackNote index values to a map.
set<unsigned> setUsedIndices;
int num_rows = GetNumRows();
for( int t=0; t<GetNumTracks(); t++ )
{
for( int r=0; r<num_rows; r++ )
FOREACH_NONEMPTY_ROW_IN_TRACK( *this, t, r )
{
TapNote tn = GetTapNote(t, r);
if( tn.type == TapNote::attack )
@@ -365,13 +328,16 @@ int NoteData::GetFirstRow() const
{
int iEarliestRowFoundSoFar = -1;
for( int i=0; i < int(m_TapNotes[0].size()); i++ )
for( unsigned t=0; t < GetNumTracks(); t++ )
{
if( !IsRowEmpty(i) )
{
iEarliestRowFoundSoFar = i;
break;
}
const TrackMap &trackMap = m_TapNotes[t];
TrackMap::const_iterator iter = trackMap.begin();
if( iter == trackMap.end() ) // trackMap is empty
continue;
if( iEarliestRowFoundSoFar == -1 )
iEarliestRowFoundSoFar = iter->first;
else
iEarliestRowFoundSoFar = min( iEarliestRowFoundSoFar, iter->first );
}
for( int i=0; i<GetNumHoldNotes(); i++ )
@@ -387,22 +353,17 @@ int NoteData::GetFirstRow() const
return iEarliestRowFoundSoFar;
}
float NoteData::GetFirstBeat() const
{
return NoteRowToBeat( GetFirstRow() );
}
int NoteData::GetLastRow() const
{
int iOldestRowFoundSoFar = 0;
for( int i = int(m_TapNotes[0].size()); i>=0; i-- ) // iterate back to front
for( unsigned t=0; t < GetNumTracks(); t++ )
{
if( !IsRowEmpty(i) )
{
iOldestRowFoundSoFar = i;
break;
}
const TrackMap &trackMap = m_TapNotes[t];
const TrackMap::const_reverse_iterator iter = trackMap.rbegin();
if( iter == trackMap.rend() ) // trackMap is empty
continue;
iOldestRowFoundSoFar = max( iOldestRowFoundSoFar, iter->first );
}
for( int i=0; i<GetNumHoldNotes(); i++ )
@@ -414,28 +375,23 @@ int NoteData::GetLastRow() const
return iOldestRowFoundSoFar;
}
float NoteData::GetLastBeat() const
{
return NoteRowToBeat( GetLastRow() );
}
int NoteData::GetNumTapNotes( float fStartBeat, float fEndBeat ) const
{
int iNumNotes = 0;
if( fEndBeat == -1 )
fEndBeat = GetNumBeats();
fEndBeat = 999999;
int iNumNotes = 0;
int iStartIndex = BeatToNoteRow( fStartBeat );
int iEndIndex = BeatToNoteRow( fEndBeat );
/* Clamp to known-good ranges. */
iStartIndex = max( iStartIndex, 0 );
iEndIndex = min( iEndIndex, GetNumRows()-1 );
iEndIndex = min( iEndIndex, GetLastRow() );
for( int t=0; t<GetNumTracks(); t++ )
{
for( int i=iStartIndex; i<=iEndIndex; i++ )
FOREACH_NONEMPTY_ROW_IN_TRACK_RANGE( *this, t, i, iStartIndex, iEndIndex )
{
TapNote tn = GetTapNoteX(t, i);
if( tn.type != TapNote::empty && tn.type != TapNote::mine )
@@ -448,13 +404,15 @@ int NoteData::GetNumTapNotes( float fStartBeat, float fEndBeat ) const
int NoteData::GetNumRowsWithTap( float fStartBeat, float fEndBeat ) const
{
if( fEndBeat == -1 )
fEndBeat = GetLastBeat();
int iNumNotes = 0;
if(fEndBeat == -1) fEndBeat = GetNumBeats();
int iStartIndex = BeatToNoteRow( fStartBeat );
int iEndIndex = BeatToNoteRow( fEndBeat );
for( int i=iStartIndex; i<=iEndIndex; i++ )
FOREACH_NONEMPTY_ROW_ALL_TRACKS_RANGE( *this, i, iStartIndex, iEndIndex )
if( IsThereATapAtRow(i) )
iNumNotes++;
@@ -463,21 +421,21 @@ int NoteData::GetNumRowsWithTap( float fStartBeat, float fEndBeat ) const
int NoteData::GetNumMines( float fStartBeat, float fEndBeat ) const
{
int iNumMines = 0;
if( fEndBeat == -1 )
fEndBeat = GetNumBeats();
fEndBeat = 999999;
int iNumMines = 0;
int iStartIndex = BeatToNoteRow( fStartBeat );
int iEndIndex = BeatToNoteRow( fEndBeat );
/* Clamp to known-good ranges. */
iStartIndex = max( iStartIndex, 0 );
iEndIndex = min( iEndIndex, GetNumRows()-1 );
iEndIndex = min( iEndIndex, GetLastRow() );
for( int t=0; t<GetNumTracks(); t++ )
{
for( int i=iStartIndex; i<=iEndIndex; i++ )
FOREACH_NONEMPTY_ROW_IN_TRACK_RANGE( *this, t, i, iStartIndex, iEndIndex )
if( GetTapNoteX(t, i).type == TapNote::mine )
iNumMines++;
}
@@ -487,13 +445,15 @@ int NoteData::GetNumMines( float fStartBeat, float fEndBeat ) const
int NoteData::GetNumRowsWithTapOrHoldHead( float fStartBeat, float fEndBeat ) const
{
if( fEndBeat == -1 )
fEndBeat = GetLastBeat();
int iNumNotes = 0;
if(fEndBeat == -1) fEndBeat = GetNumBeats();
int iStartIndex = BeatToNoteRow( fStartBeat );
int iEndIndex = BeatToNoteRow( fEndBeat );
for( int i=iStartIndex; i<=iEndIndex; i++ )
FOREACH_NONEMPTY_ROW_ALL_TRACKS_RANGE( *this, i, iStartIndex, iEndIndex )
if( IsThereATapOrHoldHeadAtRow(i) )
iNumNotes++;
@@ -542,17 +502,17 @@ int NoteData::GetNumHands( float fStartBeat, float fEndBeat ) const
* Otherwise, every row of hold notes counts, so three simultaneous hold
* notes will count as hundreds of "hands". */
if( fEndBeat == -1 )
fEndBeat = GetNumBeats();
fEndBeat = GetLastBeat();
int iStartIndex = BeatToNoteRow( fStartBeat );
int iEndIndex = BeatToNoteRow( fEndBeat );
/* Clamp to known-good ranges. */
iStartIndex = max( iStartIndex, 0 );
iEndIndex = min( iEndIndex, GetNumRows()-1 );
iEndIndex = min( iEndIndex, GetLastRow() );
int iNum = 0;
for( int i=iStartIndex; i<=iEndIndex; i++ )
FOREACH_NONEMPTY_ROW_ALL_TRACKS_RANGE( *this, i, iStartIndex, iEndIndex )
{
if( !RowNeedsHands(i) )
continue;
@@ -566,17 +526,17 @@ int NoteData::GetNumHands( float fStartBeat, float fEndBeat ) const
int NoteData::GetNumN( int MinTaps, float fStartBeat, float fEndBeat ) const
{
if( fEndBeat == -1 )
fEndBeat = GetNumBeats();
fEndBeat = GetLastBeat();
int iStartIndex = BeatToNoteRow( fStartBeat );
int iEndIndex = BeatToNoteRow( fEndBeat );
/* Clamp to known-good ranges. */
iStartIndex = max( iStartIndex, 0 );
iEndIndex = min( iEndIndex, GetNumRows()-1 );
iEndIndex = min( iEndIndex, GetLastRow() );
int iNum = 0;
for( int i=iStartIndex; i<=iEndIndex; i++ )
FOREACH_NONEMPTY_ROW_ALL_TRACKS_RANGE( *this, i, iStartIndex, iEndIndex )
{
int iNumNotesThisIndex = 0;
for( int t=0; t<GetNumTracks(); t++ )
@@ -595,7 +555,8 @@ int NoteData::GetNumN( int MinTaps, float fStartBeat, float fEndBeat ) const
int NoteData::GetNumHoldNotes( float fStartBeat, float fEndBeat ) const
{
if( fEndBeat == -1 )
fEndBeat = GetNumBeats();
fEndBeat = GetLastBeat();
int iStartIndex = BeatToNoteRow( fStartBeat );
int iEndIndex = BeatToNoteRow( fEndBeat );
@@ -615,24 +576,26 @@ void NoteData::Convert2sAnd3sToHoldNotes()
// Plus, allowing tap notes in the middle of a hold doesn't make sense!
int rows = GetLastRow();
for( int col=0; col<GetNumTracks(); col++ ) // foreach column
for( int t=0; t<GetNumTracks(); t++ ) // foreach column
{
for( int i=0; i<=rows; i++ ) // foreach TapNote element
FOREACH_NONEMPTY_ROW_IN_TRACK( *this, t, i )
{
if( GetTapNote(col,i).type != TapNote::hold_head ) // this is a HoldNote begin marker
continue;
SetTapNote(col, i, TAP_EMPTY); // clear the hold head marker
if( GetTapNote(t,i).type != TapNote::hold_head )
continue; // skip
for( int j=i+1; j<=rows; j++ ) // search for end of HoldNote
SetTapNote(t, i, TAP_EMPTY); // clear the hold head marker
// search for end of HoldNote
FOREACH_NONEMPTY_ROW_IN_TRACK_RANGE( *this, t, j, i+1, 999999 )
{
// End hold on the next note we see. This should be a hold_tail if the
// data is in a consistent state, but doesn't have to be.
if( GetTapNote(col, j).type == TapNote::empty )
if( GetTapNote(t, j).type == TapNote::empty )
continue;
SetTapNote(col, j, TAP_EMPTY);
SetTapNote(t, j, TAP_EMPTY);
AddHoldNote( HoldNote(col, i, j) );
AddHoldNote( HoldNote(t, i, j) );
break; // done searching for the end of this hold
}
}
@@ -692,20 +655,19 @@ void NoteData::From4s( const NoteData &out )
* So, make sure the character after a 4 is always a 0. */
void NoteData::Convert4sToHoldNotes()
{
int rows = GetLastRow();
for( int col=0; col<GetNumTracks(); col++ ) // foreach column
for( int t=0; t<GetNumTracks(); t++ ) // foreach column
{
for( int i=0; i<=rows; i++ ) // foreach TapNote element
FOREACH_NONEMPTY_ROW_IN_TRACK( *this, t, i )
{
if( GetTapNote(col, i).type == TapNote::hold ) // this is a HoldNote body
if( GetTapNote(t, i).type == TapNote::hold ) // this is a HoldNote body
{
HoldNote hn( col, i, 0 );
HoldNote hn( t, i, 0 );
// search for end of HoldNote
do {
SetTapNote(col, i, TAP_EMPTY);
SetTapNote( t, i, TAP_EMPTY );
i++;
} while( GetTapNote(col, i).type == TapNote::hold );
SetTapNote(col, i, TAP_EMPTY);
} while( GetTapNote(t, i).type == TapNote::hold );
SetTapNote( t, i, TAP_EMPTY );
hn.iEndRow = i;
AddHoldNote( hn );
@@ -757,14 +719,7 @@ void NoteData::LoadTransformed( const NoteData* pOriginal, int iNewNumTracks, co
void NoteData::PadTapNotes(int rows)
{
int needed = rows - m_TapNotes[0].size() + 1;
if(needed < 0)
return;
needed += 100; /* optimization: give it a little more than it needs */
for(int track = 0; track < GetNumTracks(); ++track)
m_TapNotes[track].insert( m_TapNotes[track].end(), needed, TAP_EMPTY );
// Nothing to do for a track map.
}
void NoteData::MoveTapNoteTrack(int dest, int src)
@@ -774,20 +729,34 @@ void NoteData::MoveTapNoteTrack(int dest, int src)
m_TapNotes[src].clear();
}
void NoteData::SetTapNote(int track, int row, TapNote t)
void NoteData::SetTapNote( int track, int row, TapNote t )
{
DEBUG_ASSERT( track>=0 && track<GetNumTracks() );
if(row < 0) return;
if( row < 0 )
return;
PadTapNotes(row);
m_TapNotes[track][row]=t;
// There's no point in inserting empty notes into the map.
// Any blank space in the map is defined to be empty.
// If we're trying to insert an empty at a spot where
// another note already exists, then we're really deleting
// from the map.
if( t == TAP_EMPTY )
{
TrackMap &trackMap = m_TapNotes[track];
// remove the element at this position (if any). This will return either 0 or 1.
unsigned numDeleted = trackMap.erase( row );
}
else
{
PadTapNotes(row);
m_TapNotes[track][row] = t;
}
}
void NoteData::ReserveRows( int row )
{
for(int track = 0; track < GetNumTracks(); ++track)
m_TapNotes[track].reserve( row );
// Nothing to do for a track map.
}
void NoteData::EliminateAllButOneTap(int row)
@@ -830,6 +799,50 @@ int NoteData::GetNumTracksHeldAtRow( int row )
return viTracks.size();
}
bool NoteData::GetNextTapNoteRowForTrack( int track, int &rowInOut ) const
{
const TrackMap &mapTrack = m_TapNotes[track];
// lower_bound and upper_bound have the same effect here because duplicate
// keys aren't allowed.
TrackMap::const_iterator iter = mapTrack.lower_bound( rowInOut+1 ); // "find the first note for which row+1 < key == false"
if( iter != mapTrack.end() )
{
ASSERT( iter->first > rowInOut );
rowInOut = iter->first;
return true;
}
else
{
return false;
}
}
bool NoteData::GetNextTapNoteRowForAllTracks( int &rowInOut ) const
{
int iClosestNextRow = 999999;
bool bAnyHaveNextNote = false;
for( int t=0; t<GetNumTracks(); t++ )
{
int iNewRowThisTrack = rowInOut;
if( GetNextTapNoteRowForTrack( t, iNewRowThisTrack ) )
{
bAnyHaveNextNote = true;
iClosestNextRow = min( iClosestNextRow, iNewRowThisTrack );
}
}
if( bAnyHaveNextNote )
{
rowInOut = iClosestNextRow;
return true;
}
else
{
return false;
}
}
/*
* (c) 2001-2004 Chris Danford, Glenn Maynard
* All rights reserved.
+30 -17
View File
@@ -8,13 +8,21 @@
#include <set>
#include "Attack.h"
#define FOREACH_NONEMPTY_ROW_IN_TRACK( nd, track, row ) \
for( int row = 0; (nd).GetNextTapNoteRowForTrack(track,row); )
#define FOREACH_NONEMPTY_ROW_IN_TRACK_RANGE( nd, track, row, start, last ) \
for( int row = start-1; (nd).GetNextTapNoteRowForTrack(track,row) && row <= (last); )
#define FOREACH_NONEMPTY_ROW_ALL_TRACKS( nd, row ) \
for( int row = 0; (nd).GetNextTapNoteRowForAllTracks(row); )
#define FOREACH_NONEMPTY_ROW_ALL_TRACKS_RANGE( nd, row, start, last ) \
for( int row = start-1; (nd).GetNextTapNoteRowForAllTracks(row) && row <= (last); )
class NoteData
{
/* By convention, all TrackVectors have the same size.
* If you want to set the size of one, be sure to set the rest. */
typedef vector<TapNote> TrackVector;
vector<TrackVector> m_TapNotes;
// There's no point in inserting empty notes into the map.
// Any blank space in the map is defined to be empty.
typedef map<int,TapNote> TrackMap;
vector<TrackMap> m_TapNotes;
vector<HoldNote> m_HoldNotes;
@@ -44,9 +52,7 @@ public:
* range; pretend the song goes on with TAP_EMPTYs indefinitely. */
inline TapNote GetTapNote(unsigned track, int row) const
{
if(row < 0 || row >= (int) m_TapNotes[track].size())
return TAP_EMPTY;
return m_TapNotes[track][row];
return GetTapNoteX( track, row );
}
void ReserveRows( int row );
@@ -54,8 +60,20 @@ public:
* which is much faster. Be sure that 0 <= row < GetNumRows(). */
inline TapNote GetTapNoteX(unsigned track, int row) const
{
return m_TapNotes[track][row];
const TrackMap &mapTrack = m_TapNotes[track];
TrackMap::const_iterator iter = mapTrack.find( row );
if( iter != mapTrack.end() )
return iter->second;
else
return TAP_EMPTY;
}
// Use this to iterate over notes.
// Returns the row index of the first TapNote on the track that has a row
// index > afterRow.
bool GetNextTapNoteRowForTrack( int track, int &rowInOut ) const;
bool GetNextTapNoteRowForAllTracks( int &rowInOut ) const;
void MoveTapNoteTrack(int dest, int src);
void SetTapNote(int track, int row, TapNote t);
@@ -102,15 +120,10 @@ public:
//
// statistics
//
/* Return the number of beats/rows that might contain notes. Use
* GetLast* if you need to know the location of the last note. */
float GetNumBeats() const { return NoteRowToBeat(GetNumRows()); }
int GetNumRows() const { return int(m_TapNotes[0].size()); }
float GetFirstBeat() const; // return the beat number of the first note
int GetFirstRow() const;
float GetLastBeat() const; // return the beat number of the last note
int GetLastRow() const;
int GetFirstRow() const; // return the beat number of the first note
float GetFirstBeat() const { return NoteRowToBeat( GetFirstRow() ); }
int GetLastRow() const; // return the beat number of the last note
float GetLastBeat() const { return NoteRowToBeat( GetLastRow() ); }
int GetNumTapNotes( const float fStartBeat = 0, const float fEndBeat = -1 ) const;
int GetNumMines( const float fStartBeat = 0, const float fEndBeat = -1 ) const;
int GetNumHands( const float fStartBeat = 0, const float fEndBeat = -1 ) const;
+33 -29
View File
@@ -342,8 +342,8 @@ void NoteDataUtil::LoadOverlapped( const NoteData &input, NoteData &out, int iNe
const int ShiftThreshold = BeatToNoteRow(1);
const int iNumRows = in.GetNumRows();
for( int row = 0; row < iNumRows; ++row )
const int iLastRow = in.GetLastRow();
for( int row = 0; row <= iLastRow; ++row )
{
for ( int i = 0; i < in.GetNumTracks(); i++ )
{
@@ -389,7 +389,8 @@ void NoteDataUtil::LoadTransformedLights( const NoteData &in, NoteData &out, int
out.Config(in);
out.SetNumTracks( iNewNumTracks );
for( int r=0; r < Original.GetNumRows(); ++r )
int iLastRow = Original.GetLastRow();
for( int r=0; r <= iLastRow; ++r )
{
if( Original.IsRowEmpty( r ) )
continue;
@@ -496,10 +497,10 @@ float NoteDataUtil::GetChaosRadarValue( const NoteData &in, float fSongSeconds )
return 0.0f;
// count number of triplets or 16ths
int iNumChaosNotes = 0;
int rows = in.GetLastRow();
for( int r=0; r<=rows; r++ )
FOREACH_NONEMPTY_ROW_ALL_TRACKS( in, r )
{
if( !in.IsRowEmpty(r) && GetNoteType(r) >= NOTE_TYPE_12TH )
if( GetNoteType(r) >= NOTE_TYPE_12TH )
iNumChaosNotes++;
}
@@ -531,11 +532,8 @@ void NoteDataUtil::RemoveSimultaneousNotes(NoteData &in, int iMaxSimultaneous, f
int iEndIndex = BeatToNoteRow( fEndBeat );
// turn all the HoldNotes into TapNotes
for( int r=iStartIndex; r<=iEndIndex; r++ ) // iterate backwards so we can delete
FOREACH_NONEMPTY_ROW_ALL_TRACKS_RANGE( in, r, iStartIndex, iEndIndex )
{
if( in.IsRowEmpty(r) )
continue; // skip
set<int> viTracksHeld;
in.GetTracksHeldAtRow( r, viTracksHeld );
@@ -586,7 +584,7 @@ void NoteDataUtil::RemoveMines(NoteData &in, float fStartBeat, float fEndBeat )
int iRowStart = BeatToNoteRow(fStartBeat);
int iRowEnd = BeatToNoteRow(fEndBeat);
for( int t=0; t<in.GetNumTracks(); t++ )
for( int r=iRowStart; r<=iRowEnd; r++ )
FOREACH_NONEMPTY_ROW_IN_TRACK_RANGE( in, t, r, iRowStart, iRowEnd )
if( in.GetTapNote(t,r).type == TapNote::mine )
in.SetTapNote( t, r, TAP_EMPTY );
}
@@ -738,7 +736,7 @@ static void SuperShuffleTaps( NoteData &in, int iStartIndex, int iEndIndex )
*
* This is only called by NoteDataUtil::Turn. "in" is in 4s, and iStartIndex
* and iEndIndex are in range. */
for( int r=iStartIndex; r<=iEndIndex; r++ )
FOREACH_NONEMPTY_ROW_ALL_TRACKS_RANGE( in, r, iStartIndex, iEndIndex )
{
for( int t1=0; t1<in.GetNumTracks(); t1++ )
{
@@ -771,14 +769,14 @@ void NoteDataUtil::Turn( NoteData &in, StepsType st, TrackMapping tt, float fSta
GetTrackMapping( st, tt, in.GetNumTracks(), iTakeFromTrack );
if( fEndBeat == -1 )
fEndBeat = in.GetNumBeats();
fEndBeat = in.GetLastBeat();
int iStartIndex = BeatToNoteRow( fStartBeat );
int iEndIndex = BeatToNoteRow( fEndBeat );
/* Clamp to known-good ranges. */
iStartIndex = max( iStartIndex, 0 );
iEndIndex = min( iEndIndex, in.GetNumRows()-1 );
iEndIndex = min( iEndIndex, in.GetLastRow() );
/* 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
@@ -793,7 +791,7 @@ void NoteDataUtil::Turn( NoteData &in, StepsType st, TrackMapping tt, float fSta
// transform notes
for( int t=0; t<in.GetNumTracks(); t++ )
for( int r=iStartIndex; r<=iEndIndex; r++ )
FOREACH_NONEMPTY_ROW_ALL_TRACKS_RANGE( in, r, iStartIndex, iEndIndex )
tempNoteDataOut.SetTapNote(t, r, tempNoteData.GetTapNote(iTakeFromTrack[t], r));
if( tt == super_shuffle )
@@ -806,13 +804,13 @@ void NoteDataUtil::Backwards( NoteData &in )
{
in.ConvertHoldNotesTo4s();
int max_row = in.GetLastRow();
for( int r=0; r<=max_row/2; r++ )
for( int t=0; t<in.GetNumTracks(); t++ )
{
int iRowEarlier = r;
int iRowLater = max_row-r;
for( int t=0; t<in.GetNumTracks(); t++ )
FOREACH_NONEMPTY_ROW_IN_TRACK_RANGE( in, t, r, 0, max_row/2 )
{
int iRowEarlier = r;
int iRowLater = max_row-r;
TapNote tnEarlier = in.GetTapNote(t, iRowEarlier);
TapNote tnLater = in.GetTapNote(t, iRowLater);
in.SetTapNote(t, iRowEarlier, tnLater);
@@ -825,10 +823,9 @@ void NoteDataUtil::Backwards( NoteData &in )
void NoteDataUtil::SwapSides( NoteData &in )
{
in.ConvertHoldNotesTo4s();
int max_row = in.GetLastRow();
for( int r=0; r<=max_row; r++ )
for( int t=0; t<in.GetNumTracks()/2; t++ )
{
for( int t=0; t<in.GetNumTracks()/2; t++ )
FOREACH_NONEMPTY_ROW_IN_TRACK( in, t, r )
{
int iTrackEarlier = t;
int iTrackLater = t + in.GetNumTracks()/2 + in.GetNumTracks()%2;
@@ -845,12 +842,18 @@ void NoteDataUtil::SwapSides( NoteData &in )
void NoteDataUtil::Little(NoteData &in, float fStartBeat, float fEndBeat)
{
if( fEndBeat == -1 )
fEndBeat = in.GetLastBeat();
int iStartIndex = BeatToNoteRow( fStartBeat );
int iEndIndex = BeatToNoteRow( fEndBeat );
// filter out all non-quarter notes
int max_row = in.GetLastRow();
for( int i=0; i<=max_row; i+=1 )
if( i % ROWS_PER_BEAT != 0 )
for( int c=0; c<in.GetNumTracks(); c++ )
in.SetTapNote( c, i, TAP_EMPTY );
for( int t=0; t<in.GetNumTracks(); t++ )
FOREACH_NONEMPTY_ROW_IN_TRACK_RANGE( in, t, i, iStartIndex, iEndIndex )
if( i % ROWS_PER_BEAT != 0 )
in.SetTapNote( t, i, TAP_EMPTY );
for( int i=in.GetNumHoldNotes()-1; i>=0; i-- )
if( fmodf(in.GetHoldNote(i).GetStartBeat(),1) != 0 ) // doesn't start on a beat
@@ -1508,7 +1511,8 @@ void NoteDataUtil::FixImpossibleRows( NoteData &in, StepsType st )
return;
// each row must pass at least one valid mask
for( int r=0; r<in.GetNumRows(); r++ )
int iLastRow = in.GetLastRow();
for( int r=0; r<=iLastRow; r++ )
{
// only check rows with jumps
if( in.GetNumTapNonEmptyTracks(r) < 2 )
+17 -16
View File
@@ -23,17 +23,18 @@ int NoteDataWithScoring::GetNumTapNotesWithScore( TapNoteScore tns, const float
{
int iNumSuccessfulTapNotes = 0;
if(fEndBeat == -1)
fEndBeat = GetNumBeats()+1;
if( fEndBeat == -1 )
fEndBeat = GetLastBeat();
unsigned iStartIndex = BeatToNoteRow( fStartBeat );
unsigned iEndIndex = BeatToNoteRow( fEndBeat );
int iStartIndex = BeatToNoteRow( fStartBeat );
int iEndIndex = BeatToNoteRow( fEndBeat );
iEndIndex = min( iEndIndex, GetLastRow() );
for( unsigned i=iStartIndex; i<min(float(iEndIndex), float(m_TapNoteScores[0].size())); i++ )
for( int t=0; t<GetNumTracks(); t++ )
{
for( int t=0; t<GetNumTracks(); t++ )
FOREACH_NONEMPTY_ROW_IN_TRACK_RANGE( *this, t, i, iStartIndex, iEndIndex )
{
if( this->GetTapNote(t, i).type != TapNote::empty && GetTapNoteScore(t, i) >= tns )
if( GetTapNoteScore(t, i) >= tns )
iNumSuccessfulTapNotes++;
}
}
@@ -44,13 +45,13 @@ int NoteDataWithScoring::GetNumTapNotesWithScore( TapNoteScore tns, const float
int NoteDataWithScoring::GetNumNWithScore( TapNoteScore tns, int MinTaps, const float fStartBeat, float fEndBeat ) const
{
if( fEndBeat == -1 )
fEndBeat = GetNumBeats();
fEndBeat = GetLastBeat();
int iStartIndex = BeatToNoteRow( fStartBeat );
int iEndIndex = BeatToNoteRow( fEndBeat );
iStartIndex = max( iStartIndex, 0 );
iEndIndex = min( iEndIndex, GetNumRows()-1 );
iEndIndex = min( iEndIndex, GetLastRow() );
int iNumSuccessfulDoubles = 0;
for( int i=iStartIndex; i<=iEndIndex; i++ )
@@ -76,10 +77,10 @@ int NoteDataWithScoring::GetNumNWithScore( TapNoteScore tns, int MinTaps, const
int NoteDataWithScoring::GetNumHoldNotesWithScore( HoldNoteScore hns, const float fStartBeat, float fEndBeat ) const
{
int iNumSuccessfulHolds = 0;
if( fEndBeat == -1 )
fEndBeat = GetLastBeat();
if(fEndBeat == -1)
fEndBeat = GetNumBeats();
int iNumSuccessfulHolds = 0;
int iStartIndex = BeatToNoteRow( fStartBeat );
int iEndIndex = BeatToNoteRow( fEndBeat );
@@ -98,13 +99,13 @@ int NoteDataWithScoring::GetNumHoldNotesWithScore( HoldNoteScore hns, const floa
int NoteDataWithScoring::GetSuccessfulMines( float fStartBeat, float fEndBeat ) const
{
if( fEndBeat == -1 )
fEndBeat = GetNumBeats();
fEndBeat = GetLastBeat();
int iStartIndex = BeatToNoteRow( fStartBeat );
int iEndIndex = BeatToNoteRow( fEndBeat );
iStartIndex = max( iStartIndex, 0 );
iEndIndex = min( iEndIndex, GetNumRows()-1 );
iEndIndex = min( iEndIndex, GetLastRow() );
int iNumSuccessfulMinesNotes = 0;
for( int i=iStartIndex; i<=iEndIndex; i++ )
@@ -123,14 +124,14 @@ int NoteDataWithScoring::GetSuccessfulMines( float fStartBeat, float fEndBeat )
int NoteDataWithScoring::GetSuccessfulHands( float fStartBeat, float fEndBeat ) const
{
if( fEndBeat == -1 )
fEndBeat = GetNumBeats();
fEndBeat = GetLastBeat();
int iStartIndex = BeatToNoteRow( fStartBeat );
int iEndIndex = BeatToNoteRow( fEndBeat );
/* Clamp to known-good ranges. */
iStartIndex = max( iStartIndex, 0 );
iEndIndex = min( iEndIndex, GetNumRows()-1 );
iEndIndex = min( iEndIndex, GetLastRow() );
int iNum = 0;
for( int i=iStartIndex; i<=iEndIndex; i++ )
+12
View File
@@ -38,6 +38,18 @@ struct TapNote
source = source_;
attackIndex = attackIndex_;
}
bool operator==( const TapNote &other )
{
#define COMPARE(x) if(x!=other.x) return false;
COMPARE(type);
COMPARE(source);
// COMPARE(bAttack);
// COMPARE(bKeysound);
COMPARE(attackIndex);
// COMPARE(keysoundIndex);
#undef COMPARE
return true;
}
};
const unsigned MAX_NUM_ATTACKS = 2*2*2; // 3 bits to hold the attack index currently
+2 -1
View File
@@ -115,9 +115,10 @@ static StepsType DetermineStepsType( int iPlayer, const NoteData &nd )
bool bTrackHasNote[NUM_BMS_TRACKS];
ZERO( bTrackHasNote );
int iLastRow = nd.GetLastRow();
for( int t=0; t<nd.GetNumTracks(); t++ )
{
for( int r=0; r<nd.GetNumRows(); r++ )
for( int r=0; r<=iLastRow; r++ )
{
if( nd.GetTapNoteX(t, r).type != TapNote::empty )
{
+1 -1
View File
@@ -474,7 +474,7 @@ void PlayerMinus::ApplyWaitingTransforms()
float fStartBeat, fEndBeat;
mod.GetAttackBeats( GAMESTATE->m_pCurSong, m_PlayerNumber, fStartBeat, fEndBeat );
fEndBeat = min( fEndBeat, GetNumBeats() );
fEndBeat = min( fEndBeat, GetLastBeat() );
LOG->Trace( "Applying transform '%s' from %f to %f to '%s'", mod.sModifier.c_str(), fStartBeat, fEndBeat,
GAMESTATE->m_pCurSong->GetTranslitMainTitle().c_str() );