Player::GetClosestNote, Player::GetClosestNoteDirectional with note rows

and iterators; eliminates arbitrary "999999" constant
This commit is contained in:
Glenn Maynard
2005-01-25 19:39:31 +00:00
parent ce8c71ce8b
commit f91c0b49ba
2 changed files with 35 additions and 41 deletions
+34 -40
View File
@@ -608,40 +608,43 @@ void Player::DrawHoldJudgments()
} }
} }
int Player::GetClosestNoteDirectional( int col, int iStartRow, int iMaxRowsAhead, bool bAllowGraded, bool bForward ) const int Player::GetClosestNoteDirectional( int col, int iStartRow, int iEndRow, bool bAllowGraded, bool bForward ) const
{ {
/* Be sure to check iStartRow itself, too. */ NoteData::const_iterator begin, end;
int iRow = iStartRow; m_NoteData.GetTapNoteRange( col, iStartRow, iEndRow, begin, end );
while( abs(iStartRow-iRow) <= iMaxRowsAhead )
if( !bForward )
swap( begin, end );
while( begin != end )
{ {
/* Is iRow the row we want? */ if( !bForward )
do --begin;
{
TapNote tn = m_NoteData.GetTapNote(col, iRow); /* Is this the row we want? */
do {
const TapNote &tn = begin->second;
if( tn.type == TapNote::empty ) if( tn.type == TapNote::empty )
break; break;
if( !bAllowGraded && tn.result.tns != TNS_NONE ) if( !bAllowGraded && tn.result.tns != TNS_NONE )
break; break;
return iRow;
return begin->first;
} while(0); } while(0);
if( bForward && !m_NoteData.GetNextTapNoteRowForTrack( col, iRow ) ) if( bForward )
return -1; ++begin;
if( !bForward && !m_NoteData.GetPrevTapNoteRowForTrack( col, iRow ) )
return -1;
} }
return -1; return -1;
} }
/* Find the closest note to fBeat. */ /* Find the closest note to fBeat. */
int Player::GetClosestNote( int col, float fBeat, float fMaxBeatsAhead, float fMaxBeatsBehind, bool bAllowGraded ) const int Player::GetClosestNote( int col, int iNoteRow, int iMaxRowsAhead, int iMaxRowsBehind, bool bAllowGraded ) const
{ {
// look for the closest matching step
const int iRow = BeatToNoteRow( fBeat );
// Start at iIndexStartLookingAt and search outward. // Start at iIndexStartLookingAt and search outward.
int iNextIndex = GetClosestNoteDirectional( col, iRow, BeatToNoteRow(fMaxBeatsAhead), bAllowGraded, true ); int iNextIndex = GetClosestNoteDirectional( col, iNoteRow, iNoteRow+iMaxRowsAhead, bAllowGraded, true );
int iPrevIndex = GetClosestNoteDirectional( col, iRow, BeatToNoteRow(fMaxBeatsBehind), bAllowGraded, false ); int iPrevIndex = GetClosestNoteDirectional( col, iNoteRow-iMaxRowsBehind, iNoteRow, bAllowGraded, false );
if( iNextIndex == -1 && iPrevIndex == -1 ) if( iNextIndex == -1 && iPrevIndex == -1 )
return -1; return -1;
@@ -651,12 +654,10 @@ int Player::GetClosestNote( int col, float fBeat, float fMaxBeatsAhead, float fM
return iNextIndex; return iNextIndex;
/* Figure out which row is closer. */ /* Figure out which row is closer. */
const float DistToFwd = fabsf( fBeat-NoteRowToBeat(iNextIndex) ); if( abs(iNoteRow-iNextIndex) > abs(iNoteRow-iPrevIndex) )
const float DistToBack = fabsf( fBeat-NoteRowToBeat(iPrevIndex) );
if( DistToFwd > DistToBack )
return iPrevIndex; return iPrevIndex;
return iNextIndex; else
return iNextIndex;
} }
@@ -681,10 +682,9 @@ void Player::Step( int col, const RageTimer &tm )
// //
// Check for step on a TapNote // Check for step on a TapNote
// //
int iIndexOverlappingNote = GetClosestNote( col, fSongBeat, const int iStepSearchRows = BeatToNoteRow( StepSearchDistance * GAMESTATE->m_fCurBPS * GAMESTATE->m_SongOptions.m_fMusicRate );
StepSearchDistance * GAMESTATE->m_fCurBPS * GAMESTATE->m_SongOptions.m_fMusicRate, int iIndexOverlappingNote = GetClosestNote( col, BeatToNoteRow(fSongBeat),
StepSearchDistance * GAMESTATE->m_fCurBPS * GAMESTATE->m_SongOptions.m_fMusicRate, iStepSearchRows, iStepSearchRows, false );
false );
//LOG->Trace( "iIndexStartLookingAt = %d, iNumElementsToExamine = %d", iIndexStartLookingAt, iNumElementsToExamine ); //LOG->Trace( "iIndexStartLookingAt = %d, iNumElementsToExamine = %d", iIndexStartLookingAt, iNumElementsToExamine );
@@ -945,26 +945,20 @@ void Player::Step( int col, const RageTimer &tm )
{ {
case TapNote::tap: case TapNote::tap:
case TapNote::hold_head: case TapNote::hold_head:
// don't the row if this note is a mine or tap attack // don't judge the row if this note is a mine or tap attack
if( NoteDataWithScoring::IsRowCompletelyJudged( m_NoteData, iIndexOverlappingNote ) ) if( NoteDataWithScoring::IsRowCompletelyJudged( m_NoteData, iIndexOverlappingNote ) )
OnRowCompletelyJudged( iIndexOverlappingNote ); OnRowCompletelyJudged( iIndexOverlappingNote );
} }
if( score == TNS_MISS || score == TNS_BOO ) if( score == TNS_MISS || score == TNS_BOO )
{
m_iDCState = AS2D_MISS; m_iDCState = AS2D_MISS;
} else if( score == TNS_GOOD || score == TNS_GREAT )
if( score == TNS_GOOD || score == TNS_GREAT )
{
m_iDCState = AS2D_GOOD; m_iDCState = AS2D_GOOD;
} else if( score == TNS_PERFECT || score == TNS_MARVELOUS )
if( score == TNS_PERFECT || score == TNS_MARVELOUS )
{ {
m_iDCState = AS2D_GREAT; m_iDCState = AS2D_GREAT;
if( m_pLifeMeter && m_pLifeMeter->GetLife() == 1.0f) // full life if( m_pLifeMeter && m_pLifeMeter->GetLife() == 1.0f) // full life
{
m_iDCState = AS2D_FEVER; // super celebrate time :) m_iDCState = AS2D_FEVER; // super celebrate time :)
}
} }
if( m_pNoteField ) if( m_pNoteField )
m_pNoteField->Step( col, score ); m_pNoteField->Step( col, score );
@@ -977,9 +971,9 @@ void Player::Step( int col, const RageTimer &tm )
/* Search for keyed sounds separately. If we can't find a nearby note, search /* Search for keyed sounds separately. If we can't find a nearby note, search
* backwards indefinitely, and ignore grading. */ * backwards indefinitely, and ignore grading. */
iIndexOverlappingNote = GetClosestNote( col, fSongBeat, iIndexOverlappingNote = GetClosestNote( col, BeatToNoteRow(fSongBeat),
999999.f, MAX_NOTE_ROW,
StepSearchDistance * GAMESTATE->m_fCurBPS * GAMESTATE->m_SongOptions.m_fMusicRate, iStepSearchRows,
true ); true );
if( iIndexOverlappingNote != -1 ) if( iIndexOverlappingNote != -1 )
{ {
+1 -1
View File
@@ -68,7 +68,7 @@ protected:
void DrawHoldJudgments(); void DrawHoldJudgments();
int GetClosestNoteDirectional( int col, int iStartRow, int iMaxRowsAhead, bool bAllowGraded, bool bForward ) const; int GetClosestNoteDirectional( int col, int iStartRow, int iMaxRowsAhead, bool bAllowGraded, bool bForward ) const;
int GetClosestNote( int col, float fBeat, float fMaxBeatsAhead, float fMaxBeatsBehind, bool bAllowGraded ) const; int GetClosestNote( int col, int iNoteRow, int iMaxRowsAhead, int iMaxRowsBehind, bool bAllowGraded ) const;
PlayerState* m_pPlayerState; PlayerState* m_pPlayerState;
PlayerStageStats* m_pPlayerStageStats; PlayerStageStats* m_pPlayerStageStats;