cleanup, handle IET_LEVEL_CHANGED

This commit is contained in:
Glenn Maynard
2004-09-09 22:14:33 +00:00
parent b0c6686574
commit 4e5077ef84
2 changed files with 53 additions and 16 deletions
+26 -13
View File
@@ -19,8 +19,7 @@ static float g_fTimeBeforeSlow, g_fTimeBeforeFast, g_fTimeBetweenSlow, g_fTimeBe
InputFilter::InputFilter()
{
queuemutex = new RageMutex("InputFilter");
memset( m_BeingHeld, 0, sizeof(m_BeingHeld) );
memset( m_fSecsHeld, 0, sizeof(m_fSecsHeld) );
memset( m_ButtonState, 0, sizeof(m_ButtonState) );
Reset();
ResetRepeatRate();
@@ -54,13 +53,17 @@ void InputFilter::ButtonPressed( DeviceInput di, bool Down )
{
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;
const bool WasBeingPressed = IsBeingPressed( di );
m_BeingHeld[di.device][di.button] = Down;
m_fSecsHeld[di.device][di.button] = 0;
bs.m_BeingHeld = Down;
bs.m_fSecsHeld = 0;
if( WasBeingPressed != IsBeingPressed(di) )
{
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
// 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
{
@@ -105,14 +108,24 @@ void InputFilter::Update(float fDeltaTime)
for( int b=0; b < NUM_DEVICE_BUTTONS[d]; b++ ) // foreach button
{
ButtonState &bs = m_ButtonState[d][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;
const float fOldHoldTime = m_fSecsHeld[d][b];
m_fSecsHeld[d][b] += fDeltaTime;
const float fNewHoldTime = m_fSecsHeld[d][b];
const float fOldHoldTime = bs.m_fSecsHeld;
bs.m_fSecsHeld += fDeltaTime;
const float fNewHoldTime = bs.m_fSecsHeld;
float fTimeBetweenRepeats;
InputEventType iet;
@@ -140,17 +153,17 @@ void InputFilter::Update(float fDeltaTime)
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 )
{
return m_fSecsHeld[di.device][di.button];
return m_ButtonState[di.device][di.button].m_fSecsHeld;
}
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 )
+27 -3
View File
@@ -5,7 +5,26 @@
#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
{
@@ -21,8 +40,13 @@ typedef vector<InputEvent> InputEventArray;
class RageMutex;
class InputFilter
{
bool m_BeingHeld[NUM_INPUT_DEVICES][MAX_DEVICE_BUTTONS];
float m_fSecsHeld[NUM_INPUT_DEVICES][MAX_DEVICE_BUTTONS];
struct ButtonState
{
bool m_BeingHeld;
float m_fSecsHeld;
float m_Level, m_LastLevel;
};
ButtonState m_ButtonState[NUM_INPUT_DEVICES][MAX_DEVICE_BUTTONS];
InputEventArray queue;
RageMutex *queuemutex;