optimize InputFilter::Update

This commit is contained in:
Chris Danford
2003-10-07 05:59:58 +00:00
parent 8ac398d192
commit 8c3db31ba7
5 changed files with 30 additions and 12 deletions
+10 -4
View File
@@ -27,7 +27,7 @@ InputFilter::InputFilter()
memset( m_BeingForced, 0, sizeof(m_BeingForced) ); memset( m_BeingForced, 0, sizeof(m_BeingForced) );
memset( m_fSecsHeld, 0, sizeof(m_fSecsHeld) ); memset( m_fSecsHeld, 0, sizeof(m_fSecsHeld) );
for( int d=0; d<NUM_INPUT_DEVICES; d++ ) // foreach InputDevice 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; m_fSecsToForce[d][b] = -1;
Reset(); Reset();
@@ -142,7 +142,7 @@ void InputFilter::StopForcingKey( DeviceInput di )
/* Release all buttons on the given device. */ /* Release all buttons on the given device. */
void InputFilter::ResetDevice( InputDevice dev ) 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 ); ButtonPressed( DeviceInput(dev, button), false );
} }
@@ -174,11 +174,17 @@ void InputFilter::Update(float fDeltaTime)
* things like "key pressed, key release, key repeat". */ * things like "key pressed, key release, key repeat". */
LockMut(*queuemutex); 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 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 ) if( m_fSecsToForce[d][b] > 0 )
{ {
+4 -4
View File
@@ -38,12 +38,12 @@ typedef vector<InputEvent> InputEventArray;
class RageMutex; class RageMutex;
class InputFilter class InputFilter
{ {
bool m_BeingHeld[NUM_INPUT_DEVICES][NUM_DEVICE_BUTTONS]; bool m_BeingHeld[NUM_INPUT_DEVICES][MAX_DEVICE_BUTTONS];
bool m_BeingForced[NUM_INPUT_DEVICES][NUM_DEVICE_BUTTONS]; bool m_BeingForced[NUM_INPUT_DEVICES][MAX_DEVICE_BUTTONS];
float m_fSecsHeld[NUM_INPUT_DEVICES][NUM_DEVICE_BUTTONS]; float m_fSecsHeld[NUM_INPUT_DEVICES][MAX_DEVICE_BUTTONS];
/* If > 0, then when it reaches 0, stop forcing. */ /* 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; InputEventArray queue;
RageMutex *queuemutex; RageMutex *queuemutex;
+1 -1
View File
@@ -448,7 +448,7 @@ void InputMapper::UpdateTempDItoGI()
// clear out m_tempDItoGI // clear out m_tempDItoGI
for( int d=0; d<NUM_INPUT_DEVICES; d++ ) 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(); m_tempDItoGI[d][b].MakeInvalid();
} }
+1 -1
View File
@@ -68,7 +68,7 @@ protected:
// lookup for efficiency from a DeviceInput to a GameInput // lookup for efficiency from a DeviceInput to a GameInput
// This is repopulated every time m_PItoDI changes by calling UpdateTempDItoPI(). // 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(); void UpdateTempDItoGI();
}; };
+14 -2
View File
@@ -9,8 +9,6 @@ const int NUM_JOYSTICKS = 4;
const int NUM_JOYSTICK_HATS = 1; const int NUM_JOYSTICK_HATS = 1;
const int NUM_PUMPS = 2; const int NUM_PUMPS = 2;
const int NUM_DEVICE_BUTTONS = NUM_KEYBOARD_BUTTONS;
enum InputDevice { enum InputDevice {
DEVICE_KEYBOARD = 0, DEVICE_KEYBOARD = 0,
DEVICE_JOY1, DEVICE_JOY1,
@@ -56,6 +54,20 @@ enum PumpButton {
NUM_PUMP_PAD_BUTTONS // leave this at the end 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 struct DeviceInput
{ {
public: public: