diff --git a/stepmania/src/InputFilter.cpp b/stepmania/src/InputFilter.cpp index 3e2a9f674d..0e181ecaca 100644 --- a/stepmania/src/InputFilter.cpp +++ b/stepmania/src/InputFilter.cpp @@ -18,6 +18,13 @@ InputFilter* INPUTFILTER = NULL; // global and accessable from anywhere in our program +static const float TIME_BEFORE_SLOW_REPEATS = 0.25f; +static const float TIME_BEFORE_FAST_REPEATS = 1.5f; + +static const float SLOW_REPEATS_PER_SEC = 8; +static const float FAST_REPEATS_PER_SEC = 8; + +static float g_fTimeBeforeSlow, g_fTimeBeforeFast, g_fTimeBetweenSlow, g_fTimeBetweenFast; InputFilter::InputFilter() @@ -31,6 +38,7 @@ InputFilter::InputFilter() m_fSecsToForce[d][b] = -1; Reset(); + ResetRepeatRate(); } InputFilter::~InputFilter() @@ -44,6 +52,19 @@ void InputFilter::Reset() ResetDevice( InputDevice(i) ); } +void InputFilter::SetRepeatRate( float fSlowDelay, float fSlowRate, float fFastDelay, float fFastRate ) +{ + g_fTimeBeforeSlow = fSlowDelay; + g_fTimeBeforeFast = fFastDelay; + g_fTimeBetweenSlow = 1/fSlowRate; + g_fTimeBetweenFast = 1/fFastRate; +} + +void InputFilter::ResetRepeatRate() +{ + SetRepeatRate( TIME_BEFORE_SLOW_REPEATS, SLOW_REPEATS_PER_SEC, TIME_BEFORE_FAST_REPEATS, FAST_REPEATS_PER_SEC ); +} + void InputFilter::ButtonPressed( DeviceInput di, bool Down ) { LockMut(*queuemutex); @@ -202,16 +223,16 @@ void InputFilter::Update(float fDeltaTime) float fTimeBetweenRepeats; InputEventType iet; - if( fOldHoldTime > TIME_BEFORE_SLOW_REPEATS ) + if( fOldHoldTime > g_fTimeBeforeSlow ) { - if( fOldHoldTime > TIME_BEFORE_FAST_REPEATS ) + if( fOldHoldTime > g_fTimeBeforeFast ) { - fTimeBetweenRepeats = TIME_BETWEEN_FAST_REPEATS; + fTimeBetweenRepeats = g_fTimeBetweenFast; iet = IET_FAST_REPEAT; } else { - fTimeBetweenRepeats = TIME_BETWEEN_SLOW_REPEATS; + fTimeBetweenRepeats = g_fTimeBetweenSlow; iet = IET_SLOW_REPEAT; } if( int(fOldHoldTime/fTimeBetweenRepeats) != int(fNewHoldTime/fTimeBetweenRepeats) ) @@ -234,6 +255,11 @@ float InputFilter::GetSecsHeld( DeviceInput di ) return m_fSecsHeld[di.device][di.button]; } +void InputFilter::ResetKeyRepeat( DeviceInput di ) +{ + m_fSecsHeld[di.device][di.button] = 0; +} + void InputFilter::GetInputEvents( InputEventArray &array ) { LockMut(*queuemutex); diff --git a/stepmania/src/InputFilter.h b/stepmania/src/InputFilter.h index 863273ad0b..763266af5e 100644 --- a/stepmania/src/InputFilter.h +++ b/stepmania/src/InputFilter.h @@ -15,13 +15,6 @@ #include "RageInputDevice.h" -const float TIME_BEFORE_SLOW_REPEATS = 0.25f; -const float TIME_BEFORE_FAST_REPEATS = 1.5f; - -//const float TIME_BETWEEN_SLOW_REPEATS = 0.25f; -const float TIME_BETWEEN_SLOW_REPEATS = 0.125f; -const float TIME_BETWEEN_FAST_REPEATS = 0.125f; - enum InputEventType { IET_FIRST_PRESS, IET_SLOW_REPEAT, IET_FAST_REPEAT, IET_RELEASE }; struct InputEvent : public DeviceInput @@ -59,6 +52,10 @@ public: void Reset(); void Update(float fDeltaTime); + void SetRepeatRate( float fSlowDelay, float fSlowRate, float fFastDelay, float fFastRate ); + void ResetRepeatRate(); + void ResetKeyRepeat( DeviceInput di ); + bool IsBeingPressed( DeviceInput di ); float GetSecsHeld( DeviceInput di ); diff --git a/stepmania/src/InputMapper.cpp b/stepmania/src/InputMapper.cpp index c59dc193fb..50ccbe03f7 100644 --- a/stepmania/src/InputMapper.cpp +++ b/stepmania/src/InputMapper.cpp @@ -630,3 +630,29 @@ float InputMapper::GetSecsHeld( StyleInput StyleI ) StyleToGame( StyleI, GameI ); return GetSecsHeld( GameI ); } + +void InputMapper::ResetKeyRepeat( GameInput GameI ) +{ + for( int i=0; iResetKeyRepeat( DeviceI ); + } +} + +void InputMapper::ResetKeyRepeat( MenuInput MenuI ) +{ + GameInput GameI[4]; + MenuToGame( MenuI, GameI ); + for( int i=0; i<4; i++ ) + if( GameI[i].IsValid() ) + ResetKeyRepeat( GameI[i] ); +} + +void InputMapper::ResetKeyRepeat( StyleInput StyleI ) +{ + GameInput GameI; + StyleToGame( StyleI, GameI ); + ResetKeyRepeat( GameI ); +} diff --git a/stepmania/src/InputMapper.h b/stepmania/src/InputMapper.h index 94ad6a8dd1..ef30ecf24e 100644 --- a/stepmania/src/InputMapper.h +++ b/stepmania/src/InputMapper.h @@ -62,6 +62,10 @@ public: bool IsButtonDown( MenuInput MenuI ); bool IsButtonDown( StyleInput StyleI ); + void ResetKeyRepeat( GameInput GameI ); + void ResetKeyRepeat( MenuInput MenuI ); + void ResetKeyRepeat( StyleInput StyleI ); + protected: // all the DeviceInputs that map to a GameInput DeviceInput m_GItoDI[MAX_GAME_CONTROLLERS][MAX_GAME_BUTTONS][NUM_GAME_TO_DEVICE_SLOTS];