cleanup, handle IET_LEVEL_CHANGED
This commit is contained in:
@@ -19,8 +19,7 @@ static float g_fTimeBeforeSlow, g_fTimeBeforeFast, g_fTimeBetweenSlow, g_fTimeBe
|
|||||||
InputFilter::InputFilter()
|
InputFilter::InputFilter()
|
||||||
{
|
{
|
||||||
queuemutex = new RageMutex("InputFilter");
|
queuemutex = new RageMutex("InputFilter");
|
||||||
memset( m_BeingHeld, 0, sizeof(m_BeingHeld) );
|
memset( m_ButtonState, 0, sizeof(m_ButtonState) );
|
||||||
memset( m_fSecsHeld, 0, sizeof(m_fSecsHeld) );
|
|
||||||
|
|
||||||
Reset();
|
Reset();
|
||||||
ResetRepeatRate();
|
ResetRepeatRate();
|
||||||
@@ -54,13 +53,17 @@ void InputFilter::ButtonPressed( DeviceInput di, bool Down )
|
|||||||
{
|
{
|
||||||
LockMut(*queuemutex);
|
LockMut(*queuemutex);
|
||||||
|
|
||||||
if(m_BeingHeld[di.device][di.button] == Down)
|
ButtonState &bs = m_ButtonState[di.device][di.button];
|
||||||
|
|
||||||
|
bs.m_Level = di.level;
|
||||||
|
|
||||||
|
if( bs.m_BeingHeld == Down )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const bool WasBeingPressed = IsBeingPressed( di );
|
const bool WasBeingPressed = IsBeingPressed( di );
|
||||||
|
|
||||||
m_BeingHeld[di.device][di.button] = Down;
|
bs.m_BeingHeld = Down;
|
||||||
m_fSecsHeld[di.device][di.button] = 0;
|
bs.m_fSecsHeld = 0;
|
||||||
if( WasBeingPressed != IsBeingPressed(di) )
|
if( WasBeingPressed != IsBeingPressed(di) )
|
||||||
{
|
{
|
||||||
InputEventType iet = IsBeingPressed(di)? IET_FIRST_PRESS:IET_RELEASE;
|
InputEventType iet = IsBeingPressed(di)? IET_FIRST_PRESS:IET_RELEASE;
|
||||||
@@ -97,7 +100,7 @@ void InputFilter::Update(float fDeltaTime)
|
|||||||
|
|
||||||
// Don't reconstruct "di" inside the loop. This line alone is
|
// Don't reconstruct "di" inside the loop. This line alone is
|
||||||
// taking 4% of the CPU on a P3-666.
|
// taking 4% of the CPU on a P3-666.
|
||||||
DeviceInput di( (InputDevice)0,0,now);
|
DeviceInput di( (InputDevice)0,0,1.0f,now);
|
||||||
|
|
||||||
for( int d=0; d<NUM_INPUT_DEVICES; d++ ) // foreach InputDevice
|
for( int d=0; d<NUM_INPUT_DEVICES; d++ ) // foreach InputDevice
|
||||||
{
|
{
|
||||||
@@ -105,14 +108,24 @@ void InputFilter::Update(float fDeltaTime)
|
|||||||
|
|
||||||
for( int b=0; b < NUM_DEVICE_BUTTONS[d]; b++ ) // foreach button
|
for( int b=0; b < NUM_DEVICE_BUTTONS[d]; b++ ) // foreach button
|
||||||
{
|
{
|
||||||
|
ButtonState &bs = m_ButtonState[d][b];
|
||||||
di.button = b;
|
di.button = b;
|
||||||
|
di.level = bs.m_Level;
|
||||||
|
|
||||||
if( !IsBeingPressed(di) )
|
/* Generate IET_LEVEL_CHANGED events. */
|
||||||
|
if( bs.m_LastLevel != bs.m_Level )
|
||||||
|
{
|
||||||
|
queue.push_back( InputEvent(di,IET_LEVEL_CHANGED) );
|
||||||
|
bs.m_LastLevel = bs.m_Level;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Generate IET_FAST_REPEAT and IET_SLOW_REPEAT events. */
|
||||||
|
if( !bs.m_BeingHeld )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const float fOldHoldTime = m_fSecsHeld[d][b];
|
const float fOldHoldTime = bs.m_fSecsHeld;
|
||||||
m_fSecsHeld[d][b] += fDeltaTime;
|
bs.m_fSecsHeld += fDeltaTime;
|
||||||
const float fNewHoldTime = m_fSecsHeld[d][b];
|
const float fNewHoldTime = bs.m_fSecsHeld;
|
||||||
|
|
||||||
float fTimeBetweenRepeats;
|
float fTimeBetweenRepeats;
|
||||||
InputEventType iet;
|
InputEventType iet;
|
||||||
@@ -140,17 +153,17 @@ void InputFilter::Update(float fDeltaTime)
|
|||||||
|
|
||||||
bool InputFilter::IsBeingPressed( DeviceInput di )
|
bool InputFilter::IsBeingPressed( DeviceInput di )
|
||||||
{
|
{
|
||||||
return m_BeingHeld[di.device][di.button];
|
return m_ButtonState[di.device][di.button].m_BeingHeld;
|
||||||
}
|
}
|
||||||
|
|
||||||
float InputFilter::GetSecsHeld( DeviceInput di )
|
float InputFilter::GetSecsHeld( DeviceInput di )
|
||||||
{
|
{
|
||||||
return m_fSecsHeld[di.device][di.button];
|
return m_ButtonState[di.device][di.button].m_fSecsHeld;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputFilter::ResetKeyRepeat( DeviceInput di )
|
void InputFilter::ResetKeyRepeat( DeviceInput di )
|
||||||
{
|
{
|
||||||
m_fSecsHeld[di.device][di.button] = 0;
|
m_ButtonState[di.device][di.button].m_fSecsHeld = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputFilter::GetInputEvents( InputEventArray &array )
|
void InputFilter::GetInputEvents( InputEventArray &array )
|
||||||
|
|||||||
@@ -5,7 +5,26 @@
|
|||||||
|
|
||||||
#include "RageInputDevice.h"
|
#include "RageInputDevice.h"
|
||||||
|
|
||||||
enum InputEventType { IET_FIRST_PRESS, IET_SLOW_REPEAT, IET_FAST_REPEAT, IET_RELEASE };
|
enum InputEventType
|
||||||
|
{
|
||||||
|
/* The device was just pressed. */
|
||||||
|
IET_FIRST_PRESS,
|
||||||
|
|
||||||
|
/* The device is auto-repeating. These events are guaranteed to be sent only between
|
||||||
|
* IET_FIRST_PRESS and IET_RELEASE pairs. */
|
||||||
|
IET_SLOW_REPEAT,
|
||||||
|
IET_FAST_REPEAT,
|
||||||
|
|
||||||
|
/* The device is no longer pressed. Exactly one IET_RELEASE event will be sent
|
||||||
|
* for each IET_FIRST_PRESS. */
|
||||||
|
IET_RELEASE,
|
||||||
|
|
||||||
|
/* The depression level of a button has changed. Read di.level to find the new
|
||||||
|
* value. This can be sent outside of a IET_FIRST_PRESS/IET_RELEASE pair, since
|
||||||
|
* a button/axis can have a non-zero level (eg. outside the axis dead zone) without
|
||||||
|
* being high enough to count as a press. */
|
||||||
|
IET_LEVEL_CHANGED
|
||||||
|
};
|
||||||
|
|
||||||
struct InputEvent : public DeviceInput
|
struct InputEvent : public DeviceInput
|
||||||
{
|
{
|
||||||
@@ -21,8 +40,13 @@ typedef vector<InputEvent> InputEventArray;
|
|||||||
class RageMutex;
|
class RageMutex;
|
||||||
class InputFilter
|
class InputFilter
|
||||||
{
|
{
|
||||||
bool m_BeingHeld[NUM_INPUT_DEVICES][MAX_DEVICE_BUTTONS];
|
struct ButtonState
|
||||||
float m_fSecsHeld[NUM_INPUT_DEVICES][MAX_DEVICE_BUTTONS];
|
{
|
||||||
|
bool m_BeingHeld;
|
||||||
|
float m_fSecsHeld;
|
||||||
|
float m_Level, m_LastLevel;
|
||||||
|
};
|
||||||
|
ButtonState m_ButtonState[NUM_INPUT_DEVICES][MAX_DEVICE_BUTTONS];
|
||||||
|
|
||||||
InputEventArray queue;
|
InputEventArray queue;
|
||||||
RageMutex *queuemutex;
|
RageMutex *queuemutex;
|
||||||
|
|||||||
Reference in New Issue
Block a user