From 5ccbcf455e437031cb2542db0804a341cc9150cc Mon Sep 17 00:00:00 2001 From: skidau Date: Sun, 30 Dec 2012 13:41:48 +1100 Subject: Added preliminary GameCube Steering Wheel emulation via a PC Force Feedback Steering Wheel. --- .../ControllerInterface/DInput/DInputJoystick.cpp | 27 +++++++++++++++------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'Source/Core/InputCommon') diff --git a/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputJoystick.cpp b/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputJoystick.cpp index 08d62bcfc1..5f80b6f32b 100644 --- a/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputJoystick.cpp +++ b/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputJoystick.cpp @@ -145,7 +145,7 @@ LCleanup: void InitJoystick(IDirectInput8* const idi8, std::vector& devices, HWND hwnd) { std::list joysticks; - idi8->EnumDevices( DI8DEVCLASS_GAMECTRL, DIEnumDevicesCallback, (LPVOID)&joysticks, DIEDFL_ATTACHEDONLY ); + idi8->EnumDevices( DI8DEVCLASS_GAMECTRL, DIEnumDevicesCallback, (LPVOID)&joysticks, DIEDFL_FORCEFEEDBACK | DIEDFL_ATTACHEDONLY ); // this is used to number the joysticks // multiple joysticks with the same name shall get unique ids starting at 0 @@ -254,9 +254,9 @@ Joystick::Joystick( /*const LPCDIDEVICEINSTANCE lpddi, */const LPDIRECTINPUTDEVI for (unsigned int offset = 0; offset < DIJOFS_BUTTON(0) / sizeof(LONG); ++offset) { range.diph.dwObj = offset * sizeof(LONG); - // try to set some nice power of 2 values (8192) - range.lMin = -(1 << 13); - range.lMax = (1 << 13); + // try to set some nice power of 2 values (128) to match the GameCube controls + range.lMin = -(1 << 7); + range.lMax = (1 << 7); m_device->SetProperty(DIPROP_RANGE, &range.diph); // but i guess not all devices support setting range // so i getproperty right afterward incase it didn't set :P @@ -281,17 +281,19 @@ Joystick::Joystick( /*const LPCDIDEVICEINSTANCE lpddi, */const LPDIRECTINPUTDEVI if ( objects.size() ) { // temporary - DWORD rgdwAxes[] = {DIJOFS_X, DIJOFS_Y}; - LONG rglDirection[] = {0, 0}; + DWORD rgdwAxes[2] = {DIJOFS_X, DIJOFS_Y}; + LONG rglDirection[2] = {-200, 0}; DIEFFECT eff; ZeroMemory(&eff, sizeof(eff)); eff.dwSize = sizeof(DIEFFECT); eff.dwFlags = DIEFF_CARTESIAN | DIEFF_OBJECTOFFSETS; eff.dwDuration = INFINITE; // (4 * DI_SECONDS) + eff.dwSamplePeriod = 0; eff.dwGain = DI_FFNOMINALMAX; eff.dwTriggerButton = DIEB_NOTRIGGER; - eff.cAxes = std::min((DWORD)2, (DWORD)objects.size()); + eff.dwTriggerRepeatInterval = 0; + eff.cAxes = std::min((DWORD)1, (DWORD)objects.size()); eff.rgdwAxes = rgdwAxes; eff.rglDirection = rglDirection; @@ -310,7 +312,12 @@ Joystick::Joystick( /*const LPCDIDEVICEINSTANCE lpddi, */const LPDIRECTINPUTDEVI { // ugly if ladder if (0 == f) + { + DICONSTANTFORCE diCF = {-10000}; + diCF.lMagnitude = DI_FFNOMINALMAX; eff.cbTypeSpecificParams = sizeof(DICONSTANTFORCE); + eff.lpvTypeSpecificParams = &diCF; + } else if (1 == f) eff.cbTypeSpecificParams = sizeof(DIRAMPFORCE); else @@ -528,7 +535,11 @@ ControlState Joystick::Hat::GetState() const void Joystick::ForceConstant::SetState(const ControlState state) { - const LONG new_val = LONG(10000 * state); + float force = abs(state - 0.5) * 2; + if (state < 0.5) + force = -force; + + const LONG new_val = LONG(10000 * force); LONG &val = params.lMagnitude; if (val != new_val) -- cgit v1.2.3 From 51603f052220b6240ac9c316ab791c3738e260ef Mon Sep 17 00:00:00 2001 From: skidau Date: Tue, 1 Jan 2013 13:49:22 +1100 Subject: * Implemented working pedal support. * Changed the mapping of the steering wheel to: Main Stick Left/Right = Steer Left/Right Main Stick Up = Accelerate Main Stick Down = Brake * Fixed non-force feedback controllers that were not detected --- .../Core/InputCommon/Src/ControllerInterface/DInput/DInputJoystick.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/InputCommon') diff --git a/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputJoystick.cpp b/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputJoystick.cpp index 5f80b6f32b..b7ac3bf82e 100644 --- a/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputJoystick.cpp +++ b/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputJoystick.cpp @@ -145,7 +145,7 @@ LCleanup: void InitJoystick(IDirectInput8* const idi8, std::vector& devices, HWND hwnd) { std::list joysticks; - idi8->EnumDevices( DI8DEVCLASS_GAMECTRL, DIEnumDevicesCallback, (LPVOID)&joysticks, DIEDFL_FORCEFEEDBACK | DIEDFL_ATTACHEDONLY ); + idi8->EnumDevices( DI8DEVCLASS_GAMECTRL, DIEnumDevicesCallback, (LPVOID)&joysticks, DIEDFL_ATTACHEDONLY ); // this is used to number the joysticks // multiple joysticks with the same name shall get unique ids starting at 0 -- cgit v1.2.3 From 5240e75be20791d5226e7ac589a09a102755edf2 Mon Sep 17 00:00:00 2001 From: skidau Date: Mon, 7 Jan 2013 12:25:18 +1100 Subject: Fixed the infinite rumble problem caused by r4d6056f14625. --- .../InputCommon/Src/ControllerInterface/DInput/DInputJoystick.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'Source/Core/InputCommon') diff --git a/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputJoystick.cpp b/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputJoystick.cpp index b7ac3bf82e..af6ee7e77c 100644 --- a/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputJoystick.cpp +++ b/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputJoystick.cpp @@ -535,11 +535,7 @@ ControlState Joystick::Hat::GetState() const void Joystick::ForceConstant::SetState(const ControlState state) { - float force = abs(state - 0.5) * 2; - if (state < 0.5) - force = -force; - - const LONG new_val = LONG(10000 * force); + const LONG new_val = LONG(10000 * state); LONG &val = params.lMagnitude; if (val != new_val) -- cgit v1.2.3 From b8691df723ab635b3db41e86c9324b3adb952abe Mon Sep 17 00:00:00 2001 From: Rachel Bryk Date: Tue, 8 Jan 2013 19:15:11 -0500 Subject: Allow loading controller profiles from game ini. Currently loads the same profile for all 4 controllers, and overwrites the default control settings. --- Source/Core/InputCommon/Src/InputConfig.cpp | 13 ++++++++++--- Source/Core/InputCommon/Src/InputConfig.h | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) (limited to 'Source/Core/InputCommon') diff --git a/Source/Core/InputCommon/Src/InputConfig.cpp b/Source/Core/InputCommon/Src/InputConfig.cpp index b9d2a93b99..19be23ec74 100644 --- a/Source/Core/InputCommon/Src/InputConfig.cpp +++ b/Source/Core/InputCommon/Src/InputConfig.cpp @@ -26,10 +26,13 @@ InputPlugin::~InputPlugin() delete *i; } -bool InputPlugin::LoadConfig() +bool InputPlugin::LoadConfig(std::string ini) { IniFile inifile; - if (inifile.Load(File::GetUserPath(D_CONFIG_IDX) + ini_name + ".ini")) + std::string ini2 = ini; + if (ini == "") + ini = ini_name; + if (inifile.Load(File::GetUserPath(D_CONFIG_IDX) + ini + ".ini")) { std::vector< ControllerEmu* >::const_iterator i = controllers.begin(), @@ -37,7 +40,11 @@ bool InputPlugin::LoadConfig() for (; i!=e; ++i) { // load settings from ini - (*i)->LoadConfig(inifile.GetOrCreateSection((*i)->GetName().c_str())); + std::string section; + section = (*i)->GetName(); + if (ini2 != "") + section = "Profile"; + (*i)->LoadConfig(inifile.GetOrCreateSection(section.c_str())); // update refs (*i)->UpdateReferences(g_controller_interface); } diff --git a/Source/Core/InputCommon/Src/InputConfig.h b/Source/Core/InputCommon/Src/InputConfig.h index 4d25334ce7..bf12217304 100644 --- a/Source/Core/InputCommon/Src/InputConfig.h +++ b/Source/Core/InputCommon/Src/InputConfig.h @@ -42,7 +42,7 @@ public: ~InputPlugin(); - bool LoadConfig(); + bool LoadConfig(std::string ini); void SaveConfig(); std::vector< ControllerEmu* > controllers; -- cgit v1.2.3 From e32b1526b334950068cf5f1a7eb29ea6a873274c Mon Sep 17 00:00:00 2001 From: Rachel Bryk Date: Wed, 9 Jan 2013 15:03:43 -0500 Subject: Allow setting different profiles for different controllers, and automatically use the appropriate profile directory. --- Source/Core/InputCommon/Src/InputConfig.cpp | 51 ++++++++++++++++++++++------- Source/Core/InputCommon/Src/InputConfig.h | 2 +- 2 files changed, 41 insertions(+), 12 deletions(-) (limited to 'Source/Core/InputCommon') diff --git a/Source/Core/InputCommon/Src/InputConfig.cpp b/Source/Core/InputCommon/Src/InputConfig.cpp index 19be23ec74..7d1bf11de8 100644 --- a/Source/Core/InputCommon/Src/InputConfig.cpp +++ b/Source/Core/InputCommon/Src/InputConfig.cpp @@ -16,6 +16,7 @@ // http://code.google.com/p/dolphin-emu/ #include "InputConfig.h" +#include "../../Core/Src/ConfigManager.h" InputPlugin::~InputPlugin() { @@ -26,25 +27,53 @@ InputPlugin::~InputPlugin() delete *i; } -bool InputPlugin::LoadConfig(std::string ini) +bool InputPlugin::LoadConfig(bool isGC) { IniFile inifile; - std::string ini2 = ini; - if (ini == "") - ini = ini_name; - if (inifile.Load(File::GetUserPath(D_CONFIG_IDX) + ini + ".ini")) + IniFile game_ini; + bool useProfile[4] = {false, false, false, false}; + std::string num[4] = {"1", "2", "3", "4"}; + std::string profile[4]; + + if (SConfig::GetInstance().m_LocalCoreStartupParameter.GetUniqueID() != "00000000") + { + std::string type; + if (isGC) + type = "GC"; + else + type = "Wii"; + game_ini.Load(File::GetUserPath(D_GAMECONFIG_IDX) + SConfig::GetInstance().m_LocalCoreStartupParameter.GetUniqueID() + ".ini"); + for (int i = 0; i < 4; i++) + { + if (game_ini.Exists("Core", (type + "Profile" + num[i]).c_str())) + { + useProfile[i] = true; + game_ini.Get("Core", (type + "Profile" + num[i]).c_str(), &profile[i]); + } + } + } + + if (inifile.Load(File::GetUserPath(D_CONFIG_IDX) + ini_name + ".ini")) { std::vector< ControllerEmu* >::const_iterator i = controllers.begin(), e = controllers.end(); - for (; i!=e; ++i) + for (int n = 0; i!=e; ++i, ++n) { // load settings from ini - std::string section; - section = (*i)->GetName(); - if (ini2 != "") - section = "Profile"; - (*i)->LoadConfig(inifile.GetOrCreateSection(section.c_str())); + if (useProfile[n]) + { + IniFile profile_ini; + std::string path; + if (isGC) + path = "Profiles/GCPad/"; + else + path = "Profiles/Wiimote/"; + profile_ini.Load(File::GetUserPath(D_CONFIG_IDX) + path + profile[n] + ".ini"); + (*i)->LoadConfig(profile_ini.GetOrCreateSection("Profile")); + } + else + (*i)->LoadConfig(inifile.GetOrCreateSection((*i)->GetName().c_str())); // update refs (*i)->UpdateReferences(g_controller_interface); } diff --git a/Source/Core/InputCommon/Src/InputConfig.h b/Source/Core/InputCommon/Src/InputConfig.h index bf12217304..71505bb935 100644 --- a/Source/Core/InputCommon/Src/InputConfig.h +++ b/Source/Core/InputCommon/Src/InputConfig.h @@ -42,7 +42,7 @@ public: ~InputPlugin(); - bool LoadConfig(std::string ini); + bool LoadConfig(bool isGC); void SaveConfig(); std::vector< ControllerEmu* > controllers; -- cgit v1.2.3 From fad2468e3014334e1a050d0c60deb244b85923ff Mon Sep 17 00:00:00 2001 From: Rachel Bryk Date: Wed, 9 Jan 2013 20:41:14 -0500 Subject: Make sure profile actually exists. --- Source/Core/InputCommon/Src/InputConfig.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'Source/Core/InputCommon') diff --git a/Source/Core/InputCommon/Src/InputConfig.cpp b/Source/Core/InputCommon/Src/InputConfig.cpp index 7d1bf11de8..a0b396db0a 100644 --- a/Source/Core/InputCommon/Src/InputConfig.cpp +++ b/Source/Core/InputCommon/Src/InputConfig.cpp @@ -34,21 +34,31 @@ bool InputPlugin::LoadConfig(bool isGC) bool useProfile[4] = {false, false, false, false}; std::string num[4] = {"1", "2", "3", "4"}; std::string profile[4]; + std::string path; if (SConfig::GetInstance().m_LocalCoreStartupParameter.GetUniqueID() != "00000000") { std::string type; if (isGC) + { type = "GC"; + path = "Profiles/GCPad/"; + } else + { type = "Wii"; + path = "Profiles/Wiimote/"; + } game_ini.Load(File::GetUserPath(D_GAMECONFIG_IDX) + SConfig::GetInstance().m_LocalCoreStartupParameter.GetUniqueID() + ".ini"); for (int i = 0; i < 4; i++) { if (game_ini.Exists("Core", (type + "Profile" + num[i]).c_str())) { - useProfile[i] = true; game_ini.Get("Core", (type + "Profile" + num[i]).c_str(), &profile[i]); + if (File::Exists(File::GetUserPath(D_CONFIG_IDX) + path + profile[i] + ".ini")) + useProfile[i] = true; + else + PanicAlertT("Selected controller profile does not exist"); } } } @@ -64,11 +74,6 @@ bool InputPlugin::LoadConfig(bool isGC) if (useProfile[n]) { IniFile profile_ini; - std::string path; - if (isGC) - path = "Profiles/GCPad/"; - else - path = "Profiles/Wiimote/"; profile_ini.Load(File::GetUserPath(D_CONFIG_IDX) + path + profile[n] + ".ini"); (*i)->LoadConfig(profile_ini.GetOrCreateSection("Profile")); } -- cgit v1.2.3 From 0de8fbecfa389ad03232440bcd91c10a2a7af7f2 Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Wed, 9 Jan 2013 20:26:11 -0600 Subject: Don't hardcode left-shift to disabe keyboard input on linux. Left-shift can be used for gamepad input now. Fixes issue 4968. --- Source/Core/InputCommon/Src/ControllerInterface/Xlib/Xlib.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'Source/Core/InputCommon') diff --git a/Source/Core/InputCommon/Src/ControllerInterface/Xlib/Xlib.cpp b/Source/Core/InputCommon/Src/ControllerInterface/Xlib/Xlib.cpp index c2030a059d..fa30ba5c62 100644 --- a/Source/Core/InputCommon/Src/ControllerInterface/Xlib/Xlib.cpp +++ b/Source/Core/InputCommon/Src/ControllerInterface/Xlib/Xlib.cpp @@ -116,8 +116,7 @@ KeyboardMouse::Key::Key(Display* const display, KeyCode keycode, const char* key ControlState KeyboardMouse::Key::GetState() const { const KeyCode shift = XKeysymToKeycode(m_display, XK_Shift_L); - return (m_keyboard[m_keycode / 8] & (1 << (m_keycode % 8))) != 0 - && (m_keyboard[shift / 8] & (1 << (shift % 8))) == 0; + return (m_keyboard[m_keycode / 8] & (1 << (m_keycode % 8))) != 0; } ControlState KeyboardMouse::Button::GetState() const -- cgit v1.2.3 From b9fc26540e8abd557a4b08dc951a10ca69f7a0d8 Mon Sep 17 00:00:00 2001 From: Rachel Bryk Date: Wed, 9 Jan 2013 21:56:17 -0500 Subject: Change key names, and put it in section Controls. --- Source/Core/InputCommon/Src/InputConfig.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'Source/Core/InputCommon') diff --git a/Source/Core/InputCommon/Src/InputConfig.cpp b/Source/Core/InputCommon/Src/InputConfig.cpp index a0b396db0a..1988a9ebb7 100644 --- a/Source/Core/InputCommon/Src/InputConfig.cpp +++ b/Source/Core/InputCommon/Src/InputConfig.cpp @@ -41,20 +41,20 @@ bool InputPlugin::LoadConfig(bool isGC) std::string type; if (isGC) { - type = "GC"; + type = "Pad"; path = "Profiles/GCPad/"; } else { - type = "Wii"; + type = "Wiimote"; path = "Profiles/Wiimote/"; } game_ini.Load(File::GetUserPath(D_GAMECONFIG_IDX) + SConfig::GetInstance().m_LocalCoreStartupParameter.GetUniqueID() + ".ini"); for (int i = 0; i < 4; i++) { - if (game_ini.Exists("Core", (type + "Profile" + num[i]).c_str())) + if (game_ini.Exists("Controls", (type + "Profile" + num[i]).c_str())) { - game_ini.Get("Core", (type + "Profile" + num[i]).c_str(), &profile[i]); + game_ini.Get("Controls", (type + "Profile" + num[i]).c_str(), &profile[i]); if (File::Exists(File::GetUserPath(D_CONFIG_IDX) + path + profile[i] + ".ini")) useProfile[i] = true; else -- cgit v1.2.3 From 6b8dc6802ba2303f039919be48ba59caeb411dd7 Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Sun, 13 Jan 2013 12:57:17 -0600 Subject: Fix two warnings. --- Source/Core/InputCommon/Src/ControllerInterface/Xlib/Xlib.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'Source/Core/InputCommon') diff --git a/Source/Core/InputCommon/Src/ControllerInterface/Xlib/Xlib.cpp b/Source/Core/InputCommon/Src/ControllerInterface/Xlib/Xlib.cpp index fa30ba5c62..dad0c6bbf8 100644 --- a/Source/Core/InputCommon/Src/ControllerInterface/Xlib/Xlib.cpp +++ b/Source/Core/InputCommon/Src/ControllerInterface/Xlib/Xlib.cpp @@ -115,7 +115,6 @@ KeyboardMouse::Key::Key(Display* const display, KeyCode keycode, const char* key ControlState KeyboardMouse::Key::GetState() const { - const KeyCode shift = XKeysymToKeycode(m_display, XK_Shift_L); return (m_keyboard[m_keycode / 8] & (1 << (m_keycode % 8))) != 0; } -- cgit v1.2.3 From 38b01d176a266ac67e2473f16c645760a991fb66 Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Thu, 17 Jan 2013 15:40:44 -0600 Subject: Start to make possible use of "full analog surface". (useful for triggers on some silly physical gamepads) --- .../ControllerInterface/ControllerInterface.cpp | 4 +-- .../Src/ControllerInterface/ControllerInterface.h | 32 +++++++++++++++++++++- 2 files changed, 33 insertions(+), 3 deletions(-) (limited to 'Source/Core/InputCommon') diff --git a/Source/Core/InputCommon/Src/ControllerInterface/ControllerInterface.cpp b/Source/Core/InputCommon/Src/ControllerInterface/ControllerInterface.cpp index 82cfe2469e..e6877f5731 100644 --- a/Source/Core/InputCommon/Src/ControllerInterface/ControllerInterface.cpp +++ b/Source/Core/InputCommon/Src/ControllerInterface/ControllerInterface.cpp @@ -461,7 +461,7 @@ ControllerInterface::Device::Control* ControllerInterface::InputReference::Detec i = device->Inputs().begin(), e = device->Inputs().end(); for (std::vector::iterator state = states.begin(); i != e; ++i) - *state++ = ((*i)->GetState() > INPUT_DETECT_THRESHOLD); + *state++ = ((*i)->GetState() > (1 - INPUT_DETECT_THRESHOLD)); while (time < ms) { @@ -477,7 +477,7 @@ ControllerInterface::Device::Control* ControllerInterface::InputReference::Detec if (false == *state) return *i; } - else + else if ((*i)->GetState() < (1 - INPUT_DETECT_THRESHOLD)) *state = false; } Common::SleepCurrentThread(10); time += 10; diff --git a/Source/Core/InputCommon/Src/ControllerInterface/ControllerInterface.h b/Source/Core/InputCommon/Src/ControllerInterface/ControllerInterface.h index 7c5a236d75..b846bb56e8 100644 --- a/Source/Core/InputCommon/Src/ControllerInterface/ControllerInterface.h +++ b/Source/Core/InputCommon/Src/ControllerInterface/ControllerInterface.h @@ -87,7 +87,7 @@ public: Input* ToInput() { return this; } }; - + // // Output // @@ -122,6 +122,36 @@ public: protected: void AddInput(Input* const i); void AddOutput(Output* const o); + + class FullAnalogSurface : public Input + { + public: + FullAnalogSurface(Input* low, Input* high) + : m_low(*low), m_high(*high) + {} + + ControlState GetState() const + { + return (1 + m_high.GetState() - m_low.GetState()) / 2; + } + + std::string GetName() const + { + return m_low.GetName() + *m_high.GetName().rbegin(); + } + + private: + Input& m_low; + Input& m_high; + }; + + void AddAnalogInputs(Input* low, Input* high) + { + AddInput(low); + AddInput(high); + AddInput(new FullAnalogSurface(low, high)); + AddInput(new FullAnalogSurface(high, low)); + } private: std::vector m_inputs; -- cgit v1.2.3 From f97d2a93c4167a4b6aec0ae69536395380d427e3 Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Thu, 17 Jan 2013 15:41:18 -0600 Subject: Add "full analog surface" support in DInput,OSX,SDL backends. (should not be needed for XInput) --- .../InputCommon/Src/ControllerInterface/DInput/DInputJoystick.cpp | 4 ++-- Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXJoystick.mm | 4 ++-- Source/Core/InputCommon/Src/ControllerInterface/SDL/SDL.cpp | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'Source/Core/InputCommon') diff --git a/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputJoystick.cpp b/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputJoystick.cpp index af6ee7e77c..9bc5364e76 100644 --- a/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputJoystick.cpp +++ b/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputJoystick.cpp @@ -267,8 +267,8 @@ Joystick::Joystick( /*const LPCDIDEVICEINSTANCE lpddi, */const LPDIRECTINPUTDEVI const LONG& ax = (&m_state_in.lX)[offset]; // each axis gets a negative and a positive input instance associated with it - AddInput(new Axis(offset, ax, base, range.lMin-base)); - AddInput(new Axis(offset, ax, base, range.lMax-base)); + AddAnalogInputs(new Axis(offset, ax, base, range.lMin-base), + new Axis(offset, ax, base, range.lMax-base)); } } diff --git a/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXJoystick.mm b/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXJoystick.mm index 129a5f38e0..60c0cc8c50 100644 --- a/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXJoystick.mm +++ b/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXJoystick.mm @@ -64,8 +64,8 @@ Joystick::Joystick(IOHIDDeviceRef device, std::string name, int index) AddInput(new Hat(e, m_device, Hat::down)); AddInput(new Hat(e, m_device, Hat::left)); } else { - AddInput(new Axis(e, m_device, Axis::negative)); - AddInput(new Axis(e, m_device, Axis::positive)); + AddAnalogInputs(new Axis(e, m_device, Axis::negative), + new Axis(e, m_device, Axis::positive)); } } CFRelease(axes); diff --git a/Source/Core/InputCommon/Src/ControllerInterface/SDL/SDL.cpp b/Source/Core/InputCommon/Src/ControllerInterface/SDL/SDL.cpp index c7c6898ecd..5473f7bcb3 100644 --- a/Source/Core/InputCommon/Src/ControllerInterface/SDL/SDL.cpp +++ b/Source/Core/InputCommon/Src/ControllerInterface/SDL/SDL.cpp @@ -86,8 +86,8 @@ Joystick::Joystick(SDL_Joystick* const joystick, const int sdl_index, const unsi for (u8 i = 0; i != SDL_JoystickNumAxes(m_joystick); ++i) { // each axis gets a negative and a positive input instance associated with it - AddInput(new Axis(i, m_joystick, -32768)); - AddInput(new Axis(i, m_joystick, 32767)); + AddAnalogInputs(new Axis(i, m_joystick, -32768), + new Axis(i, m_joystick, 32767)); } #ifdef USE_SDL_HAPTIC -- cgit v1.2.3 From 2f28d938cf640390cd8979c6104f3dbe8795e1e6 Mon Sep 17 00:00:00 2001 From: Grant Paul Date: Thu, 17 Jan 2013 23:32:07 -0800 Subject: Add support for the mouse cursor and mouse clicking events on OS X. --- .../ControllerInterface/ControllerInterface.cpp | 2 +- .../InputCommon/Src/ControllerInterface/OSX/OSX.h | 2 +- .../InputCommon/Src/ControllerInterface/OSX/OSX.mm | 8 ++- .../Src/ControllerInterface/OSX/OSXKeyboard.h | 32 ++++++++++- .../Src/ControllerInterface/OSX/OSXKeyboard.mm | 67 +++++++++++++++++++++- 5 files changed, 105 insertions(+), 6 deletions(-) (limited to 'Source/Core/InputCommon') diff --git a/Source/Core/InputCommon/Src/ControllerInterface/ControllerInterface.cpp b/Source/Core/InputCommon/Src/ControllerInterface/ControllerInterface.cpp index e6877f5731..8e96231674 100644 --- a/Source/Core/InputCommon/Src/ControllerInterface/ControllerInterface.cpp +++ b/Source/Core/InputCommon/Src/ControllerInterface/ControllerInterface.cpp @@ -45,7 +45,7 @@ void ControllerInterface::Initialize() ciface::Xlib::Init(m_devices, m_hwnd); #endif #ifdef CIFACE_USE_OSX - ciface::OSX::Init(m_devices); + ciface::OSX::Init(m_devices, m_hwnd); #endif #ifdef CIFACE_USE_SDL ciface::SDL::Init(m_devices); diff --git a/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSX.h b/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSX.h index 0458d87e1d..225906c35d 100644 --- a/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSX.h +++ b/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSX.h @@ -7,7 +7,7 @@ namespace ciface namespace OSX { -void Init(std::vector& devices); +void Init(std::vector& devices, void *window); void DeInit(); void DeviceElementDebugPrint(const void *, void *); diff --git a/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSX.mm b/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSX.mm index bf4f49bac6..aef8f283c1 100644 --- a/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSX.mm +++ b/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSX.mm @@ -1,5 +1,6 @@ #include #include +#include #include "../ControllerInterface.h" #include "OSX.h" @@ -131,6 +132,7 @@ void DeviceDebugPrint(IOHIDDeviceRef device) #endif } +static void *g_window; static void DeviceMatching_callback(void* inContext, IOReturn inResult, @@ -150,7 +152,7 @@ static void DeviceMatching_callback(void* inContext, if (IOHIDDeviceConformsTo(inIOHIDDeviceRef, kHIDPage_GenericDesktop, kHIDUsage_GD_Keyboard)) devices->push_back(new Keyboard(inIOHIDDeviceRef, - name, kbd_name_counts[name]++)); + name, kbd_name_counts[name]++, g_window)); #if 0 else if (IOHIDDeviceConformsTo(inIOHIDDeviceRef, kHIDPage_GenericDesktop, kHIDUsage_GD_Mouse)) @@ -162,13 +164,15 @@ static void DeviceMatching_callback(void* inContext, name, joy_name_counts[name]++)); } -void Init(std::vector& devices) +void Init(std::vector& devices, void *window) { HIDManager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone); if (!HIDManager) NSLog(@"Failed to create HID Manager reference"); + g_window = window; + IOHIDManagerSetDeviceMatching(HIDManager, NULL); // Callbacks for acquisition or loss of a matching device diff --git a/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXKeyboard.h b/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXKeyboard.h index 1a7fcd045b..d59651c98a 100644 --- a/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXKeyboard.h +++ b/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXKeyboard.h @@ -21,21 +21,51 @@ private: const IOHIDDeviceRef m_device; std::string m_name; }; + class Cursor : public Input + { + public: + std::string GetName() const; + bool IsDetectable() { return false; } + Cursor(u8 index, const float& axis, const bool positive) : m_index(index), m_axis(axis), m_positive(positive) {} + ControlState GetState() const; + private: + const float& m_axis; + const u8 m_index; + const bool m_positive; + }; + class Button : public Input + { + public: + std::string GetName() const; + Button(u8 index, const unsigned char& button) : m_index(index), m_button(button) {} + ControlState GetState() const; + private: + const unsigned char& m_button; + const u8 m_index; + }; public: bool UpdateInput(); bool UpdateOutput(); - Keyboard(IOHIDDeviceRef device, std::string name, int index); + Keyboard(IOHIDDeviceRef device, std::string name, int index, void *window); std::string GetName() const; std::string GetSource() const; int GetId() const; private: + struct + { + float x, y; + } m_cursor; + const IOHIDDeviceRef m_device; const std::string m_device_name; int m_index; + void *m_window; + uint32_t m_windowid; + unsigned char m_mousebuttons[3]; }; } diff --git a/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXKeyboard.mm b/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXKeyboard.mm index 7543d507dd..56e360019a 100644 --- a/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXKeyboard.mm +++ b/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXKeyboard.mm @@ -1,5 +1,7 @@ #include #include +#include +#include // wxWidgets #include "../ControllerInterface.h" #include "OSXKeyboard.h" @@ -9,10 +11,11 @@ namespace ciface namespace OSX { -Keyboard::Keyboard(IOHIDDeviceRef device, std::string name, int index) +Keyboard::Keyboard(IOHIDDeviceRef device, std::string name, int index, void *window) : m_device(device) , m_device_name(name) , m_index(index) + , m_window(window) { // This class should only recieve Keyboard or Keypad devices // Now, filter on just the buttons we can handle sanely @@ -39,10 +42,48 @@ Keyboard::Keyboard(IOHIDDeviceRef device, std::string name, int index) } CFRelease(elements); } + + m_windowid = [[(NSView *)(((wxWindow *)window)->GetHandle()) window] windowNumber]; + + // cursor, with a hax for-loop + for (unsigned int i=0; i<4; ++i) + AddInput(new Cursor(!!(i&2), (&m_cursor.x)[i/2], !!(i&1))); + + for (u8 i = 0; i < sizeof(m_mousebuttons) / sizeof(m_mousebuttons[0]); ++i) + AddInput(new Button(i, m_mousebuttons[i])); } bool Keyboard::UpdateInput() { + CGRect bounds = CGRectZero; + uint32_t windowid[1] = { m_windowid }; + CFArrayRef windowArray = CFArrayCreate(NULL, (const void **) windowid, 1, NULL); + CFArrayRef windowDescriptions = CGWindowListCreateDescriptionFromArray(windowArray); + CFDictionaryRef windowDescription = (CFDictionaryRef) CFArrayGetValueAtIndex((CFArrayRef) windowDescriptions, 0); + + if (CFDictionaryContainsKey(windowDescription, kCGWindowBounds)) + { + CFDictionaryRef boundsDictionary = (CFDictionaryRef) CFDictionaryGetValue(windowDescription, kCGWindowBounds); + + if (boundsDictionary != NULL) + CGRectMakeWithDictionaryRepresentation(boundsDictionary, &bounds); + } + + CFRelease(windowArray); + + CGEventRef event = CGEventCreate(nil); + CGPoint loc = CGEventGetLocation(event); + CFRelease(event); + + loc.x -= bounds.origin.x; + loc.y -= bounds.origin.y; + m_cursor.x = loc.x / bounds.size.width * 2 - 1.0; + m_cursor.y = loc.y / bounds.size.height * 2 - 1.0; + + m_mousebuttons[0] = CGEventSourceButtonState(kCGEventSourceStateHIDSystemState, kCGMouseButtonLeft); + m_mousebuttons[1] = CGEventSourceButtonState(kCGEventSourceStateHIDSystemState, kCGMouseButtonRight); + m_mousebuttons[2] = CGEventSourceButtonState(kCGEventSourceStateHIDSystemState, kCGMouseButtonCenter); + return true; } @@ -201,10 +242,34 @@ ControlState Keyboard::Key::GetState() const return 0; } +ControlState Keyboard::Cursor::GetState() const +{ + return std::max(0.0f, ControlState(m_axis) / (m_positive ? 1.0f : -1.0f)); +} + +ControlState Keyboard::Button::GetState() const +{ + return (m_button != 0); +} + +std::string Keyboard::Cursor::GetName() const +{ + static char tmpstr[] = "Cursor .."; + tmpstr[7] = (char)('X' + m_index); + tmpstr[8] = (m_positive ? '+' : '-'); + return tmpstr; +} + +std::string Keyboard::Button::GetName() const +{ + return std::string("Click ") + char('0' + m_index); +} + std::string Keyboard::Key::GetName() const { return m_name; } + } } -- cgit v1.2.3 From 6ec95d30af4ce33090d896414107844bea18c612 Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Sat, 19 Jan 2013 19:16:01 -0600 Subject: Allow emulated wiimote to be tilted 180 degrees in each direction. (was 90) Fixes issue 3492. --- Source/Core/InputCommon/Src/ControllerEmu.cpp | 1 + Source/Core/InputCommon/Src/ControllerEmu.h | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'Source/Core/InputCommon') diff --git a/Source/Core/InputCommon/Src/ControllerEmu.cpp b/Source/Core/InputCommon/Src/ControllerEmu.cpp index 9065888d7d..2e6ad10617 100644 --- a/Source/Core/InputCommon/Src/ControllerEmu.cpp +++ b/Source/Core/InputCommon/Src/ControllerEmu.cpp @@ -295,6 +295,7 @@ ControllerEmu::Tilt::Tilt(const char* const _name) settings.push_back(new Setting(_trans("Dead Zone"), 0, 0, 50)); settings.push_back(new Setting(_trans("Circle Stick"), 0)); + settings.push_back(new Setting(_trans("Angle"), 0.9f, 0, 180)); } ControllerEmu::Cursor::Cursor(const char* const _name) diff --git a/Source/Core/InputCommon/Src/ControllerEmu.h b/Source/Core/InputCommon/Src/ControllerEmu.h index 888e0c7fa9..6084a610a1 100644 --- a/Source/Core/InputCommon/Src/ControllerEmu.h +++ b/Source/Core/InputCommon/Src/ControllerEmu.h @@ -307,6 +307,7 @@ public: ControlState deadzone = settings[0]->value; ControlState circle = settings[1]->value; + auto const angle = settings[2]->value / 1.8f; ControlState m = controls[4]->control_ref->State(); // modifier code @@ -363,8 +364,8 @@ public: m_tilt[1] = std::max(m_tilt[1] - 0.1f, yy); } - *y = C(m_tilt[1] * range + base); - *x = C(m_tilt[0] * range + base); + *y = C(m_tilt[1] * angle * range + base); + *x = C(m_tilt[0] * angle * range + base); } private: float m_tilt[2]; -- cgit v1.2.3 From b7d32b0a3d810736b2e1151d6d8b9da85ebfbcf3 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 23 Jan 2013 23:29:50 -0500 Subject: mem_fun -> mem_fn. mem_fun is deprecated in C++11. Also it does everything mem_fun can do, but more conveniently. --- Source/Core/InputCommon/Src/UDPWiimote.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/InputCommon') diff --git a/Source/Core/InputCommon/Src/UDPWiimote.cpp b/Source/Core/InputCommon/Src/UDPWiimote.cpp index f14f9ed7e2..83799f2a43 100644 --- a/Source/Core/InputCommon/Src/UDPWiimote.cpp +++ b/Source/Core/InputCommon/Src/UDPWiimote.cpp @@ -134,7 +134,7 @@ UDPWiimote::UDPWiimote(const char *_port, const char * name, int _index) : initBroadcastIPv6(); std::lock_guard lk(d->termLock); - d->thread = std::thread(std::mem_fun(&UDPWiimote::mainThread), this); + d->thread = std::thread(std::mem_fn(&UDPWiimote::mainThread), this); return; } -- cgit v1.2.3 From fe7e691d77550195f71ae2b7af67c6395493908d Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 23 Jan 2013 23:38:49 -0500 Subject: Revert "mem_fun -> mem_fn." This reverts commit b7d32b0a3d810736b2e1151d6d8b9da85ebfbcf3. OSX C++ std library in charge of holding back progress (as usual). --- Source/Core/InputCommon/Src/UDPWiimote.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/InputCommon') diff --git a/Source/Core/InputCommon/Src/UDPWiimote.cpp b/Source/Core/InputCommon/Src/UDPWiimote.cpp index 83799f2a43..f14f9ed7e2 100644 --- a/Source/Core/InputCommon/Src/UDPWiimote.cpp +++ b/Source/Core/InputCommon/Src/UDPWiimote.cpp @@ -134,7 +134,7 @@ UDPWiimote::UDPWiimote(const char *_port, const char * name, int _index) : initBroadcastIPv6(); std::lock_guard lk(d->termLock); - d->thread = std::thread(std::mem_fn(&UDPWiimote::mainThread), this); + d->thread = std::thread(std::mem_fun(&UDPWiimote::mainThread), this); return; } -- cgit v1.2.3