mirror of https://github.com/PCSX2/pcsx2.git
InputManager: Add UpdateSettings() to sources
This commit is contained in:
parent
dbc176fe25
commit
7555091d56
|
@ -887,26 +887,32 @@ void InputManager::PollSources()
|
||||||
template <typename T>
|
template <typename T>
|
||||||
static void UpdateInputSourceState(SettingsInterface& si, InputSourceType type, bool default_state)
|
static void UpdateInputSourceState(SettingsInterface& si, InputSourceType type, bool default_state)
|
||||||
{
|
{
|
||||||
const bool old_state = (s_input_sources[static_cast<u32>(type)] != nullptr);
|
const bool enabled = si.GetBoolValue("InputSources", InputManager::InputSourceToString(type), default_state);
|
||||||
const bool new_state = si.GetBoolValue("InputSources", InputManager::InputSourceToString(type), default_state);
|
if (enabled)
|
||||||
if (old_state == new_state)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (new_state)
|
|
||||||
{
|
{
|
||||||
std::unique_ptr<InputSource> source = std::make_unique<T>();
|
if (s_input_sources[static_cast<u32>(type)])
|
||||||
if (!source->Initialize(si))
|
|
||||||
{
|
{
|
||||||
Console.Error("(InputManager) Source '%s' failed to initialize.", InputManager::InputSourceToString(type));
|
s_input_sources[static_cast<u32>(type)]->UpdateSettings(si);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::unique_ptr<InputSource> source = std::make_unique<T>();
|
||||||
|
if (!source->Initialize(si))
|
||||||
|
{
|
||||||
|
Console.Error("(InputManager) Source '%s' failed to initialize.", InputManager::InputSourceToString(type));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
s_input_sources[static_cast<u32>(type)] = std::move(source);
|
s_input_sources[static_cast<u32>(type)] = std::move(source);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
s_input_sources[static_cast<u32>(type)]->Shutdown();
|
if (s_input_sources[static_cast<u32>(type)])
|
||||||
s_input_sources[static_cast<u32>(type)].reset();
|
{
|
||||||
|
s_input_sources[static_cast<u32>(type)]->Shutdown();
|
||||||
|
s_input_sources[static_cast<u32>(type)].reset();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,7 @@ public:
|
||||||
virtual ~InputSource();
|
virtual ~InputSource();
|
||||||
|
|
||||||
virtual bool Initialize(SettingsInterface& si) = 0;
|
virtual bool Initialize(SettingsInterface& si) = 0;
|
||||||
|
virtual void UpdateSettings(SettingsInterface& si) = 0;
|
||||||
virtual void Shutdown() = 0;
|
virtual void Shutdown() = 0;
|
||||||
|
|
||||||
virtual void PollEvents() = 0;
|
virtual void PollEvents() = 0;
|
||||||
|
|
|
@ -74,20 +74,42 @@ bool SDLInputSource::Initialize(SettingsInterface& si)
|
||||||
Console.Error("Controller database resource is missing.");
|
Console.Error("Controller database resource is missing.");
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool ds4_rumble_enabled = si.GetBoolValue("InputSources", "SDLControllerEnhancedMode", false);
|
LoadSettings(si);
|
||||||
if (ds4_rumble_enabled)
|
SetHints();
|
||||||
|
return InitializeSubsystem();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SDLInputSource::UpdateSettings(SettingsInterface& si)
|
||||||
|
{
|
||||||
|
const bool old_controller_enhanced_mode = m_controller_enhanced_mode;
|
||||||
|
|
||||||
|
LoadSettings(si);
|
||||||
|
|
||||||
|
if (m_controller_enhanced_mode != old_controller_enhanced_mode)
|
||||||
{
|
{
|
||||||
Console.WriteLn("Enabling PS4/PS5 enhanced mode.");
|
ShutdownSubsystem();
|
||||||
|
SetHints();
|
||||||
|
InitializeSubsystem();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SDLInputSource::LoadSettings(SettingsInterface& si)
|
||||||
|
{
|
||||||
|
m_controller_enhanced_mode = si.GetBoolValue("InputSources", "SDLControllerEnhancedMode", false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SDLInputSource::SetHints()
|
||||||
|
{
|
||||||
#if SDL_VERSION_ATLEAST(2, 0, 9)
|
#if SDL_VERSION_ATLEAST(2, 0, 9)
|
||||||
SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS4, "true");
|
SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE, m_controller_enhanced_mode ? "1" : "0");
|
||||||
SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE, "true");
|
|
||||||
#endif
|
#endif
|
||||||
#if SDL_VERSION_ATLEAST(2, 0, 16)
|
#if SDL_VERSION_ATLEAST(2, 0, 16)
|
||||||
SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS5, "true");
|
SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS5_RUMBLE, m_controller_enhanced_mode ? "1" : "0");
|
||||||
SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS5_RUMBLE, "true");
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SDLInputSource::InitializeSubsystem()
|
||||||
|
{
|
||||||
if (SDL_InitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER | SDL_INIT_HAPTIC) < 0)
|
if (SDL_InitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER | SDL_INIT_HAPTIC) < 0)
|
||||||
{
|
{
|
||||||
Console.Error("SDL_InitSubSystem(SDL_INIT_JOYSTICK |SDL_INIT_GAMECONTROLLER | SDL_INIT_HAPTIC) failed");
|
Console.Error("SDL_InitSubSystem(SDL_INIT_JOYSTICK |SDL_INIT_GAMECONTROLLER | SDL_INIT_HAPTIC) failed");
|
||||||
|
@ -99,7 +121,7 @@ bool SDLInputSource::Initialize(SettingsInterface& si)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDLInputSource::Shutdown()
|
void SDLInputSource::ShutdownSubsystem()
|
||||||
{
|
{
|
||||||
while (!m_controllers.empty())
|
while (!m_controllers.empty())
|
||||||
CloseGameController(m_controllers.begin()->joystick_id);
|
CloseGameController(m_controllers.begin()->joystick_id);
|
||||||
|
|
|
@ -30,6 +30,7 @@ public:
|
||||||
~SDLInputSource();
|
~SDLInputSource();
|
||||||
|
|
||||||
bool Initialize(SettingsInterface& si) override;
|
bool Initialize(SettingsInterface& si) override;
|
||||||
|
void UpdateSettings(SettingsInterface& si) override;
|
||||||
void Shutdown() override;
|
void Shutdown() override;
|
||||||
|
|
||||||
void PollEvents() override;
|
void PollEvents() override;
|
||||||
|
@ -62,6 +63,11 @@ private:
|
||||||
|
|
||||||
using ControllerDataVector = std::vector<ControllerData>;
|
using ControllerDataVector = std::vector<ControllerData>;
|
||||||
|
|
||||||
|
bool InitializeSubsystem();
|
||||||
|
void ShutdownSubsystem();
|
||||||
|
void LoadSettings(SettingsInterface& si);
|
||||||
|
void SetHints();
|
||||||
|
|
||||||
ControllerDataVector::iterator GetControllerDataForJoystickId(int id);
|
ControllerDataVector::iterator GetControllerDataForJoystickId(int id);
|
||||||
ControllerDataVector::iterator GetControllerDataForPlayerId(int id);
|
ControllerDataVector::iterator GetControllerDataForPlayerId(int id);
|
||||||
int GetFreePlayerId() const;
|
int GetFreePlayerId() const;
|
||||||
|
@ -75,4 +81,5 @@ private:
|
||||||
ControllerDataVector m_controllers;
|
ControllerDataVector m_controllers;
|
||||||
|
|
||||||
bool m_sdl_subsystem_initialized = false;
|
bool m_sdl_subsystem_initialized = false;
|
||||||
|
bool m_controller_enhanced_mode = false;
|
||||||
};
|
};
|
||||||
|
|
|
@ -110,6 +110,10 @@ bool XInputSource::Initialize(SettingsInterface& si)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void XInputSource::UpdateSettings(SettingsInterface& si)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void XInputSource::Shutdown()
|
void XInputSource::Shutdown()
|
||||||
{
|
{
|
||||||
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
|
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
|
||||||
|
|
|
@ -30,6 +30,7 @@ public:
|
||||||
~XInputSource();
|
~XInputSource();
|
||||||
|
|
||||||
bool Initialize(SettingsInterface& si) override;
|
bool Initialize(SettingsInterface& si) override;
|
||||||
|
void UpdateSettings(SettingsInterface& si) override;
|
||||||
void Shutdown() override;
|
void Shutdown() override;
|
||||||
|
|
||||||
void PollEvents() override;
|
void PollEvents() override;
|
||||||
|
|
Loading…
Reference in New Issue