Files
itgmania212121/stepmania/src/InputFilter.cpp
T

122 lines
2.7 KiB
C++
Raw Normal View History

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"
2003-07-26 21:58:48 +00:00
#include "RageThreads.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
2003-07-26 21:58:48 +00:00
InputFilter::InputFilter()
2003-06-22 04:38:05 +00:00
{
2003-07-26 21:58:48 +00:00
queuemutex = new RageMutex;
2003-07-26 22:29:34 +00:00
Reset();
2003-07-26 21:58:48 +00:00
}
InputFilter::~InputFilter()
{
delete queuemutex;
2003-06-22 04:38:05 +00:00
}
void InputFilter::Reset()
{
for( int i=0; i<NUM_INPUT_DEVICES; i++ )
ResetDevice( InputDevice(i) );
}
void InputFilter::ButtonPressed( DeviceInput di, bool Down )
{
if(m_BeingHeld[di.device][di.button] == Down)
return;
m_BeingHeld[di.device][di.button] = Down;
m_fSecsHeld[di.device][di.button] = 0;
2002-04-16 17:31:00 +00:00
InputEventType iet = Down? IET_FIRST_PRESS:IET_RELEASE;
2003-07-14 06:21:12 +00:00
2003-07-26 21:58:48 +00:00
LockMut(*queuemutex);
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 );
}
void InputFilter::Update(float fDeltaTime)
2002-04-16 17:31:00 +00:00
{
INPUTMAN->Update( fDeltaTime );
2002-04-16 17:31:00 +00:00
2003-07-14 06:21:12 +00:00
/* Make sure that nothing gets inserted while we do this, to prevent
* things like "key pressed, key release, key repeat". */
2003-07-26 21:58:48 +00:00
LockMut(*queuemutex);
2003-07-14 06:21:12 +00:00
2002-04-16 17:31:00 +00:00
for( int d=0; d<NUM_INPUT_DEVICES; d++ ) // foreach InputDevice
{
for( int b=0; b < NUM_DEVICE_BUTTONS; b++ ) // foreach button
2002-04-16 17:31:00 +00:00
{
if(!m_BeingHeld[d][b])
continue;
2002-04-16 17:31:00 +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
{
if( fOldHoldTime > TIME_BEFORE_FAST_REPEATS )
2002-04-16 17:31:00 +00:00
{
fTimeBetweenRepeats = TIME_BETWEEN_FAST_REPEATS;
iet = IET_FAST_REPEAT;
2002-04-16 17:31:00 +00:00
}
else
{
fTimeBetweenRepeats = TIME_BETWEEN_SLOW_REPEATS;
iet = IET_SLOW_REPEAT;
2002-08-21 22:49:13 +00:00
}
if( int(fOldHoldTime/fTimeBetweenRepeats) != int(fNewHoldTime/fTimeBetweenRepeats) )
2003-07-14 06:21:12 +00:00
{
RageTimer now;
DeviceInput di( (InputDevice)d,b,now);
2003-07-14 06:21:12 +00:00
queue.push_back( InputEvent(di,iet) );
}
2002-04-16 17:31:00 +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 )
{
2003-07-26 21:58:48 +00:00
LockMut(*queuemutex);
array = queue;
queue.clear();
}