From 754bce5c982633957d726359708c5dd68afedd81 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sat, 22 Jan 2005 03:11:29 +0000 Subject: [PATCH] optimize rendering iteration --- stepmania/src/NoteData.cpp | 15 +++++++++++++++ stepmania/src/NoteData.h | 7 ++++++- stepmania/src/NoteField.cpp | 8 ++++++-- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/stepmania/src/NoteData.cpp b/stepmania/src/NoteData.cpp index 422ffc0067..320504f2d8 100644 --- a/stepmania/src/NoteData.cpp +++ b/stepmania/src/NoteData.cpp @@ -772,6 +772,21 @@ bool NoteData::GetPrevTapNoteRowForTrack( int track, int &rowInOut ) const return true; } +/* Return an iterator range. This can be used to iterate trackwise over a range of + * notes. It's like FOREACH_NONEMPTY_ROW_IN_TRACK_RANGE, except it only requires + * two map searches (iterating is O(1)), but the iterators will become invalid if + * the notes they represent disappear, so you need to pay attention to how you modify + * the data. */ +void NoteData::GetTapNoteRange( int iTrack, int iStartRow, int iEndRow, TrackMap::const_iterator &begin, TrackMap::const_iterator &end ) const +{ + ASSERT_M( iTrack < GetNumTracks(), ssprintf("%i,%i", iTrack, GetNumTracks()) ); + ASSERT_M( iStartRow <= iEndRow, ssprintf("%i > %i", iStartRow, iEndRow) ); + + const TrackMap &mapTrack = m_TapNotes[iTrack]; + begin = mapTrack.lower_bound( iStartRow ); + end = mapTrack.upper_bound( iEndRow ); +} + bool NoteData::GetNextTapNoteRowForAllTracks( int &rowInOut ) const { int iClosestNextRow = 999999; diff --git a/stepmania/src/NoteData.h b/stepmania/src/NoteData.h index 09bf6ed35c..56b8d4ec84 100644 --- a/stepmania/src/NoteData.h +++ b/stepmania/src/NoteData.h @@ -21,9 +21,12 @@ class NoteData { +public: + typedef map TrackMap; + +private: // There's no point in inserting empty notes into the map. // Any blank space in the map is defined to be empty. - typedef map TrackMap; vector m_TapNotes; vector m_HoldNotes; @@ -60,6 +63,8 @@ public: bool GetNextTapNoteRowForAllTracks( int &rowInOut ) const; bool GetPrevTapNoteRowForTrack( int track, int &rowInOut ) const; + void GetTapNoteRange( int iTrack, int iStartRow, int iEndRow, TrackMap::const_iterator &begin, TrackMap::const_iterator &end ) const; + void MoveTapNoteTrack( int dest, int src ); void SetTapNote( int track, int row, const TapNote& tn ); diff --git a/stepmania/src/NoteField.cpp b/stepmania/src/NoteField.cpp index 48bdfd84a2..fd911675d3 100644 --- a/stepmania/src/NoteField.cpp +++ b/stepmania/src/NoteField.cpp @@ -605,9 +605,13 @@ void NoteField::DrawPrimitives() NextDisplay = CurDisplay; ++NextDisplay; // draw notes from furthest to closest - FOREACH_NONEMPTY_ROW_IN_TRACK_RANGE_REVERSE( *m_pNoteData, c, i, iFirstIndexToDraw, iLastIndexToDraw ) + + NoteData::TrackMap::const_iterator begin, end; + m_pNoteData->GetTapNoteRange( c, iFirstIndexToDraw, iLastIndexToDraw, begin, end ); + for( ; begin != end; ++begin ) { - const TapNote &tn = m_pNoteData->GetTapNote(c, i); + int i = begin->first; + const TapNote &tn = begin->second; //m_pNoteData->GetTapNote(c, i); if( tn.type == TapNote::empty ) // no note here continue; // skip