From 7b9b4245deecfa146d7ae5e19d0a0764225b048f Mon Sep 17 00:00:00 2001 From: Hyper <34012267+hyperbx@users.noreply.github.com> Date: Tue, 28 Jan 2025 00:38:46 +0000 Subject: [PATCH] SDL/HID fixes and clean-up (#224) --- UnleashedRecomp/CMakeLists.txt | 2 +- UnleashedRecomp/gpu/video.cpp | 2 +- UnleashedRecomp/hid/driver/sdl_hid.cpp | 42 ++++++++++++------- UnleashedRecomp/hid/hid.h | 2 +- UnleashedRecomp/patches/frontend_listener.h | 2 +- UnleashedRecomp/patches/input_patches.cpp | 6 +-- UnleashedRecomp/patches/inspire_patches.cpp | 2 +- UnleashedRecomp/patches/player_patches.cpp | 2 +- .../{ui/window_events.h => sdl_events.h} | 2 +- UnleashedRecomp/{ui => }/sdl_listener.cpp | 0 UnleashedRecomp/{ui => }/sdl_listener.h | 0 UnleashedRecomp/ui/game_window.cpp | 2 +- UnleashedRecomp/ui/game_window.h | 2 +- UnleashedRecomp/ui/installer_wizard.cpp | 2 +- UnleashedRecomp/ui/message_window.cpp | 11 ++--- 15 files changed, 47 insertions(+), 32 deletions(-) rename UnleashedRecomp/{ui/window_events.h => sdl_events.h} (96%) rename UnleashedRecomp/{ui => }/sdl_listener.cpp (100%) rename UnleashedRecomp/{ui => }/sdl_listener.h (100%) diff --git a/UnleashedRecomp/CMakeLists.txt b/UnleashedRecomp/CMakeLists.txt index 3ddcab6..10a6968 100644 --- a/UnleashedRecomp/CMakeLists.txt +++ b/UnleashedRecomp/CMakeLists.txt @@ -156,7 +156,6 @@ set(UNLEASHED_RECOMP_UI_CXX_SOURCES "ui/message_window.cpp" "ui/options_menu_thumbnails.cpp" "ui/options_menu.cpp" - "ui/sdl_listener.cpp" "ui/game_window.cpp" ) @@ -231,6 +230,7 @@ set(UNLEASHED_RECOMP_CXX_SOURCES "exports.cpp" "main.cpp" "misc_impl.cpp" + "sdl_listener.cpp" "stdafx.cpp" "version.cpp" diff --git a/UnleashedRecomp/gpu/video.cpp b/UnleashedRecomp/gpu/video.cpp index 23ad086..13d6481 100644 --- a/UnleashedRecomp/gpu/video.cpp +++ b/UnleashedRecomp/gpu/video.cpp @@ -24,10 +24,10 @@ #include #include #include -#include #include #include #include +#include #include #if defined(ASYNC_PSO_DEBUG) || defined(PSO_CACHING) diff --git a/UnleashedRecomp/hid/driver/sdl_hid.cpp b/UnleashedRecomp/hid/driver/sdl_hid.cpp index 1cc989d..5032642 100644 --- a/UnleashedRecomp/hid/driver/sdl_hid.cpp +++ b/UnleashedRecomp/hid/driver/sdl_hid.cpp @@ -127,6 +127,11 @@ public: SDL_GameControllerRumble(controller, vibration.wLeftMotorSpeed * 256, vibration.wRightMotorSpeed * 256, VIBRATION_TIMEOUT_MS); } + + void SetLED(const uint8_t r, const uint8_t g, const uint8_t b) const + { + SDL_GameControllerSetLED(controller, r, g, b); + } }; std::array g_controllers; @@ -182,6 +187,15 @@ static void SetControllerInputDevice(Controller* controller) } } +static void SetControllerTimeOfDayLED(Controller& controller, bool isNight) +{ + auto r = isNight ? 22 : 0; + auto g = isNight ? 0 : 37; + auto b = isNight ? 101 : 184; + + controller.SetLED(r, g, b); +} + int HID_OnSDLEvent(void*, SDL_Event* event) { switch (event->type) @@ -191,7 +205,13 @@ int HID_OnSDLEvent(void*, SDL_Event* event) const auto freeIndex = FindFreeController(); if (freeIndex != -1) - g_controllers[freeIndex] = Controller(event->cdevice.which); + { + auto controller = Controller(event->cdevice.which); + + g_controllers[freeIndex] = controller; + + SetControllerTimeOfDayLED(controller, App::s_isWerehog); + } break; } @@ -258,17 +278,8 @@ int HID_OnSDLEvent(void*, SDL_Event* event) case SDL_USER_EVILSONIC: { - auto* controller = FindController(event->cdevice.which); - - if (!controller) - break; - - auto isNight = event->user.code; - auto r = isNight ? 22 : 0; - auto g = isNight ? 0 : 37; - auto b = isNight ? 101 : 184; - - SDL_GameControllerSetLED(controller->controller, r, g, b); + for (auto& controller : g_controllers) + SetControllerTimeOfDayLED(controller, event->user.code); break; } @@ -279,12 +290,15 @@ int HID_OnSDLEvent(void*, SDL_Event* event) void hid::Init() { + SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1"); + SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_GAMECUBE, "1"); SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS3, "1"); SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS4, "1"); + SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE, "1"); SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS5, "1"); - SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_GAMECUBE, "1"); + SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS5_PLAYER_LED, "1"); + SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS5_RUMBLE, "1"); SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_WII, "1"); - SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1"); SDL_SetHint(SDL_HINT_XINPUT_ENABLED, "1"); SDL_InitSubSystem(SDL_INIT_EVENTS); diff --git a/UnleashedRecomp/hid/hid.h b/UnleashedRecomp/hid/hid.h index da8d973..caf09b2 100644 --- a/UnleashedRecomp/hid/hid.h +++ b/UnleashedRecomp/hid/hid.h @@ -35,12 +35,12 @@ namespace hid extern uint16_t g_prohibitedButtons; void Init(); - void SetProhibitedButtons(uint16_t wButtons); uint32_t GetState(uint32_t dwUserIndex, XAMINPUT_STATE* pState); uint32_t SetState(uint32_t dwUserIndex, XAMINPUT_VIBRATION* pVibration); uint32_t GetCapabilities(uint32_t dwUserIndex, XAMINPUT_CAPABILITIES* pCaps); + void SetProhibitedButtons(uint16_t wButtons); bool IsInputAllowed(); bool IsInputDeviceController(); std::string GetInputDeviceName(); diff --git a/UnleashedRecomp/patches/frontend_listener.h b/UnleashedRecomp/patches/frontend_listener.h index 64cd9f8..1042443 100644 --- a/UnleashedRecomp/patches/frontend_listener.h +++ b/UnleashedRecomp/patches/frontend_listener.h @@ -1,9 +1,9 @@ #pragma once #include -#include #include #include +#include class FrontendListener : public SDLEventListener { diff --git a/UnleashedRecomp/patches/input_patches.cpp b/UnleashedRecomp/patches/input_patches.cpp index fa2efa2..e4cac4c 100644 --- a/UnleashedRecomp/patches/input_patches.cpp +++ b/UnleashedRecomp/patches/input_patches.cpp @@ -1,8 +1,8 @@ #include #include -#include #include #include +#include constexpr double WORLD_MAP_ROTATE_DEADZONE = 0.69999999; constexpr double WORLD_MAP_CURSOR_DEADZONE = 0.30000001; @@ -42,7 +42,7 @@ public: } g_worldMapCursorParamsOrbis; -#ifdef UI_KBM_SUPPORT +#ifdef UNLEASHED_RECOMP_UI_KBM_SUPPORT class WorldMapCursorParamsMouse : public WorldMapCursorParams { public: @@ -128,7 +128,7 @@ public: switch (event->type) { -#ifdef UI_KBM_SUPPORT +#ifdef UNLEASHED_RECOMP_UI_KBM_SUPPORT case SDL_MOUSEMOTION: { if (!ms_isMouseDown) diff --git a/UnleashedRecomp/patches/inspire_patches.cpp b/UnleashedRecomp/patches/inspire_patches.cpp index 3527ca1..f7cfcf6 100644 --- a/UnleashedRecomp/patches/inspire_patches.cpp +++ b/UnleashedRecomp/patches/inspire_patches.cpp @@ -1,9 +1,9 @@ #include "inspire_patches.h" #include #include -#include #include #include +#include static SWA::Inspire::CScene* g_pScene; static std::string g_sceneName; diff --git a/UnleashedRecomp/patches/player_patches.cpp b/UnleashedRecomp/patches/player_patches.cpp index 0208658..807b1fe 100644 --- a/UnleashedRecomp/patches/player_patches.cpp +++ b/UnleashedRecomp/patches/player_patches.cpp @@ -1,9 +1,9 @@ #include #include -#include #include #include #include +#include static uint32_t g_lastEnemyScore; static uint32_t g_lastTrickScore; diff --git a/UnleashedRecomp/ui/window_events.h b/UnleashedRecomp/sdl_events.h similarity index 96% rename from UnleashedRecomp/ui/window_events.h rename to UnleashedRecomp/sdl_events.h index 3a0c592..f23ac99 100644 --- a/UnleashedRecomp/ui/window_events.h +++ b/UnleashedRecomp/sdl_events.h @@ -1,7 +1,7 @@ #pragma once #include -#include "ui/game_window.h" +#include #define SDL_USER_EVILSONIC (SDL_USEREVENT + 1) diff --git a/UnleashedRecomp/ui/sdl_listener.cpp b/UnleashedRecomp/sdl_listener.cpp similarity index 100% rename from UnleashedRecomp/ui/sdl_listener.cpp rename to UnleashedRecomp/sdl_listener.cpp diff --git a/UnleashedRecomp/ui/sdl_listener.h b/UnleashedRecomp/sdl_listener.h similarity index 100% rename from UnleashedRecomp/ui/sdl_listener.h rename to UnleashedRecomp/sdl_listener.h diff --git a/UnleashedRecomp/ui/game_window.cpp b/UnleashedRecomp/ui/game_window.cpp index 6223e42..81fb201 100644 --- a/UnleashedRecomp/ui/game_window.cpp +++ b/UnleashedRecomp/ui/game_window.cpp @@ -3,8 +3,8 @@ #include #include #include -#include #include +#include #include #if _WIN32 diff --git a/UnleashedRecomp/ui/game_window.h b/UnleashedRecomp/ui/game_window.h index 6bd703a..0ede5c1 100644 --- a/UnleashedRecomp/ui/game_window.h +++ b/UnleashedRecomp/ui/game_window.h @@ -1,8 +1,8 @@ #pragma once #include -#include #include +#include #define DEFAULT_WIDTH 1280 #define DEFAULT_HEIGHT 720 diff --git a/UnleashedRecomp/ui/installer_wizard.cpp b/UnleashedRecomp/ui/installer_wizard.cpp index d16988b..944bde7 100644 --- a/UnleashedRecomp/ui/installer_wizard.cpp +++ b/UnleashedRecomp/ui/installer_wizard.cpp @@ -12,10 +12,10 @@ #include #include #include -#include #include #include #include +#include #include #include diff --git a/UnleashedRecomp/ui/message_window.cpp b/UnleashedRecomp/ui/message_window.cpp index 6769873..d704250 100644 --- a/UnleashedRecomp/ui/message_window.cpp +++ b/UnleashedRecomp/ui/message_window.cpp @@ -1,17 +1,18 @@ #include "message_window.h" -#include "imgui_utils.h" #include +#include #include #include #include #include -#include +#include #include -#include -#include #include +#include +#include + +#include #include -#include constexpr double OVERLAY_CONTAINER_COMMON_MOTION_START = 0; constexpr double OVERLAY_CONTAINER_COMMON_MOTION_END = 11;