From 8a315634dc664b040e4c53c4a165b998a56ff6a0 Mon Sep 17 00:00:00 2001 From: Jason Felds Date: Tue, 31 May 2011 01:20:22 -0400 Subject: [PATCH] Bring TickcountSegments to refactored level. I wonder how many of the 8 will be claimed upon wakeup. --- src/NoteField.cpp | 6 +-- src/NotesLoaderKSF.cpp | 7 ++-- src/NotesWriterSSC.cpp | 2 +- src/TimingData.cpp | 33 +++++++-------- src/TimingData.h | 77 ----------------------------------- src/TimingSegments.cpp | 61 +++++++++++++++++++++++++++- src/TimingSegments.h | 92 ++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 176 insertions(+), 102 deletions(-) diff --git a/src/NoteField.cpp b/src/NoteField.cpp index 86373a7b34..e54b650bd5 100644 --- a/src/NoteField.cpp +++ b/src/NoteField.cpp @@ -946,11 +946,11 @@ void NoteField::DrawPrimitives() // Tickcount text FOREACH_CONST( TickcountSegment, timing.m_TickcountSegments, seg ) { - if( seg->m_iStartRow >= iFirstRowToDraw && seg->m_iStartRow <= iLastRowToDraw ) + if( seg->GetRow() >= iFirstRowToDraw && seg->GetRow() <= iLastRowToDraw ) { - float fBeat = NoteRowToBeat(seg->m_iStartRow); + float fBeat = seg->GetBeat(); if( IS_ON_SCREEN(fBeat) ) - DrawTickcountText( fBeat, seg->m_iTicks ); + DrawTickcountText( fBeat, seg->GetTicks() ); } } } diff --git a/src/NotesLoaderKSF.cpp b/src/NotesLoaderKSF.cpp index 276f0c1e49..604c049ea1 100644 --- a/src/NotesLoaderKSF.cpp +++ b/src/NotesLoaderKSF.cpp @@ -541,13 +541,12 @@ static bool LoadGlobalData( const RString &sPath, Song &out, bool &bKIUCompliant * and stops. It will be called again in LoadFromKSFFile for the * actual steps. */ iTickCount = StringToInt( sParams[1] ); - iTickCount = iTickCount > 0 ? iTickCount : 2; // again, Direct Move uses 4 as a default. + iTickCount = iTickCount > 0 ? iTickCount : 4; // add a tickcount for those using the [Player] // CheckpointsUseTimeSignatures metric. -aj // It's not with timesigs now -DaisuMaster - TickcountSegment tcs; - tcs.m_iStartRow = BeatToNoteRow(0.0f); - tcs.m_iTicks = iTickCount > ROWS_PER_BEAT ? ROWS_PER_BEAT : iTickCount; + TickcountSegment tcs(0); + tcs.SetTicks(iTickCount > ROWS_PER_BEAT ? ROWS_PER_BEAT : iTickCount); out.m_SongTiming.AddTickcountSegment( tcs ); } else if ( sValueName=="STEP" ) diff --git a/src/NotesWriterSSC.cpp b/src/NotesWriterSSC.cpp index 716a34f7c5..46b12ee872 100644 --- a/src/NotesWriterSSC.cpp +++ b/src/NotesWriterSSC.cpp @@ -122,7 +122,7 @@ static void GetTimingTags( vector &lines, TimingData timing, bool bIsSo ASSERT( !timing.m_TickcountSegments.empty() ); w.Init( "TICKCOUNTS" ); FOREACH_CONST( TickcountSegment, timing.m_TickcountSegments, ts ) - w.Write( ts->m_iStartRow, ts->m_iTicks ); + w.Write( ts->GetRow(), ts->GetTicks() ); w.Finish(); ASSERT( !timing.m_ComboSegments.empty() ); diff --git a/src/TimingData.cpp b/src/TimingData.cpp index bee63236e2..2cf4bded87 100644 --- a/src/TimingData.cpp +++ b/src/TimingData.cpp @@ -205,21 +205,21 @@ void TimingData::SetTickcountAtRow( int iRow, int iTicks ) { unsigned i; for( i=0; i= iRow ) + if( m_TickcountSegments[i].GetRow() >= iRow ) break; - if( i == m_TickcountSegments.size() || m_TickcountSegments[i].m_iStartRow != iRow ) + if( i == m_TickcountSegments.size() || m_TickcountSegments[i].GetRow() != iRow ) { // No TickcountSegment here. Make a new segment if required. - if( i == 0 || m_TickcountSegments[i-1].m_iTicks != iTicks ) + if( i == 0 || m_TickcountSegments[i-1].GetTicks() != iTicks ) AddTickcountSegment( TickcountSegment(iRow, iTicks ) ); } else // TickcountSegment being modified is m_TickcountSegments[i] { - if( i > 0 && m_TickcountSegments[i-1].m_iTicks == iTicks ) + if( i > 0 && m_TickcountSegments[i-1].GetTicks() == iTicks ) m_TickcountSegments.erase( m_TickcountSegments.begin()+i, m_TickcountSegments.begin()+i+1 ); else - m_TickcountSegments[i].m_iTicks = iTicks; + m_TickcountSegments[i].SetTicks(iTicks); } } @@ -732,7 +732,7 @@ int TimingData::GetTickcountSegmentIndexAtRow( int iRow ) const { unsigned i; for (i=0; i < m_TickcountSegments.size() - 1; i++ ) - if( m_TickcountSegments[i+1].m_iStartRow > iRow ) + if( m_TickcountSegments[i+1].GetRow() > iRow ) break; return static_cast(i); } @@ -749,7 +749,7 @@ TickcountSegment& TimingData::GetTickcountSegmentAtRow( int iRow ) int TimingData::GetTickcountAtRow( int iRow ) const { - return m_TickcountSegments[GetTickcountSegmentIndexAtRow( iRow )].m_iTicks; + return m_TickcountSegments[GetTickcountSegmentIndexAtRow( iRow )].GetTicks(); } float TimingData::GetPreviousLabelSegmentBeatAtRow( int iRow ) const @@ -1071,13 +1071,14 @@ void TimingData::ScaleRegion( float fScale, int iStartIndex, int iEndIndex, bool for ( unsigned i = 0; i < m_TickcountSegments.size(); i++ ) { - const int iSegStart = m_TickcountSegments[i].m_iStartRow; + TickcountSegment &t = m_TickcountSegments[i]; + const int iSegStart = t.GetRow(); if( iSegStart < iStartIndex ) continue; else if( iSegStart > iEndIndex ) - m_TickcountSegments[i].m_iStartRow += lrintf( (iEndIndex - iStartIndex) * (fScale - 1) ); + t.SetRow(t.GetRow() + lrintf( (iEndIndex - iStartIndex) * (fScale - 1) )); else - m_TickcountSegments[i].m_iStartRow = lrintf( (iSegStart - iStartIndex) * fScale ) + iStartIndex; + t.SetRow(lrintf( (iSegStart - iStartIndex) * fScale ) + iStartIndex); } for ( unsigned i = 0; i < m_ComboSegments.size(); i++ ) @@ -1209,9 +1210,9 @@ void TimingData::InsertRows( int iStartRow, int iRowsToAdd ) for( unsigned i = 0; i < m_TickcountSegments.size(); i++ ) { TickcountSegment &tick = m_TickcountSegments[i]; - if( tick.m_iStartRow < iStartRow ) + if( tick.GetRow() < iStartRow ) continue; - tick.m_iStartRow += iRowsToAdd; + tick.SetRow(tick.GetRow() + iRowsToAdd); } for( unsigned i = 0; i < m_ComboSegments.size(); i++ ) @@ -1354,13 +1355,13 @@ void TimingData::DeleteRows( int iStartRow, int iRowsToDelete ) for( unsigned i = 0; i < m_TickcountSegments.size(); i++ ) { TickcountSegment &tick = m_TickcountSegments[i]; - + int keyRow = tick.GetRow(); // Before deleted region: - if( tick.m_iStartRow < iStartRow ) + if( keyRow < iStartRow ) continue; // Inside deleted region: - if( tick.m_iStartRow < iStartRow+iRowsToDelete ) + if( keyRow < iStartRow+iRowsToDelete ) { m_TickcountSegments.erase( m_TickcountSegments.begin()+i, m_TickcountSegments.begin()+i+1 ); --i; @@ -1368,7 +1369,7 @@ void TimingData::DeleteRows( int iStartRow, int iRowsToDelete ) } // After deleted region: - tick.m_iStartRow -= iRowsToDelete; + tick.SetRow(keyRow - iRowsToDelete); } for( unsigned i = 0; i < m_ComboSegments.size(); i++ ) diff --git a/src/TimingData.h b/src/TimingData.h index d3465a0fe3..8c003c5e85 100644 --- a/src/TimingData.h +++ b/src/TimingData.h @@ -412,83 +412,6 @@ struct WarpSegment bool operator>=( const WarpSegment &other ) const { return !operator<(other); } }; -/** - * @brief Identifies when a chart is to have a different tickcount value for hold notes. - * - * A tickcount segment is used to better replicate the checkpoint hold - * system used by various based video games. The number is used to - * represent how many ticks can be counted in one beat. - */ -struct TickcountSegment -{ - /** - * @brief Creates a simple Tickcount Segment with default values. - * - * It is best to override the values as soon as possible. - */ - TickcountSegment() : m_iStartRow(-1), m_iTicks(2) { } - /** - * @brief Creates a Tickcount Segment with the specified starting row and beats per second. - * @param s the starting row of this segment. - * @param t the amount of ticks counted per beat. - */ - TickcountSegment( int s, int t ): m_iStartRow(max(0, s)), - m_iTicks(max(0, t)) {} - /** - * @brief The row in which the TickcountSegment activates. - */ - int m_iStartRow; - /** - * @brief The amount of ticks counted per beat. - */ - int m_iTicks; - - /** - * @brief Compares two TickcountSegments to see if they are equal to each other. - * @param other the other TickcountSegment to compare to. - * @return the equality of the two segments. - */ - bool operator==( const TickcountSegment &other ) const - { - COMPARE( m_iStartRow ); - COMPARE( m_iTicks ); - return true; - } - /** - * @brief Compares two TickcountSegments to see if they are not equal to each other. - * @param other the other TickcountSegment to compare to. - * @return the inequality of the two segments. - */ - bool operator!=( const TickcountSegment &other ) const { return !operator==(other); } - /** - * @brief Compares two TickcountSegments to see if one is less than the other. - * @param other the other TickcountSegment to compare to. - * @return the truth/falsehood of if the first is less than the second. - */ - bool operator<( const TickcountSegment &other ) const { return m_iStartRow < other.m_iStartRow; } - /** - * @brief Compares two TickcountSegments to see if one is less than or equal to the other. - * @param other the other TickcountSegment to compare to. - * @return the truth/falsehood of if the first is less or equal to than the second. - */ - bool operator<=( const TickcountSegment &other ) const - { - return ( operator<(other) || operator==(other) ); - } - /** - * @brief Compares two TickcountSegments to see if one is greater than the other. - * @param other the other TickcountSegment to compare to. - * @return the truth/falsehood of if the first is greater than the second. - */ - bool operator>( const TickcountSegment &other ) const { return !operator<=(other); } - /** - * @brief Compares two TickcountSegments to see if one is greater than or equal to the other. - * @param other the other TickcountSegment to compare to. - * @return the truth/falsehood of if the first is greater than or equal to the second. - */ - bool operator>=( const TickcountSegment &other ) const { return !operator<(other); } -}; - /** * @brief Identifies when a chart is to have a different combo multiplier value. * diff --git a/src/TimingSegments.cpp b/src/TimingSegments.cpp index 4d1f6df95d..2cf8c3da51 100644 --- a/src/TimingSegments.cpp +++ b/src/TimingSegments.cpp @@ -31,7 +31,7 @@ float TimingSegment::GetBeat() const } FakeSegment::FakeSegment(): - TimingSegment(-1), lengthBeats(-1) {} + TimingSegment(), lengthBeats(-1) {} FakeSegment::FakeSegment( int s, int r ): TimingSegment(max(0, s)), lengthBeats(NoteRowToBeat(max(0, r))) {} @@ -89,6 +89,65 @@ bool FakeSegment::operator>=( const FakeSegment &other ) const return !this->operator<(other); } +TickcountSegment::TickcountSegment() : + TimingSegment(), ticks(4) {} + +TickcountSegment::TickcountSegment(int s) : + TimingSegment(s), ticks(4) {} + +TickcountSegment::TickcountSegment(float s) : + TimingSegment(s), ticks(4) {} + +TickcountSegment::TickcountSegment( int s, int t ): + TimingSegment(max(0, s)), ticks(max(0, t)) {} + +TickcountSegment::TickcountSegment( float s, int t ): + TimingSegment(max(0, s)), ticks(max(0, t)) {} + +int TickcountSegment::GetTicks() const +{ + return this->ticks; +} + +void TickcountSegment::SetTicks(const int i) +{ + this->ticks = i; +} + +bool TickcountSegment::operator==( const TickcountSegment &other ) const +{ + if (this->GetRow() != other.GetRow()) return false; + if (this->GetTicks() != other.GetTicks()) return false; + return true; +} + +bool TickcountSegment::operator!=( const TickcountSegment &other ) const +{ + return !this->operator==(other); +} + +bool TickcountSegment::operator<( const TickcountSegment &other ) const +{ + if (this->GetRow() < other.GetRow()) return true; + if (this->GetRow() > other.GetRow()) return false; + return this->GetTicks() < other.GetTicks(); +} + +bool TickcountSegment::operator<=( const TickcountSegment &other ) const +{ + return ( this->operator<(other) || this->operator==(other) ); +} + +bool TickcountSegment::operator>( const TickcountSegment &other ) const +{ + return !this->operator<=(other); +} + +bool TickcountSegment::operator>=( const TickcountSegment &other ) const +{ + return !this->operator<(other); +} + /** * @file * @author Jason Felds (c) 2011 diff --git a/src/TimingSegments.h b/src/TimingSegments.h index 44c2050bc2..5c34e7ac6b 100644 --- a/src/TimingSegments.h +++ b/src/TimingSegments.h @@ -153,6 +153,98 @@ private: float lengthBeats; }; +/** + * @brief Identifies when a chart is to have a different tickcount value + * for hold notes. + * + * A tickcount segment is used to better replicate the checkpoint hold + * system used by various based video games. The number is used to + * represent how many ticks can be counted in one beat. + */ +struct TickcountSegment : public TimingSegment +{ + /** + * @brief Creates a simple Tickcount Segment with default values. + * + * It is best to override the values as soon as possible. + */ + TickcountSegment(); + /** + * @brief Creates a TickcountSegment with specified values. + * @param s the starting row. */ + TickcountSegment(int s); + /** + * @brief Creates a TickcountSegment with specified values. + * @param s the starting beat. */ + TickcountSegment(float s); + /** + * @brief Creates a Tickcount Segment with the specified values. + * @param s the starting row. + * @param t the amount of ticks counted per beat. + */ + TickcountSegment( int s, int t ); + /** + * @brief Creates a Tickcount Segment with the specified values. + * @param s the starting beat. + * @param t the amount of ticks counted per beat. + */ + TickcountSegment( float s, int t ); + + /** + * @brief Get the number of ticks in this TickcountSegment. + * @return the tickcount. */ + int GetTicks() const; + + /** + * @brief Set the number of ticks in this TickcountSegment. + * @param i the tickcount. */ + void SetTicks(const int i); + + /** + * @brief Compares two TickcountSegments to see if they are equal to each other. + * @param other the other TickcountSegment to compare to. + * @return the equality of the two segments. + */ + bool operator==( const TickcountSegment &other ) const; + /** + * @brief Compares two TickcountSegments to see if they are not equal to each other. + * @param other the other TickcountSegment to compare to. + * @return the inequality of the two segments. + */ + bool operator!=( const TickcountSegment &other ) const; + /** + * @brief Compares two TickcountSegments to see if one is less than the other. + * @param other the other TickcountSegment to compare to. + * @return the truth/falsehood of if the first is less than the second. + */ + bool operator<( const TickcountSegment &other ) const; + /** + * @brief Compares two TickcountSegments to see if one is less than or equal to the other. + * @param other the other TickcountSegment to compare to. + * @return the truth/falsehood of if the first is less or equal to than the second. + */ + bool operator<=( const TickcountSegment &other ) const; + /** + * @brief Compares two TickcountSegments to see if one is greater than the other. + * @param other the other TickcountSegment to compare to. + * @return the truth/falsehood of if the first is greater than the second. + */ + bool operator>( const TickcountSegment &other ) const; + /** + * @brief Compares two TickcountSegments to see if one is greater than or equal to the other. + * @param other the other TickcountSegment to compare to. + * @return the truth/falsehood of if the first is greater than or equal to the second. + */ + bool operator>=( const TickcountSegment &other ) const; + +private: + /** + * @brief The amount of ticks counted per beat. + */ + int ticks; +}; + + #undef COMPARE