From d2454d4b3b8d896d3b6a693c4a7db1177aff2e7b Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 20 Jul 2022 14:41:06 +0200 Subject: [PATCH] - DirectInput cleanup Removing ancient code that's only useful on pre-XP OSs. --- src/common/engine/m_joy.cpp | 2 +- src/common/platform/win32/i_input.cpp | 66 ++---------------------- src/common/platform/win32/i_keyboard.cpp | 11 ++-- src/common/platform/win32/i_mouse.cpp | 11 ++-- 4 files changed, 11 insertions(+), 79 deletions(-) diff --git a/src/common/engine/m_joy.cpp b/src/common/engine/m_joy.cpp index 578287ad5..4d64f420f 100644 --- a/src/common/engine/m_joy.cpp +++ b/src/common/engine/m_joy.cpp @@ -169,7 +169,7 @@ void M_SaveJoystickConfig(IJoystickConfig *joy) char key[32], value[32]; int axislen, numaxes; - if (M_SetJoystickConfigSection(joy, true)) + if (GameConfig != NULL && M_SetJoystickConfigSection(joy, true)) { GameConfig->ClearCurrentSection(); if (!joy->IsSensitivityDefault()) diff --git a/src/common/platform/win32/i_input.cpp b/src/common/platform/win32/i_input.cpp index a5ea5ad44..f8b2c429b 100644 --- a/src/common/platform/win32/i_input.cpp +++ b/src/common/platform/win32/i_input.cpp @@ -93,7 +93,6 @@ FJoystickCollection *JoyDevices[NUM_JOYDEVICES]; extern HINSTANCE g_hInst; -static HMODULE DInputDLL; bool GUICapture; extern FMouse *Mouse; @@ -116,7 +115,6 @@ extern BOOL paused; static bool noidle = false; LPDIRECTINPUT8 g_pdi; -LPDIRECTINPUT g_pdi3; extern bool AppActive; @@ -523,58 +521,12 @@ bool I_InitInput (void *hwnd) noidle = !!Args->CheckParm ("-noidle"); g_pdi = NULL; - g_pdi3 = NULL; - // Try for DirectInput 8 first, then DirectInput 3 for NT 4's benefit. - DInputDLL = LoadLibraryA("dinput8.dll"); - if (DInputDLL != NULL) + hr = DirectInput8Create(g_hInst, DIRECTINPUT_VERSION, IID_IDirectInput8, (void **)&g_pdi, NULL); + if (FAILED(hr)) { - typedef HRESULT (WINAPI *blah)(HINSTANCE, DWORD, REFIID, LPVOID *, LPUNKNOWN); - blah di8c = (blah)GetProcAddress(DInputDLL, "DirectInput8Create"); - if (di8c != NULL) - { - hr = di8c(g_hInst, DIRECTINPUT_VERSION, IID_IDirectInput8, (void **)&g_pdi, NULL); - if (FAILED(hr)) - { - Printf(TEXTCOLOR_ORANGE "DirectInput8Create failed: %08lx\n", hr); - g_pdi = NULL; // Just to be sure DirectInput8Create didn't change it - } - } - else - { - Printf(TEXTCOLOR_ORANGE "Could not find DirectInput8Create in dinput8.dll\n"); - } - } - - if (g_pdi == NULL) - { - if (DInputDLL != NULL) - { - FreeLibrary(DInputDLL); - } - DInputDLL = LoadLibraryA ("dinput.dll"); - if (DInputDLL == NULL) - { - I_FatalError ("Could not load dinput.dll: %08lx", GetLastError()); - } - - typedef HRESULT (WINAPI *blah)(HINSTANCE, DWORD, LPDIRECTINPUT*, LPUNKNOWN); -#ifdef UNICODE - blah dic = (blah)GetProcAddress (DInputDLL, "DirectInputCreateW"); -#else - blah dic = (blah)GetProcAddress(DInputDLL, "DirectInputCreateA"); -#endif - - if (dic == NULL) - { - I_FatalError ("dinput.dll is corrupt"); - } - - hr = dic (g_hInst, 0x0300, &g_pdi3, NULL); - if (FAILED(hr)) - { - I_FatalError ("DirectInputCreate failed: %08lx", hr); - } + Printf(TEXTCOLOR_ORANGE "DirectInput8Create failed: %08lx\n", hr); + g_pdi = NULL; // Just to be sure DirectInput8Create didn't change it } Printf ("I_StartupMouse\n"); @@ -622,16 +574,6 @@ void I_ShutdownInput () g_pdi->Release (); g_pdi = NULL; } - if (g_pdi3) - { - g_pdi3->Release (); - g_pdi3 = NULL; - } - if (DInputDLL != NULL) - { - FreeLibrary (DInputDLL); - DInputDLL = NULL; - } } void I_GetEvent () diff --git a/src/common/platform/win32/i_keyboard.cpp b/src/common/platform/win32/i_keyboard.cpp index e1222d969..33cf6da5b 100644 --- a/src/common/platform/win32/i_keyboard.cpp +++ b/src/common/platform/win32/i_keyboard.cpp @@ -89,7 +89,6 @@ protected: // EXTERNAL DATA DECLARATIONS ---------------------------------------------- extern LPDIRECTINPUT8 g_pdi; -extern LPDIRECTINPUT g_pdi3; extern bool GUICapture; // PRIVATE DATA DEFINITIONS ------------------------------------------------ @@ -320,17 +319,13 @@ bool FDInputKeyboard::GetDevice() { HRESULT hr; - if (g_pdi3 != NULL) - { // DirectInput3 interface - hr = g_pdi3->CreateDevice(GUID_SysKeyboard, (LPDIRECTINPUTDEVICE*)&Device, NULL); - } - else if (g_pdi != NULL) + if (g_pdi != NULL) { // DirectInput8 interface hr = g_pdi->CreateDevice(GUID_SysKeyboard, &Device, NULL); } else { - hr = -1; + hr = E_FAIL; } if (FAILED(hr)) { @@ -383,7 +378,7 @@ void FDInputKeyboard::ProcessInput() for (;;) { - DWORD cbObjectData = g_pdi3 ? sizeof(DIDEVICEOBJECTDATA_DX3) : sizeof(DIDEVICEOBJECTDATA); + DWORD cbObjectData = sizeof(DIDEVICEOBJECTDATA); dwElements = 1; hr = Device->GetDeviceData(cbObjectData, &od, &dwElements, 0); if (hr == DIERR_INPUTLOST || hr == DIERR_NOTACQUIRED) diff --git a/src/common/platform/win32/i_mouse.cpp b/src/common/platform/win32/i_mouse.cpp index 15e52ce75..f9fb1b8ab 100644 --- a/src/common/platform/win32/i_mouse.cpp +++ b/src/common/platform/win32/i_mouse.cpp @@ -140,7 +140,6 @@ static void CenterMouse(int x, int y, LONG *centx, LONG *centy); // EXTERNAL DATA DECLARATIONS ---------------------------------------------- extern LPDIRECTINPUT8 g_pdi; -extern LPDIRECTINPUT g_pdi3; extern bool GUICapture; extern int BlockMouseMove; @@ -680,17 +679,13 @@ bool FDInputMouse::GetDevice() { HRESULT hr; - if (g_pdi3 != NULL) - { // DirectInput3 interface - hr = g_pdi3->CreateDevice(GUID_SysMouse, (LPDIRECTINPUTDEVICE*)&Device, NULL); - } - else if (g_pdi != NULL) + if (g_pdi != NULL) { // DirectInput8 interface hr = g_pdi->CreateDevice(GUID_SysMouse, &Device, NULL); } else { - hr = -1; + hr = E_FAIL; } if (FAILED(hr)) { @@ -783,7 +778,7 @@ void FDInputMouse::ProcessInput() event_t ev = { 0 }; for (;;) { - DWORD cbObjectData = g_pdi3 ? sizeof(DIDEVICEOBJECTDATA_DX3) : sizeof(DIDEVICEOBJECTDATA); + DWORD cbObjectData = sizeof(DIDEVICEOBJECTDATA); dwElements = 1; hr = Device->GetDeviceData(cbObjectData, &od, &dwElements, 0); if (hr == DIERR_INPUTLOST || hr == DIERR_NOTACQUIRED)