optimize InputFilter::Update
This commit is contained in:
@@ -27,7 +27,7 @@ InputFilter::InputFilter()
|
||||
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
|
||||
for( int b=0; b < NUM_DEVICE_BUTTONS[d]; b++ ) // foreach button
|
||||
m_fSecsToForce[d][b] = -1;
|
||||
|
||||
Reset();
|
||||
@@ -142,7 +142,7 @@ void InputFilter::StopForcingKey( DeviceInput di )
|
||||
/* Release all buttons on the given device. */
|
||||
void InputFilter::ResetDevice( InputDevice dev )
|
||||
{
|
||||
for( int button = 0; button < NUM_DEVICE_BUTTONS; ++button )
|
||||
for( int button = 0; button < NUM_DEVICE_BUTTONS[dev]; ++button )
|
||||
ButtonPressed( DeviceInput(dev, button), false );
|
||||
}
|
||||
|
||||
@@ -174,11 +174,17 @@ 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,now);
|
||||
|
||||
for( int d=0; d<NUM_INPUT_DEVICES; d++ ) // foreach InputDevice
|
||||
{
|
||||
for( int b=0; b < NUM_DEVICE_BUTTONS; b++ ) // foreach button
|
||||
di.device = (InputDevice)d;
|
||||
|
||||
for( int b=0; b < NUM_DEVICE_BUTTONS[d]; b++ ) // foreach button
|
||||
{
|
||||
DeviceInput di( (InputDevice)d,b,now);
|
||||
di.button = b;
|
||||
|
||||
if( m_fSecsToForce[d][b] > 0 )
|
||||
{
|
||||
|
||||
@@ -38,12 +38,12 @@ typedef vector<InputEvent> InputEventArray;
|
||||
class RageMutex;
|
||||
class InputFilter
|
||||
{
|
||||
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];
|
||||
bool m_BeingHeld[NUM_INPUT_DEVICES][MAX_DEVICE_BUTTONS];
|
||||
bool m_BeingForced[NUM_INPUT_DEVICES][MAX_DEVICE_BUTTONS];
|
||||
float m_fSecsHeld[NUM_INPUT_DEVICES][MAX_DEVICE_BUTTONS];
|
||||
|
||||
/* If > 0, then when it reaches 0, stop forcing. */
|
||||
float m_fSecsToForce[NUM_INPUT_DEVICES][NUM_DEVICE_BUTTONS];
|
||||
float m_fSecsToForce[NUM_INPUT_DEVICES][MAX_DEVICE_BUTTONS];
|
||||
InputEventArray queue;
|
||||
RageMutex *queuemutex;
|
||||
|
||||
|
||||
@@ -448,7 +448,7 @@ void InputMapper::UpdateTempDItoGI()
|
||||
// clear out m_tempDItoGI
|
||||
for( int d=0; d<NUM_INPUT_DEVICES; d++ )
|
||||
{
|
||||
for( int b=0; b<NUM_DEVICE_BUTTONS; b++ )
|
||||
for( int b=0; b<NUM_DEVICE_BUTTONS[d]; b++ )
|
||||
{
|
||||
m_tempDItoGI[d][b].MakeInvalid();
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ protected:
|
||||
|
||||
// lookup for efficiency from a DeviceInput to a GameInput
|
||||
// This is repopulated every time m_PItoDI changes by calling UpdateTempDItoPI().
|
||||
GameInput m_tempDItoGI[NUM_INPUT_DEVICES][NUM_DEVICE_BUTTONS];
|
||||
GameInput m_tempDItoGI[NUM_INPUT_DEVICES][MAX_DEVICE_BUTTONS];
|
||||
void UpdateTempDItoGI();
|
||||
};
|
||||
|
||||
|
||||
@@ -9,8 +9,6 @@ const int NUM_JOYSTICKS = 4;
|
||||
const int NUM_JOYSTICK_HATS = 1;
|
||||
const int NUM_PUMPS = 2;
|
||||
|
||||
const int NUM_DEVICE_BUTTONS = NUM_KEYBOARD_BUTTONS;
|
||||
|
||||
enum InputDevice {
|
||||
DEVICE_KEYBOARD = 0,
|
||||
DEVICE_JOY1,
|
||||
@@ -56,6 +54,20 @@ enum PumpButton {
|
||||
NUM_PUMP_PAD_BUTTONS // leave this at the end
|
||||
};
|
||||
|
||||
|
||||
const int NUM_DEVICE_BUTTONS[NUM_INPUT_DEVICES] =
|
||||
{
|
||||
NUM_KEYBOARD_BUTTONS, // DEVICE_KEYBOARD
|
||||
NUM_JOYSTICK_BUTTONS, // DEVICE_JOY1
|
||||
NUM_JOYSTICK_BUTTONS, // DEVICE_JOY2
|
||||
NUM_JOYSTICK_BUTTONS, // DEVICE_JOY3
|
||||
NUM_JOYSTICK_BUTTONS, // DEVICE_JOY4
|
||||
NUM_PUMP_PAD_BUTTONS, // DEVICE_PUMP1
|
||||
NUM_PUMP_PAD_BUTTONS, // DEVICE_PUMP2
|
||||
};
|
||||
|
||||
const int MAX_DEVICE_BUTTONS = NUM_KEYBOARD_BUTTONS;
|
||||
|
||||
struct DeviceInput
|
||||
{
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user