From b5d4e8d37ec240632c7be40d6f670da10d9de2a4 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Thu, 13 Nov 2014 00:10:02 -0800 Subject: ControllerInterface: Remove unused "force" parameter I'm not sure when this nonsense of forcing locking the mutex when it's already taken should have ever taken effect, but let's be thankful it isn't now. That was a badly worded sentence. --- .../InputCommon/ControllerInterface/ControllerInterface.cpp | 12 ++++-------- .../InputCommon/ControllerInterface/ControllerInterface.h | 4 ++-- 2 files changed, 6 insertions(+), 10 deletions(-) (limited to 'Source/Core/InputCommon/ControllerInterface') diff --git a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp index e75df76a36..ddfde30118 100644 --- a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp +++ b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp @@ -135,13 +135,11 @@ void ControllerInterface::Shutdown() // // Update input for all devices, return true if all devices returned successful // -bool ControllerInterface::UpdateInput(const bool force) +bool ControllerInterface::UpdateInput() { std::unique_lock lk(update_lock, std::defer_lock); - if (force) - lk.lock(); - else if (!lk.try_lock()) + if (!lk.try_lock()) return false; size_t ok_count = 0; @@ -163,13 +161,11 @@ bool ControllerInterface::UpdateInput(const bool force) // // Update output for all devices, return true if all devices returned successful // -bool ControllerInterface::UpdateOutput(const bool force) +bool ControllerInterface::UpdateOutput() { std::unique_lock lk(update_lock, std::defer_lock); - if (force) - lk.lock(); - else if (!lk.try_lock()) + if (!lk.try_lock()) return false; size_t ok_count = 0; diff --git a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.h b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.h index 2420b65ed7..56723b123f 100644 --- a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.h +++ b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.h @@ -120,8 +120,8 @@ public: bool IsInit() const { return m_is_init; } void UpdateReference(ControlReference* control, const ciface::Core::DeviceQualifier& default_device) const; - bool UpdateInput(const bool force = false); - bool UpdateOutput(const bool force = false); + bool UpdateInput(); + bool UpdateOutput(); std::recursive_mutex update_lock; -- cgit v1.2.3 From 0c056c64118673ece8fefcc22fa64b78c5431ab6 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Thu, 13 Nov 2014 00:35:29 -0800 Subject: DInput: Remove the unsupported Lights output The LEDs feature doesn't actually do anything: the SetState method is entirely commented out. --- .../DInput/DInputKeyboardMouse.cpp | 65 ---------------------- .../DInput/DInputKeyboardMouse.h | 13 ----- 2 files changed, 78 deletions(-) (limited to 'Source/Core/InputCommon/ControllerInterface') diff --git a/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp b/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp index 05f28c79ae..692826aebb 100644 --- a/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp +++ b/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp @@ -30,17 +30,6 @@ static const struct #include "InputCommon/ControllerInterface/DInput/NamedKeys.h" // NOLINT }; -static const struct -{ - const BYTE code; - const char* const name; -} named_lights[] = -{ - { VK_NUMLOCK, "NUM LOCK" }, - { VK_CAPITAL, "CAPS LOCK" }, - { VK_SCROLL, "SCROLL LOCK" } -}; - // lil silly static HWND hwnd; @@ -102,16 +91,11 @@ KeyboardMouse::KeyboardMouse(const LPDIRECTINPUTDEVICE8 kb_device, const LPDIREC m_last_update = GetTickCount(); ZeroMemory(&m_state_in, sizeof(m_state_in)); - ZeroMemory(m_state_out, sizeof(m_state_out)); - ZeroMemory(&m_current_state_out, sizeof(m_current_state_out)); // KEYBOARD // add keys for (u8 i = 0; i < sizeof(named_keys)/sizeof(*named_keys); ++i) AddInput(new Key(i, m_state_in.keyboard[named_keys[i].code])); - // add lights - for (u8 i = 0; i < sizeof(named_lights)/sizeof(*named_lights); ++i) - AddOutput(new Light(i)); // MOUSE // get caps @@ -198,45 +182,6 @@ bool KeyboardMouse::UpdateInput() return false; } -bool KeyboardMouse::UpdateOutput() -{ - class KInput : public INPUT - { - public: - KInput( const unsigned char key, const bool up = false ) - { - memset( this, 0, sizeof(*this) ); - type = INPUT_KEYBOARD; - ki.wVk = key; - - if (up) - ki.dwFlags = KEYEVENTF_KEYUP; - } - }; - - std::vector< KInput > kbinputs; - for (unsigned int i = 0; i < sizeof(m_state_out)/sizeof(*m_state_out); ++i) - { - bool want_on = false; - if (m_state_out[i]) - want_on = m_state_out[i] > GetTickCount() % 255 ; // light should flash when output is 0.5 - - // lights are set to their original state when output is zero - if (want_on ^ m_current_state_out[i]) - { - kbinputs.push_back(KInput(named_lights[i].code)); // press - kbinputs.push_back(KInput(named_lights[i].code, true)); // release - - m_current_state_out[i] ^= 1; - } - } - - if (kbinputs.size()) - return ( kbinputs.size() == SendInput( (UINT)kbinputs.size(), &kbinputs[0], sizeof( kbinputs[0] ) ) ); - else - return true; -} - std::string KeyboardMouse::GetName() const { return "Keyboard Mouse"; @@ -280,11 +225,6 @@ std::string KeyboardMouse::Cursor::GetName() const return tmpstr; } -std::string KeyboardMouse::Light::GetName() const -{ - return named_lights[m_index].name; -} - // get/set state ControlState KeyboardMouse::Key::GetState() const { @@ -306,10 +246,5 @@ ControlState KeyboardMouse::Cursor::GetState() const return std::max(0.0, ControlState(m_axis) / (m_positive ? 1.0 : -1.0)); } -void KeyboardMouse::Light::SetState(const ControlState state) -{ - //state_out[m_index] = (unsigned char)(state * 255); -} - } } diff --git a/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.h b/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.h index f4ad99db2d..0f3dfece83 100644 --- a/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.h +++ b/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.h @@ -76,19 +76,8 @@ private: const bool m_positive; }; - class Light : public Output - { - public: - std::string GetName() const; - Light(u8 index) : m_index(index) {} - void SetState(ControlState state); - private: - const u8 m_index; - }; - public: bool UpdateInput(); - bool UpdateOutput(); KeyboardMouse(const LPDIRECTINPUTDEVICE8 kb_device, const LPDIRECTINPUTDEVICE8 mo_device); ~KeyboardMouse(); @@ -103,8 +92,6 @@ private: DWORD m_last_update; State m_state_in; - unsigned char m_state_out[3]; // NUM CAPS SCROLL - bool m_current_state_out[3]; // NUM CAPS SCROLL }; } -- cgit v1.2.3 From 367a42dcfdf61e5fcd3e3444190ed25d4d8fc114 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Thu, 13 Nov 2014 00:53:24 -0800 Subject: ControllerInterface: Implement dummy UpdateInput / UpdateOutputs Make the implementation here a bit easier. --- Source/Core/InputCommon/ControllerInterface/Android/Android.h | 3 --- Source/Core/InputCommon/ControllerInterface/Device.h | 4 ++-- Source/Core/InputCommon/ControllerInterface/OSX/OSXJoystick.h | 2 -- Source/Core/InputCommon/ControllerInterface/OSX/OSXJoystick.mm | 5 ----- Source/Core/InputCommon/ControllerInterface/OSX/OSXKeyboard.h | 3 +-- Source/Core/InputCommon/ControllerInterface/OSX/OSXKeyboard.mm | 5 ----- Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.cpp | 5 ----- Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.h | 1 - Source/Core/InputCommon/ControllerInterface/Xlib/Xlib.cpp | 6 ------ Source/Core/InputCommon/ControllerInterface/Xlib/Xlib.h | 1 - 10 files changed, 3 insertions(+), 32 deletions(-) (limited to 'Source/Core/InputCommon/ControllerInterface') diff --git a/Source/Core/InputCommon/ControllerInterface/Android/Android.h b/Source/Core/InputCommon/ControllerInterface/Android/Android.h index 309f42e604..5d6767aa03 100644 --- a/Source/Core/InputCommon/ControllerInterface/Android/Android.h +++ b/Source/Core/InputCommon/ControllerInterface/Android/Android.h @@ -39,9 +39,6 @@ private: }; public: - bool UpdateInput() { return true; } - bool UpdateOutput() { return true; } - Touchscreen(int padID); ~Touchscreen() {} diff --git a/Source/Core/InputCommon/ControllerInterface/Device.h b/Source/Core/InputCommon/ControllerInterface/Device.h index c23c0d29bf..6b9c0d2994 100644 --- a/Source/Core/InputCommon/ControllerInterface/Device.h +++ b/Source/Core/InputCommon/ControllerInterface/Device.h @@ -100,8 +100,8 @@ public: virtual std::string GetName() const = 0; virtual int GetId() const = 0; virtual std::string GetSource() const = 0; - virtual bool UpdateInput() = 0; - virtual bool UpdateOutput() = 0; + virtual bool UpdateInput() { return true; } + virtual bool UpdateOutput() { return true; } virtual void ClearInputState(); diff --git a/Source/Core/InputCommon/ControllerInterface/OSX/OSXJoystick.h b/Source/Core/InputCommon/ControllerInterface/OSX/OSXJoystick.h index ffbe475840..728d55dde8 100644 --- a/Source/Core/InputCommon/ControllerInterface/OSX/OSXJoystick.h +++ b/Source/Core/InputCommon/ControllerInterface/OSX/OSXJoystick.h @@ -72,8 +72,6 @@ private: }; public: - bool UpdateInput(); - Joystick(IOHIDDeviceRef device, std::string name, int index); ~Joystick(); diff --git a/Source/Core/InputCommon/ControllerInterface/OSX/OSXJoystick.mm b/Source/Core/InputCommon/ControllerInterface/OSX/OSXJoystick.mm index 93dea13c28..bdba40c410 100644 --- a/Source/Core/InputCommon/ControllerInterface/OSX/OSXJoystick.mm +++ b/Source/Core/InputCommon/ControllerInterface/OSX/OSXJoystick.mm @@ -90,11 +90,6 @@ Joystick::~Joystick() m_ff_device->Release(); } -bool Joystick::UpdateInput() -{ - return true; -} - std::string Joystick::GetName() const { return m_device_name; diff --git a/Source/Core/InputCommon/ControllerInterface/OSX/OSXKeyboard.h b/Source/Core/InputCommon/ControllerInterface/OSX/OSXKeyboard.h index 36705075ee..c38235c2b8 100644 --- a/Source/Core/InputCommon/ControllerInterface/OSX/OSXKeyboard.h +++ b/Source/Core/InputCommon/ControllerInterface/OSX/OSXKeyboard.h @@ -53,8 +53,7 @@ private: }; public: - bool UpdateInput(); - bool UpdateOutput(); + bool UpdateInput() override; Keyboard(IOHIDDeviceRef device, std::string name, int index, void *window); diff --git a/Source/Core/InputCommon/ControllerInterface/OSX/OSXKeyboard.mm b/Source/Core/InputCommon/ControllerInterface/OSX/OSXKeyboard.mm index 1294346e1b..5a97b27488 100644 --- a/Source/Core/InputCommon/ControllerInterface/OSX/OSXKeyboard.mm +++ b/Source/Core/InputCommon/ControllerInterface/OSX/OSXKeyboard.mm @@ -89,11 +89,6 @@ bool Keyboard::UpdateInput() return true; } -bool Keyboard::UpdateOutput() -{ - return true; -} - std::string Keyboard::GetName() const { return m_device_name; diff --git a/Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.cpp b/Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.cpp index 13ace15997..4d7cc26b4d 100644 --- a/Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.cpp +++ b/Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.cpp @@ -286,11 +286,6 @@ bool KeyboardMouse::UpdateInput() return true; } -bool KeyboardMouse::UpdateOutput() -{ - return true; -} - std::string KeyboardMouse::GetName() const { // This is the name string we got from the X server for this master diff --git a/Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.h b/Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.h index a75c74bba5..064dd997f7 100644 --- a/Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.h +++ b/Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.h @@ -99,7 +99,6 @@ private: public: bool UpdateInput() override; - bool UpdateOutput() override; KeyboardMouse(Window window, int opcode, int pointer_deviceid, int keyboard_deviceid); ~KeyboardMouse(); diff --git a/Source/Core/InputCommon/ControllerInterface/Xlib/Xlib.cpp b/Source/Core/InputCommon/ControllerInterface/Xlib/Xlib.cpp index 973368a78e..e938cfc1bc 100644 --- a/Source/Core/InputCommon/ControllerInterface/Xlib/Xlib.cpp +++ b/Source/Core/InputCommon/ControllerInterface/Xlib/Xlib.cpp @@ -68,12 +68,6 @@ bool KeyboardMouse::UpdateInput() return true; } -bool KeyboardMouse::UpdateOutput() -{ - return true; -} - - std::string KeyboardMouse::GetName() const { return "Keyboard Mouse"; diff --git a/Source/Core/InputCommon/ControllerInterface/Xlib/Xlib.h b/Source/Core/InputCommon/ControllerInterface/Xlib/Xlib.h index 237b3a484e..61d520d08c 100644 --- a/Source/Core/InputCommon/ControllerInterface/Xlib/Xlib.h +++ b/Source/Core/InputCommon/ControllerInterface/Xlib/Xlib.h @@ -71,7 +71,6 @@ private: public: bool UpdateInput() override; - bool UpdateOutput() override; KeyboardMouse(Window window); ~KeyboardMouse(); -- cgit v1.2.3 From 61fcfc4bf2058d971af6882af2765ad34d935fcb Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Thu, 13 Nov 2014 00:56:32 -0800 Subject: ControllerInterface: Remove unused ClearInputState --- .../ControllerInterface/ControllerInterface.cpp | 3 --- .../ControllerInterface/DInput/DInputJoystick.cpp | 11 +++-------- .../ControllerInterface/DInput/DInputJoystick.h | 2 -- Source/Core/InputCommon/ControllerInterface/Device.cpp | 14 -------------- Source/Core/InputCommon/ControllerInterface/Device.h | 2 -- .../Core/InputCommon/ControllerInterface/XInput/XInput.cpp | 5 ----- .../Core/InputCommon/ControllerInterface/XInput/XInput.h | 2 -- 7 files changed, 3 insertions(+), 36 deletions(-) (limited to 'Source/Core/InputCommon/ControllerInterface') diff --git a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp index ddfde30118..95ce7e5d96 100644 --- a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp +++ b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp @@ -148,9 +148,6 @@ bool ControllerInterface::UpdateInput() { if (d->UpdateInput()) ++ok_count; - //else - // disabled. it might be causing problems - //(*d)->ClearInputState(); } return (m_devices.size() == ok_count); diff --git a/Source/Core/InputCommon/ControllerInterface/DInput/DInputJoystick.cpp b/Source/Core/InputCommon/ControllerInterface/DInput/DInputJoystick.cpp index ecd5db838c..0c1ed5aa18 100644 --- a/Source/Core/InputCommon/ControllerInterface/DInput/DInputJoystick.cpp +++ b/Source/Core/InputCommon/ControllerInterface/DInput/DInputJoystick.cpp @@ -149,7 +149,9 @@ Joystick::Joystick( /*const LPCDIDEVICEINSTANCE lpddi, */const LPDIRECTINPUTDEVI InitForceFeedback(m_device, (int)objects.size()); } - ClearInputState(); + ZeroMemory(&m_state_in, sizeof(m_state_in)); + // set hats to center + memset(m_state_in.rgdwPOV, 0xFF, sizeof(m_state_in.rgdwPOV)); } Joystick::~Joystick() @@ -158,13 +160,6 @@ Joystick::~Joystick() m_device->Release(); } -void Joystick::ClearInputState() -{ - ZeroMemory(&m_state_in, sizeof(m_state_in)); - // set hats to center - memset(m_state_in.rgdwPOV, 0xFF, sizeof(m_state_in.rgdwPOV)); -} - std::string Joystick::GetName() const { return GetDeviceName(m_device); diff --git a/Source/Core/InputCommon/ControllerInterface/DInput/DInputJoystick.h b/Source/Core/InputCommon/ControllerInterface/DInput/DInputJoystick.h index 0ac535cdfe..17770afe5a 100644 --- a/Source/Core/InputCommon/ControllerInterface/DInput/DInputJoystick.h +++ b/Source/Core/InputCommon/ControllerInterface/DInput/DInputJoystick.h @@ -54,8 +54,6 @@ private: public: bool UpdateInput(); - void ClearInputState(); - Joystick(const LPDIRECTINPUTDEVICE8 device, const unsigned int index); ~Joystick(); diff --git a/Source/Core/InputCommon/ControllerInterface/Device.cpp b/Source/Core/InputCommon/ControllerInterface/Device.cpp index 84af8649a8..f96c637426 100644 --- a/Source/Core/InputCommon/ControllerInterface/Device.cpp +++ b/Source/Core/InputCommon/ControllerInterface/Device.cpp @@ -66,20 +66,6 @@ Device::Output* Device::FindOutput(const std::string &name) const return nullptr; } -// -// Device :: ClearInputState -// -// Device classes should override this function -// ControllerInterface will call this when the device returns failure during UpdateInput -// used to try to set all buttons and axes to their default state when user unplugs a gamepad during play -// buttons/axes that were held down at the time of unplugging should be seen as not pressed after unplugging -// -void Device::ClearInputState() -{ - // this is going to be called for every UpdateInput call that fails - // kinda slow but, w/e, should only happen when user unplugs a device while playing -} - bool Device::Control::InputGateOn() { if (SConfig::GetInstance().m_BackgroundInput) diff --git a/Source/Core/InputCommon/ControllerInterface/Device.h b/Source/Core/InputCommon/ControllerInterface/Device.h index 6b9c0d2994..abc7a68185 100644 --- a/Source/Core/InputCommon/ControllerInterface/Device.h +++ b/Source/Core/InputCommon/ControllerInterface/Device.h @@ -103,8 +103,6 @@ public: virtual bool UpdateInput() { return true; } virtual bool UpdateOutput() { return true; } - virtual void ClearInputState(); - const std::vector& Inputs() const { return m_inputs; } const std::vector& Outputs() const { return m_outputs; } diff --git a/Source/Core/InputCommon/ControllerInterface/XInput/XInput.cpp b/Source/Core/InputCommon/ControllerInterface/XInput/XInput.cpp index 37949e03ac..961b92270b 100644 --- a/Source/Core/InputCommon/ControllerInterface/XInput/XInput.cpp +++ b/Source/Core/InputCommon/ControllerInterface/XInput/XInput.cpp @@ -165,11 +165,6 @@ Device::Device(const XINPUT_CAPABILITIES& caps, u8 index) AddOutput(new Motor(i, (&m_state_out.wLeftMotorSpeed)[i], 65535)); } - ClearInputState(); -} - -void Device::ClearInputState() -{ ZeroMemory(&m_state_in, sizeof(m_state_in)); } diff --git a/Source/Core/InputCommon/ControllerInterface/XInput/XInput.h b/Source/Core/InputCommon/ControllerInterface/XInput/XInput.h index 3c9eadc395..0092870265 100644 --- a/Source/Core/InputCommon/ControllerInterface/XInput/XInput.h +++ b/Source/Core/InputCommon/ControllerInterface/XInput/XInput.h @@ -76,8 +76,6 @@ public: bool UpdateInput(); bool UpdateOutput(); - void ClearInputState(); - Device(const XINPUT_CAPABILITIES& capabilities, u8 index); std::string GetName() const; -- cgit v1.2.3 From f2787f620eebbbfb746f59cfbd0318210297061b Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Thu, 13 Nov 2014 00:55:14 -0800 Subject: ControllerInterface: Make UpdateInput / UpdateOutput return void The return values here have never been checked, so it doesn't make sense to return a value to begin with. --- .../ControllerInterface/ControllerInterface.cpp | 26 +++++----------------- .../ControllerInterface/ControllerInterface.h | 4 ++-- .../ControllerInterface/DInput/DInputJoystick.cpp | 6 ++--- .../ControllerInterface/DInput/DInputJoystick.h | 2 +- .../DInput/DInputKeyboardMouse.cpp | 6 +---- .../DInput/DInputKeyboardMouse.h | 2 +- .../Core/InputCommon/ControllerInterface/Device.h | 4 ++-- .../ForceFeedback/ForceFeedbackDevice.cpp | 14 +++--------- .../ForceFeedback/ForceFeedbackDevice.h | 2 +- .../ControllerInterface/OSX/OSXKeyboard.h | 2 +- .../ControllerInterface/OSX/OSXKeyboard.mm | 4 +--- .../InputCommon/ControllerInterface/SDL/SDL.cpp | 7 ++---- .../Core/InputCommon/ControllerInterface/SDL/SDL.h | 4 ++-- .../ControllerInterface/XInput/XInput.cpp | 12 ++++------ .../ControllerInterface/XInput/XInput.h | 4 ++-- .../ControllerInterface/Xlib/XInput2.cpp | 4 +--- .../InputCommon/ControllerInterface/Xlib/XInput2.h | 2 +- .../InputCommon/ControllerInterface/Xlib/Xlib.cpp | 4 +--- .../InputCommon/ControllerInterface/Xlib/Xlib.h | 2 +- 19 files changed, 35 insertions(+), 76 deletions(-) (limited to 'Source/Core/InputCommon/ControllerInterface') diff --git a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp index 95ce7e5d96..74aa6de3a3 100644 --- a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp +++ b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp @@ -135,22 +135,15 @@ void ControllerInterface::Shutdown() // // Update input for all devices, return true if all devices returned successful // -bool ControllerInterface::UpdateInput() +void ControllerInterface::UpdateInput() { std::unique_lock lk(update_lock, std::defer_lock); if (!lk.try_lock()) - return false; - - size_t ok_count = 0; + return; for (ciface::Core::Device* d : m_devices) - { - if (d->UpdateInput()) - ++ok_count; - } - - return (m_devices.size() == ok_count); + d->UpdateInput(); } // @@ -158,22 +151,15 @@ bool ControllerInterface::UpdateInput() // // Update output for all devices, return true if all devices returned successful // -bool ControllerInterface::UpdateOutput() +void ControllerInterface::UpdateOutput() { std::unique_lock lk(update_lock, std::defer_lock); if (!lk.try_lock()) - return false; - - size_t ok_count = 0; + return; for (ciface::Core::Device* d : m_devices) - { - if (d->UpdateOutput()) - ++ok_count; - } - - return (m_devices.size() == ok_count); + d->UpdateOutput(); } // diff --git a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.h b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.h index 56723b123f..9600aded63 100644 --- a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.h +++ b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.h @@ -120,8 +120,8 @@ public: bool IsInit() const { return m_is_init; } void UpdateReference(ControlReference* control, const ciface::Core::DeviceQualifier& default_device) const; - bool UpdateInput(); - bool UpdateOutput(); + void UpdateInput(); + void UpdateOutput(); std::recursive_mutex update_lock; diff --git a/Source/Core/InputCommon/ControllerInterface/DInput/DInputJoystick.cpp b/Source/Core/InputCommon/ControllerInterface/DInput/DInputJoystick.cpp index 0c1ed5aa18..bc8638293e 100644 --- a/Source/Core/InputCommon/ControllerInterface/DInput/DInputJoystick.cpp +++ b/Source/Core/InputCommon/ControllerInterface/DInput/DInputJoystick.cpp @@ -177,7 +177,7 @@ std::string Joystick::GetSource() const // update IO -bool Joystick::UpdateInput() +void Joystick::UpdateInput() { HRESULT hr = 0; @@ -215,9 +215,7 @@ bool Joystick::UpdateInput() // try reacquire if input lost if (DIERR_INPUTLOST == hr || DIERR_NOTACQUIRED == hr) - hr = m_device->Acquire(); - - return SUCCEEDED(hr); + m_device->Acquire(); } // get name diff --git a/Source/Core/InputCommon/ControllerInterface/DInput/DInputJoystick.h b/Source/Core/InputCommon/ControllerInterface/DInput/DInputJoystick.h index 17770afe5a..f1af8102cd 100644 --- a/Source/Core/InputCommon/ControllerInterface/DInput/DInputJoystick.h +++ b/Source/Core/InputCommon/ControllerInterface/DInput/DInputJoystick.h @@ -52,7 +52,7 @@ private: }; public: - bool UpdateInput(); + void UpdateInput() override; Joystick(const LPDIRECTINPUTDEVICE8 device, const unsigned int index); ~Joystick(); diff --git a/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp b/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp index 692826aebb..c96e51a830 100644 --- a/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp +++ b/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp @@ -139,7 +139,7 @@ void GetMousePos(ControlState* const x, ControlState* const y) *y = (ControlState)point.y / (ControlState)win_height * 2 - 1; } -bool KeyboardMouse::UpdateInput() +void KeyboardMouse::UpdateInput() { DIMOUSESTATE2 tmp_mouse; @@ -175,11 +175,7 @@ bool KeyboardMouse::UpdateInput() // update mouse cursor GetMousePos(&m_state_in.cursor.x, &m_state_in.cursor.y); - - return true; } - - return false; } std::string KeyboardMouse::GetName() const diff --git a/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.h b/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.h index 0f3dfece83..704635057e 100644 --- a/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.h +++ b/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.h @@ -77,7 +77,7 @@ private: }; public: - bool UpdateInput(); + void UpdateInput() override; KeyboardMouse(const LPDIRECTINPUTDEVICE8 kb_device, const LPDIRECTINPUTDEVICE8 mo_device); ~KeyboardMouse(); diff --git a/Source/Core/InputCommon/ControllerInterface/Device.h b/Source/Core/InputCommon/ControllerInterface/Device.h index abc7a68185..6f54f9adf5 100644 --- a/Source/Core/InputCommon/ControllerInterface/Device.h +++ b/Source/Core/InputCommon/ControllerInterface/Device.h @@ -100,8 +100,8 @@ public: virtual std::string GetName() const = 0; virtual int GetId() const = 0; virtual std::string GetSource() const = 0; - virtual bool UpdateInput() { return true; } - virtual bool UpdateOutput() { return true; } + virtual void UpdateInput() {} + virtual void UpdateOutput() {} const std::vector& Inputs() const { return m_inputs; } const std::vector& Outputs() const { return m_outputs; } diff --git a/Source/Core/InputCommon/ControllerInterface/ForceFeedback/ForceFeedbackDevice.cpp b/Source/Core/InputCommon/ControllerInterface/ForceFeedback/ForceFeedbackDevice.cpp index 4350444492..f8efad343a 100644 --- a/Source/Core/InputCommon/ControllerInterface/ForceFeedback/ForceFeedbackDevice.cpp +++ b/Source/Core/InputCommon/ControllerInterface/ForceFeedback/ForceFeedbackDevice.cpp @@ -133,10 +133,8 @@ bool ForceFeedbackDevice::InitForceFeedback(const LPDIRECTINPUTDEVICE8 device, i return true; } -bool ForceFeedbackDevice::UpdateOutput() +void ForceFeedbackDevice::UpdateOutput() { - size_t ok_count = 0; - DIEFFECT eff; memset(&eff, 0, sizeof(eff)); eff.dwSize = sizeof(DIEFFECT); @@ -151,22 +149,16 @@ bool ForceFeedbackDevice::UpdateOutput() eff.cbTypeSpecificParams = state.size; eff.lpvTypeSpecificParams = state.params; // set params and start effect - ok_count += SUCCEEDED(state.iface->SetParameters(&eff, DIEP_TYPESPECIFICPARAMS | DIEP_START)); + state.iface->SetParameters(&eff, DIEP_TYPESPECIFICPARAMS | DIEP_START); } else { - ok_count += SUCCEEDED(state.iface->Stop()); + state.iface->Stop(); } state.params = nullptr; } - else - { - ++ok_count; - } } - - return (m_state_out.size() == ok_count); } template<> diff --git a/Source/Core/InputCommon/ControllerInterface/ForceFeedback/ForceFeedbackDevice.h b/Source/Core/InputCommon/ControllerInterface/ForceFeedback/ForceFeedbackDevice.h index 31a1884aae..8b26ffeff2 100644 --- a/Source/Core/InputCommon/ControllerInterface/ForceFeedback/ForceFeedbackDevice.h +++ b/Source/Core/InputCommon/ControllerInterface/ForceFeedback/ForceFeedbackDevice.h @@ -52,7 +52,7 @@ private: public: bool InitForceFeedback(const LPDIRECTINPUTDEVICE8, int cAxes); - bool UpdateOutput(); + void UpdateOutput() override; virtual ~ForceFeedbackDevice(); private: diff --git a/Source/Core/InputCommon/ControllerInterface/OSX/OSXKeyboard.h b/Source/Core/InputCommon/ControllerInterface/OSX/OSXKeyboard.h index c38235c2b8..06e686fc6a 100644 --- a/Source/Core/InputCommon/ControllerInterface/OSX/OSXKeyboard.h +++ b/Source/Core/InputCommon/ControllerInterface/OSX/OSXKeyboard.h @@ -53,7 +53,7 @@ private: }; public: - bool UpdateInput() override; + void UpdateInput() override; Keyboard(IOHIDDeviceRef device, std::string name, int index, void *window); diff --git a/Source/Core/InputCommon/ControllerInterface/OSX/OSXKeyboard.mm b/Source/Core/InputCommon/ControllerInterface/OSX/OSXKeyboard.mm index 5a97b27488..0e876f4173 100644 --- a/Source/Core/InputCommon/ControllerInterface/OSX/OSXKeyboard.mm +++ b/Source/Core/InputCommon/ControllerInterface/OSX/OSXKeyboard.mm @@ -54,7 +54,7 @@ Keyboard::Keyboard(IOHIDDeviceRef device, std::string name, int index, void *win AddInput(new Button(i, m_mousebuttons[i])); } -bool Keyboard::UpdateInput() +void Keyboard::UpdateInput() { CGRect bounds = CGRectZero; uint32_t windowid[1] = { m_windowid }; @@ -85,8 +85,6 @@ bool Keyboard::UpdateInput() m_mousebuttons[0] = CGEventSourceButtonState(kCGEventSourceStateHIDSystemState, kCGMouseButtonLeft); m_mousebuttons[1] = CGEventSourceButtonState(kCGEventSourceStateHIDSystemState, kCGMouseButtonRight); m_mousebuttons[2] = CGEventSourceButtonState(kCGEventSourceStateHIDSystemState, kCGMouseButtonCenter); - - return true; } std::string Keyboard::GetName() const diff --git a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp index b745f7b2d4..5428778163 100644 --- a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp +++ b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp @@ -316,15 +316,13 @@ void Joystick::TriangleEffect::SetState(ControlState state) } #endif -bool Joystick::UpdateInput() +void Joystick::UpdateInput() { // each joystick is doin this, o well SDL_JoystickUpdate(); - - return true; } -bool Joystick::UpdateOutput() +void Joystick::UpdateOutput() { #ifdef USE_SDL_HAPTIC for (auto &i : m_state_out) @@ -359,7 +357,6 @@ bool Joystick::UpdateOutput() } } #endif - return true; } std::string Joystick::GetName() const diff --git a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.h b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.h index 76fc028ec9..d1aeb38f4a 100644 --- a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.h +++ b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.h @@ -134,8 +134,8 @@ private: #endif public: - bool UpdateInput() override; - bool UpdateOutput() override; + void UpdateInput() override; + void UpdateOutput() override; Joystick(SDL_Joystick* const joystick, const int sdl_index, const unsigned int index); ~Joystick(); diff --git a/Source/Core/InputCommon/ControllerInterface/XInput/XInput.cpp b/Source/Core/InputCommon/ControllerInterface/XInput/XInput.cpp index 961b92270b..68d7eeb479 100644 --- a/Source/Core/InputCommon/ControllerInterface/XInput/XInput.cpp +++ b/Source/Core/InputCommon/ControllerInterface/XInput/XInput.cpp @@ -203,23 +203,19 @@ std::string Device::GetSource() const // Update I/O -bool Device::UpdateInput() +void Device::UpdateInput() { - return (ERROR_SUCCESS == PXInputGetState(m_index, &m_state_in)); + PXInputGetState(m_index, &m_state_in); } -bool Device::UpdateOutput() +void Device::UpdateOutput() { // this if statement is to make rumble work better when multiple ControllerInterfaces are using the device // only calls XInputSetState if the state changed if (memcmp(&m_state_out, &m_current_state_out, sizeof(m_state_out))) { m_current_state_out = m_state_out; - return (ERROR_SUCCESS == PXInputSetState(m_index, &m_state_out)); - } - else - { - return true; + PXInputSetState(m_index, &m_state_out); } } diff --git a/Source/Core/InputCommon/ControllerInterface/XInput/XInput.h b/Source/Core/InputCommon/ControllerInterface/XInput/XInput.h index 0092870265..17ee333e97 100644 --- a/Source/Core/InputCommon/ControllerInterface/XInput/XInput.h +++ b/Source/Core/InputCommon/ControllerInterface/XInput/XInput.h @@ -73,8 +73,8 @@ private: }; public: - bool UpdateInput(); - bool UpdateOutput(); + void UpdateInput() override; + void UpdateOutput() override; Device(const XINPUT_CAPABILITIES& capabilities, u8 index); diff --git a/Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.cpp b/Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.cpp index 4d7cc26b4d..1d7d080d7e 100644 --- a/Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.cpp +++ b/Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.cpp @@ -208,7 +208,7 @@ void KeyboardMouse::UpdateCursor() m_state.cursor.y = win_y / (float)win_attribs.height * 2 - 1; } -bool KeyboardMouse::UpdateInput() +void KeyboardMouse::UpdateInput() { XFlush(m_display); @@ -282,8 +282,6 @@ bool KeyboardMouse::UpdateInput() m_state.axis.y *= MOUSE_AXIS_SMOOTHING; m_state.axis.y += delta_y; m_state.axis.y /= MOUSE_AXIS_SMOOTHING+1.0f; - - return true; } std::string KeyboardMouse::GetName() const diff --git a/Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.h b/Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.h index 064dd997f7..3f31aa50f2 100644 --- a/Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.h +++ b/Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.h @@ -98,7 +98,7 @@ private: void UpdateCursor(); public: - bool UpdateInput() override; + void UpdateInput() override; KeyboardMouse(Window window, int opcode, int pointer_deviceid, int keyboard_deviceid); ~KeyboardMouse(); diff --git a/Source/Core/InputCommon/ControllerInterface/Xlib/Xlib.cpp b/Source/Core/InputCommon/ControllerInterface/Xlib/Xlib.cpp index e938cfc1bc..9a700a9c99 100644 --- a/Source/Core/InputCommon/ControllerInterface/Xlib/Xlib.cpp +++ b/Source/Core/InputCommon/ControllerInterface/Xlib/Xlib.cpp @@ -49,7 +49,7 @@ KeyboardMouse::~KeyboardMouse() XCloseDisplay(m_display); } -bool KeyboardMouse::UpdateInput() +void KeyboardMouse::UpdateInput() { XQueryKeymap(m_display, m_state.keyboard); @@ -64,8 +64,6 @@ bool KeyboardMouse::UpdateInput() // the mouse position as a range from -1 to 1 m_state.cursor.x = (float)win_x / (float)win_attribs.width * 2 - 1; m_state.cursor.y = (float)win_y / (float)win_attribs.height * 2 - 1; - - return true; } std::string KeyboardMouse::GetName() const diff --git a/Source/Core/InputCommon/ControllerInterface/Xlib/Xlib.h b/Source/Core/InputCommon/ControllerInterface/Xlib/Xlib.h index 61d520d08c..0c2f79c8b3 100644 --- a/Source/Core/InputCommon/ControllerInterface/Xlib/Xlib.h +++ b/Source/Core/InputCommon/ControllerInterface/Xlib/Xlib.h @@ -70,7 +70,7 @@ private: }; public: - bool UpdateInput() override; + void UpdateInput() override; KeyboardMouse(Window window); ~KeyboardMouse(); -- cgit v1.2.3 From 1b3d0173f5492fa19e3b440d43623ca2145c2a82 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Thu, 13 Nov 2014 00:49:18 -0800 Subject: SDL: Apply updates immediately rather than going through UpdateOutput We're going to remove UpdateOutput as it's redundant, and horribly complicates the code. --- .../InputCommon/ControllerInterface/SDL/SDL.cpp | 171 ++++++++------------- .../Core/InputCommon/ControllerInterface/SDL/SDL.h | 57 +++---- 2 files changed, 84 insertions(+), 144 deletions(-) (limited to 'Source/Core/InputCommon/ControllerInterface') diff --git a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp index 5428778163..a46a08100d 100644 --- a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp +++ b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp @@ -121,40 +121,26 @@ Joystick::Joystick(SDL_Joystick* const joystick, const int sdl_index, const unsi // constant effect if (supported_effects & SDL_HAPTIC_CONSTANT) - { - m_state_out.push_back(EffectIDState()); - AddOutput(new ConstantEffect(m_state_out.back())); - } + AddOutput(new ConstantEffect(m_haptic)); // ramp effect if (supported_effects & SDL_HAPTIC_RAMP) - { - m_state_out.push_back(EffectIDState()); - AddOutput(new RampEffect(m_state_out.back())); - } + AddOutput(new RampEffect(m_haptic)); // sine effect if (supported_effects & SDL_HAPTIC_SINE) - { - m_state_out.push_back(EffectIDState()); - AddOutput(new SineEffect(m_state_out.back())); - } + AddOutput(new SineEffect(m_haptic)); #ifdef SDL_HAPTIC_SQUARE // square effect if (supported_effects & SDL_HAPTIC_SQUARE) - { - m_state_out.push_back(EffectIDState()); - AddOutput(new SquareEffect(m_state_out.back())); - } + AddOutput(new SquareEffect(m_haptic)); + #endif // defined(SDL_HAPTIC_SQUARE) // triangle effect if (supported_effects & SDL_HAPTIC_TRIANGLE) - { - m_state_out.push_back(EffectIDState()); - AddOutput(new TriangleEffect(m_state_out.back())); - } + AddOutput(new TriangleEffect(m_haptic)); } #endif @@ -167,13 +153,6 @@ Joystick::~Joystick() { // stop/destroy all effects SDL_HapticStopAll(m_haptic); - for (auto &i : m_state_out) - { - if (i.id != -1) - { - SDL_HapticDestroyEffect(m_haptic, i.id); - } - } // close haptic first SDL_HapticClose(m_haptic); } @@ -184,6 +163,26 @@ Joystick::~Joystick() } #ifdef USE_SDL_HAPTIC +void Joystick::HapticEffect::Update() +{ + if (m_id == -1 && m_effect.type > 0) + { + m_id = SDL_HapticNewEffect(m_haptic, &m_effect); + if (m_id > -1) + SDL_HapticRunEffect(m_haptic, m_id, 1); + } + else if (m_id > -1 && m_effect.type == 0) + { + SDL_HapticStopEffect(m_haptic, m_id); + SDL_HapticDestroyEffect(m_haptic, m_id); + m_id = -1; + } + else if (m_id > -1) + { + SDL_HapticUpdateEffect(m_haptic, m_id, &m_effect); + } +} + std::string Joystick::ConstantEffect::GetName() const { return "Constant"; @@ -215,58 +214,51 @@ void Joystick::ConstantEffect::SetState(ControlState state) { if (state) { - m_effect.effect.type = SDL_HAPTIC_CONSTANT; - m_effect.effect.constant.length = SDL_HAPTIC_INFINITY; + m_effect.type = SDL_HAPTIC_CONSTANT; + m_effect.constant.length = SDL_HAPTIC_INFINITY; } else { - m_effect.effect.type = 0; + m_effect.type = 0; } - const Sint16 old = m_effect.effect.constant.level; - m_effect.effect.constant.level = (Sint16)(state * 0x7FFF); - if (old != m_effect.effect.constant.level) - m_effect.changed = true; + m_effect.constant.level = (Sint16)(state * 0x7FFF); + Update(); } void Joystick::RampEffect::SetState(ControlState state) { if (state) { - m_effect.effect.type = SDL_HAPTIC_RAMP; - m_effect.effect.ramp.length = SDL_HAPTIC_INFINITY; + m_effect.type = SDL_HAPTIC_RAMP; + m_effect.ramp.length = SDL_HAPTIC_INFINITY; } else { - m_effect.effect.type = 0; + m_effect.type = 0; } - const Sint16 old = m_effect.effect.ramp.start; - m_effect.effect.ramp.start = (Sint16)(state * 0x7FFF); - if (old != m_effect.effect.ramp.start) - m_effect.changed = true; + m_effect.ramp.start = (Sint16)(state * 0x7FFF); + Update(); } void Joystick::SineEffect::SetState(ControlState state) { if (state) { - m_effect.effect.type = SDL_HAPTIC_SINE; - m_effect.effect.periodic.length = 250; + m_effect.type = SDL_HAPTIC_SINE; + m_effect.periodic.length = 250; } else { - m_effect.effect.type = 0; + m_effect.type = 0; } - const Sint16 old = m_effect.effect.periodic.magnitude; - m_effect.effect.periodic.period = 5; - m_effect.effect.periodic.magnitude = (Sint16)(state * 0x5000); - m_effect.effect.periodic.attack_length = 0; - m_effect.effect.periodic.fade_length = 500; - - if (old != m_effect.effect.periodic.magnitude) - m_effect.changed = true; + m_effect.periodic.period = 5; + m_effect.periodic.magnitude = (Sint16)(state * 0x5000); + m_effect.periodic.attack_length = 0; + m_effect.periodic.fade_length = 500; + Update(); } #ifdef SDL_HAPTIC_SQUARE @@ -274,22 +266,19 @@ void Joystick::SquareEffect::SetState(ControlState state) { if (state) { - m_effect.effect.type = SDL_HAPTIC_SQUARE; - m_effect.effect.periodic.length = 250; + m_effect.type = SDL_HAPTIC_SQUARE; + m_effect.periodic.length = 250; } else { - m_effect.effect.type = 0; + m_effect.type = 0; } - const Sint16 old = m_effect.effect.periodic.magnitude; - m_effect.effect.periodic.period = 5; - m_effect.effect.periodic.magnitude = state * 0x5000; - m_effect.effect.periodic.attack_length = 0; - m_effect.effect.periodic.fade_length = 100; - - if (old != m_effect.effect.periodic.magnitude) - m_effect.changed = true; + m_effect.periodic.period = 5; + m_effect.periodic.magnitude = state * 0x5000; + m_effect.periodic.attack_length = 0; + m_effect.periodic.fade_length = 100; + Update(); } #endif // defined(SDL_HAPTIC_SQUARE) @@ -297,22 +286,19 @@ void Joystick::TriangleEffect::SetState(ControlState state) { if (state) { - m_effect.effect.type = SDL_HAPTIC_TRIANGLE; - m_effect.effect.periodic.length = 250; + m_effect.type = SDL_HAPTIC_TRIANGLE; + m_effect.periodic.length = 250; } else { - m_effect.effect.type = 0; + m_effect.type = 0; } - const Sint16 old = m_effect.effect.periodic.magnitude; - m_effect.effect.periodic.period = 5; - m_effect.effect.periodic.magnitude = (Sint16)(state * 0x5000); - m_effect.effect.periodic.attack_length = 0; - m_effect.effect.periodic.fade_length = 100; - - if (old != m_effect.effect.periodic.magnitude) - m_effect.changed = true; + m_effect.periodic.period = 5; + m_effect.periodic.magnitude = (Sint16)(state * 0x5000); + m_effect.periodic.attack_length = 0; + m_effect.periodic.fade_length = 100; + Update(); } #endif @@ -322,43 +308,6 @@ void Joystick::UpdateInput() SDL_JoystickUpdate(); } -void Joystick::UpdateOutput() -{ -#ifdef USE_SDL_HAPTIC - for (auto &i : m_state_out) - { - if (i.changed) // if SetState was called on this output - { - if (-1 == i.id) // effect isn't currently uploaded - { - if (i.effect.type) // if outputstate is >0 this would be true - { - if ((i.id = SDL_HapticNewEffect(m_haptic, &i.effect)) > -1) // upload the effect - { - SDL_HapticRunEffect(m_haptic, i.id, 1); // run the effect - } - } - } - else // effect is already uploaded - { - if (i.effect.type) // if ouputstate >0 - { - SDL_HapticUpdateEffect(m_haptic, i.id, &i.effect); // update the effect - } - else - { - SDL_HapticStopEffect(m_haptic, i.id); // else, stop and remove the effect - SDL_HapticDestroyEffect(m_haptic, i.id); - i.id = -1; // mark it as not uploaded - } - } - - i.changed = false; - } - } -#endif -} - std::string Joystick::GetName() const { return StripSpaces(GetJoystickName(m_sdl_index)); diff --git a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.h b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.h index d1aeb38f4a..dc4c52063f 100644 --- a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.h +++ b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.h @@ -33,17 +33,6 @@ class Joystick : public Core::Device { private: -#ifdef USE_SDL_HAPTIC - struct EffectIDState - { - EffectIDState() : effect(SDL_HapticEffect()), id(-1), changed(false) {} - - SDL_HapticEffect effect; - int id; - bool changed; - }; -#endif - class Button : public Core::Device::Input { public: @@ -80,62 +69,65 @@ private: }; #ifdef USE_SDL_HAPTIC - class ConstantEffect : public Output + class HapticEffect : public Output { public: + HapticEffect(SDL_Haptic* haptic) : m_haptic(haptic), m_id(-1) {} + ~HapticEffect() { m_effect.type = 0; Update(); } + + protected: + void Update(); + + SDL_HapticEffect m_effect; + SDL_Haptic* m_haptic; + int m_id; + }; + + class ConstantEffect : public HapticEffect + { + public: + ConstantEffect(SDL_Haptic* haptic) : HapticEffect(haptic) {} std::string GetName() const override; - ConstantEffect(EffectIDState& effect) : m_effect(effect) {} void SetState(ControlState state) override; - private: - EffectIDState& m_effect; }; - class RampEffect : public Output + class RampEffect : public HapticEffect { public: + RampEffect(SDL_Haptic* haptic) : HapticEffect(haptic) {} std::string GetName() const override; - RampEffect(EffectIDState& effect) : m_effect(effect) {} void SetState(ControlState state) override; - private: - EffectIDState& m_effect; }; - class SineEffect : public Output + class SineEffect : public HapticEffect { public: + SineEffect(SDL_Haptic* haptic) : HapticEffect(haptic) {} std::string GetName() const override; - SineEffect(EffectIDState& effect) : m_effect(effect) {} void SetState(ControlState state) override; - private: - EffectIDState& m_effect; }; #ifdef SDL_HAPTIC_SQUARE - class SquareEffect : public Output + class SquareEffect : public HapticEffect { public: + SquareEffect(SDL_Haptic* haptic) : HapticEffect(haptic) {} std::string GetName() const; - SquareEffect(EffectIDState& effect) : m_effect(effect) {} void SetState(ControlState state); - private: - EffectIDState& m_effect; }; #endif // defined(SDL_HAPTIC_SQUARE) - class TriangleEffect : public Output + class TriangleEffect : public HapticEffect { public: + TriangleEffect(SDL_Haptic* haptic) : HapticEffect(haptic) {} std::string GetName() const override; - TriangleEffect(EffectIDState& effect) : m_effect(effect) {} void SetState(ControlState state) override; - private: - EffectIDState& m_effect; }; #endif public: void UpdateInput() override; - void UpdateOutput() override; Joystick(SDL_Joystick* const joystick, const int sdl_index, const unsigned int index); ~Joystick(); @@ -150,7 +142,6 @@ private: const unsigned int m_index; #ifdef USE_SDL_HAPTIC - std::list m_state_out; SDL_Haptic* m_haptic; #endif }; -- cgit v1.2.3 From 1958a10b6f5ba8348268b077f6410dadb2a20c8f Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Thu, 13 Nov 2014 01:10:55 -0800 Subject: XInput: Apply immediately as well --- .../Core/InputCommon/ControllerInterface/XInput/XInput.cpp | 14 ++++---------- .../Core/InputCommon/ControllerInterface/XInput/XInput.h | 8 +++++--- 2 files changed, 9 insertions(+), 13 deletions(-) (limited to 'Source/Core/InputCommon/ControllerInterface') diff --git a/Source/Core/InputCommon/ControllerInterface/XInput/XInput.cpp b/Source/Core/InputCommon/ControllerInterface/XInput/XInput.cpp index 68d7eeb479..2bf98bb0b3 100644 --- a/Source/Core/InputCommon/ControllerInterface/XInput/XInput.cpp +++ b/Source/Core/InputCommon/ControllerInterface/XInput/XInput.cpp @@ -121,7 +121,6 @@ Device::Device(const XINPUT_CAPABILITIES& caps, u8 index) : m_index(index), m_subtype(caps.SubType) { ZeroMemory(&m_state_out, sizeof(m_state_out)); - ZeroMemory(&m_current_state_out, sizeof(m_current_state_out)); // XInputGetCaps seems to always claim all capabilities are supported // but I will leave all this stuff in, incase m$ fixes xinput up a bit @@ -162,7 +161,7 @@ Device::Device(const XINPUT_CAPABILITIES& caps, u8 index) { //WORD val = (&caps.Vibration.wLeftMotorSpeed)[i]; // should be max value / nope, more lies if ((&caps.Vibration.wLeftMotorSpeed)[i]) - AddOutput(new Motor(i, (&m_state_out.wLeftMotorSpeed)[i], 65535)); + AddOutput(new Motor(i, this, (&m_state_out.wLeftMotorSpeed)[i], 65535)); } ZeroMemory(&m_state_in, sizeof(m_state_in)); @@ -208,15 +207,9 @@ void Device::UpdateInput() PXInputGetState(m_index, &m_state_in); } -void Device::UpdateOutput() +void Device::UpdateMotors() { - // this if statement is to make rumble work better when multiple ControllerInterfaces are using the device - // only calls XInputSetState if the state changed - if (memcmp(&m_state_out, &m_current_state_out, sizeof(m_state_out))) - { - m_current_state_out = m_state_out; - PXInputSetState(m_index, &m_state_out); - } + PXInputSetState(m_index, &m_state_out); } // GET name/source/id @@ -261,6 +254,7 @@ ControlState Device::Axis::GetState() const void Device::Motor::SetState(ControlState state) { m_motor = (WORD)(state * m_range); + m_parent->UpdateMotors(); } } diff --git a/Source/Core/InputCommon/ControllerInterface/XInput/XInput.h b/Source/Core/InputCommon/ControllerInterface/XInput/XInput.h index 17ee333e97..94c1549a53 100644 --- a/Source/Core/InputCommon/ControllerInterface/XInput/XInput.h +++ b/Source/Core/InputCommon/ControllerInterface/XInput/XInput.h @@ -64,17 +64,17 @@ private: { public: std::string GetName() const; - Motor(u8 index, WORD& motor, WORD range) : m_index(index), m_motor(motor), m_range(range) {} + Motor(u8 index, Device* parent, WORD &motor, WORD range) : m_index(index), m_parent(parent), m_motor(motor), m_range(range) {} void SetState(ControlState state); private: WORD& m_motor; const WORD m_range; const u8 m_index; + Device* m_parent; }; public: void UpdateInput() override; - void UpdateOutput() override; Device(const XINPUT_CAPABILITIES& capabilities, u8 index); @@ -82,9 +82,11 @@ public: int GetId() const; std::string GetSource() const; + void UpdateMotors(); + private: XINPUT_STATE m_state_in; - XINPUT_VIBRATION m_state_out, m_current_state_out; + XINPUT_VIBRATION m_state_out; const BYTE m_subtype; const u8 m_index; }; -- cgit v1.2.3 From 86e4da2c071b6185803ed40045497bcf4e325f0d Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Thu, 13 Nov 2014 01:27:26 -0800 Subject: ForceFeedback: Apply immediately as well --- .../ForceFeedback/ForceFeedbackDevice.cpp | 111 +++++++++------------ .../ForceFeedback/ForceFeedbackDevice.h | 21 +--- 2 files changed, 52 insertions(+), 80 deletions(-) (limited to 'Source/Core/InputCommon/ControllerInterface') diff --git a/Source/Core/InputCommon/ControllerInterface/ForceFeedback/ForceFeedbackDevice.cpp b/Source/Core/InputCommon/ControllerInterface/ForceFeedback/ForceFeedbackDevice.cpp index f8efad343a..c6b1974a89 100644 --- a/Source/Core/InputCommon/ControllerInterface/ForceFeedback/ForceFeedbackDevice.cpp +++ b/Source/Core/InputCommon/ControllerInterface/ForceFeedback/ForceFeedbackDevice.cpp @@ -38,17 +38,6 @@ static const ForceType force_type_names[] = //{GUID_Friction, "Friction"}, }; -ForceFeedbackDevice::~ForceFeedbackDevice() -{ - // release the ff effect iface's - for (EffectState& state : m_state_out) - { - state.iface->Stop(); - state.iface->Unload(); - state.iface->Release(); - } -} - bool ForceFeedbackDevice::InitForceFeedback(const LPDIRECTINPUTDEVICE8 device, int cAxes) { if (cAxes == 0) @@ -107,14 +96,12 @@ bool ForceFeedbackDevice::InitForceFeedback(const LPDIRECTINPUTDEVICE8 device, i LPDIRECTINPUTEFFECT pEffect; if (SUCCEEDED(device->CreateEffect(f.guid, &eff, &pEffect, nullptr))) { - m_state_out.push_back(EffectState(pEffect)); - if (f.guid == GUID_ConstantForce) - AddOutput(new ForceConstant(f.name, m_state_out.back())); + AddOutput(new ForceConstant(f.name, pEffect)); else if (f.guid == GUID_RampForce) - AddOutput(new ForceRamp(f.name, m_state_out.back())); + AddOutput(new ForceRamp(f.name, pEffect)); else - AddOutput(new ForcePeriodic(f.name, m_state_out.back())); + AddOutput(new ForcePeriodic(f.name, pEffect)); } } @@ -133,32 +120,32 @@ bool ForceFeedbackDevice::InitForceFeedback(const LPDIRECTINPUTDEVICE8 device, i return true; } -void ForceFeedbackDevice::UpdateOutput() +template +ForceFeedbackDevice::Force

::~Force() { - DIEFFECT eff; - memset(&eff, 0, sizeof(eff)); + m_iface->Stop(); + m_iface->Unload(); + m_iface->Release(); +} + +template +void ForceFeedbackDevice::Force

::Update() +{ + DIEFFECT eff = {}; eff.dwSize = sizeof(DIEFFECT); eff.dwFlags = DIEFF_CARTESIAN | DIEFF_OBJECTOFFSETS; - for (EffectState& state : m_state_out) - { - if (state.params) - { - if (state.size) - { - eff.cbTypeSpecificParams = state.size; - eff.lpvTypeSpecificParams = state.params; - // set params and start effect - state.iface->SetParameters(&eff, DIEP_TYPESPECIFICPARAMS | DIEP_START); - } - else - { - state.iface->Stop(); - } + eff.cbTypeSpecificParams = sizeof(P); + eff.lpvTypeSpecificParams = ¶ms; - state.params = nullptr; - } - } + // set params and start effect + m_iface->SetParameters(&eff, DIEP_TYPESPECIFICPARAMS | DIEP_START); +} + +template +void ForceFeedbackDevice::Force

::Stop() +{ + m_iface->Stop(); } template<> @@ -166,15 +153,14 @@ void ForceFeedbackDevice::ForceConstant::SetState(const ControlState state) { const LONG new_val = LONG(10000 * state); - LONG &val = params.lMagnitude; - if (val != new_val) - { - val = new_val; - m_state.params = ¶ms; // tells UpdateOutput the state has changed + if (params.lMagnitude == new_val) + return; - // tells UpdateOutput to either start or stop the force - m_state.size = new_val ? sizeof(params) : 0; - } + params.lMagnitude = new_val; + if (new_val) + Update(); + else + Stop(); } template<> @@ -182,14 +168,14 @@ void ForceFeedbackDevice::ForceRamp::SetState(const ControlState state) { const LONG new_val = LONG(10000 * state); - if (params.lStart != new_val) - { - params.lStart = params.lEnd = new_val; - m_state.params = ¶ms; // tells UpdateOutput the state has changed + if (params.lStart == new_val) + return; - // tells UpdateOutput to either start or stop the force - m_state.size = new_val ? sizeof(params) : 0; - } + params.lStart = params.lEnd = new_val; + if (new_val) + Update(); + else + Stop(); } template<> @@ -197,22 +183,19 @@ void ForceFeedbackDevice::ForcePeriodic::SetState(const ControlState state) { const DWORD new_val = DWORD(10000 * state); - DWORD &val = params.dwMagnitude; - if (val != new_val) - { - val = new_val; - //params.dwPeriod = 0;//DWORD(0.05 * DI_SECONDS); // zero is working fine for me - - m_state.params = ¶ms; // tells UpdateOutput the state has changed + if (params.dwMagnitude == new_val) + return; - // tells UpdateOutput to either start or stop the force - m_state.size = new_val ? sizeof(params) : 0; - } + params.dwMagnitude = new_val; + if (new_val) + Update(); + else + Stop(); } template -ForceFeedbackDevice::Force

::Force(const std::string& name, EffectState& state) -: m_name(name), m_state(state) +ForceFeedbackDevice::Force

::Force(const std::string& name, LPDIRECTINPUTEFFECT iface) +: m_name(name), m_iface(iface) { memset(¶ms, 0, sizeof(params)); } diff --git a/Source/Core/InputCommon/ControllerInterface/ForceFeedback/ForceFeedbackDevice.h b/Source/Core/InputCommon/ControllerInterface/ForceFeedback/ForceFeedbackDevice.h index 8b26ffeff2..c42f0d41f7 100644 --- a/Source/Core/InputCommon/ControllerInterface/ForceFeedback/ForceFeedbackDevice.h +++ b/Source/Core/InputCommon/ControllerInterface/ForceFeedback/ForceFeedbackDevice.h @@ -25,25 +25,19 @@ namespace ForceFeedback class ForceFeedbackDevice : public Core::Device { private: - struct EffectState - { - EffectState(LPDIRECTINPUTEFFECT eff) : iface(eff), params(nullptr), size(0) {} - - LPDIRECTINPUTEFFECT iface; - void* params; // null when force hasn't changed - u8 size; // zero when force should stop - }; - template class Force : public Output { public: std::string GetName() const; - Force(const std::string& name, EffectState& state); + Force(const std::string& name, LPDIRECTINPUTEFFECT iface); + ~Force(); void SetState(ControlState state); + void Update(); + void Stop(); private: const std::string m_name; - EffectState& m_state; + LPDIRECTINPUTEFFECT m_iface; P params; }; typedef Force ForceConstant; @@ -52,11 +46,6 @@ private: public: bool InitForceFeedback(const LPDIRECTINPUTDEVICE8, int cAxes); - void UpdateOutput() override; - - virtual ~ForceFeedbackDevice(); -private: - std::list m_state_out; }; -- cgit v1.2.3 From f3b739341ee5ad000e8c58b971ed7e273dd9870e Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Thu, 13 Nov 2014 01:11:43 -0800 Subject: HW: Remove UpdateOutput All of the rumble interfaces are now immediate mode. --- .../ControllerInterface/ControllerInterface.cpp | 24 ---------------------- .../ControllerInterface/ControllerInterface.h | 1 - .../Core/InputCommon/ControllerInterface/Device.h | 1 - 3 files changed, 26 deletions(-) (limited to 'Source/Core/InputCommon/ControllerInterface') diff --git a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp index 74aa6de3a3..3eb1b95ff2 100644 --- a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp +++ b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp @@ -98,9 +98,6 @@ void ControllerInterface::Shutdown() for (ciface::Core::Device::Output* o : d->Outputs()) o->SetState(0); - // Update output - d->UpdateOutput(); - // Delete device delete d; } @@ -146,22 +143,6 @@ void ControllerInterface::UpdateInput() d->UpdateInput(); } -// -// UpdateOutput -// -// Update output for all devices, return true if all devices returned successful -// -void ControllerInterface::UpdateOutput() -{ - std::unique_lock lk(update_lock, std::defer_lock); - - if (!lk.try_lock()) - return; - - for (ciface::Core::Device* d : m_devices) - d->UpdateOutput(); -} - // // InputReference :: State // @@ -278,14 +259,9 @@ ciface::Core::Device::Control* ControllerInterface::OutputReference::Detect(cons // this loop is to make stuff like flashing keyboard LEDs work while (ms > (slept += 10)) - { - // TODO: improve this to update more than just the default device's output - device->UpdateOutput(); Common::SleepCurrentThread(10); - } State(0); - device->UpdateOutput(); } return nullptr; } diff --git a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.h b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.h index 9600aded63..9ab8427ad2 100644 --- a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.h +++ b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.h @@ -121,7 +121,6 @@ public: void UpdateReference(ControlReference* control, const ciface::Core::DeviceQualifier& default_device) const; void UpdateInput(); - void UpdateOutput(); std::recursive_mutex update_lock; diff --git a/Source/Core/InputCommon/ControllerInterface/Device.h b/Source/Core/InputCommon/ControllerInterface/Device.h index 6f54f9adf5..fa536e4116 100644 --- a/Source/Core/InputCommon/ControllerInterface/Device.h +++ b/Source/Core/InputCommon/ControllerInterface/Device.h @@ -101,7 +101,6 @@ public: virtual int GetId() const = 0; virtual std::string GetSource() const = 0; virtual void UpdateInput() {} - virtual void UpdateOutput() {} const std::vector& Inputs() const { return m_inputs; } const std::vector& Outputs() const { return m_outputs; } -- cgit v1.2.3