optimize InputFilter::Update (.5ms -> .05ms on k7/1000)
This commit is contained in:
@@ -5,7 +5,23 @@
|
||||
#include "RageUtil.h"
|
||||
#include "RageThreads.h"
|
||||
#include "Preference.h"
|
||||
#include "Foreach.h"
|
||||
|
||||
#include <set>
|
||||
namespace
|
||||
{
|
||||
/* Maintain a set of all interesting buttons: buttons which are being held
|
||||
* down, or which were held down and need a RELEASE event. We use this to
|
||||
* optimize InputFilter::Update, so we don't have to process every button
|
||||
* we know about when most of them aren't in use. This set is protected
|
||||
* by queuemutex. */
|
||||
typedef pair<InputDevice,DeviceButton> Button;
|
||||
set<Button> g_ButtonsToProcess;
|
||||
void ActivateButton( const DeviceInput &di )
|
||||
{
|
||||
g_ButtonsToProcess.insert( make_pair(di.device, di.button) );
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Some input devices require debouncing. Do this on both press and release. After
|
||||
* reporting a change in state, don't report another for the debounce period. If a
|
||||
@@ -101,6 +117,8 @@ void InputFilter::ButtonPressed( const DeviceInput &di, bool Down )
|
||||
bs.m_BeingHeld = Down;
|
||||
bs.m_BeingHeldTime = di.ts;
|
||||
}
|
||||
|
||||
ActivateButton( di );
|
||||
}
|
||||
|
||||
void InputFilter::SetButtonComment( const DeviceInput &di, const CString &sComment )
|
||||
@@ -120,6 +138,7 @@ void InputFilter::ResetDevice( InputDevice device )
|
||||
|
||||
void InputFilter::Update(float fDeltaTime)
|
||||
{
|
||||
RageTimer foo;
|
||||
RageTimer now;
|
||||
|
||||
// Constructing the DeviceInput inside the nested loops caues terrible
|
||||
@@ -138,18 +157,14 @@ void InputFilter::Update(float fDeltaTime)
|
||||
* things like "key pressed, key release, key repeat". */
|
||||
LockMut(*queuemutex);
|
||||
|
||||
// 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,1.0f,now);
|
||||
|
||||
FOREACH_InputDevice( d )
|
||||
set<Button> Buttons( g_ButtonsToProcess );
|
||||
FOREACHS( Button, Buttons, b )
|
||||
{
|
||||
di.device = d;
|
||||
|
||||
for( int b=0; b < GetNumDeviceButtons(d); b++ ) // foreach button
|
||||
{
|
||||
ButtonState &bs = m_ButtonState[d][b];
|
||||
di.button = b;
|
||||
di.device = b->first;
|
||||
di.button = b->second;
|
||||
ButtonState &bs = m_ButtonState[di.device][di.button];
|
||||
di.level = bs.m_Level;
|
||||
|
||||
/* Generate IET_FIRST_PRESS and IET_RELEASE events. */
|
||||
@@ -172,7 +187,10 @@ void InputFilter::Update(float fDeltaTime)
|
||||
|
||||
/* Generate IET_FAST_REPEAT and IET_SLOW_REPEAT events. */
|
||||
if( !bs.m_bLastReportedHeld )
|
||||
{
|
||||
g_ButtonsToProcess.erase( make_pair(di.device, di.button) );
|
||||
continue;
|
||||
}
|
||||
|
||||
const float fOldHoldTime = bs.m_fSecsHeld;
|
||||
bs.m_fSecsHeld += fDeltaTime;
|
||||
@@ -215,8 +233,6 @@ void InputFilter::Update(float fDeltaTime)
|
||||
queue.push_back( InputEvent(di,iet) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool InputFilter::IsBeingPressed( const DeviceInput &di )
|
||||
|
||||
Reference in New Issue
Block a user