slight comment/cleanup
This commit is contained in:
+35
-40
@@ -23,8 +23,8 @@ struct ButtonState
|
|||||||
// The time that we actually reported the last event (used for debouncing).
|
// The time that we actually reported the last event (used for debouncing).
|
||||||
RageTimer m_LastReportTime;
|
RageTimer m_LastReportTime;
|
||||||
|
|
||||||
// The timestamp of the last reported change. Unlike m_BeingHeldTime, this
|
// The timestamp of the last reported change. Unlike m_BeingHeldTime, this
|
||||||
// value is debounced along with the input state. (This is the same as
|
// value is debounced along with the input state. (This is the same as
|
||||||
// m_fSecsHeld, except this isn't affected by Update scaling.)
|
// m_fSecsHeld, except this isn't affected by Update scaling.)
|
||||||
RageTimer m_LastInputTime;
|
RageTimer m_LastInputTime;
|
||||||
};
|
};
|
||||||
@@ -45,9 +45,9 @@ struct DeviceButtonPair
|
|||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
/* Maintain a set of all interesting buttons: buttons which are being held
|
/* Maintain a set of all interesting buttons: buttons which are being held
|
||||||
* down, or which were held down and need a RELEASE event. We use this to
|
* down, or which were held down and need a RELEASE event. We use this to
|
||||||
* optimize InputFilter::Update, so we don't have to process every button
|
* optimize InputFilter::Update, so we don't have to process every button
|
||||||
* we know about when most of them aren't in use. This set is protected
|
* we know about when most of them aren't in use. This set is protected
|
||||||
* by queuemutex. */
|
* by queuemutex. */
|
||||||
typedef map<DeviceButtonPair, ButtonState> ButtonStateMap;
|
typedef map<DeviceButtonPair, ButtonState> ButtonStateMap;
|
||||||
ButtonStateMap g_ButtonStates;
|
ButtonStateMap g_ButtonStates;
|
||||||
@@ -64,22 +64,19 @@ namespace
|
|||||||
set<DeviceInput> g_DisableRepeat;
|
set<DeviceInput> g_DisableRepeat;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/* Some input devices require debouncing. Do this on both press and release.
|
||||||
* Some input devices require debouncing. Do this on both press and release. After
|
* After reporting a change in state, don't report another for the debounce
|
||||||
* reporting a change in state, don't report another for the debounce period. If a
|
* period. If a button is reported pressed, report it. If the button is
|
||||||
* button is reported pressed, report it. If the button is immediately reported
|
* immediately reported released, wait a period before reporting it; if the
|
||||||
* released, wait a period before reporting it; if the button is repressed during
|
* button is repressed during that time, the release is never reported.
|
||||||
* that time, the release is never reported.
|
|
||||||
*
|
|
||||||
* The detail is important: if a button is pressed for 1ms and released, we must
|
* The detail is important: if a button is pressed for 1ms and released, we must
|
||||||
* always report it, even if the debounce period is 10ms, since it might be a coin
|
* always report it, even if the debounce period is 10ms, since it might be a
|
||||||
* counter with a very short signal. The only time we discard events is if a button
|
* coin counter with a very short signal. The only time we discard events is if
|
||||||
* is pressed, released and then pressed again quickly.
|
* a button is pressed, released and then pressed again quickly.
|
||||||
*
|
*
|
||||||
* This delay in events is ordinarily not noticable, because the we report initial
|
* This delay in events is ordinarily not noticable, because we report initial
|
||||||
* presses and releases immediately. However, if a real press is ever delayed,
|
* presses and releases immediately. However, if a real press is ever delayed,
|
||||||
* this won't cause timing problems, because the event timestamp is preserved.
|
* this won't cause timing problems, because the event timestamp is preserved. */
|
||||||
*/
|
|
||||||
static Preference<float> g_fInputDebounceTime( "InputDebounceTime", 0 );
|
static Preference<float> g_fInputDebounceTime( "InputDebounceTime", 0 );
|
||||||
|
|
||||||
InputFilter* INPUTFILTER = NULL; // global and accessable from anywhere in our program
|
InputFilter* INPUTFILTER = NULL; // global and accessable from anywhere in our program
|
||||||
@@ -148,7 +145,7 @@ void InputFilter::ButtonPressed( const DeviceInput &di )
|
|||||||
|
|
||||||
ButtonState &bs = GetButtonState( di );
|
ButtonState &bs = GetButtonState( di );
|
||||||
|
|
||||||
/* Flush any delayed input, like Update() (in case Update() isn't being called). */
|
// Flush any delayed input, like Update() (in case Update() isn't being called).
|
||||||
RageTimer now;
|
RageTimer now;
|
||||||
CheckButtonChange( bs, di, now );
|
CheckButtonChange( bs, di, now );
|
||||||
|
|
||||||
@@ -161,7 +158,7 @@ void InputFilter::ButtonPressed( const DeviceInput &di )
|
|||||||
bs.m_BeingHeldTime = di.ts;
|
bs.m_BeingHeldTime = di.ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Try to report presses immediately. */
|
// Try to report presses immediately.
|
||||||
MakeButtonStateList( g_CurrentState );
|
MakeButtonStateList( g_CurrentState );
|
||||||
CheckButtonChange( bs, di, now );
|
CheckButtonChange( bs, di, now );
|
||||||
}
|
}
|
||||||
@@ -173,7 +170,7 @@ void InputFilter::SetButtonComment( const DeviceInput &di, const RString &sComme
|
|||||||
bs.m_sComment = sComment;
|
bs.m_sComment = sComment;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Release all buttons on the given device. */
|
/** @brief Release all buttons on the given device. */
|
||||||
void InputFilter::ResetDevice( InputDevice device )
|
void InputFilter::ResetDevice( InputDevice device )
|
||||||
{
|
{
|
||||||
LockMut(*queuemutex);
|
LockMut(*queuemutex);
|
||||||
@@ -188,7 +185,7 @@ void InputFilter::ResetDevice( InputDevice device )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check for reportable presses. */
|
/** @brief Check for reportable presses. */
|
||||||
void InputFilter::CheckButtonChange( ButtonState &bs, DeviceInput di, const RageTimer &now )
|
void InputFilter::CheckButtonChange( ButtonState &bs, DeviceInput di, const RageTimer &now )
|
||||||
{
|
{
|
||||||
if( bs.m_BeingHeld == bs.m_bLastReportedHeld )
|
if( bs.m_BeingHeld == bs.m_bLastReportedHeld )
|
||||||
@@ -222,13 +219,11 @@ void InputFilter::ReportButtonChange( const DeviceInput &di, InputEventType t )
|
|||||||
ie.type = t;
|
ie.type = t;
|
||||||
ie.di = di;
|
ie.di = di;
|
||||||
|
|
||||||
/*
|
/* Include a list of all buttons that were pressed at the time of this event.
|
||||||
* Include a list of all buttons that were pressed at the time of this event. We
|
* We can create this efficiently using g_ButtonStates. Use a vector and not
|
||||||
* can create this efficiently using g_ButtonStates. Use a vector and not a
|
* a map, for efficiency; most code will not use this information. Iterating
|
||||||
* map, for efficiency; most code will not use this information. Iterating over
|
* over g_ButtonStates will be in DeviceInput order, so users can binary
|
||||||
* g_ButtonStates will be in DeviceInput order, so users can binary search this
|
* search this list (eg. std::lower_bound). */
|
||||||
* list (eg. std::lower_bound).
|
|
||||||
*/
|
|
||||||
ie.m_ButtonState = g_CurrentState;
|
ie.m_ButtonState = g_CurrentState;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -251,8 +246,8 @@ void InputFilter::Update( float fDeltaTime )
|
|||||||
|
|
||||||
INPUTMAN->Update();
|
INPUTMAN->Update();
|
||||||
|
|
||||||
/* Make sure that nothing gets inserted while we do this, to prevent
|
/* Make sure that nothing gets inserted while we do this, to prevent things
|
||||||
* things like "key pressed, key release, key repeat". */
|
* like "key pressed, key release, key repeat". */
|
||||||
LockMut(*queuemutex);
|
LockMut(*queuemutex);
|
||||||
|
|
||||||
DeviceInput di( InputDevice_Invalid, DeviceButton_Invalid, 1.0f, now );
|
DeviceInput di( InputDevice_Invalid, DeviceButton_Invalid, 1.0f, now );
|
||||||
@@ -267,21 +262,21 @@ void InputFilter::Update( float fDeltaTime )
|
|||||||
di.button = b->first.button;
|
di.button = b->first.button;
|
||||||
ButtonState &bs = b->second;
|
ButtonState &bs = b->second;
|
||||||
|
|
||||||
/* Generate IET_FIRST_PRESS and IET_RELEASE events that were delayed. */
|
// Generate IET_FIRST_PRESS and IET_RELEASE events that were delayed.
|
||||||
CheckButtonChange( bs, di, now );
|
CheckButtonChange( bs, di, now );
|
||||||
|
|
||||||
/* Generate IET_REPEAT events. */
|
// Generate IET_REPEAT events.
|
||||||
if( !bs.m_bLastReportedHeld )
|
if( !bs.m_bLastReportedHeld )
|
||||||
{
|
{
|
||||||
// If the key isn't pressed, and hasn't been pressed for a while (so debouncing
|
// If the key isn't pressed, and hasn't been pressed for a while
|
||||||
// isn't interested in it), purge the entry.
|
// (so debouncing isn't interested in it), purge the entry.
|
||||||
if( now - bs.m_LastReportTime > g_fInputDebounceTime &&
|
if( now - bs.m_LastReportTime > g_fInputDebounceTime &&
|
||||||
bs.m_DeviceInput.level == 0.0f )
|
bs.m_DeviceInput.level == 0.0f )
|
||||||
ButtonsToErase.push_back( b );
|
ButtonsToErase.push_back( b );
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If repeats are disabled for this button, skip. */
|
// If repeats are disabled for this button, skip.
|
||||||
if( g_DisableRepeat.find(di) != g_DisableRepeat.end() )
|
if( g_DisableRepeat.find(di) != g_DisableRepeat.end() )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -306,9 +301,9 @@ void InputFilter::Update( float fDeltaTime )
|
|||||||
fRepeatTime = ftruncf( fNewHoldTime, g_fTimeBetweenRepeats );
|
fRepeatTime = ftruncf( fNewHoldTime, g_fTimeBetweenRepeats );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set the timestamp to the exact time of the repeat. This way,
|
/* Set the timestamp to the exact time of the repeat. This way, as long
|
||||||
* as long as tab/` aren't being used, the timestamp will always
|
* as tab/` aren't being used, the timestamp will always increase steadily
|
||||||
* increase steadily during repeats. */
|
* during repeats. */
|
||||||
di.ts = bs.m_LastInputTime + fRepeatTime;
|
di.ts = bs.m_LastInputTime + fRepeatTime;
|
||||||
|
|
||||||
ReportButtonChange( di, IET_REPEAT );
|
ReportButtonChange( di, IET_REPEAT );
|
||||||
@@ -371,12 +366,12 @@ void InputFilter::ResetKeyRepeat( const DeviceInput &di )
|
|||||||
GetButtonState( di ).m_fSecsHeld = 0;
|
GetButtonState( di ).m_fSecsHeld = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Stop repeating the specified key until released. */
|
/** @brief Stop repeating the specified key until released. */
|
||||||
void InputFilter::RepeatStopKey( const DeviceInput &di )
|
void InputFilter::RepeatStopKey( const DeviceInput &di )
|
||||||
{
|
{
|
||||||
LockMut(*queuemutex);
|
LockMut(*queuemutex);
|
||||||
|
|
||||||
/* If the button is up, do nothing. */
|
// If the button is up, do nothing.
|
||||||
ButtonState &bs = GetButtonState( di );
|
ButtonState &bs = GetButtonState( di );
|
||||||
if( !bs.m_bLastReportedHeld )
|
if( !bs.m_bLastReportedHeld )
|
||||||
return;
|
return;
|
||||||
|
|||||||
+1
-1
@@ -36,7 +36,7 @@
|
|||||||
#include <set>
|
#include <set>
|
||||||
#include <float.h>
|
#include <float.h>
|
||||||
|
|
||||||
/** @brief: The version of the .ssc file format. */
|
/** @brief The version of the .ssc file format. */
|
||||||
const static float VERSION_NUMBER = 0.52f;
|
const static float VERSION_NUMBER = 0.52f;
|
||||||
const int FILE_CACHE_VERSION = 164; // increment this to invalidate cache
|
const int FILE_CACHE_VERSION = 164; // increment this to invalidate cache
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user