From f652510cc5da4549e4813c141bd8f76817e0b56e Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Thu, 14 Sep 2006 20:39:54 +0000 Subject: [PATCH] RepeatStopKey: stop repeating a key until it's released --- stepmania/src/InputFilter.cpp | 21 +++++++++++++++++++++ stepmania/src/InputFilter.h | 1 + stepmania/src/InputMapper.cpp | 20 ++++++++++++++++++++ stepmania/src/InputMapper.h | 3 +++ 4 files changed, 45 insertions(+) diff --git a/stepmania/src/InputFilter.cpp b/stepmania/src/InputFilter.cpp index e7f2903f11..af21b09d35 100644 --- a/stepmania/src/InputFilter.cpp +++ b/stepmania/src/InputFilter.cpp @@ -43,6 +43,7 @@ namespace } DeviceInputList g_CurrentState; + set g_DisableRepeat; } /* @@ -178,6 +179,9 @@ void InputFilter::CheckButtonChange( ButtonState &bs, DeviceInput di, const Rage di.ts = bs.m_BeingHeldTime; ReportButtonChange( di, bs.m_bLastReportedHeld? IET_FIRST_PRESS:IET_RELEASE ); + + if( !bs.m_bLastReportedHeld ) + g_DisableRepeat.erase( di ); } void InputFilter::ReportButtonChange( const DeviceInput &di, InputEventType t ) @@ -245,6 +249,10 @@ void InputFilter::Update( float fDeltaTime ) continue; } + /* If repeats are disabled for this button, skip. */ + if( g_DisableRepeat.find(di) != g_DisableRepeat.end() ) + continue; + const float fOldHoldTime = bs.m_fSecsHeld; bs.m_fSecsHeld += fDeltaTime; const float fNewHoldTime = bs.m_fSecsHeld; @@ -320,6 +328,19 @@ void InputFilter::ResetKeyRepeat( const DeviceInput &di ) GetButtonState( di ).m_fSecsHeld = 0; } +/* Stop repeating the specified key until released. */ +void InputFilter::RepeatStopKey( const DeviceInput &di ) +{ + LockMut(*queuemutex); + + /* If the button is up, do nothing. */ + ButtonState &bs = GetButtonState( di ); + if( !bs.m_bLastReportedHeld ) + return; + + g_DisableRepeat.insert( di ); +} + void InputFilter::GetInputEvents( vector &array ) { array.clear(); diff --git a/stepmania/src/InputFilter.h b/stepmania/src/InputFilter.h index 86177ae26c..061a1cd523 100644 --- a/stepmania/src/InputFilter.h +++ b/stepmania/src/InputFilter.h @@ -47,6 +47,7 @@ public: void SetRepeatRate( float fDelay, float fRepeatRate ); void ResetRepeatRate(); void ResetKeyRepeat( const DeviceInput &di ); + void RepeatStopKey( const DeviceInput &di ); // If aButtonState is NULL, use the last reported state. bool IsBeingPressed( const DeviceInput &di, const DeviceInputList *pButtonState = NULL ) const; diff --git a/stepmania/src/InputMapper.cpp b/stepmania/src/InputMapper.cpp index f6c0389d6a..3ca6018aee 100644 --- a/stepmania/src/InputMapper.cpp +++ b/stepmania/src/InputMapper.cpp @@ -811,6 +811,26 @@ bool InputMapper::IsBeingPressed( const MenuInput &MenuI, PlayerNumber pn ) return false; } +void InputMapper::RepeatStopKey( const GameInput &GameI ) +{ + for( int i=0; iRepeatStopKey( DeviceI ); + } +} + +void InputMapper::RepeatStopKey( MenuButton MenuI, PlayerNumber pn ) +{ + GameInput GameI[4]; + MenuToGame( MenuI, pn, GameI ); + for( int i=0; i<4; i++ ) + if( GameI[i].IsValid() ) + RepeatStopKey( GameI[i] ); +} + float InputMapper::GetSecsHeld( const GameInput &GameI, MultiPlayer mp ) { float fMaxSecsHeld = 0; diff --git a/stepmania/src/InputMapper.h b/stepmania/src/InputMapper.h index 89e782274c..479d96966b 100644 --- a/stepmania/src/InputMapper.h +++ b/stepmania/src/InputMapper.h @@ -49,6 +49,9 @@ public: void ResetKeyRepeat( const GameInput &GameI ); void ResetKeyRepeat( const MenuInput &MenuI, PlayerNumber pn ); + void RepeatStopKey( const GameInput &GameI ); + void RepeatStopKey( MenuButton MenuI, PlayerNumber pn ); + struct Mapping { bool IsEndMarker() const { return iSlotIndex==-1; }