add ForceKey, StopForcingKey
This commit is contained in:
@@ -23,6 +23,13 @@ InputFilter* INPUTFILTER = NULL; // global and accessable from anywhere in our p
|
|||||||
InputFilter::InputFilter()
|
InputFilter::InputFilter()
|
||||||
{
|
{
|
||||||
queuemutex = new RageMutex;
|
queuemutex = new RageMutex;
|
||||||
|
memset( m_BeingHeld, 0, sizeof(m_BeingHeld) );
|
||||||
|
memset( m_BeingForced, 0, sizeof(m_BeingForced) );
|
||||||
|
memset( m_fSecsHeld, 0, sizeof(m_fSecsHeld) );
|
||||||
|
for( int d=0; d<NUM_INPUT_DEVICES; d++ ) // foreach InputDevice
|
||||||
|
for( int b=0; b < NUM_DEVICE_BUTTONS; b++ ) // foreach button
|
||||||
|
m_fSecsToForce[d][b] = -1;
|
||||||
|
|
||||||
Reset();
|
Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,17 +46,66 @@ void InputFilter::Reset()
|
|||||||
|
|
||||||
void InputFilter::ButtonPressed( DeviceInput di, bool Down )
|
void InputFilter::ButtonPressed( DeviceInput di, bool Down )
|
||||||
{
|
{
|
||||||
|
LockMut(*queuemutex);
|
||||||
|
|
||||||
if(m_BeingHeld[di.device][di.button] == Down)
|
if(m_BeingHeld[di.device][di.button] == Down)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
const bool WasBeingPressed = IsBeingPressed( di );
|
||||||
|
|
||||||
m_BeingHeld[di.device][di.button] = Down;
|
m_BeingHeld[di.device][di.button] = Down;
|
||||||
m_fSecsHeld[di.device][di.button] = 0;
|
m_fSecsHeld[di.device][di.button] = 0;
|
||||||
|
|
||||||
InputEventType iet = Down? IET_FIRST_PRESS:IET_RELEASE;
|
if( WasBeingPressed != IsBeingPressed(di) )
|
||||||
|
{
|
||||||
LockMut(*queuemutex);
|
InputEventType iet = IsBeingPressed(di)? IET_FIRST_PRESS:IET_RELEASE;
|
||||||
queue.push_back( InputEvent(di,iet) );
|
queue.push_back( InputEvent(di,iet) );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Force a key down. Duration is the amount of time to force the key, or 0 to force
|
||||||
|
* it until we explicitly call StopForcingKey. */
|
||||||
|
void InputFilter::ForceKey( DeviceInput di, float duration )
|
||||||
|
{
|
||||||
|
LockMut(*queuemutex);
|
||||||
|
|
||||||
|
if( m_BeingForced[di.device][di.button] )
|
||||||
|
return;
|
||||||
|
|
||||||
|
const bool WasBeingPressed = IsBeingPressed( di );
|
||||||
|
|
||||||
|
m_BeingForced[di.device][di.button] = true;
|
||||||
|
m_fSecsToForce[di.device][di.button] = duration;
|
||||||
|
m_fSecsHeld[di.device][di.button] = 0;
|
||||||
|
|
||||||
|
/* Send an IET_FIRST_PRESS event if the key wasn't already down. */
|
||||||
|
if( WasBeingPressed != IsBeingPressed( di ) )
|
||||||
|
{
|
||||||
|
InputEventType iet = IsBeingPressed(di)? IET_FIRST_PRESS:IET_RELEASE;
|
||||||
|
queue.push_back( InputEvent(di,iet) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void InputFilter::StopForcingKey( DeviceInput di )
|
||||||
|
{
|
||||||
|
LockMut(*queuemutex);
|
||||||
|
|
||||||
|
if( !m_BeingForced[di.device][di.button] )
|
||||||
|
return;
|
||||||
|
|
||||||
|
const bool WasBeingPressed = IsBeingPressed( di );
|
||||||
|
|
||||||
|
m_BeingForced[di.device][di.button] = false;
|
||||||
|
m_fSecsToForce[di.device][di.button] = 0;
|
||||||
|
m_fSecsHeld[di.device][di.button] = 0;
|
||||||
|
|
||||||
|
/* Send an IET_RELEASE event if the key is no longer down. */
|
||||||
|
if( WasBeingPressed != IsBeingPressed(di) )
|
||||||
|
{
|
||||||
|
InputEventType iet = IsBeingPressed(di)? IET_FIRST_PRESS:IET_RELEASE;
|
||||||
|
queue.push_back( InputEvent(di,iet) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Release all buttons on the given device. */
|
/* Release all buttons on the given device. */
|
||||||
void InputFilter::ResetDevice( InputDevice dev )
|
void InputFilter::ResetDevice( InputDevice dev )
|
||||||
@@ -60,6 +116,8 @@ void InputFilter::ResetDevice( InputDevice dev )
|
|||||||
|
|
||||||
void InputFilter::Update(float fDeltaTime)
|
void InputFilter::Update(float fDeltaTime)
|
||||||
{
|
{
|
||||||
|
RageTimer now;
|
||||||
|
|
||||||
INPUTMAN->Update( fDeltaTime );
|
INPUTMAN->Update( fDeltaTime );
|
||||||
|
|
||||||
/* Make sure that nothing gets inserted while we do this, to prevent
|
/* Make sure that nothing gets inserted while we do this, to prevent
|
||||||
@@ -70,7 +128,16 @@ void InputFilter::Update(float fDeltaTime)
|
|||||||
{
|
{
|
||||||
for( int b=0; b < NUM_DEVICE_BUTTONS; b++ ) // foreach button
|
for( int b=0; b < NUM_DEVICE_BUTTONS; b++ ) // foreach button
|
||||||
{
|
{
|
||||||
if(!m_BeingHeld[d][b])
|
DeviceInput di( (InputDevice)d,b,now);
|
||||||
|
|
||||||
|
if( m_fSecsToForce[d][b] > 0 )
|
||||||
|
{
|
||||||
|
m_fSecsToForce[d][b] -= fDeltaTime;
|
||||||
|
if( m_fSecsToForce[d][b] <= 0 )
|
||||||
|
StopForcingKey( di );
|
||||||
|
}
|
||||||
|
|
||||||
|
if( !IsBeingPressed(di) )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const float fOldHoldTime = m_fSecsHeld[d][b];
|
const float fOldHoldTime = m_fSecsHeld[d][b];
|
||||||
@@ -93,8 +160,6 @@ void InputFilter::Update(float fDeltaTime)
|
|||||||
}
|
}
|
||||||
if( int(fOldHoldTime/fTimeBetweenRepeats) != int(fNewHoldTime/fTimeBetweenRepeats) )
|
if( int(fOldHoldTime/fTimeBetweenRepeats) != int(fNewHoldTime/fTimeBetweenRepeats) )
|
||||||
{
|
{
|
||||||
RageTimer now;
|
|
||||||
DeviceInput di( (InputDevice)d,b,now);
|
|
||||||
queue.push_back( InputEvent(di,iet) );
|
queue.push_back( InputEvent(di,iet) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -105,7 +170,7 @@ void InputFilter::Update(float fDeltaTime)
|
|||||||
|
|
||||||
bool InputFilter::IsBeingPressed( DeviceInput di )
|
bool InputFilter::IsBeingPressed( DeviceInput di )
|
||||||
{
|
{
|
||||||
return m_BeingHeld[di.device][di.button];
|
return m_BeingHeld[di.device][di.button] || m_BeingForced[di.device][di.button];
|
||||||
}
|
}
|
||||||
|
|
||||||
float InputFilter::GetSecsHeld( DeviceInput di )
|
float InputFilter::GetSecsHeld( DeviceInput di )
|
||||||
|
|||||||
@@ -39,11 +39,17 @@ class RageMutex;
|
|||||||
class InputFilter
|
class InputFilter
|
||||||
{
|
{
|
||||||
bool m_BeingHeld[NUM_INPUT_DEVICES][NUM_DEVICE_BUTTONS];
|
bool m_BeingHeld[NUM_INPUT_DEVICES][NUM_DEVICE_BUTTONS];
|
||||||
|
bool m_BeingForced[NUM_INPUT_DEVICES][NUM_DEVICE_BUTTONS];
|
||||||
float m_fSecsHeld[NUM_INPUT_DEVICES][NUM_DEVICE_BUTTONS];
|
float m_fSecsHeld[NUM_INPUT_DEVICES][NUM_DEVICE_BUTTONS];
|
||||||
|
|
||||||
|
/* If > 0, then when it reaches 0, stop forcing. */
|
||||||
|
float m_fSecsToForce[NUM_INPUT_DEVICES][NUM_DEVICE_BUTTONS];
|
||||||
InputEventArray queue;
|
InputEventArray queue;
|
||||||
RageMutex *queuemutex;
|
RageMutex *queuemutex;
|
||||||
|
|
||||||
|
void ForceKey( DeviceInput di, float duration );
|
||||||
|
void StopForcingKey( DeviceInput di );
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void ButtonPressed( DeviceInput di, bool Down );
|
void ButtonPressed( DeviceInput di, bool Down );
|
||||||
void ResetDevice( InputDevice dev );
|
void ResetDevice( InputDevice dev );
|
||||||
|
|||||||
Reference in New Issue
Block a user