Address the loops.

This commit is contained in:
Jason Felds
2013-04-30 20:44:36 -04:00
parent e2ea061fdc
commit 1be7ad9415
+20 -20
View File
@@ -78,20 +78,20 @@ void InputMapper::AddDefaultMappingsForCurrentGameIfUnmapped()
vector<AutoMappingEntry> aMaps; vector<AutoMappingEntry> aMaps;
aMaps.reserve( 32 ); aMaps.reserve( 32 );
FOREACH_CONST( AutoMappingEntry, g_DefaultKeyMappings.m_vMaps, iter ) for (AutoMappingEntry const &iter : g_DefaultKeyMappings.m_vMaps)
aMaps.push_back( *iter ); aMaps.push_back( iter );
FOREACH_CONST( AutoMappingEntry, m_pInputScheme->m_pAutoMappings->m_vMaps, iter ) for (AutoMappingEntry const &iter : m_pInputScheme->m_pAutoMappings->m_vMaps)
aMaps.push_back( *iter ); aMaps.push_back( iter );
/* There may be duplicate GAME_BUTTON maps. Process the list backwards, /* There may be duplicate GAME_BUTTON maps. Process the list backwards,
* so game-specific mappings override g_DefaultKeyMappings. */ * so game-specific mappings override g_DefaultKeyMappings. */
std::reverse( aMaps.begin(), aMaps.end() ); std::reverse( aMaps.begin(), aMaps.end() );
FOREACH( AutoMappingEntry, aMaps, m ) for (AutoMappingEntry const &m : aMaps)
{ {
DeviceButton key = m->m_deviceButton; DeviceButton key = m.m_deviceButton;
DeviceInput DeviceI( DEVICE_KEYBOARD, key ); DeviceInput DeviceI( DEVICE_KEYBOARD, key );
GameInput GameI( m->m_bSecondController ? GameController_2 : GameController_1, m->m_gb ); GameInput GameI( m.m_bSecondController ? GameController_2 : GameController_1, m.m_gb );
if( !IsMapped(DeviceI) ) // if this key isn't already being used by another user-made mapping if( !IsMapped(DeviceI) ) // if this key isn't already being used by another user-made mapping
{ {
if( !GameI.IsValid() ) if( !GameI.IsValid() )
@@ -526,10 +526,10 @@ void InputMapper::Unmap( InputDevice id )
void InputMapper::ApplyMapping( const vector<AutoMappingEntry> &vMmaps, GameController gc, InputDevice id ) void InputMapper::ApplyMapping( const vector<AutoMappingEntry> &vMmaps, GameController gc, InputDevice id )
{ {
map<GameInput, int> MappedButtons; map<GameInput, int> MappedButtons;
FOREACH_CONST( AutoMappingEntry, vMmaps, iter ) for (AutoMappingEntry const &iter : vMmaps)
{ {
GameController map_gc = gc; GameController map_gc = gc;
if( iter->m_bSecondController ) if( iter.m_bSecondController )
{ {
map_gc = (GameController)(map_gc+1); map_gc = (GameController)(map_gc+1);
@@ -540,8 +540,8 @@ void InputMapper::ApplyMapping( const vector<AutoMappingEntry> &vMmaps, GameCont
continue; continue;
} }
DeviceInput di( id, iter->m_deviceButton ); DeviceInput di( id, iter.m_deviceButton );
GameInput gi( map_gc, iter->m_gb ); GameInput gi( map_gc, iter.m_gb );
int iSlot = MappedButtons[gi]; int iSlot = MappedButtons[gi];
++MappedButtons[gi]; ++MappedButtons[gi];
SetInputMap( di, gi, iSlot );//maps[k].iSlotIndex ); SetInputMap( di, gi, iSlot );//maps[k].iSlotIndex );
@@ -559,10 +559,10 @@ void InputMapper::AutoMapJoysticksForCurrentGame()
// file automaps - Add these first so that they can match before the hard-coded mappings // file automaps - Add these first so that they can match before the hard-coded mappings
vector<RString> vs; vector<RString> vs;
GetDirListing( AUTOMAPPINGS_DIR "*.ini", vs, false, true ); GetDirListing( AUTOMAPPINGS_DIR "*.ini", vs, false, true );
FOREACH_CONST( RString, vs, sFilePath ) for (RString const &sFilePath : vs)
{ {
InputMappings km; InputMappings km;
km.ReadMappings( m_pInputScheme, *sFilePath, true ); km.ReadMappings( m_pInputScheme, sFilePath, true );
AutoMappings mapping( m_pInputScheme->m_szName, km.m_sDeviceRegex, km.m_sDescription ); AutoMappings mapping( m_pInputScheme->m_szName, km.m_sDeviceRegex, km.m_sDescription );
@@ -597,13 +597,13 @@ void InputMapper::AutoMapJoysticksForCurrentGame()
// apply auto mappings // apply auto mappings
int iNumJoysticksMapped = 0; int iNumJoysticksMapped = 0;
FOREACH_CONST( InputDeviceInfo, vDevices, device ) for (InputDeviceInfo const &device : vDevices)
{ {
InputDevice id = device->id; InputDevice id = device.id;
const RString &sDescription = device->sDesc; const RString &sDescription = device.sDesc;
FOREACH_CONST( AutoMappings, vAutoMappings, mapping ) for (AutoMappings const &mapping : vAutoMappings)
{ {
Regex regex( mapping->m_sDriverRegex ); Regex regex( mapping.m_sDriverRegex );
if( !regex.Compare(sDescription) ) if( !regex.Compare(sDescription) )
continue; // driver names don't match continue; // driver names don't match
@@ -613,10 +613,10 @@ void InputMapper::AutoMapJoysticksForCurrentGame()
break; // stop mapping. We already mapped one device for each game controller. break; // stop mapping. We already mapped one device for each game controller.
LOG->Info( "Applying default joystick mapping #%d for device '%s' (%s)", LOG->Info( "Applying default joystick mapping #%d for device '%s' (%s)",
iNumJoysticksMapped+1, mapping->m_sDriverRegex.c_str(), mapping->m_sControllerName.c_str() ); iNumJoysticksMapped+1, mapping.m_sDriverRegex.c_str(), mapping.m_sControllerName.c_str() );
Unmap( id ); Unmap( id );
ApplyMapping( mapping->m_vMaps, gc, id ); ApplyMapping( mapping.m_vMaps, gc, id );
iNumJoysticksMapped++; iNumJoysticksMapped++;
} }