remove hard-coded track limit in NoteData

This commit is contained in:
Chris Danford
2004-09-25 07:59:56 +00:00
parent b1d8b2a51e
commit 3e140b0af9
4 changed files with 71 additions and 69 deletions
+23
View File
@@ -16,6 +16,29 @@
GameManager* GAMEMAN = NULL; // global and accessable from anywhere in our program GameManager* GAMEMAN = NULL; // global and accessable from anywhere in our program
enum
{
TRACK_1 = 0,
TRACK_2,
TRACK_3,
TRACK_4,
TRACK_5,
TRACK_6,
TRACK_7,
TRACK_8,
TRACK_9,
TRACK_10,
TRACK_11,
TRACK_12,
TRACK_13, // BMS reader needs 13 tracks
// MD 10/26/03 - BMS reader needs a whole lot more than 13 tracks - more like 16
// because we have 11-16, 18, 19, 21-26, 28, 29 for IIDX double (bm-double7)
TRACK_14,
TRACK_15,
TRACK_16,
// MD 10/26/03 end
};
enum enum
{ {
GAME_DANCE, // Dance Dance Revolution GAME_DANCE, // Dance Dance Revolution
+43 -43
View File
@@ -12,14 +12,13 @@
NoteData::NoteData() NoteData::NoteData()
{ {
m_iNumTracks = 0;
Init(); Init();
} }
void NoteData::Init() void NoteData::Init()
{ {
ClearAll(); ClearAll();
m_iNumTracks = 0; // must do this after calling ClearAll()! m_TapNotes.clear();
} }
NoteData::~NoteData() NoteData::~NoteData()
@@ -28,26 +27,25 @@ NoteData::~NoteData()
int NoteData::GetNumTracks() const int NoteData::GetNumTracks() const
{ {
return m_iNumTracks; return m_TapNotes.size();
} }
void NoteData::SetNumTracks( int iNewNumTracks ) void NoteData::SetNumTracks( int iNewNumTracks )
{ {
m_iNumTracks = iNewNumTracks; ASSERT( iNewNumTracks > 0 );
// Make sure that all tracks are of the same length m_TapNotes.resize( iNewNumTracks );
ASSERT( m_iNumTracks > 0 );
int rows = m_TapNotes[0].size();
for( int t=0; t<MAX_NOTE_TRACKS; t++ ) // Enforce that all track vectors have the same length.
unsigned uNumRows = m_TapNotes[0].size();
for( unsigned t=0; t<m_TapNotes.size(); t++ )
{ {
if( t<m_iNumTracks ) m_TapNotes[t].resize( uNumRows, TAP_EMPTY );
m_TapNotes[t].resize( rows, TAP_EMPTY );
else
m_TapNotes[t].clear();
} }
/* Remove all hold notes that are out of bounds. */ /* 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 ) for( int h = m_HoldNotes.size()-1; h >= 0; --h )
if( m_HoldNotes[h].iTrack >= iNewNumTracks ) if( m_HoldNotes[h].iTrack >= iNewNumTracks )
m_HoldNotes.erase( m_HoldNotes.begin()+h ); m_HoldNotes.erase( m_HoldNotes.begin()+h );
@@ -58,17 +56,17 @@ void NoteData::SetNumTracks( int iNewNumTracks )
void NoteData::ClearRange( int iNoteIndexBegin, int iNoteIndexEnd ) void NoteData::ClearRange( int iNoteIndexBegin, int iNoteIndexEnd )
{ {
this->ConvertHoldNotesTo4s(); this->ConvertHoldNotesTo4s();
for( int c=0; c<m_iNumTracks; c++ ) for( unsigned t=0; t<m_TapNotes.size(); t++ )
{ {
for( int i=iNoteIndexBegin; i <= iNoteIndexEnd; i++ ) for( int i=iNoteIndexBegin; i <= iNoteIndexEnd; i++ )
SetTapNote(c, i, TAP_EMPTY); SetTapNote(t, i, TAP_EMPTY);
} }
this->Convert4sToHoldNotes(); this->Convert4sToHoldNotes();
} }
void NoteData::ClearAll() void NoteData::ClearAll()
{ {
for( int t=0; t<m_iNumTracks; t++ ) for( unsigned t=0; t<m_TapNotes.size(); t++ )
m_TapNotes[t].clear(); m_TapNotes[t].clear();
m_HoldNotes.clear(); m_HoldNotes.clear();
} }
@@ -77,7 +75,7 @@ void NoteData::ClearAll()
* all data in the range is overwritten.) */ * all data in the range is overwritten.) */
void NoteData::CopyRange( const NoteData* pFrom, int iFromIndexBegin, int iFromIndexEnd, int iToIndexBegin ) void NoteData::CopyRange( const NoteData* pFrom, int iFromIndexBegin, int iFromIndexEnd, int iToIndexBegin )
{ {
ASSERT( pFrom->m_iNumTracks == m_iNumTracks ); ASSERT( pFrom->GetNumTracks() == GetNumTracks() );
NoteData From, To; NoteData From, To;
From.To4s( *pFrom ); From.To4s( *pFrom );
@@ -88,7 +86,7 @@ void NoteData::CopyRange( const NoteData* pFrom, int iFromIndexBegin, int iFromI
while( f<=iFromIndexEnd ) while( f<=iFromIndexEnd )
{ {
for( int c=0; c<m_iNumTracks; c++ ) for( unsigned c=0; c<GetNumTracks(); c++ )
{ {
TapNote tn = From.GetTapNote( c, f ); TapNote tn = From.GetTapNote( c, f );
if( tn.type == TapNote::attack ) if( tn.type == TapNote::attack )
@@ -110,7 +108,7 @@ void NoteData::CopyRange( const NoteData* pFrom, int iFromIndexBegin, int iFromI
void NoteData::Config( const NoteData &From ) void NoteData::Config( const NoteData &From )
{ {
m_iNumTracks = From.m_iNumTracks; SetNumTracks( From.GetNumTracks() );
} }
void NoteData::CopyAll( const NoteData* pFrom ) void NoteData::CopyAll( const NoteData* pFrom )
@@ -118,7 +116,7 @@ void NoteData::CopyAll( const NoteData* pFrom )
Config(*pFrom); Config(*pFrom);
ClearAll(); ClearAll();
for( int c=0; c<m_iNumTracks; c++ ) for( unsigned c=0; c<GetNumTracks(); c++ )
m_TapNotes[c] = pFrom->m_TapNotes[c]; m_TapNotes[c] = pFrom->m_TapNotes[c];
m_HoldNotes = pFrom->m_HoldNotes; m_HoldNotes = pFrom->m_HoldNotes;
m_AttackMap = pFrom->m_AttackMap; m_AttackMap = pFrom->m_AttackMap;
@@ -130,7 +128,7 @@ bool NoteData::IsRowEmpty( int index ) const
if( index < 0 || index >= GetNumRows() ) if( index < 0 || index >= GetNumRows() )
return true; return true;
for( int t=0; t<m_iNumTracks; t++ ) for( unsigned t=0; t<GetNumTracks(); t++ )
if( GetTapNoteX(t, index).type != TapNote::empty ) if( GetTapNoteX(t, index).type != TapNote::empty )
return false; return false;
return true; return true;
@@ -138,7 +136,7 @@ bool NoteData::IsRowEmpty( int index ) const
bool NoteData::IsRangeEmpty( int track, int iIndexBegin, int iIndexEnd ) const bool NoteData::IsRangeEmpty( int track, int iIndexBegin, int iIndexEnd ) const
{ {
ASSERT( track<m_iNumTracks ); ASSERT( track < GetNumTracks() );
CLAMP( iIndexBegin, 0, GetNumRows()-1 ); CLAMP( iIndexBegin, 0, GetNumRows()-1 );
CLAMP( iIndexEnd, 0, GetNumRows()-1 ); CLAMP( iIndexEnd, 0, GetNumRows()-1 );
@@ -152,7 +150,7 @@ bool NoteData::IsRangeEmpty( int track, int iIndexBegin, int iIndexEnd ) const
int NoteData::GetNumTapNonEmptyTracks( int index ) const int NoteData::GetNumTapNonEmptyTracks( int index ) const
{ {
int iNum = 0; int iNum = 0;
for( int t=0; t<m_iNumTracks; t++ ) for( unsigned t=0; t<GetNumTracks(); t++ )
if( GetTapNote(t, index).type != TapNote::empty ) if( GetTapNote(t, index).type != TapNote::empty )
iNum++; iNum++;
return iNum; return iNum;
@@ -160,7 +158,7 @@ int NoteData::GetNumTapNonEmptyTracks( int index ) const
void NoteData::GetTapNonEmptyTracks( int index, set<int>& addTo ) const void NoteData::GetTapNonEmptyTracks( int index, set<int>& addTo ) const
{ {
for( int t=0; t<m_iNumTracks; t++ ) for( unsigned t=0; t<GetNumTracks(); t++ )
if( GetTapNote(t, index).type != TapNote::empty ) if( GetTapNote(t, index).type != TapNote::empty )
addTo.insert(t); addTo.insert(t);
} }
@@ -171,7 +169,7 @@ int NoteData::GetFirstNonEmptyTrack( int index ) const
if( index < 0 || index >= GetNumRows() ) if( index < 0 || index >= GetNumRows() )
return 0; return 0;
for( int t=0; t<m_iNumTracks; t++ ) for( unsigned t=0; t<GetNumTracks(); t++ )
if( GetTapNoteX( t, index ).type != TapNote::empty ) if( GetTapNoteX( t, index ).type != TapNote::empty )
return t; return t;
return -1; return -1;
@@ -184,7 +182,7 @@ int NoteData::GetNumTracksWithTap( int index ) const
return 0; return 0;
int iNum = 0; int iNum = 0;
for( int t=0; t<m_iNumTracks; t++ ) for( unsigned t=0; t<GetNumTracks(); t++ )
{ {
TapNote tn = GetTapNoteX( t, index ); TapNote tn = GetTapNoteX( t, index );
if( tn.type == TapNote::tap ) if( tn.type == TapNote::tap )
@@ -200,7 +198,7 @@ int NoteData::GetNumTracksWithTapOrHoldHead( int index ) const
return 0; return 0;
int iNum = 0; int iNum = 0;
for( int t=0; t<m_iNumTracks; t++ ) for( unsigned t=0; t<GetNumTracks(); t++ )
{ {
TapNote tn = GetTapNoteX( t, index ); TapNote tn = GetTapNoteX( t, index );
if( tn.type == TapNote::tap || tn.type == TapNote::hold_head ) if( tn.type == TapNote::tap || tn.type == TapNote::hold_head )
@@ -215,7 +213,7 @@ int NoteData::GetFirstTrackWithTap( int index ) const
if( index < 0 || index >= GetNumRows() ) if( index < 0 || index >= GetNumRows() )
return -1; return -1;
for( int t=0; t<m_iNumTracks; t++ ) for( unsigned t=0; t<GetNumTracks(); t++ )
{ {
TapNote tn = GetTapNoteX( t, index ); TapNote tn = GetTapNoteX( t, index );
if( tn.type == TapNote::tap ) if( tn.type == TapNote::tap )
@@ -230,7 +228,7 @@ int NoteData::GetFirstTrackWithTapOrHoldHead( int index ) const
if( index < 0 || index >= GetNumRows() ) if( index < 0 || index >= GetNumRows() )
return -1; return -1;
for( int t=0; t<m_iNumTracks; t++ ) for( unsigned t=0; t<GetNumTracks(); t++ )
{ {
TapNote tn = GetTapNoteX( t, index ); TapNote tn = GetTapNoteX( t, index );
if( tn.type == TapNote::tap || tn.type == TapNote::hold_head ) if( tn.type == TapNote::tap || tn.type == TapNote::hold_head )
@@ -328,7 +326,7 @@ void NoteData::PruneUnusedAttacksFromMap()
set<unsigned> setUsedIndices; set<unsigned> setUsedIndices;
int num_rows = GetNumRows(); int num_rows = GetNumRows();
for( int t=0; t<m_iNumTracks; t++ ) for( unsigned t=0; t<GetNumTracks(); t++ )
{ {
for( int r=0; r<num_rows; r++ ) for( int r=0; r<num_rows; r++ )
{ {
@@ -435,7 +433,7 @@ int NoteData::GetNumTapNotes( float fStartBeat, float fEndBeat ) const
iStartIndex = max( iStartIndex, 0 ); iStartIndex = max( iStartIndex, 0 );
iEndIndex = min( iEndIndex, GetNumRows()-1 ); iEndIndex = min( iEndIndex, GetNumRows()-1 );
for( int t=0; t<m_iNumTracks; t++ ) for( unsigned t=0; t<GetNumTracks(); t++ )
{ {
for( int i=iStartIndex; i<=iEndIndex; i++ ) for( int i=iStartIndex; i<=iEndIndex; i++ )
{ {
@@ -477,7 +475,7 @@ int NoteData::GetNumMines( float fStartBeat, float fEndBeat ) const
iStartIndex = max( iStartIndex, 0 ); iStartIndex = max( iStartIndex, 0 );
iEndIndex = min( iEndIndex, GetNumRows()-1 ); iEndIndex = min( iEndIndex, GetNumRows()-1 );
for( int t=0; t<m_iNumTracks; t++ ) for( unsigned t=0; t<GetNumTracks(); t++ )
{ {
for( int i=iStartIndex; i<=iEndIndex; i++ ) for( int i=iStartIndex; i<=iEndIndex; i++ )
if( GetTapNoteX(t, i).type == TapNote::mine ) if( GetTapNoteX(t, i).type == TapNote::mine )
@@ -505,7 +503,7 @@ int NoteData::GetNumRowsWithTapOrHoldHead( float fStartBeat, float fEndBeat ) co
int NoteData::RowNeedsHands( const int row ) const int NoteData::RowNeedsHands( const int row ) const
{ {
int iNumNotesThisIndex = 0; int iNumNotesThisIndex = 0;
for( int t=0; t<m_iNumTracks; t++ ) for( unsigned t=0; t<GetNumTracks(); t++ )
{ {
TapNote tn = GetTapNoteX(t, row); TapNote tn = GetTapNoteX(t, row);
switch( tn.type ) switch( tn.type )
@@ -581,7 +579,7 @@ int NoteData::GetNumN( int MinTaps, float fStartBeat, float fEndBeat ) const
for( int i=iStartIndex; i<=iEndIndex; i++ ) for( int i=iStartIndex; i<=iEndIndex; i++ )
{ {
int iNumNotesThisIndex = 0; int iNumNotesThisIndex = 0;
for( int t=0; t<m_iNumTracks; t++ ) for( unsigned t=0; t<GetNumTracks(); t++ )
{ {
TapNote tn = GetTapNoteX(t, i); TapNote tn = GetTapNoteX(t, i);
if( tn.type != TapNote::mine && tn.type != TapNote::empty ) // mines don't count if( tn.type != TapNote::mine && tn.type != TapNote::empty ) // mines don't count
@@ -617,7 +615,7 @@ void NoteData::Convert2sAnd3sToHoldNotes()
// Plus, allowing tap notes in the middle of a hold doesn't make sense! // Plus, allowing tap notes in the middle of a hold doesn't make sense!
int rows = GetLastRow(); int rows = GetLastRow();
for( int col=0; col<m_iNumTracks; col++ ) // foreach column for( int col=0; col<GetNumTracks(); col++ ) // foreach column
{ {
for( int i=0; i<=rows; i++ ) // foreach TapNote element for( int i=0; i<=rows; i++ ) // foreach TapNote element
{ {
@@ -695,7 +693,7 @@ void NoteData::From4s( const NoteData &out )
void NoteData::Convert4sToHoldNotes() void NoteData::Convert4sToHoldNotes()
{ {
int rows = GetLastRow(); int rows = GetLastRow();
for( int col=0; col<m_iNumTracks; col++ ) // foreach column for( int col=0; col<GetNumTracks(); col++ ) // foreach column
{ {
for( int i=0; i<=rows; i++ ) // foreach TapNote element for( int i=0; i<=rows; i++ ) // foreach TapNote element
{ {
@@ -738,14 +736,14 @@ void NoteData::LoadTransformed( const NoteData* pOriginal, int iNewNumTracks, co
Original.To4s( *pOriginal ); Original.To4s( *pOriginal );
Config( Original ); Config( Original );
m_iNumTracks = iNewNumTracks; SetNumTracks( iNewNumTracks );
// copy tracks // copy tracks
for( int t=0; t<m_iNumTracks; t++ ) for( unsigned t=0; t<GetNumTracks(); t++ )
{ {
const int iOriginalTrack = iOriginalTrackToTakeFrom[t]; const int iOriginalTrack = iOriginalTrackToTakeFrom[t];
ASSERT_M( iOriginalTrack < Original.m_iNumTracks, ssprintf("from %i >= %i (to %i)", ASSERT_M( iOriginalTrack < Original.GetNumTracks(), ssprintf("from %i >= %i (to %i)",
iOriginalTrack, Original.m_iNumTracks, iOriginalTrackToTakeFrom[t])); iOriginalTrack, Original.GetNumTracks(), iOriginalTrackToTakeFrom[t]));
if( iOriginalTrack == -1 ) if( iOriginalTrack == -1 )
continue; continue;
@@ -765,7 +763,7 @@ void NoteData::PadTapNotes(int rows)
needed += 100; /* optimization: give it a little more than it needs */ needed += 100; /* optimization: give it a little more than it needs */
for(int track = 0; track < m_iNumTracks; ++track) for(int track = 0; track < GetNumTracks(); ++track)
m_TapNotes[track].insert( m_TapNotes[track].end(), needed, TAP_EMPTY ); m_TapNotes[track].insert( m_TapNotes[track].end(), needed, TAP_EMPTY );
} }
@@ -778,6 +776,8 @@ void NoteData::MoveTapNoteTrack(int dest, int src)
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); PadTapNotes(row);
@@ -786,7 +786,7 @@ void NoteData::SetTapNote(int track, int row, TapNote t)
void NoteData::ReserveRows( int row ) void NoteData::ReserveRows( int row )
{ {
for(int track = 0; track < m_iNumTracks; ++track) for(int track = 0; track < GetNumTracks(); ++track)
m_TapNotes[track].reserve( row ); m_TapNotes[track].reserve( row );
} }
@@ -797,7 +797,7 @@ void NoteData::EliminateAllButOneTap(int row)
PadTapNotes(row); PadTapNotes(row);
int track; int track;
for(track = 0; track < m_iNumTracks; ++track) for(track = 0; track < GetNumTracks(); ++track)
{ {
if( m_TapNotes[track][row].type == TapNote::tap ) if( m_TapNotes[track][row].type == TapNote::tap )
break; break;
@@ -805,7 +805,7 @@ void NoteData::EliminateAllButOneTap(int row)
track++; track++;
for( ; track < m_iNumTracks; ++track) for( ; track < GetNumTracks(); ++track)
{ {
if( m_TapNotes[track][row].type == TapNote::tap ) if( m_TapNotes[track][row].type == TapNote::tap )
m_TapNotes[track][row] = TAP_EMPTY; m_TapNotes[track][row] = TAP_EMPTY;
+4 -3
View File
@@ -11,9 +11,10 @@
class NoteData class NoteData
{ {
/* Keep this aligned, so that they all have the same size. */ /* By convention, all TrackVectors have the same size.
vector<TapNote> m_TapNotes[MAX_NOTE_TRACKS]; * If you want to set the size of one, be sure to set the rest. */
int m_iNumTracks; typedef vector<TapNote> TrackVector;
vector<TrackVector> m_TapNotes;
vector<HoldNote> m_HoldNotes; vector<HoldNote> m_HoldNotes;
+1 -23
View File
@@ -52,29 +52,7 @@ extern TapNote TAP_ADDITION_TAP;
extern TapNote TAP_ADDITION_MINE; extern TapNote TAP_ADDITION_MINE;
// TODO: Don't have a hard-coded track limit. // TODO: Don't have a hard-coded track limit.
enum const int MAX_NOTE_TRACKS = 16;
{
TRACK_1 = 0,
TRACK_2,
TRACK_3,
TRACK_4,
TRACK_5,
TRACK_6,
TRACK_7,
TRACK_8,
TRACK_9,
TRACK_10,
TRACK_11,
TRACK_12,
TRACK_13, // BMS reader needs 13 tracks
// MD 10/26/03 - BMS reader needs a whole lot more than 13 tracks - more like 16
// because we have 11-16, 18, 19, 21-26, 28, 29 for IIDX double (bm-double7)
TRACK_14,
TRACK_15,
TRACK_16,
// MD 10/26/03 end
MAX_NOTE_TRACKS // leave this at the end
};
const int BEATS_PER_MEASURE = 4; const int BEATS_PER_MEASURE = 4;
const int ROWS_PER_BEAT = 48; // It is important that this number is evenly divisible by 2, 3, and 4. const int ROWS_PER_BEAT = 48; // It is important that this number is evenly divisible by 2, 3, and 4.