diff options
Diffstat (limited to 'platform/windows/joypad_windows.cpp')
-rw-r--r-- | platform/windows/joypad_windows.cpp | 49 |
1 files changed, 0 insertions, 49 deletions
diff --git a/platform/windows/joypad_windows.cpp b/platform/windows/joypad_windows.cpp index 821d4eb685..38a4065ef9 100644 --- a/platform/windows/joypad_windows.cpp +++ b/platform/windows/joypad_windows.cpp @@ -53,7 +53,6 @@ JoypadWindows::JoypadWindows() { } JoypadWindows::JoypadWindows(HWND *hwnd) { - input = Input::get_singleton(); hWnd = hwnd; joypad_count = 0; @@ -76,18 +75,14 @@ JoypadWindows::JoypadWindows(HWND *hwnd) { } JoypadWindows::~JoypadWindows() { - close_joypad(); dinput->Release(); unload_xinput(); } bool JoypadWindows::have_device(const GUID &p_guid) { - for (int i = 0; i < JOYPADS_MAX; i++) { - if (d_joypads[i].guid == p_guid) { - d_joypads[i].confirmed = true; return true; } @@ -97,7 +92,6 @@ bool JoypadWindows::have_device(const GUID &p_guid) { // adapted from SDL2, works a lot better than the MSDN version bool JoypadWindows::is_xinput_device(const GUID *p_guid) { - static GUID IID_ValveStreamingGamepad = { MAKELONG(0x28DE, 0x11FF), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } }; static GUID IID_X360WiredGamepad = { MAKELONG(0x045E, 0x02A1), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } }; static GUID IID_X360WirelessGamepad = { MAKELONG(0x045E, 0x028E), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } }; @@ -120,7 +114,6 @@ bool JoypadWindows::is_xinput_device(const GUID *p_guid) { return false; } for (unsigned int i = 0; i < dev_list_count; i++) { - RID_DEVICE_INFO rdi; char dev_name[128]; UINT rdiSize = sizeof(rdi); @@ -132,7 +125,6 @@ bool JoypadWindows::is_xinput_device(const GUID *p_guid) { (MAKELONG(rdi.hid.dwVendorId, rdi.hid.dwProductId) == (LONG)p_guid->Data1) && (GetRawInputDeviceInfoA(dev_list[i].hDevice, RIDI_DEVICENAME, &dev_name, &nameSize) != (UINT)-1) && (strstr(dev_name, "IG_") != nullptr)) { - free(dev_list); return true; } @@ -142,7 +134,6 @@ bool JoypadWindows::is_xinput_device(const GUID *p_guid) { } bool JoypadWindows::setup_dinput_joypad(const DIDEVICEINSTANCE *instance) { - HRESULT hr; int num = input->get_unused_joy_id(); @@ -189,9 +180,7 @@ bool JoypadWindows::setup_dinput_joypad(const DIDEVICEINSTANCE *instance) { } void JoypadWindows::setup_joypad_object(const DIDEVICEOBJECTINSTANCE *ob, int p_joy_id) { - if (ob->dwType & DIDFT_AXIS) { - HRESULT res; DIPROPRANGE prop_range; DIPROPDWORD dilong; @@ -240,7 +229,6 @@ void JoypadWindows::setup_joypad_object(const DIDEVICEOBJECTINSTANCE *ob, int p_ } BOOL CALLBACK JoypadWindows::enumCallback(const DIDEVICEINSTANCE *p_instance, void *p_context) { - JoypadWindows *self = (JoypadWindows *)p_context; if (self->is_xinput_device(&p_instance->guidProduct)) { return DIENUM_CONTINUE; @@ -250,7 +238,6 @@ BOOL CALLBACK JoypadWindows::enumCallback(const DIDEVICEINSTANCE *p_instance, vo } BOOL CALLBACK JoypadWindows::objectsCallback(const DIDEVICEOBJECTINSTANCE *instance, void *context) { - JoypadWindows *self = (JoypadWindows *)context; self->setup_joypad_object(instance, self->id_to_change); @@ -258,11 +245,8 @@ BOOL CALLBACK JoypadWindows::objectsCallback(const DIDEVICEOBJECTINSTANCE *insta } void JoypadWindows::close_joypad(int id) { - if (id == -1) { - for (int i = 0; i < JOYPADS_MAX; i++) { - close_joypad(i); } return; @@ -281,18 +265,14 @@ void JoypadWindows::close_joypad(int id) { } void JoypadWindows::probe_joypads() { - DWORD dwResult; for (DWORD i = 0; i < XUSER_MAX_COUNT; i++) { - ZeroMemory(&x_joypads[i].state, sizeof(XINPUT_STATE)); dwResult = xinput_get_state(i, &x_joypads[i].state); if (dwResult == ERROR_SUCCESS) { - int id = input->get_unused_joy_id(); if (id != -1 && !x_joypads[i].attached) { - x_joypads[i].attached = true; x_joypads[i].id = id; x_joypads[i].ff_timestamp = 0; @@ -302,7 +282,6 @@ void JoypadWindows::probe_joypads() { input->joy_connection_changed(id, true, "XInput Gamepad", "__XINPUT_DEVICE__"); } } else if (x_joypads[i].attached) { - x_joypads[i].attached = false; attached_joypads[x_joypads[i].id] = false; input->joy_connection_changed(x_joypads[i].id, false, ""); @@ -310,27 +289,22 @@ void JoypadWindows::probe_joypads() { } for (int i = 0; i < joypad_count; i++) { - d_joypads[i].confirmed = false; } dinput->EnumDevices(DI8DEVCLASS_GAMECTRL, enumCallback, this, DIEDFL_ATTACHEDONLY); for (int i = 0; i < joypad_count; i++) { - if (!d_joypads[i].confirmed) { - close_joypad(i); } } } void JoypadWindows::process_joypads() { - HRESULT hr; for (int i = 0; i < XUSER_MAX_COUNT; i++) { - xinput_gamepad &joy = x_joypads[i]; if (!joy.attached) { continue; @@ -339,10 +313,8 @@ void JoypadWindows::process_joypads() { xinput_get_state(i, &joy.state); if (joy.state.dwPacketNumber != joy.last_packet) { - int button_mask = XINPUT_GAMEPAD_DPAD_UP; for (int j = 0; j <= 16; j++) { - input->joy_button(joy.id, j, joy.state.Gamepad.wButtons & button_mask); button_mask = button_mask * 2; } @@ -372,7 +344,6 @@ void JoypadWindows::process_joypads() { } for (int i = 0; i < JOYPADS_MAX; i++) { - dinput_gamepad *joy = &d_joypads[i]; if (!joy->attached) @@ -393,18 +364,13 @@ void JoypadWindows::process_joypads() { post_hat(joy->id, js.rgdwPOV[0]); for (int j = 0; j < 128; j++) { - if (js.rgbButtons[j] & 0x80) { - if (!joy->last_buttons[j]) { - input->joy_button(joy->id, j, true); joy->last_buttons[j] = true; } } else { - if (joy->last_buttons[j]) { - input->joy_button(joy->id, j, false); joy->last_buttons[j] = false; } @@ -417,7 +383,6 @@ void JoypadWindows::process_joypads() { int values[] = { js.lX, js.lY, js.lZ, js.lRx, js.lRy, js.lRz }; for (int j = 0; j < joy->joy_axis.size(); j++) { - for (int k = 0; k < count; k++) { if (joy->joy_axis[j] == axes[k]) { input->joy_axis(joy->id, j, axis_correct(values[k])); @@ -430,7 +395,6 @@ void JoypadWindows::process_joypads() { } void JoypadWindows::post_hat(int p_device, DWORD p_dpad) { - int dpad_val = 0; // Should be -1 when centered, but according to docs: @@ -441,42 +405,33 @@ void JoypadWindows::post_hat(int p_device, DWORD p_dpad) { dpad_val = Input::HAT_MASK_CENTER; } if (p_dpad == 0) { - dpad_val = Input::HAT_MASK_UP; } else if (p_dpad == 4500) { - dpad_val = (Input::HAT_MASK_UP | Input::HAT_MASK_RIGHT); } else if (p_dpad == 9000) { - dpad_val = Input::HAT_MASK_RIGHT; } else if (p_dpad == 13500) { - dpad_val = (Input::HAT_MASK_RIGHT | Input::HAT_MASK_DOWN); } else if (p_dpad == 18000) { - dpad_val = Input::HAT_MASK_DOWN; } else if (p_dpad == 22500) { - dpad_val = (Input::HAT_MASK_DOWN | Input::HAT_MASK_LEFT); } else if (p_dpad == 27000) { - dpad_val = Input::HAT_MASK_LEFT; } else if (p_dpad == 31500) { - dpad_val = (Input::HAT_MASK_LEFT | Input::HAT_MASK_UP); } input->joy_hat(p_device, dpad_val); }; Input::JoyAxis JoypadWindows::axis_correct(int p_val, bool p_xinput, bool p_trigger, bool p_negate) const { - Input::JoyAxis jx; if (Math::abs(p_val) < MIN_JOY_AXIS) { jx.min = p_trigger ? 0 : -1; @@ -484,7 +439,6 @@ Input::JoyAxis JoypadWindows::axis_correct(int p_val, bool p_xinput, bool p_trig return jx; } if (p_xinput) { - if (p_trigger) { jx.min = 0; jx.value = (float)p_val / MAX_TRIGGER; @@ -534,7 +488,6 @@ void JoypadWindows::joypad_vibration_stop_xinput(int p_device, uint64_t p_timest } void JoypadWindows::load_xinput() { - xinput_get_state = &_xinput_get_state; xinput_set_state = &_xinput_set_state; xinput_dll = LoadLibrary("XInput1_4.dll"); @@ -561,9 +514,7 @@ void JoypadWindows::load_xinput() { } void JoypadWindows::unload_xinput() { - if (xinput_dll) { - FreeLibrary((HMODULE)xinput_dll); } } |