Skip to content

Commit 2f16058

Browse files
committed
Unify directions and buttons in gamepad controls
1 parent ef4f6e4 commit 2f16058

File tree

7 files changed

+120
-147
lines changed

7 files changed

+120
-147
lines changed

DesktopEmulator/DesktopInfrastructure/EmulatorInterfaces.hpp

+10-12
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,20 @@ namespace V32
1616
// =============================================================================
1717

1818

19-
// button codes for input events
20-
enum class GamepadButtons
21-
{
22-
Start = 0,
23-
A, B, X, Y, L, R
24-
};
25-
26-
// -----------------------------------------------------------------------------
27-
28-
// directions codes for input events
29-
enum class GamepadDirections
19+
// gamepad controls for input events
20+
enum class GamepadControls
3021
{
3122
Left = 0,
3223
Right,
3324
Up,
34-
Down
25+
Down,
26+
ButtonStart,
27+
ButtonA,
28+
ButtonB,
29+
ButtonX,
30+
ButtonY,
31+
ButtonL,
32+
ButtonR
3533
};
3634

3735

DesktopEmulator/Emulator/Settings.cpp

+13-13
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ KeyboardMapping KeyboardProfile;
108108
map< SDL_JoystickGUID, JoystickMapping* > JoystickProfiles;
109109

110110
// maps {Vircon gamepads} --> {PC devices}
111-
DeviceInfo MappedGamepads[ Constants::MaximumGamepads ];
111+
DeviceInfo MappedGamepads[ Constants::GamepadPorts ];
112112

113113

114114
// =============================================================================
@@ -462,12 +462,12 @@ void AssignInputDevices()
462462
bool IsKeyboardUsed = false;
463463

464464
// update mappings for gamepads
465-
for( int Gamepad = 0; Gamepad < Constants::MaximumGamepads; Gamepad++ )
465+
for( int Gamepad = 0; Gamepad < Constants::GamepadPorts; Gamepad++ )
466466
{
467467
DeviceInfo* GamepadDevice = &MappedGamepads[ Gamepad ];
468468

469469
// preemptively disconnect the gamepad
470-
Vircon.GamepadController.ProcessConnectionChange( Gamepad, false );
470+
Vircon.GamepadController.SetGamepadConnection( Gamepad, false );
471471

472472
// process non-joystick devices
473473
if( GamepadDevice->Type == DeviceTypes::NoDevice )
@@ -482,7 +482,7 @@ void AssignInputDevices()
482482
else
483483
{
484484
IsKeyboardUsed = true;
485-
Vircon.GamepadController.ProcessConnectionChange( Gamepad, true );
485+
Vircon.GamepadController.SetGamepadConnection( Gamepad, true );
486486
}
487487

488488
continue;
@@ -506,7 +506,7 @@ void AssignInputDevices()
506506
{
507507
MappedInstanceIDs.insert( JoystickInstanceID );
508508
GamepadDevice->InstanceID = JoystickInstanceID;
509-
Vircon.GamepadController.ProcessConnectionChange( Gamepad, true );
509+
Vircon.GamepadController.SetGamepadConnection( Gamepad, true );
510510
break;
511511
}
512512
}
@@ -539,13 +539,13 @@ void SetDefaultSettings()
539539
Vircon.UnloadMemoryCard();
540540

541541
// set keyboard for first gamepad
542-
Vircon.GamepadController.ProcessConnectionChange( 0, true );
542+
Vircon.GamepadController.SetGamepadConnection( 0, true );
543543
MappedGamepads[ 0 ].Type = DeviceTypes::Keyboard;
544544

545545
// set no device for the rest of gamepads
546-
for( int i = 1; i < Constants::MaximumGamepads; i++ )
546+
for( int i = 1; i < Constants::GamepadPorts; i++ )
547547
{
548-
Vircon.GamepadController.ProcessConnectionChange( i, false );
548+
Vircon.GamepadController.SetGamepadConnection( i, false );
549549
MappedGamepads[ i ].Type = DeviceTypes::NoDevice;
550550
}
551551

@@ -643,15 +643,15 @@ void LoadSettings( const string& FilePath )
643643
Vircon.SPU.NumberOfBuffers = NumberOfBuffers;
644644

645645
// configure gamepads
646-
for( int Gamepad = 0; Gamepad < Constants::MaximumGamepads; Gamepad++ )
646+
for( int Gamepad = 0; Gamepad < Constants::GamepadPorts; Gamepad++ )
647647
{
648648
// access the Nth gamepad element
649649
string GamepadElementName = string("gamepad-") + to_string( Gamepad+1 );
650650
XMLElement* GamepadRoot = GetRequiredElement( SettingsRoot, GamepadElementName.c_str() );
651651

652652
// preemptively leave the gamepad unmapped and disconnected
653653
// unless a valid profile is found for it later
654-
Vircon.GamepadController.ProcessConnectionChange( Gamepad, false );
654+
Vircon.GamepadController.SetGamepadConnection( Gamepad, false );
655655
MappedGamepads[ Gamepad ].Type = DeviceTypes::NoDevice;
656656

657657
// read profile name
@@ -668,7 +668,7 @@ void LoadSettings( const string& FilePath )
668668
if( ToLowerCase( ProfileName ) == "keyboard" )
669669
{
670670
MappedGamepads[ Gamepad ].Type = DeviceTypes::Keyboard;
671-
Vircon.GamepadController.ProcessConnectionChange( Gamepad, true );
671+
Vircon.GamepadController.SetGamepadConnection( Gamepad, true );
672672
continue;
673673
}
674674

@@ -680,7 +680,7 @@ void LoadSettings( const string& FilePath )
680680
{
681681
MappedGamepads[ Gamepad ].Type = DeviceTypes::Joystick;
682682
MappedGamepads[ Gamepad ].GUID = Position->first;
683-
Vircon.GamepadController.ProcessConnectionChange( Gamepad, true );
683+
Vircon.GamepadController.SetGamepadConnection( Gamepad, true );
684684
continue;
685685
}
686686
}
@@ -810,7 +810,7 @@ void SaveSettings( const string& FilePath )
810810
SettingsRoot->LinkEndChild( AudioBuffersElement );
811811

812812
// save gamepad profiles
813-
for( int Gamepad = 0; Gamepad < Constants::MaximumGamepads; Gamepad++ )
813+
for( int Gamepad = 0; Gamepad < Constants::GamepadPorts; Gamepad++ )
814814
{
815815
// determine profile name
816816
DeviceInfo MappedDevice = MappedGamepads[ Gamepad ];

DesktopEmulator/Emulator/Settings.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ extern KeyboardMapping KeyboardProfile;
140140
extern std::map< SDL_JoystickGUID, JoystickMapping* > JoystickProfiles;
141141

142142
// maps {Vircon gamepads} --> {PC devices}
143-
extern DeviceInfo MappedGamepads[ V32::Constants::MaximumGamepads ];
143+
extern DeviceInfo MappedGamepads[ V32::Constants::GamepadPorts ];
144144

145145

146146
// =============================================================================

0 commit comments

Comments
 (0)