From 3d83bdf90698cf4a455eceffd415ec8468ae7496 Mon Sep 17 00:00:00 2001 From: Steve Checkoway Date: Sun, 9 Jul 2006 20:20:57 +0000 Subject: [PATCH] Allow one Player to share the NoteField of another Player. Also calculate the distance to the closest note or -1 if no note is close. --- stepmania/src/Player.cpp | 16 ++++++++++++++++ stepmania/src/Player.h | 3 +++ 2 files changed, 19 insertions(+) diff --git a/stepmania/src/Player.cpp b/stepmania/src/Player.cpp index 3a2b6756f3..3e26e4422b 100644 --- a/stepmania/src/Player.cpp +++ b/stepmania/src/Player.cpp @@ -443,6 +443,12 @@ void Player::Load( const NoteData& noteData ) } } +void Player::SetSharedNoteField( Player *pPlayer ) +{ + ASSERT( m_pNoteField ); + m_pNoteField->SetSharedNoteField( pPlayer->m_pNoteField ); +} + void Player::Update( float fDeltaTime ) { // Don't update if we havn't been loaded yet. @@ -923,6 +929,16 @@ int Player::GetClosestNote( int col, int iNoteRow, int iMaxRowsAhead, int iMaxRo return iNextIndex; } +int Player::GetClosestNoteDistance( int col, int row ) const +{ + const int iStepSearchRows = BeatToNoteRow( StepSearchDistance * GAMESTATE->m_fCurBPS * GAMESTATE->m_SongOptions.m_fMusicRate ); + int iIndexOverlappingNote = GetClosestNote( col, row, iStepSearchRows, iStepSearchRows, false ); + + if( iIndexOverlappingNote <= 0 ) + return iIndexOverlappingNote; + return abs( iIndexOverlappingNote - row ); +} + void Player::Step( int col, const RageTimer &tm, bool bHeld ) { diff --git a/stepmania/src/Player.h b/stepmania/src/Player.h index 230c642736..45bfc332c4 100644 --- a/stepmania/src/Player.h +++ b/stepmania/src/Player.h @@ -69,10 +69,13 @@ public: void SetPaused( bool bPaused ) { m_bPaused = bPaused; } float GetMaxStepDistanceSeconds(); + // Returns -1 if no notes are close, otherwise return the distance to a nongraded note. + int GetClosestNoteDistance( int col, int row ) const; NoteData m_NoteData; bool HasNoteField() { return m_pNoteField != NULL; } + void SetSharedNoteField( Player *pPlayer ); protected: void HandleStep( int col, const RageTimer &tm, bool bHeld );