Simplify. Don't pass the button pressed bool along. This can be derived from the level every time.

This commit is contained in:
Steve Checkoway
2006-09-15 08:31:53 +00:00
parent fe95757304
commit 125fccc33c
8 changed files with 26 additions and 39 deletions
@@ -24,12 +24,12 @@ void InputHandler_Carbon::QueueCallBack( void *target, int result, void *refcon,
IOHIDEventStruct event;
AbsoluteTime zeroTime = { 0, 0 };
HIDDevice *dev = This->m_vDevices[int( refcon )];
vector<pair<DeviceInput, bool> > vPresses;
vector<DeviceInput> vPresses;
while( (result = CALL(queue, getNextEvent, &event, zeroTime, 0)) == kIOReturnSuccess )
dev->GetButtonPresses( vPresses, int(event.elementCookie), int(event.value), now );
for( vector<pair<DeviceInput, bool> >::const_iterator i = vPresses.begin(); i != vPresses.end(); ++i )
This->ButtonPressed( i->first, i->second );
FOREACH_CONST( DeviceInput, vPresses, i )
This->ButtonPressed( *i, i->level > 0.5f );
}
static void RunLoopStarted( CFRunLoopObserverRef o, CFRunLoopActivity a, void *sem )
+1 -2
View File
@@ -103,8 +103,7 @@ public:
* The value of the element is passed to determine if this is a push or a release. The time
* is provided as an optimization.
*/
virtual void GetButtonPresses( vector<pair<DeviceInput, bool> >& vPresses, int cookie,
int value, const RageTimer& now ) const = 0;
virtual void GetButtonPresses( vector<DeviceInput>& vPresses, int cookie, int value, const RageTimer& now ) const = 0;
/*
* Returns the number of IDs assigned starting from startID. This is not meaningful for devices like
@@ -132,8 +132,7 @@ bool JoystickDevice::SupportsVidPid( int vid, int pid )
return true;
}
void JoystickDevice::GetButtonPresses( vector<pair<DeviceInput, bool> >& vPresses, int cookie,
int value, const RageTimer& now ) const
void JoystickDevice::GetButtonPresses( vector<DeviceInput>& vPresses, int cookie, int value, const RageTimer& now ) const
{
FOREACH_CONST( Joystick, m_vSticks, i )
{
@@ -143,48 +142,48 @@ void JoystickDevice::GetButtonPresses( vector<pair<DeviceInput, bool> >& vPresse
{
float level = SCALE( value, js.x_min, js.x_max, -1.0f, 1.0f );
vPresses.push_back( make_pair(DeviceInput(js.id, JOY_LEFT, max(-level, 0.0f), now), level < -0.5f) );
vPresses.push_back( make_pair(DeviceInput(js.id, JOY_RIGHT, max(level, 0.0f), now), level > 0.5f) );
vPresses.push_back( DeviceInput(js.id, JOY_LEFT, max(-level, 0.0f), now) );
vPresses.push_back( DeviceInput(js.id, JOY_RIGHT, max(level, 0.0f), now) );
break;
}
else if( js.y_axis == cookie )
{
float level = SCALE( value, js.y_min, js.y_max, -1.0f, 1.0f );
vPresses.push_back( make_pair(DeviceInput(js.id, JOY_UP, max(-level, 0.0f), now), level < -0.5f) );
vPresses.push_back( make_pair(DeviceInput(js.id, JOY_DOWN, max(level, 0.0f), now), level > 0.5f) );
vPresses.push_back( DeviceInput(js.id, JOY_UP, max(-level, 0.0f), now) );
vPresses.push_back( DeviceInput(js.id, JOY_DOWN, max(level, 0.0f), now) );
break;
}
else if( js.z_axis == cookie )
{
float level = SCALE( value, js.z_min, js.z_max, -1.0f, 1.0f );
vPresses.push_back( make_pair(DeviceInput(js.id, JOY_Z_UP, max(-level, 0.0f), now), level < -0.5f) );
vPresses.push_back( make_pair(DeviceInput(js.id, JOY_Z_DOWN, max(level, 0.0f), now), level > 0.5f) );
vPresses.push_back( DeviceInput(js.id, JOY_Z_UP, max(-level, 0.0f), now) );
vPresses.push_back( DeviceInput(js.id, JOY_Z_DOWN, max(level, 0.0f), now) );
break;
}
else if( js.x_rot == cookie )
{
float level = SCALE( value, js.rx_min, js.rx_max, -1.0f, 1.0f );
vPresses.push_back( make_pair(DeviceInput(js.id, JOY_ROT_LEFT, max(-level, 0.0f), now), level < -0.5f) );
vPresses.push_back( make_pair(DeviceInput(js.id, JOY_ROT_RIGHT, max(level, 0.0f), now), level > 0.5f) );
vPresses.push_back( DeviceInput(js.id, JOY_ROT_LEFT, max(-level, 0.0f), now) );
vPresses.push_back( DeviceInput(js.id, JOY_ROT_RIGHT, max(level, 0.0f), now) );
break;
}
else if( js.y_rot == cookie )
{
float level = SCALE( value, js.ry_min, js.ry_max, -1.0f, 1.0f );
vPresses.push_back( make_pair(DeviceInput(js.id, JOY_ROT_UP, max(-level, 0.0f), now), level < -0.5f) );
vPresses.push_back( make_pair(DeviceInput(js.id, JOY_ROT_DOWN, max(level, 0.0f), now), level > 0.5f) );
vPresses.push_back( DeviceInput(js.id, JOY_ROT_UP, max(-level, 0.0f), now) );
vPresses.push_back( DeviceInput(js.id, JOY_ROT_DOWN, max(level, 0.0f), now) );
break;
}
else if( js.z_rot == cookie )
{
float level = SCALE( value, js.rz_min, js.rz_max, -1.0f, 1.0f );
vPresses.push_back( make_pair(DeviceInput(js.id, JOY_ROT_Z_UP, max(-level, 0.0f), now), level < -0.5f) );
vPresses.push_back( make_pair(DeviceInput(js.id, JOY_ROT_Z_DOWN, max(level, 0.0f), now), level > 0.5f) );
vPresses.push_back( DeviceInput(js.id, JOY_ROT_Z_UP, max(-level, 0.0f), now) );
vPresses.push_back( DeviceInput(js.id, JOY_ROT_Z_DOWN, max(level, 0.0f), now) );
break;
}
else
@@ -195,7 +194,7 @@ void JoystickDevice::GetButtonPresses( vector<pair<DeviceInput, bool> >& vPresse
iter = js.mapping.find( cookie );
if( iter != js.mapping.end() )
{
vPresses.push_back( make_pair(DeviceInput(js.id, iter->second, value, now), value) );
vPresses.push_back( DeviceInput(js.id, iter->second, value, now) );
break;
}
}
@@ -31,8 +31,7 @@ protected:
bool SupportsVidPid( int vid, int pid );
public:
void GetButtonPresses( vector<pair<DeviceInput, bool> >& vPresses, int cookie,
int value, const RageTimer& now ) const;
void GetButtonPresses( vector<DeviceInput>& vPresses, int cookie, int value, const RageTimer& now ) const;
int AssignIDs( InputDevice startID );
void GetDevicesAndDescriptions( vector<InputDeviceInfo>& vDevices ) const;
};
@@ -166,13 +166,12 @@ void KeyboardDevice::Open()
AddElementToQueue( i->first );
}
void KeyboardDevice::GetButtonPresses( vector<pair<DeviceInput, bool> >& vPresses, int cookie,
int value, const RageTimer& now ) const
void KeyboardDevice::GetButtonPresses( vector<DeviceInput>& vPresses, int cookie, int value, const RageTimer& now ) const
{
hash_map<int, DeviceButton>::const_iterator iter = m_Mapping.find( cookie );
if( iter != m_Mapping.end() )
vPresses.push_back( pair<DeviceInput, bool>(DeviceInput(DEVICE_KEYBOARD, iter->second, value, now), value) );
vPresses.push_back( DeviceInput(DEVICE_KEYBOARD, iter->second, value, now) );
}
@@ -15,8 +15,7 @@ protected:
void Open();
public:
void GetButtonPresses( vector<pair<DeviceInput, bool> >& vPresses, int cookie,
int value, const RageTimer& now ) const;
void GetButtonPresses( vector<DeviceInput>& vPresses, int cookie, int value, const RageTimer& now ) const;
void GetDevicesAndDescriptions( vector<InputDeviceInfo>& vDevices ) const;
static bool DeviceButtonToMacVirtualKey( DeviceButton button, UInt8 &iMacVKOut );
+3 -10
View File
@@ -11,8 +11,7 @@ void PumpDevice::Open()
AddElementToQueue( 8 );
}
void PumpDevice::GetButtonPresses( vector<pair<DeviceInput, bool> >& vPresses, int cookie,
int value, const RageTimer& now ) const
void PumpDevice::GetButtonPresses( vector<DeviceInput>& vPresses, int cookie, int value, const RageTimer& now ) const
{
DeviceButton db1 = DeviceButton_Invalid;
DeviceButton db2 = DeviceButton_Invalid;
@@ -46,15 +45,9 @@ void PumpDevice::GetButtonPresses( vector<pair<DeviceInput, bool> >& vPresses, i
break;
}
if( db1 != DeviceButton_Invalid )
{
DeviceInput di( m_Id, db1, pressed1 ? 1.0f : 0.0f , now );
vPresses.push_back( pair<DeviceInput, bool>(di, pressed1) );
}
vPresses.push_back( DeviceInput(m_Id, db1, pressed1 ? 1.0f : 0.0f , now) );
if( db2 != DeviceButton_Invalid )
{
DeviceInput di( m_Id, db2, pressed2 ? 1.0f : 0.0f , now );
vPresses.push_back( pair<DeviceInput, bool>(di, pressed2) );
}
vPresses.push_back( DeviceInput(m_Id, db2, pressed2 ? 1.0f : 0.0f , now) );
}
int PumpDevice::AssignIDs( InputDevice startID )
+1 -2
View File
@@ -16,8 +16,7 @@ protected:
bool SupportsVidPid( int vid, int pid ) { return vid == 0x0d2f && pid == 0x0001; }
public:
void GetButtonPresses( vector<pair<DeviceInput, bool> >& vPresses, int cookie,
int value, const RageTimer& now ) const;
void GetButtonPresses( vector<DeviceInput>& vPresses, int cookie, int value, const RageTimer& now ) const;
int AssignIDs( InputDevice startID );
void GetDevicesAndDescriptions( vector<InputDeviceInfo>& vDevices ) const;
};