mirror of
https://github.com/hedge-dev/UnleashedRecomp.git
synced 2025-04-28 13:27:58 +03:00
Lightbar active fix when gamepad plugged first prior to game launch
Another attempt to fix the lightbar by redoing the controller state mangement. For some reason: the Lightbar gets disabled when a controller is already plugged prior to game launch. It reverts back to normal until the next game event.
This commit is contained in:
parent
458938c2ae
commit
75dacf5578
1 changed files with 15 additions and 30 deletions
|
@ -10,13 +10,6 @@
|
|||
#define TRANSLATE_INPUT(S, X) SDL_GameControllerGetButton(controller, S) << FirstBitLow(X)
|
||||
#define VIBRATION_TIMEOUT_MS 5000
|
||||
|
||||
struct LEDColor
|
||||
{
|
||||
uint8_t r;
|
||||
uint8_t g;
|
||||
uint8_t b;
|
||||
};
|
||||
|
||||
class Controller
|
||||
{
|
||||
public:
|
||||
|
@ -26,7 +19,6 @@ public:
|
|||
XAMINPUT_GAMEPAD state{};
|
||||
XAMINPUT_VIBRATION vibration{ 0, 0 };
|
||||
int index{};
|
||||
LEDColor ledColor{ 0, 0, 0 };
|
||||
|
||||
Controller() = default;
|
||||
|
||||
|
@ -87,6 +79,7 @@ public:
|
|||
memset(&state, 0, sizeof(state));
|
||||
}
|
||||
|
||||
|
||||
void PollAxis()
|
||||
{
|
||||
if (!CanPoll())
|
||||
|
@ -144,16 +137,13 @@ 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)
|
||||
void SetLED(const uint8_t r, const uint8_t g, const uint8_t b) const
|
||||
{
|
||||
if (SDL_GameControllerHasLED(controller))
|
||||
{
|
||||
SDL_GameControllerSetLED(controller, r, g, b);
|
||||
ledColor = { r, g, b };
|
||||
}
|
||||
SDL_GameControllerSetLED(controller, r, g, b);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
std::array<Controller, 4> g_controllers;
|
||||
Controller* g_activeController;
|
||||
|
||||
|
@ -218,20 +208,14 @@ static void SetControllerTimeOfDayLED(Controller& controller, bool isNight)
|
|||
auto g = isNight ? 0 : 37;
|
||||
auto b = isNight ? 101 : 184;
|
||||
|
||||
controller.SetLED(r, g, b);
|
||||
}
|
||||
|
||||
static void UpdateAllControllerLEDs(bool isNight)
|
||||
{
|
||||
for (auto& controller : g_controllers)
|
||||
// Ensure the lightbar is set correctly
|
||||
if (SDL_GameControllerHasLED(controller.controller))
|
||||
{
|
||||
if (controller.CanPoll())
|
||||
{
|
||||
SetControllerTimeOfDayLED(controller, isNight);
|
||||
}
|
||||
SDL_GameControllerSetLED(controller.controller, r, g, b);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int HID_OnSDLEvent(void*, SDL_Event* event)
|
||||
{
|
||||
switch (event->type)
|
||||
|
@ -246,8 +230,7 @@ int HID_OnSDLEvent(void*, SDL_Event* event)
|
|||
|
||||
g_controllers[freeIndex] = controller;
|
||||
|
||||
// Reapply the stored LED color state
|
||||
controller.SetLED(controller.ledColor.r, controller.ledColor.g, controller.ledColor.b);
|
||||
SetControllerTimeOfDayLED(controller, App::s_isWerehog);
|
||||
|
||||
// Ensure Player 1's controller is always the active controller
|
||||
if (freeIndex == 0)
|
||||
|
@ -344,8 +327,8 @@ int HID_OnSDLEvent(void*, SDL_Event* event)
|
|||
|
||||
case SDL_USER_EVILSONIC:
|
||||
{
|
||||
// Update all controller LEDs to follow Player 1's LED
|
||||
UpdateAllControllerLEDs(event->user.code);
|
||||
for (auto& controller : g_controllers)
|
||||
SetControllerTimeOfDayLED(controller, event->user.code);
|
||||
|
||||
break;
|
||||
}
|
||||
|
@ -354,6 +337,8 @@ int HID_OnSDLEvent(void*, SDL_Event* event)
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void hid::Init()
|
||||
{
|
||||
SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1");
|
||||
|
@ -362,7 +347,7 @@ void hid::Init()
|
|||
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_PS5_PLAYER_LED, "0"); // Disable Player LED for PS5 controllers
|
||||
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_XINPUT_ENABLED, "1");
|
||||
|
@ -375,6 +360,7 @@ void hid::Init()
|
|||
SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER);
|
||||
}
|
||||
|
||||
|
||||
uint32_t hid::GetState(uint32_t dwUserIndex, XAMINPUT_STATE* pState)
|
||||
{
|
||||
static uint32_t packet;
|
||||
|
@ -425,4 +411,3 @@ uint32_t hid::GetCapabilities(uint32_t dwUserIndex, XAMINPUT_CAPABILITIES* pCaps
|
|||
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue