diff --git a/stepmania/src/TimingData.cpp b/stepmania/src/TimingData.cpp index 3e2f3a44f1..b6a4035a85 100644 --- a/stepmania/src/TimingData.cpp +++ b/stepmania/src/TimingData.cpp @@ -4,66 +4,35 @@ #include "RageUtil.h" #include "RageLog.h" #include "NoteTypes.h" +#include "Foreach.h" #include -void BPMSegment::SetBPM( float f ) -{ - m_fBPS = f / 60.0f; -} - -float BPMSegment::GetBPM() const -{ - return m_fBPS * 60.0f; -} - TimingData::TimingData() { m_fBeat0OffsetInSeconds = 0; } -static int CompareBPMSegments(const BPMSegment &seg1, const BPMSegment &seg2) -{ - return seg1.m_iStartIndex < seg2.m_iStartIndex; -} - -void SortBPMSegmentsArray( vector &arrayBPMSegments ) -{ - sort( arrayBPMSegments.begin(), arrayBPMSegments.end(), CompareBPMSegments ); -} - -static int CompareStopSegments(const StopSegment &seg1, const StopSegment &seg2) -{ - return seg1.m_iStartRow < seg2.m_iStartRow; -} - -void SortStopSegmentsArray( vector &arrayStopSegments ) -{ - sort( arrayStopSegments.begin(), arrayStopSegments.end(), CompareStopSegments ); -} - void TimingData::GetActualBPM( float &fMinBPMOut, float &fMaxBPMOut ) const { fMinBPMOut = FLT_MAX; fMaxBPMOut = 0; - for( unsigned i=0; iGetBPM(); + fMaxBPMOut = max( fBPM, fMaxBPMOut ); + fMinBPMOut = min( fBPM, fMinBPMOut ); } } void TimingData::AddBPMSegment( const BPMSegment &seg ) { - m_BPMSegments.push_back( seg ); - SortBPMSegmentsArray( m_BPMSegments ); + m_BPMSegments.insert( upper_bound(m_BPMSegments.begin(), m_BPMSegments.end(), seg), seg ); } void TimingData::AddStopSegment( const StopSegment &seg ) { - m_StopSegments.push_back( seg ); - SortStopSegmentsArray( m_StopSegments ); + m_StopSegments.insert( upper_bound(m_StopSegments.begin(), m_StopSegments.end(), seg), seg ); } /* Change an existing BPM segment, merge identical segments together or insert a new one. */ @@ -187,10 +156,7 @@ BPMSegment& TimingData::GetBPMSegmentAtBeat( float fBeat ) { static BPMSegment empty; if( m_BPMSegments.empty() ) - { - empty = BPMSegment(); return empty; - } int i = GetBPMSegmentIndexAtBeat( fBeat ); return m_BPMSegments[i]; diff --git a/stepmania/src/TimingData.h b/stepmania/src/TimingData.h index 7cbc3a104f..d9577710e2 100644 --- a/stepmania/src/TimingData.h +++ b/stepmania/src/TimingData.h @@ -9,13 +9,13 @@ struct BPMSegment { - BPMSegment() { m_iStartIndex = -1; m_fBPS = -1; } - BPMSegment( int s, float b ) { m_iStartIndex = s; m_fBPS = b/60.0f; } + BPMSegment() : m_iStartIndex(-1), m_fBPS(-1.0f) { } + BPMSegment( int s, float b ) { m_iStartIndex = max( 0, s ); SetBPM( b ); } int m_iStartIndex; float m_fBPS; - void SetBPM( float f ); - float GetBPM() const; + void SetBPM( float f ) { m_fBPS = f / 60.0f; } + float GetBPM() const { return m_fBPS * 60.0f; } bool operator==( const BPMSegment &other ) const { @@ -24,12 +24,13 @@ struct BPMSegment return true; } bool operator!=( const BPMSegment &other ) const { return !operator==(other); } + bool operator<( const BPMSegment &other ) const { return m_iStartIndex < other.m_iStartIndex; } }; struct StopSegment { - StopSegment() { m_fStopSeconds = -1; m_iStartRow = -1; } - StopSegment( int s, float f ) { m_iStartRow = s; m_fStopSeconds = f; } + StopSegment() : m_iStartRow(-1), m_fStopSeconds(-1.0f) { } + StopSegment( int s, float f ) { m_iStartRow = max( 0, s ); m_fStopSeconds = max( 0.0f, f ); } int m_iStartRow; float m_fStopSeconds; @@ -40,6 +41,7 @@ struct StopSegment return true; } bool operator!=( const StopSegment &other ) const { return !operator==(other); } + bool operator<( const StopSegment &other ) const { return m_iStartRow < other.m_iStartRow; } }; class TimingData