FakeSegments refactored.

Few things of note:

1) Slowly going away from hungarian notation.
2) Trying to respect public/private members.
2a) Yes, structs can work like this.
3) Trying to not require horizontal scrolling.

If anyone else wants a crack, go ahead:
we have 9 segments left. :)
This commit is contained in:
Jason Felds
2011-05-31 00:51:25 -04:00
parent 62365ee9e9
commit 1d3000e520
6 changed files with 189 additions and 133 deletions
+3 -3
View File
@@ -1012,11 +1012,11 @@ void NoteField::DrawPrimitives()
{
FOREACH_CONST( FakeSegment, timing.m_FakeSegments, 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) )
DrawFakeText( fBeat, seg->m_fLengthBeats );
DrawFakeText( fBeat, seg->GetLength() );
}
}
}
+1 -1
View File
@@ -146,7 +146,7 @@ static void GetTimingTags( vector<RString> &lines, TimingData timing, bool bIsSo
{
w.Init( "FAKES" );
FOREACH_CONST( FakeSegment, timing.m_FakeSegments, fs )
w.Write( fs->m_iStartRow, fs->m_fLengthBeats );
w.Write( fs->GetRow(), fs->GetLength() );
w.Finish();
}
+22 -18
View File
@@ -327,7 +327,7 @@ void TimingData::SetFakeAtRow( int iRow, float fNew )
{
unsigned i;
for( i=0; i<m_FakeSegments.size(); i++ )
if( m_FakeSegments[i].m_iStartRow == iRow )
if( m_FakeSegments[i].GetRow() == iRow )
break;
bool valid = iRow > 0 && fNew > 0;
if( i == m_FakeSegments.size() )
@@ -341,7 +341,7 @@ void TimingData::SetFakeAtRow( int iRow, float fNew )
{
if( valid )
{
m_FakeSegments[i].m_fLengthBeats = fNew;
m_FakeSegments[i].SetLength(fNew);
}
else
m_FakeSegments.erase( m_FakeSegments.begin()+i, m_FakeSegments.begin()+i+1 );
@@ -442,9 +442,9 @@ float TimingData::GetFakeAtRow( int iFakeRow ) const
{
for( unsigned i=0; i<m_FakeSegments.size(); i++ )
{
if( m_FakeSegments[i].m_iStartRow == iFakeRow )
if( m_FakeSegments[i].GetRow() == iFakeRow )
{
return m_FakeSegments[i].m_fLengthBeats;
return m_FakeSegments[i].GetLength();
}
}
return 0;
@@ -538,7 +538,7 @@ int TimingData::GetFakeSegmentIndexAtRow( int iNoteRow ) const
for( i=0; i<m_FakeSegments.size()-1; i++ )
{
const FakeSegment& s = m_FakeSegments[i+1];
if( s.m_iStartRow > iNoteRow )
if( s.GetRow() > iNoteRow )
break;
}
return static_cast<int>(i);
@@ -574,7 +574,8 @@ bool TimingData::IsFakeAtRow( int iNoteRow ) const
int i = GetFakeSegmentIndexAtRow( iNoteRow );
const FakeSegment& s = m_FakeSegments[i];
if( s.m_iStartRow <= iNoteRow && iNoteRow < ( s.m_iStartRow + BeatToNoteRow(s.m_fLengthBeats) ) )
float beatRow = NoteRowToBeat(iNoteRow);
if( s.GetBeat() <= beatRow && beatRow < ( s.GetBeat() + s.GetLength() ) )
{
return true;
}
@@ -1114,21 +1115,24 @@ void TimingData::ScaleRegion( float fScale, int iStartIndex, int iEndIndex, bool
for( unsigned i = 0; i < m_FakeSegments.size(); i++ )
{
const int iSegStartRow = m_FakeSegments[i].m_iStartRow;
const int iSegEndRow = iSegStartRow + BeatToNoteRow( m_FakeSegments[i].m_fLengthBeats );
FakeSegment &f = m_FakeSegments[i];
const int iSegStartRow = f.GetRow();
const int iSegEndRow = iSegStartRow + BeatToNoteRow( f.GetLength() );
if( iSegEndRow >= iStartIndex )
{
if( iSegEndRow > iEndIndex )
m_FakeSegments[i].m_fLengthBeats += NoteRowToBeat(lrintf((iEndIndex - iStartIndex) * (fScale - 1)));
f.SetLength(f.GetLength()
+ NoteRowToBeat(lrintf((iEndIndex - iStartIndex) * (fScale - 1))));
else
m_FakeSegments[i].m_fLengthBeats = NoteRowToBeat(lrintf((iSegEndRow - iStartIndex) * fScale));
f.SetLength(NoteRowToBeat(lrintf((iSegEndRow - iStartIndex) * fScale)));
}
if( iSegStartRow < iStartIndex )
continue;
else if( iSegStartRow > iEndIndex )
m_FakeSegments[i].m_iStartRow += lrintf((iEndIndex - iStartIndex) * (fScale - 1));
f.SetRow(f.GetRow()
+ lrintf((iEndIndex - iStartIndex) * (fScale - 1)));
else
m_FakeSegments[i].m_iStartRow = lrintf((iSegStartRow - iStartIndex) * fScale) + iStartIndex;
f.SetRow(lrintf((iSegStartRow - iStartIndex) * fScale) + iStartIndex);
}
for( unsigned i = 0; i < m_ScrollSegments.size(); i++ )
@@ -1236,9 +1240,9 @@ void TimingData::InsertRows( int iStartRow, int iRowsToAdd )
for( unsigned i = 0; i < m_FakeSegments.size(); i++ )
{
FakeSegment &fake = m_FakeSegments[i];
if( fake.m_iStartRow < iStartRow )
if( fake.GetRow() < iStartRow )
continue;
fake.m_iStartRow += iRowsToAdd;
fake.SetRow(fake.GetRow() + iRowsToAdd);
}
for( unsigned i = 0; i < m_ScrollSegments.size(); i++ )
@@ -1422,18 +1426,18 @@ void TimingData::DeleteRows( int iStartRow, int iRowsToDelete )
for( unsigned i = 0; i < m_FakeSegments.size(); i++ )
{
FakeSegment &fake = m_FakeSegments[i];
if( fake.m_iStartRow < iStartRow )
int keyRow = fake.GetRow();
if( keyRow < iStartRow )
continue;
if( fake.m_iStartRow < iStartRow+iRowsToDelete )
if( keyRow < iStartRow+iRowsToDelete )
{
m_FakeSegments.erase( m_FakeSegments.begin()+i, m_FakeSegments.begin()+i+1 );
--i;
continue;
}
fake.m_iStartRow -= iRowsToDelete;
fake.SetRow(keyRow - iRowsToDelete);
}
for( unsigned i = 0; i < m_ScrollSegments.size(); i++ )
-108
View File
@@ -854,114 +854,6 @@ struct ScrollSegment
bool operator>=( const ScrollSegment &other ) const { return !operator<(other); }
};
/**
* @brief Identifies when a whole region of arrows is to be ignored.
*
* FakeSegments are similar to the Fake Tap Notes in that the contents
* inside are neither for nor against the player. They can be useful for
* mission modes, in conjunction with WarpSegments, or perhaps other
* uses not thought up at the time of this comment. Unlike the Warp
* Segments, these are not magically jumped over: instead, these are
* drawn normally.
*
* These were inspired by the Pump It Up series. */
struct FakeSegment
{
/**
* @brief Create a simple Fake Segment with default values.
*
* It is best to override the values as soon as possible.
*/
FakeSegment() : m_iStartRow(-1), m_fLengthBeats(-1) { }
/**
* @brief Create a Fake Segment with the specified values.
* @param s the starting row of this segment.
* @param r the number of rows this segment lasts.
*/
FakeSegment( int s, int r ): m_iStartRow(s),
m_fLengthBeats(NoteRowToBeat(r)) {}
/**
* @brief Creates a Fake Segment with the specified values.
* @param s the starting row of this segment.
* @param b the number of beats this segment lasts.
*/
FakeSegment( int s, float b ): m_iStartRow(max(0, s)),
m_fLengthBeats(max(0, b)) {}
/**
* @brief Create a Fake Segment with the specified values.
* @param s the starting beat in this segment.
* @param r the number of rows this segment lasts.
*/
FakeSegment( float s, int r ):
m_iStartRow(max(0, BeatToNoteRow(s))),
m_fLengthBeats(max(0, NoteRowToBeat(r))) {}
/**
* @brief Creates a Fake Segment with the specified values.
* @param s the starting beat of this segment.
* @param b the number of beats this segment lasts.
*/
FakeSegment( float s, float b ):
m_iStartRow(BeatToNoteRow(s)),
m_fLengthBeats(b) {}
/**
* @brief The row in which the FakeSegment activates.
*/
int m_iStartRow;
/**
* @brief The number of beats the FakeSegment is alive for.
*/
float m_fLengthBeats;
/**
* @brief Compares two FakeSegments to see if they are equal to each other.
* @param other the other FakeSegment to compare to.
* @return the equality of the two segments.
*/
bool operator==( const FakeSegment &other ) const
{
COMPARE( m_iStartRow );
COMPARE( m_fLengthBeats );
return true;
}
/**
* @brief Compares two FakeSegments to see if they are not equal to each other.
* @param other the other FakeSegment to compare to.
* @return the inequality of the two segments.
*/
bool operator!=( const FakeSegment &other ) const { return !operator==(other); }
/**
* @brief Compares two FakeSegments to see if one is less than the other.
* @param other the other FakeSegment to compare to.
* @return the truth/falsehood of if the first is less than the second.
*/
bool operator<( const FakeSegment &other ) const
{
return m_iStartRow < other.m_iStartRow ||
( m_iStartRow == other.m_iStartRow && m_fLengthBeats < other.m_fLengthBeats );
}
/**
* @brief Compares two FakeSegments to see if one is less than or equal to the other.
* @param other the other FakeSegment to compare to.
* @return the truth/falsehood of if the first is less or equal to than the second.
*/
bool operator<=( const FakeSegment &other ) const
{
return ( operator<(other) || operator==(other) );
}
/**
* @brief Compares two FakeSegments to see if one is greater than the other.
* @param other the other FakeSegment to compare to.
* @return the truth/falsehood of if the first is greater than the second.
*/
bool operator>( const FakeSegment &other ) const { return !operator<=(other); }
/**
* @brief Compares two FakeSegments to see if one is greater than or equal to the other.
* @param other the other FakeSegment to compare to.
* @return the truth/falsehood of if the first is greater than or equal to the second.
*/
bool operator>=( const FakeSegment &other ) const { return !operator<(other); }
};
/**
* @brief Holds data for translating beats<->seconds.
*/
+65 -3
View File
@@ -1,10 +1,13 @@
#include "TimingSegments.h"
TimingSegment::TimingSegment() : startingRow(-1) {}
TimingSegment::TimingSegment() :
startingRow(-1) {}
TimingSegment::TimingSegment(int s) : startingRow(s) {}
TimingSegment::TimingSegment(int s) :
startingRow(s) {}
TimingSegment::TimingSegment(float s) : startingRow(BeatToNoteRow(s)) {}
TimingSegment::TimingSegment(float s) :
startingRow(BeatToNoteRow(s)) {}
TimingSegment::~TimingSegment() {}
@@ -27,6 +30,65 @@ float TimingSegment::GetBeat() const
return NoteRowToBeat(this->startingRow);
}
FakeSegment::FakeSegment():
TimingSegment(-1), lengthBeats(-1) {}
FakeSegment::FakeSegment( int s, int r ):
TimingSegment(max(0, s)), lengthBeats(NoteRowToBeat(max(0, r))) {}
FakeSegment::FakeSegment( int s, float b ):
TimingSegment(max(0, s)), lengthBeats(max(0, b)) {}
FakeSegment::FakeSegment( float s, int r ):
TimingSegment(max(0, s)), lengthBeats(max(0, NoteRowToBeat(r))) {}
FakeSegment::FakeSegment( float s, float b ):
TimingSegment(max(0, s)), lengthBeats(max(0, b)) {}
float FakeSegment::GetLength() const
{
return this->lengthBeats;
}
void FakeSegment::SetLength(const float b)
{
this->lengthBeats = b;
}
bool FakeSegment::operator==( const FakeSegment &other ) const
{
if (this->GetRow() != other.GetRow()) return false;
if (this->GetLength() != other.GetLength()) return false;
return true;
}
bool FakeSegment::operator!=( const FakeSegment &other ) const
{
return !this->operator==(other);
}
bool FakeSegment::operator<( const FakeSegment &other ) const
{
if (this->GetRow() < other.GetRow()) return true;
if (this->GetRow() > other.GetRow()) return false;
return this->GetLength() < other.GetLength();
}
bool FakeSegment::operator<=( const FakeSegment &other ) const
{
return ( this->operator<(other) || this->operator==(other) );
}
bool FakeSegment::operator>( const FakeSegment &other ) const
{
return !this->operator<=(other);
}
bool FakeSegment::operator>=( const FakeSegment &other ) const
{
return !this->operator<(other);
}
/**
* @file
* @author Jason Felds (c) 2011
+98
View File
@@ -56,6 +56,104 @@ private:
int startingRow;
};
/**
* @brief Identifies when a whole region of arrows is to be ignored.
*
* FakeSegments are similar to the Fake Tap Notes in that the contents
* inside are neither for nor against the player. They can be useful for
* mission modes, in conjunction with WarpSegments, or perhaps other
* uses not thought up at the time of this comment. Unlike the Warp
* Segments, these are not magically jumped over: instead, these are
* drawn normally.
*
* These were inspired by the Pump It Up series. */
struct FakeSegment : public TimingSegment
{
/**
* @brief Create a simple Fake Segment with default values.
*
* It is best to override the values as soon as possible.
*/
FakeSegment();
/**
* @brief Create a Fake Segment with the specified values.
* @param s the starting row of this segment.
* @param r the number of rows this segment lasts.
*/
FakeSegment( int s, int r );
/**
* @brief Creates a Fake Segment with the specified values.
* @param s the starting row of this segment.
* @param b the number of beats this segment lasts.
*/
FakeSegment( int s, float b );
/**
* @brief Create a Fake Segment with the specified values.
* @param s the starting beat in this segment.
* @param r the number of rows this segment lasts.
*/
FakeSegment( float s, int r );
/**
* @brief Creates a Fake Segment with the specified values.
* @param s the starting beat of this segment.
* @param b the number of beats this segment lasts.
*/
FakeSegment( float s, float b );
/**
* @brief Get the length in beats of the FakeSegment.
* @return the length in beats. */
float GetLength() const;
/**
* @brief Set the length in beats of the FakeSegment.
* @param b the length in beats. */
void SetLength(const float b);
/**
* @brief Compares two FakeSegments to see if they are equal to each other.
* @param other the other FakeSegment to compare to.
* @return the equality of the two segments.
*/
bool operator==( const FakeSegment &other ) const;
/**
* @brief Compares two FakeSegments to see if they are not equal to each other.
* @param other the other FakeSegment to compare to.
* @return the inequality of the two segments.
*/
bool operator!=( const FakeSegment &other ) const;
/**
* @brief Compares two FakeSegments to see if one is less than the other.
* @param other the other FakeSegment to compare to.
* @return the truth/falsehood of if the first is less than the second.
*/
bool operator<( const FakeSegment &other ) const;
/**
* @brief Compares two FakeSegments to see if one is less than or equal to the other.
* @param other the other FakeSegment to compare to.
* @return the truth/falsehood of if the first is less or equal to than the second.
*/
bool operator<=( const FakeSegment &other ) const;
/**
* @brief Compares two FakeSegments to see if one is greater than the other.
* @param other the other FakeSegment to compare to.
* @return the truth/falsehood of if the first is greater than the second.
*/
bool operator>( const FakeSegment &other ) const;
/**
* @brief Compares two FakeSegments to see if one is greater than or equal to the other.
* @param other the other FakeSegment to compare to.
* @return the truth/falsehood of if the first is greater than or equal to the second.
*/
bool operator>=( const FakeSegment &other ) const;
private:
/**
* @brief The number of beats the FakeSegment is alive for.
*/
float lengthBeats;
};
#undef COMPARE
#endif