summaryrefslogtreecommitdiff
path: root/Source/Core/InputCommon/ControllerInterface
diff options
context:
space:
mode:
authorScott Mansell <phiren@gmail.com>2021-05-14 20:51:33 +1200
committerGitHub <noreply@github.com>2021-05-14 20:51:33 +1200
commit9f91fb64479d3df14489378a6b4fb3ffa7d12f2d (patch)
tree702ec73b3745420750d05644c639f357492e57a1 /Source/Core/InputCommon/ControllerInterface
parent099bf16326c1549246fd1bd976fb1242e7ba0875 (diff)
parentf3ffac00583bd03d0620226392a2b15f3cfd273b (diff)
Merge pull request #9688 from Filoppi/input_cleanup
Input cleanup
Diffstat (limited to 'Source/Core/InputCommon/ControllerInterface')
-rw-r--r--Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp4
-rw-r--r--Source/Core/InputCommon/ControllerInterface/DualShockUDPClient/DualShockUDPClient.cpp12
-rw-r--r--Source/Core/InputCommon/ControllerInterface/DualShockUDPClient/DualShockUDPProto.h2
-rw-r--r--Source/Core/InputCommon/ControllerInterface/OSX/OSX.mm8
-rw-r--r--Source/Core/InputCommon/ControllerInterface/OSX/OSXJoystick.mm5
-rw-r--r--Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp6
-rw-r--r--Source/Core/InputCommon/ControllerInterface/Touch/ButtonManager.cpp40
-rw-r--r--Source/Core/InputCommon/ControllerInterface/Touch/ButtonManager.h10
-rw-r--r--Source/Core/InputCommon/ControllerInterface/Win32/Win32.cpp18
-rw-r--r--Source/Core/InputCommon/ControllerInterface/evdev/evdev.cpp6
10 files changed, 66 insertions, 45 deletions
diff --git a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp
index fe176ce7f7..0cae47c741 100644
--- a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp
+++ b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp
@@ -237,7 +237,7 @@ void ControllerInterface::AddDevice(std::shared_ptr<ciface::Core::Device> device
device->SetId(id);
}
- NOTICE_LOG_FMT(SERIALINTERFACE, "Added device: {}", device->GetQualifiedName());
+ NOTICE_LOG_FMT(CONTROLLERINTERFACE, "Added device: {}", device->GetQualifiedName());
m_devices.emplace_back(std::move(device));
}
@@ -252,7 +252,7 @@ void ControllerInterface::RemoveDevice(std::function<bool(const ciface::Core::De
auto it = std::remove_if(m_devices.begin(), m_devices.end(), [&callback](const auto& dev) {
if (callback(dev.get()))
{
- NOTICE_LOG_FMT(SERIALINTERFACE, "Removed device: {}", dev->GetQualifiedName());
+ NOTICE_LOG_FMT(CONTROLLERINTERFACE, "Removed device: {}", dev->GetQualifiedName());
return true;
}
return false;
diff --git a/Source/Core/InputCommon/ControllerInterface/DualShockUDPClient/DualShockUDPClient.cpp b/Source/Core/InputCommon/ControllerInterface/DualShockUDPClient/DualShockUDPClient.cpp
index 99767dee4c..ea855632c9 100644
--- a/Source/Core/InputCommon/ControllerInterface/DualShockUDPClient/DualShockUDPClient.cpp
+++ b/Source/Core/InputCommon/ControllerInterface/DualShockUDPClient/DualShockUDPClient.cpp
@@ -205,7 +205,7 @@ static bool IsSameController(const Proto::MessageType::PortInfo& a,
static void HotplugThreadFunc()
{
Common::SetCurrentThreadName("DualShockUDPClient Hotplug Thread");
- INFO_LOG_FMT(SERIALINTERFACE, "DualShockUDPClient hotplug thread started");
+ INFO_LOG_FMT(CONTROLLERINTERFACE, "DualShockUDPClient hotplug thread started");
while (s_hotplug_thread_running.IsSet())
{
@@ -225,7 +225,7 @@ static void HotplugThreadFunc()
if (server.m_socket.send(&list_ports, sizeof list_ports, server.m_address, server.m_port) !=
sf::Socket::Status::Done)
{
- ERROR_LOG_FMT(SERIALINTERFACE, "DualShockUDPClient HotplugThreadFunc send failed");
+ ERROR_LOG_FMT(CONTROLLERINTERFACE, "DualShockUDPClient HotplugThreadFunc send failed");
}
}
}
@@ -277,7 +277,7 @@ static void HotplugThreadFunc()
}
}
}
- INFO_LOG_FMT(SERIALINTERFACE, "DualShockUDPClient hotplug thread stopped");
+ INFO_LOG_FMT(CONTROLLERINTERFACE, "DualShockUDPClient hotplug thread stopped");
}
static void StartHotplugThread()
@@ -310,7 +310,7 @@ static void StopHotplugThread()
static void Restart()
{
- INFO_LOG_FMT(SERIALINTERFACE, "DualShockUDPClient Restart");
+ INFO_LOG_FMT(CONTROLLERINTERFACE, "DualShockUDPClient Restart");
StopHotplugThread();
@@ -394,7 +394,7 @@ void Init()
void PopulateDevices()
{
- INFO_LOG_FMT(SERIALINTERFACE, "DualShockUDPClient PopulateDevices");
+ INFO_LOG_FMT(CONTROLLERINTERFACE, "DualShockUDPClient PopulateDevices");
// s_servers has already been updated so we can't use it to know which devices we removed,
// also it's good to remove all of them before adding new ones so that their id will be set
@@ -510,7 +510,7 @@ void Device::UpdateInput()
if (m_socket.send(&data_req, sizeof(data_req), m_server_address, m_server_port) !=
sf::Socket::Status::Done)
{
- ERROR_LOG_FMT(SERIALINTERFACE, "DualShockUDPClient UpdateInput send failed");
+ ERROR_LOG_FMT(CONTROLLERINTERFACE, "DualShockUDPClient UpdateInput send failed");
}
}
diff --git a/Source/Core/InputCommon/ControllerInterface/DualShockUDPClient/DualShockUDPProto.h b/Source/Core/InputCommon/ControllerInterface/DualShockUDPClient/DualShockUDPProto.h
index 582b483555..5d445e11da 100644
--- a/Source/Core/InputCommon/ControllerInterface/DualShockUDPClient/DualShockUDPProto.h
+++ b/Source/Core/InputCommon/ControllerInterface/DualShockUDPClient/DualShockUDPProto.h
@@ -249,7 +249,7 @@ struct Message
if (crc32_in_header != crc32_calculated)
{
NOTICE_LOG_FMT(
- SERIALINTERFACE,
+ CONTROLLERINTERFACE,
"DualShockUDPClient Received message with bad CRC in header: got {:08x}, expected {:08x}",
crc32_in_header, crc32_calculated);
return std::nullopt;
diff --git a/Source/Core/InputCommon/ControllerInterface/OSX/OSX.mm b/Source/Core/InputCommon/ControllerInterface/OSX/OSX.mm
index de878b6a3e..63bddf499e 100644
--- a/Source/Core/InputCommon/ControllerInterface/OSX/OSX.mm
+++ b/Source/Core/InputCommon/ControllerInterface/OSX/OSX.mm
@@ -178,11 +178,11 @@ void Init(void* window)
HIDManager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
if (!HIDManager)
- ERROR_LOG_FMT(SERIALINTERFACE, "Failed to create HID Manager reference");
+ ERROR_LOG_FMT(CONTROLLERINTERFACE, "Failed to create HID Manager reference");
IOHIDManagerSetDeviceMatching(HIDManager, nullptr);
if (IOHIDManagerOpen(HIDManager, kIOHIDOptionsTypeNone) != kIOReturnSuccess)
- ERROR_LOG_FMT(SERIALINTERFACE, "Failed to open HID Manager");
+ ERROR_LOG_FMT(CONTROLLERINTERFACE, "Failed to open HID Manager");
// Callbacks for acquisition or loss of a matching device
IOHIDManagerRegisterDeviceMatchingCallback(HIDManager, DeviceMatchingCallback, nullptr);
@@ -198,7 +198,7 @@ void Init(void* window)
// Enable hotplugging
s_hotplug_thread = std::thread([] {
Common::SetCurrentThreadName("IOHIDManager Hotplug Thread");
- NOTICE_LOG_FMT(SERIALINTERFACE, "IOHIDManager hotplug thread started");
+ NOTICE_LOG_FMT(CONTROLLERINTERFACE, "IOHIDManager hotplug thread started");
IOHIDManagerScheduleWithRunLoop(HIDManager, CFRunLoopGetCurrent(), OurRunLoop);
s_stopper.AddToRunLoop(CFRunLoopGetCurrent(), OurRunLoop);
@@ -206,7 +206,7 @@ void Init(void* window)
s_stopper.RemoveFromRunLoop(CFRunLoopGetCurrent(), OurRunLoop);
IOHIDManagerUnscheduleFromRunLoop(HIDManager, CFRunLoopGetCurrent(), OurRunLoop);
- NOTICE_LOG_FMT(SERIALINTERFACE, "IOHIDManager hotplug thread stopped");
+ NOTICE_LOG_FMT(CONTROLLERINTERFACE, "IOHIDManager hotplug thread stopped");
});
}
diff --git a/Source/Core/InputCommon/ControllerInterface/OSX/OSXJoystick.mm b/Source/Core/InputCommon/ControllerInterface/OSX/OSXJoystick.mm
index 39794426a8..f08f704275 100644
--- a/Source/Core/InputCommon/ControllerInterface/OSX/OSXJoystick.mm
+++ b/Source/Core/InputCommon/ControllerInterface/OSX/OSXJoystick.mm
@@ -109,8 +109,9 @@ void Joystick::AddElements(CFArrayRef elements, std::set<IOHIDElementCookie>& co
break;
}
- NOTICE_LOG_FMT(SERIALINTERFACE, "Unknown IOHIDElement, ignoring (Usage: {:x}, Type: {:x})",
- usage, IOHIDElementGetType(e));
+ NOTICE_LOG_FMT(CONTROLLERINTERFACE,
+ "Unknown IOHIDElement, ignoring (Usage: {:x}, Type: {:x})", usage,
+ IOHIDElementGetType(e));
break;
}
diff --git a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp
index e232fd6ee7..f908181c8d 100644
--- a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp
+++ b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp
@@ -81,7 +81,7 @@ void Init()
{
#if !SDL_VERSION_ATLEAST(2, 0, 0)
if (SDL_Init(SDL_INIT_JOYSTICK) != 0)
- ERROR_LOG_FMT(SERIALINTERFACE, "SDL failed to initialize");
+ ERROR_LOG_FMT(CONTROLLERINTERFACE, "SDL failed to initialize");
return;
#else
s_hotplug_thread = std::thread([] {
@@ -95,14 +95,14 @@ void Init()
if (SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC) != 0)
{
- ERROR_LOG_FMT(SERIALINTERFACE, "SDL failed to initialize");
+ ERROR_LOG_FMT(CONTROLLERINTERFACE, "SDL failed to initialize");
return;
}
const Uint32 custom_events_start = SDL_RegisterEvents(2);
if (custom_events_start == static_cast<Uint32>(-1))
{
- ERROR_LOG_FMT(SERIALINTERFACE, "SDL failed to register custom events");
+ ERROR_LOG_FMT(CONTROLLERINTERFACE, "SDL failed to register custom events");
return;
}
s_stop_event_type = custom_events_start;
diff --git a/Source/Core/InputCommon/ControllerInterface/Touch/ButtonManager.cpp b/Source/Core/InputCommon/ControllerInterface/Touch/ButtonManager.cpp
index 75f69b8823..a749f83a01 100644
--- a/Source/Core/InputCommon/ControllerInterface/Touch/ButtonManager.cpp
+++ b/Source/Core/InputCommon/ControllerInterface/Touch/ButtonManager.cpp
@@ -766,7 +766,7 @@ bool InputDevice::PressEvent(int button, int action)
if (binding.second->m_bind_type == BIND_BUTTON)
m_buttons[binding.second->m_button_type] = action == BUTTON_PRESSED ? true : false;
else
- m_axises[binding.second->m_button_type] = action == BUTTON_PRESSED ? 1.0f : 0.0f;
+ m_axes[binding.second->m_button_type] = action == BUTTON_PRESSED ? 1.0f : 0.0f;
handled = true;
}
}
@@ -780,34 +780,54 @@ void InputDevice::AxisEvent(int axis, float value)
if (binding.second->m_bind == axis)
{
if (binding.second->m_bind_type == BIND_AXIS)
- m_axises[binding.second->m_button_type] = value;
+ m_axes[binding.second->m_button_type] = value;
else
m_buttons[binding.second->m_button_type] = value > 0.5f ? true : false;
}
}
}
-bool InputDevice::ButtonValue(int pad_id, ButtonType button)
+bool InputDevice::ButtonValue(int pad_id, ButtonType button) const
{
- const auto& binding = m_input_binds.find(std::make_pair(pad_id, button));
+ const auto binding = m_input_binds.find(std::make_pair(pad_id, button));
if (binding == m_input_binds.end())
return false;
if (binding->second->m_bind_type == BIND_BUTTON)
- return m_buttons[binding->second->m_button_type];
+ {
+ const auto button = m_buttons.find(binding->second->m_button_type);
+ if (button == m_buttons.end())
+ return false;
+ return button->second;
+ }
else
- return (m_axises[binding->second->m_button_type] * binding->second->m_neg) > 0.5f;
+ {
+ const auto axis = m_axes.find(binding->second->m_button_type);
+ if (axis == m_axes.end())
+ return false;
+ return (axis->second * binding->second->m_neg) > 0.5f;
+ }
}
-float InputDevice::AxisValue(int pad_id, ButtonType axis)
+float InputDevice::AxisValue(int pad_id, ButtonType axis) const
{
- const auto& binding = m_input_binds.find(std::make_pair(pad_id, axis));
+ const auto binding = m_input_binds.find(std::make_pair(pad_id, axis));
if (binding == m_input_binds.end())
return 0.0f;
if (binding->second->m_bind_type == BIND_AXIS)
- return m_axises[binding->second->m_button_type] * binding->second->m_neg;
+ {
+ const auto axis = m_axes.find(binding->second->m_button_type);
+ if (axis == m_axes.end())
+ return 0.0f;
+ return axis->second * binding->second->m_neg;
+ }
else
- return m_buttons[binding->second->m_button_type] == BUTTON_PRESSED ? 1.0f : 0.0f;
+ {
+ const auto button = m_buttons.find(binding->second->m_button_type);
+ if (button == m_buttons.end())
+ return 0.0f;
+ return button->second == BUTTON_PRESSED ? 1.0f : 0.0f;
+ }
}
} // namespace ButtonManager
diff --git a/Source/Core/InputCommon/ControllerInterface/Touch/ButtonManager.h b/Source/Core/InputCommon/ControllerInterface/Touch/ButtonManager.h
index 2139c2e2ca..13b52bb989 100644
--- a/Source/Core/InputCommon/ControllerInterface/Touch/ButtonManager.h
+++ b/Source/Core/InputCommon/ControllerInterface/Touch/ButtonManager.h
@@ -210,7 +210,7 @@ private:
public:
Button() : m_state(BUTTON_RELEASED) {}
void SetState(ButtonState state) { m_state = state; }
- bool Pressed() { return m_state == BUTTON_PRESSED; }
+ bool Pressed() const { return m_state == BUTTON_PRESSED; }
~Button() {}
};
class Axis
@@ -221,7 +221,7 @@ private:
public:
Axis() : m_value(0.0f) {}
void SetValue(float value) { m_value = value; }
- float AxisValue() { return m_value; }
+ float AxisValue() const { return m_value; }
~Axis() {}
};
@@ -244,7 +244,7 @@ class InputDevice
private:
const std::string m_dev;
std::map<ButtonType, bool> m_buttons;
- std::map<ButtonType, float> m_axises;
+ std::map<ButtonType, float> m_axes;
// Key is pad_id and ButtonType
std::map<std::pair<int, ButtonType>, sBind*> m_input_binds;
@@ -263,8 +263,8 @@ public:
}
bool PressEvent(int button, int action);
void AxisEvent(int axis, float value);
- bool ButtonValue(int pad_id, ButtonType button);
- float AxisValue(int pad_id, ButtonType axis);
+ bool ButtonValue(int pad_id, ButtonType button) const;
+ float AxisValue(int pad_id, ButtonType axis) const;
};
void Init(const std::string&);
diff --git a/Source/Core/InputCommon/ControllerInterface/Win32/Win32.cpp b/Source/Core/InputCommon/ControllerInterface/Win32/Win32.cpp
index 096ad31827..b7cf19a13d 100644
--- a/Source/Core/InputCommon/ControllerInterface/Win32/Win32.cpp
+++ b/Source/Core/InputCommon/ControllerInterface/Win32/Win32.cpp
@@ -53,7 +53,7 @@ void ciface::Win32::Init(void* hwnd)
if (FAILED(CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED)))
{
- ERROR_LOG_FMT(SERIALINTERFACE, "CoInitializeEx failed: {}", GetLastError());
+ ERROR_LOG_FMT(CONTROLLERINTERFACE, "CoInitializeEx failed: {}", GetLastError());
return;
}
Common::ScopeGuard uninit([] { CoUninitialize(); });
@@ -67,12 +67,12 @@ void ciface::Win32::Init(void* hwnd)
ATOM window_class = RegisterClassEx(&window_class_info);
if (!window_class)
{
- NOTICE_LOG_FMT(SERIALINTERFACE, "RegisterClassEx failed: {}", GetLastError());
+ NOTICE_LOG_FMT(CONTROLLERINTERFACE, "RegisterClassEx failed: {}", GetLastError());
return;
}
Common::ScopeGuard unregister([&window_class] {
if (!UnregisterClass(MAKEINTATOM(window_class), GetModuleHandle(nullptr)))
- ERROR_LOG_FMT(SERIALINTERFACE, "UnregisterClass failed: {}", GetLastError());
+ ERROR_LOG_FMT(CONTROLLERINTERFACE, "UnregisterClass failed: {}", GetLastError());
});
message_window = CreateWindowEx(0, L"Message", nullptr, 0, 0, 0, 0, 0, HWND_MESSAGE, nullptr,
@@ -80,12 +80,12 @@ void ciface::Win32::Init(void* hwnd)
promise_guard.Exit();
if (!message_window)
{
- ERROR_LOG_FMT(SERIALINTERFACE, "CreateWindowEx failed: {}", GetLastError());
+ ERROR_LOG_FMT(CONTROLLERINTERFACE, "CreateWindowEx failed: {}", GetLastError());
return;
}
Common::ScopeGuard destroy([&] {
if (!DestroyWindow(message_window))
- ERROR_LOG_FMT(SERIALINTERFACE, "DestroyWindow failed: {}", GetLastError());
+ ERROR_LOG_FMT(CONTROLLERINTERFACE, "DestroyWindow failed: {}", GetLastError());
});
std::array<RAWINPUTDEVICE, 2> devices;
@@ -103,7 +103,7 @@ void ciface::Win32::Init(void* hwnd)
if (!RegisterRawInputDevices(devices.data(), static_cast<UINT>(devices.size()),
static_cast<UINT>(sizeof(decltype(devices)::value_type))))
{
- ERROR_LOG_FMT(SERIALINTERFACE, "RegisterRawInputDevices failed: {}", GetLastError());
+ ERROR_LOG_FMT(CONTROLLERINTERFACE, "RegisterRawInputDevices failed: {}", GetLastError());
return;
}
@@ -128,18 +128,18 @@ void ciface::Win32::PopulateDevices(void* hwnd)
s_done_populating.Reset();
PostMessage(s_message_window, WM_INPUT_DEVICE_CHANGE, 0, 0);
if (!s_done_populating.WaitFor(std::chrono::seconds(10)))
- ERROR_LOG_FMT(SERIALINTERFACE, "win32 timed out when trying to populate devices");
+ ERROR_LOG_FMT(CONTROLLERINTERFACE, "win32 timed out when trying to populate devices");
}
else
{
- ERROR_LOG_FMT(SERIALINTERFACE,
+ ERROR_LOG_FMT(CONTROLLERINTERFACE,
"win32 asked to populate devices, but device thread isn't running");
}
}
void ciface::Win32::DeInit()
{
- NOTICE_LOG_FMT(SERIALINTERFACE, "win32 DeInit");
+ NOTICE_LOG_FMT(CONTROLLERINTERFACE, "win32 DeInit");
if (s_thread.joinable())
{
PostMessage(s_message_window, WM_DOLPHIN_STOP, 0, 0);
diff --git a/Source/Core/InputCommon/ControllerInterface/evdev/evdev.cpp b/Source/Core/InputCommon/ControllerInterface/evdev/evdev.cpp
index 214dd323ac..265d81ad40 100644
--- a/Source/Core/InputCommon/ControllerInterface/evdev/evdev.cpp
+++ b/Source/Core/InputCommon/ControllerInterface/evdev/evdev.cpp
@@ -253,7 +253,7 @@ static void AddDeviceNode(const char* devnode)
auto evdev_device = FindDeviceWithUniqueIDAndPhysicalLocation(uniq, phys);
if (evdev_device)
{
- NOTICE_LOG_FMT(SERIALINTERFACE,
+ NOTICE_LOG_FMT(CONTROLLERINTERFACE,
"evdev combining devices with unique id: {}, physical location: {}", uniq, phys);
evdev_device->AddNode(devnode, fd, dev);
@@ -282,7 +282,7 @@ static void AddDeviceNode(const char* devnode)
static void HotplugThreadFunc()
{
Common::SetCurrentThreadName("evdev Hotplug Thread");
- NOTICE_LOG_FMT(SERIALINTERFACE, "evdev hotplug thread started");
+ NOTICE_LOG_FMT(CONTROLLERINTERFACE, "evdev hotplug thread started");
udev* const udev = udev_new();
Common::ScopeGuard udev_guard([udev] { udev_unref(udev); });
@@ -337,7 +337,7 @@ static void HotplugThreadFunc()
AddDeviceNode(devnode);
}
}
- NOTICE_LOG_FMT(SERIALINTERFACE, "evdev hotplug thread stopped");
+ NOTICE_LOG_FMT(CONTROLLERINTERFACE, "evdev hotplug thread stopped");
}
static void StartHotplugThread()