2003-02-16 04:01:45 +00:00
|
|
|
#include "global.h"
|
2002-04-16 17:31:00 +00:00
|
|
|
/*
|
|
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
|
Class: InputFilter
|
|
|
|
|
|
|
|
|
|
Desc: See header.
|
|
|
|
|
|
2002-05-19 01:59:48 +00:00
|
|
|
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
|
2002-04-16 17:31:00 +00:00
|
|
|
Chris Danford
|
|
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "InputFilter.h"
|
2002-05-01 19:14:55 +00:00
|
|
|
#include "RageLog.h"
|
2002-04-16 17:31:00 +00:00
|
|
|
#include "RageInput.h"
|
2002-06-14 22:25:22 +00:00
|
|
|
|
2002-04-16 17:31:00 +00:00
|
|
|
|
2002-05-19 01:59:48 +00:00
|
|
|
InputFilter* INPUTFILTER = NULL; // global and accessable from anywhere in our program
|
2002-04-16 17:31:00 +00:00
|
|
|
|
2002-09-08 06:10:23 +00:00
|
|
|
InputFilter::InputFilter()
|
2003-06-22 04:38:05 +00:00
|
|
|
{
|
|
|
|
|
Reset();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void InputFilter::Reset()
|
2002-09-08 06:10:23 +00:00
|
|
|
{
|
2003-02-16 01:35:48 +00:00
|
|
|
memset(m_BeingHeld, 0, sizeof(m_BeingHeld));
|
|
|
|
|
|
2002-09-08 06:10:23 +00:00
|
|
|
for( int i=0; i<NUM_INPUT_DEVICES; i++ )
|
|
|
|
|
{
|
|
|
|
|
for( int j=0; j<NUM_DEVICE_BUTTONS; j++ )
|
2002-10-18 19:01:32 +00:00
|
|
|
m_fSecsHeld[i][j] = 0;
|
2002-09-08 06:10:23 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-02-16 01:35:48 +00:00
|
|
|
void InputFilter::ButtonPressed( DeviceInput di, bool Down )
|
2002-09-08 06:10:23 +00:00
|
|
|
{
|
2003-02-16 01:35:48 +00:00
|
|
|
if(m_BeingHeld[di.device][di.button] == Down)
|
|
|
|
|
return;
|
2002-09-08 06:10:23 +00:00
|
|
|
|
2003-02-16 01:35:48 +00:00
|
|
|
m_BeingHeld[di.device][di.button] = Down;
|
|
|
|
|
m_fSecsHeld[di.device][di.button] = 0;
|
2002-04-16 17:31:00 +00:00
|
|
|
|
2003-02-16 01:35:48 +00:00
|
|
|
InputEventType iet = Down? IET_FIRST_PRESS:IET_RELEASE;
|
|
|
|
|
queue.push_back( InputEvent(di,iet) );
|
2002-10-18 19:01:32 +00:00
|
|
|
}
|
|
|
|
|
|
2003-06-21 20:58:40 +00:00
|
|
|
/* Release all buttons on the given device. */
|
|
|
|
|
void InputFilter::ResetDevice( InputDevice dev )
|
|
|
|
|
{
|
|
|
|
|
for( int button = 0; button < NUM_DEVICE_BUTTONS; ++button )
|
|
|
|
|
ButtonPressed( DeviceInput(dev, button), false );
|
|
|
|
|
}
|
|
|
|
|
|
2003-02-16 01:35:48 +00:00
|
|
|
void InputFilter::Update(float fDeltaTime)
|
2002-04-16 17:31:00 +00:00
|
|
|
{
|
2002-11-29 20:37:12 +00:00
|
|
|
INPUTMAN->Update( fDeltaTime );
|
2002-04-16 17:31:00 +00:00
|
|
|
|
|
|
|
|
for( int d=0; d<NUM_INPUT_DEVICES; d++ ) // foreach InputDevice
|
|
|
|
|
{
|
2003-02-16 01:35:48 +00:00
|
|
|
for( int b=0; b < NUM_DEVICE_BUTTONS; b++ ) // foreach button
|
2002-04-16 17:31:00 +00:00
|
|
|
{
|
2003-02-16 01:35:48 +00:00
|
|
|
if(!m_BeingHeld[d][b])
|
|
|
|
|
continue;
|
2002-04-16 17:31:00 +00:00
|
|
|
|
2003-02-16 01:35:48 +00:00
|
|
|
const float fOldHoldTime = m_fSecsHeld[d][b];
|
|
|
|
|
m_fSecsHeld[d][b] += fDeltaTime;
|
|
|
|
|
const float fNewHoldTime = m_fSecsHeld[d][b];
|
|
|
|
|
|
|
|
|
|
float fTimeBetweenRepeats;
|
|
|
|
|
InputEventType iet;
|
|
|
|
|
if( fOldHoldTime > TIME_BEFORE_SLOW_REPEATS )
|
2002-04-16 17:31:00 +00:00
|
|
|
{
|
2003-02-16 01:35:48 +00:00
|
|
|
if( fOldHoldTime > TIME_BEFORE_FAST_REPEATS )
|
2002-04-16 17:31:00 +00:00
|
|
|
{
|
2003-02-16 01:35:48 +00:00
|
|
|
fTimeBetweenRepeats = TIME_BETWEEN_FAST_REPEATS;
|
|
|
|
|
iet = IET_FAST_REPEAT;
|
2002-04-16 17:31:00 +00:00
|
|
|
}
|
2003-02-16 01:35:48 +00:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fTimeBetweenRepeats = TIME_BETWEEN_SLOW_REPEATS;
|
|
|
|
|
iet = IET_SLOW_REPEAT;
|
2002-08-21 22:49:13 +00:00
|
|
|
}
|
2003-02-16 01:35:48 +00:00
|
|
|
if( int(fOldHoldTime/fTimeBetweenRepeats) != int(fNewHoldTime/fTimeBetweenRepeats) )
|
|
|
|
|
queue.push_back( InputEvent(InputDevice(d),b,iet) );
|
|
|
|
|
|
2002-04-16 17:31:00 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-02-16 01:35:48 +00:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool InputFilter::IsBeingPressed( DeviceInput di )
|
|
|
|
|
{
|
|
|
|
|
return m_BeingHeld[di.device][di.button];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float InputFilter::GetSecsHeld( DeviceInput di )
|
|
|
|
|
{
|
|
|
|
|
return m_fSecsHeld[di.device][di.button];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void InputFilter::GetInputEvents( InputEventArray &array )
|
|
|
|
|
{
|
|
|
|
|
array = queue;
|
|
|
|
|
queue.clear();
|
2002-07-31 19:40:40 +00:00
|
|
|
}
|