From efc61b33d63510a15cf533b1bd64420a95e49f4f Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Thu, 29 Apr 2004 00:33:09 +0000 Subject: [PATCH] simplify RangeOverlaps add ContainedByRange --- stepmania/src/NoteField.cpp | 11 +++-------- stepmania/src/NoteTypes.h | 14 ++++++++------ 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/stepmania/src/NoteField.cpp b/stepmania/src/NoteField.cpp index d1f97b06cc..f9a5910ac9 100644 --- a/stepmania/src/NoteField.cpp +++ b/stepmania/src/NoteField.cpp @@ -568,6 +568,8 @@ void NoteField::DrawPrimitives() } const bool bIsActive = m_ActiveHoldNotes[hn]; + const bool bIsHoldingNote = m_HeldHoldNotes[hn]; + const float fLife = GetHoldNoteLife( hn ); if( bIsActive ) SearchForSongBeat()->m_GhostArrowRow.SetHoldIsActive( hn.iTrack ); @@ -576,16 +578,9 @@ void NoteField::DrawPrimitives() bool bIsInSelectionRange = false; if( m_fBeginMarker!=-1 && m_fEndMarker!=-1 ) - bIsInSelectionRange = - m_fBeginMarker <= hn.GetStartBeat() && - hn.GetStartBeat() <= m_fEndMarker && - m_fBeginMarker <= hn.GetEndBeat() && - hn.GetEndBeat() <= m_fEndMarker; + bIsInSelectionRange = hn.ContainedByRange( BeatToNoteRow( m_fBeginMarker ), BeatToNoteRow( m_fEndMarker ) ); NoteDisplayCols *nd = CurDisplay->second; - - const bool bIsHoldingNote = m_HeldHoldNotes[hn]; - const float fLife = GetHoldNoteLife( hn ); nd->display[c].DrawHold( hn, bIsHoldingNote, bIsActive, fLife, bIsInSelectionRange ? fSelectedRangeGlow : m_fPercentFadeToFail, false, m_fYReverseOffsetPixels ); } diff --git a/stepmania/src/NoteTypes.h b/stepmania/src/NoteTypes.h index 32b35708f1..a159479f75 100644 --- a/stepmania/src/NoteTypes.h +++ b/stepmania/src/NoteTypes.h @@ -145,20 +145,22 @@ struct HoldNote bool RowIsInRange( int row ) const { return iStartRow <= row && row <= iEndRow; } bool RangeOverlaps( int start, int end ) const { - return - ( iStartRow >= start && end >= iEndRow ) || // other consumes us - ( iStartRow <= start && end <= iEndRow ) || // other inside us - ( iStartRow <= start && start <= iEndRow ) || // other overlaps us - ( iStartRow <= end && end <= iEndRow ); // other overlaps us + /* If the range doesn't overlap us, then start and end are either both before + * us or both after us. */ + return !( (start < iStartRow && end < iStartRow) || + (start > iEndRow && end > iEndRow) ); } bool RangeOverlaps( const HoldNote &hn ) const { return RangeOverlaps(hn.iStartRow, hn.iEndRow); } bool RangeInside( int start, int end ) const { return iStartRow <= start && end <= iEndRow; } + bool ContainedByRange( int start, int end ) const { return start <= iStartRow && iEndRow <= end; } float GetStartBeat() const { return NoteRowToBeat( iStartRow ); } float GetEndBeat() const { return NoteRowToBeat( iEndRow ); } - int iTrack; + + /* Invariant: iStartRow <= iEndRow */ int iStartRow; int iEndRow; + int iTrack; };