mirror of
https://github.com/hedge-dev/UnleashedRecomp.git
synced 2025-10-30 07:11:05 +00: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 TRANSLATE_INPUT(S, X) SDL_GameControllerGetButton(controller, S) << FirstBitLow(X)
|
||||||
#define VIBRATION_TIMEOUT_MS 5000
|
#define VIBRATION_TIMEOUT_MS 5000
|
||||||
|
|
||||||
struct LEDColor
|
|
||||||
{
|
|
||||||
uint8_t r;
|
|
||||||
uint8_t g;
|
|
||||||
uint8_t b;
|
|
||||||
};
|
|
||||||
|
|
||||||
class Controller
|
class Controller
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
@ -26,7 +19,6 @@ public:
|
||||||
XAMINPUT_GAMEPAD state{};
|
XAMINPUT_GAMEPAD state{};
|
||||||
XAMINPUT_VIBRATION vibration{ 0, 0 };
|
XAMINPUT_VIBRATION vibration{ 0, 0 };
|
||||||
int index{};
|
int index{};
|
||||||
LEDColor ledColor{ 0, 0, 0 };
|
|
||||||
|
|
||||||
Controller() = default;
|
Controller() = default;
|
||||||
|
|
||||||
|
|
@ -87,6 +79,7 @@ public:
|
||||||
memset(&state, 0, sizeof(state));
|
memset(&state, 0, sizeof(state));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PollAxis()
|
void PollAxis()
|
||||||
{
|
{
|
||||||
if (!CanPoll())
|
if (!CanPoll())
|
||||||
|
|
@ -144,16 +137,13 @@ public:
|
||||||
SDL_GameControllerRumble(controller, vibration.wLeftMotorSpeed * 256, vibration.wRightMotorSpeed * 256, VIBRATION_TIMEOUT_MS);
|
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);
|
SDL_GameControllerSetLED(controller, r, g, b);
|
||||||
ledColor = { r, g, b };
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
std::array<Controller, 4> g_controllers;
|
std::array<Controller, 4> g_controllers;
|
||||||
Controller* g_activeController;
|
Controller* g_activeController;
|
||||||
|
|
||||||
|
|
@ -218,19 +208,13 @@ static void SetControllerTimeOfDayLED(Controller& controller, bool isNight)
|
||||||
auto g = isNight ? 0 : 37;
|
auto g = isNight ? 0 : 37;
|
||||||
auto b = isNight ? 101 : 184;
|
auto b = isNight ? 101 : 184;
|
||||||
|
|
||||||
controller.SetLED(r, g, b);
|
// Ensure the lightbar is set correctly
|
||||||
|
if (SDL_GameControllerHasLED(controller.controller))
|
||||||
|
{
|
||||||
|
SDL_GameControllerSetLED(controller.controller, r, g, b);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void UpdateAllControllerLEDs(bool isNight)
|
|
||||||
{
|
|
||||||
for (auto& controller : g_controllers)
|
|
||||||
{
|
|
||||||
if (controller.CanPoll())
|
|
||||||
{
|
|
||||||
SetControllerTimeOfDayLED(controller, isNight);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int HID_OnSDLEvent(void*, SDL_Event* event)
|
int HID_OnSDLEvent(void*, SDL_Event* event)
|
||||||
{
|
{
|
||||||
|
|
@ -246,8 +230,7 @@ int HID_OnSDLEvent(void*, SDL_Event* event)
|
||||||
|
|
||||||
g_controllers[freeIndex] = controller;
|
g_controllers[freeIndex] = controller;
|
||||||
|
|
||||||
// Reapply the stored LED color state
|
SetControllerTimeOfDayLED(controller, App::s_isWerehog);
|
||||||
controller.SetLED(controller.ledColor.r, controller.ledColor.g, controller.ledColor.b);
|
|
||||||
|
|
||||||
// Ensure Player 1's controller is always the active controller
|
// Ensure Player 1's controller is always the active controller
|
||||||
if (freeIndex == 0)
|
if (freeIndex == 0)
|
||||||
|
|
@ -344,8 +327,8 @@ int HID_OnSDLEvent(void*, SDL_Event* event)
|
||||||
|
|
||||||
case SDL_USER_EVILSONIC:
|
case SDL_USER_EVILSONIC:
|
||||||
{
|
{
|
||||||
// Update all controller LEDs to follow Player 1's LED
|
for (auto& controller : g_controllers)
|
||||||
UpdateAllControllerLEDs(event->user.code);
|
SetControllerTimeOfDayLED(controller, event->user.code);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -354,6 +337,8 @@ int HID_OnSDLEvent(void*, SDL_Event* event)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void hid::Init()
|
void hid::Init()
|
||||||
{
|
{
|
||||||
SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1");
|
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, "1");
|
||||||
SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE, "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, "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_PS5_RUMBLE, "1");
|
||||||
SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_WII, "1");
|
SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_WII, "1");
|
||||||
SDL_SetHint(SDL_HINT_XINPUT_ENABLED, "1");
|
SDL_SetHint(SDL_HINT_XINPUT_ENABLED, "1");
|
||||||
|
|
@ -375,6 +360,7 @@ void hid::Init()
|
||||||
SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER);
|
SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint32_t hid::GetState(uint32_t dwUserIndex, XAMINPUT_STATE* pState)
|
uint32_t hid::GetState(uint32_t dwUserIndex, XAMINPUT_STATE* pState)
|
||||||
{
|
{
|
||||||
static uint32_t packet;
|
static uint32_t packet;
|
||||||
|
|
@ -425,4 +411,3 @@ uint32_t hid::GetCapabilities(uint32_t dwUserIndex, XAMINPUT_CAPABILITIES* pCaps
|
||||||
|
|
||||||
return ERROR_SUCCESS;
|
return ERROR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue