@ -18,16 +18,8 @@
namespace InputCommon {
static std : : shared_ptr < Keyboard > keyboard ;
static std : : shared_ptr < MotionEmu > motion_emu ;
# ifdef HAVE_SDL2
static std : : unique_ptr < SDL : : State > sdl ;
# endif
static std : : unique_ptr < CemuhookUDP : : State > udp ;
static std : : shared_ptr < GCButtonFactory > gcbuttons ;
static std : : shared_ptr < GCAnalogFactory > gcanalog ;
void Init ( ) {
struct InputSubsystem : : Impl {
void Initialize ( ) {
auto gcadapter = std : : make_shared < GCAdapter : : Adapter > ( ) ;
gcbuttons = std : : make_shared < GCButtonFactory > ( gcadapter ) ;
Input : : RegisterFactory < Input : : ButtonDevice > ( " gcpad " , gcbuttons ) ;
@ -44,10 +36,11 @@ void Init() {
# ifdef HAVE_SDL2
sdl = SDL : : Init ( ) ;
# endif
udp = CemuhookUDP : : Init ( ) ;
}
}
void Shutdown ( ) {
void Shutdown ( ) {
Input : : UnregisterFactory < Input : : ButtonDevice > ( " keyboard " ) ;
keyboard . reset ( ) ;
Input : : UnregisterFactory < Input : : AnalogDevice > ( " analog_from_button " ) ;
@ -62,47 +55,9 @@ void Shutdown() {
gcbuttons . reset ( ) ;
gcanalog . reset ( ) ;
}
Keyboard * GetKeyboard ( ) {
return keyboard . get ( ) ;
}
MotionEmu * GetMotionEmu ( ) {
return motion_emu . get ( ) ;
}
GCButtonFactory * GetGCButtons ( ) {
return gcbuttons . get ( ) ;
}
GCAnalogFactory * GetGCAnalogs ( ) {
return gcanalog . get ( ) ;
}
std : : string GenerateKeyboardParam ( int key_code ) {
Common : : ParamPackage param {
{ " engine " , " keyboard " } ,
{ " code " , std : : to_string ( key_code ) } ,
} ;
return param . Serialize ( ) ;
}
std : : string GenerateAnalogParamFromKeys ( int key_up , int key_down , int key_left , int key_right ,
int key_modifier , float modifier_scale ) {
Common : : ParamPackage circle_pad_param {
{ " engine " , " analog_from_button " } ,
{ " up " , GenerateKeyboardParam ( key_up ) } ,
{ " down " , GenerateKeyboardParam ( key_down ) } ,
{ " left " , GenerateKeyboardParam ( key_left ) } ,
{ " right " , GenerateKeyboardParam ( key_right ) } ,
{ " modifier " , GenerateKeyboardParam ( key_modifier ) } ,
{ " modifier_scale " , std : : to_string ( modifier_scale ) } ,
} ;
return circle_pad_param . Serialize ( ) ;
}
}
std : : vector < Common : : ParamPackage > GetInputDevices ( ) {
[[nodiscard]] std : : vector < Common : : ParamPackage > GetInputDevices ( ) const {
std : : vector < Common : : ParamPackage > devices = {
Common : : ParamPackage { { " display " , " Any " } , { " class " , " any " } } ,
Common : : ParamPackage { { " display " , " Keyboard/Mouse " } , { " class " , " key " } } ,
@ -114,11 +69,10 @@ std::vector<Common::ParamPackage> GetInputDevices() {
auto udp_devices = udp - > GetInputDevices ( ) ;
devices . insert ( devices . end ( ) , udp_devices . begin ( ) , udp_devices . end ( ) ) ;
return devices ;
}
}
std : : unordered_map < Settings : : NativeButton : : Values , Common : : ParamPackage > GetButtonMappingForDevice (
const Common : : ParamPackage & params ) {
std : : unordered_map < Settings : : NativeButton : : Values , Common : : ParamPackage > mappings ;
[[nodiscard]] AnalogMapping GetAnalogMappingForDevice (
const Common : : ParamPackage & params ) const {
if ( ! params . Has ( " class " ) | | params . Get ( " class " , " " ) = = " any " ) {
return { } ;
}
@ -128,15 +82,14 @@ std::unordered_map<Settings::NativeButton::Values, Common::ParamPackage> GetButt
}
# ifdef HAVE_SDL2
if ( params . Get ( " class " , " " ) = = " sdl " ) {
return sdl - > GetButton MappingForDevice ( params ) ;
return sdl - > GetAnalog MappingForDevice ( params ) ;
}
# endif
return { } ;
}
}
std : : unordered_map < Settings : : NativeAnalog : : Values , Common : : ParamPackage > GetAnalogMappingForDevice (
const Common : : ParamPackage & params ) {
std : : unordered_map < Settings : : NativeAnalog : : Values , Common : : ParamPackage > mappings ;
[[nodiscard]] ButtonMapping GetButtonMappingForDevice (
const Common : : ParamPackage & params ) const {
if ( ! params . Has ( " class " ) | | params . Get ( " class " , " " ) = = " any " ) {
return { } ;
}
@ -146,23 +99,106 @@ std::unordered_map<Settings::NativeAnalog::Values, Common::ParamPackage> GetAnal
}
# ifdef HAVE_SDL2
if ( params . Get ( " class " , " " ) = = " sdl " ) {
return sdl - > GetAnalog MappingForDevice ( params ) ;
return sdl - > GetButton MappingForDevice ( params ) ;
}
# endif
return { } ;
}
std : : shared_ptr < Keyboard > keyboard ;
std : : shared_ptr < MotionEmu > motion_emu ;
# ifdef HAVE_SDL2
std : : unique_ptr < SDL : : State > sdl ;
# endif
std : : unique_ptr < CemuhookUDP : : State > udp ;
std : : shared_ptr < GCButtonFactory > gcbuttons ;
std : : shared_ptr < GCAnalogFactory > gcanalog ;
} ;
InputSubsystem : : InputSubsystem ( ) : impl { std : : make_unique < Impl > ( ) } { }
InputSubsystem : : ~ InputSubsystem ( ) = default ;
void InputSubsystem : : Initialize ( ) {
impl - > Initialize ( ) ;
}
void InputSubsystem : : Shutdown ( ) {
impl - > Shutdown ( ) ;
}
Keyboard * InputSubsystem : : GetKeyboard ( ) {
return impl - > keyboard . get ( ) ;
}
const Keyboard * InputSubsystem : : GetKeyboard ( ) const {
return impl - > keyboard . get ( ) ;
}
MotionEmu * InputSubsystem : : GetMotionEmu ( ) {
return impl - > motion_emu . get ( ) ;
}
const MotionEmu * InputSubsystem : : GetMotionEmu ( ) const {
return impl - > motion_emu . get ( ) ;
}
std : : vector < Common : : ParamPackage > InputSubsystem : : GetInputDevices ( ) const {
return impl - > GetInputDevices ( ) ;
}
AnalogMapping InputSubsystem : : GetAnalogMappingForDevice ( const Common : : ParamPackage & device ) const {
return impl - > GetAnalogMappingForDevice ( device ) ;
}
ButtonMapping InputSubsystem : : GetButtonMappingForDevice ( const Common : : ParamPackage & device ) const {
return impl - > GetButtonMappingForDevice ( device ) ;
}
GCAnalogFactory * InputSubsystem : : GetGCAnalogs ( ) {
return impl - > gcanalog . get ( ) ;
}
const GCAnalogFactory * InputSubsystem : : GetGCAnalogs ( ) const {
return impl - > gcanalog . get ( ) ;
}
namespace Polling {
GCButtonFactory * InputSubsystem : : GetGCButtons ( ) {
return impl - > gcbuttons . get ( ) ;
}
std : : vector < std : : unique_ptr < DevicePoller > > GetPollers ( DeviceType type ) {
std : : vector < std : : unique_ptr < DevicePoller > > pollers ;
const GCButtonFactory * InputSubsystem : : GetGCButtons ( ) const {
return impl - > gcbuttons . get ( ) ;
}
std : : vector < std : : unique_ptr < Polling : : DevicePoller > > InputSubsystem : : GetPollers (
Polling : : DeviceType type ) const {
# ifdef HAVE_SDL2
pollers = sdl - > GetPollers ( type ) ;
return impl - > sdl - > GetPollers ( type ) ;
# else
return { } ;
# endif
}
return pollers ;
std : : string GenerateKeyboardParam ( int key_code ) {
Common : : ParamPackage param {
{ " engine " , " keyboard " } ,
{ " code " , std : : to_string ( key_code ) } ,
} ;
return param . Serialize ( ) ;
}
} // namespace Polling
std : : string GenerateAnalogParamFromKeys ( int key_up , int key_down , int key_left , int key_right ,
int key_modifier , float modifier_scale ) {
Common : : ParamPackage circle_pad_param {
{ " engine " , " analog_from_button " } ,
{ " up " , GenerateKeyboardParam ( key_up ) } ,
{ " down " , GenerateKeyboardParam ( key_down ) } ,
{ " left " , GenerateKeyboardParam ( key_left ) } ,
{ " right " , GenerateKeyboardParam ( key_right ) } ,
{ " modifier " , GenerateKeyboardParam ( key_modifier ) } ,
{ " modifier_scale " , std : : to_string ( modifier_scale ) } ,
} ;
return circle_pad_param . Serialize ( ) ;
}
} // namespace InputCommon