Compare commits

...

23 commits

Author SHA1 Message Date
Al. Lopez
fc69a51c48
Merge 2385bd435a into 9ace79a4d2 2025-08-03 14:58:31 -04:00
Al. Lopez
2385bd435a
Merge branch 'hedge-dev:main' into ControllerHotplugImprovements 2025-04-12 21:29:47 -04:00
Al. Lopez
6e7a2f6a13
Merge branch 'hedge-dev:main' into ControllerHotplugImprovements 2025-04-06 16:10:02 -04:00
Al. Lopez
b1d446cf2d
Merge branch 'hedge-dev:main' into ControllerHotplugImprovements 2025-03-29 21:17:08 -04:00
AL2009man
de94e9004f proper Daytime Lightbar and Player LED priority
This adds a else portion for the IsNight Lightbar code. This is done by replicating isNight's dimmer lights and apply it to the Day portion for consistency.

additionally: Player LED indicator should now play nicely when Player 0 (onboard inputs) and Player 1 (external) will respect it, although: you'll see the controller showing "Player 2" for a brief moment.
2025-03-24 01:07:45 -04:00
AL2009man
cebf5e6a1b remove code leftover
this is to ensure there isn't any conflictions with other PRs
2025-03-22 02:04:43 -04:00
AL2009man
8758808d6e Improved Virtual Gamepad and Lightbar/Player LED detection
When Player 0 (which is typically a Virtual Controller, or Onboard Inputs like Steam Deck under Steam Input mode): it'll attempt to provide or change Player LED numbers or lightbar (in DualShock 4's case). Now: Player LED Index color will only apply if it's explificially "Player 1" and not "Player 0".

it also improves PlayStation lightbar when hotswapping controllers. it should now follow Player 1's Lightbar (due to being tied to Player 1) instead of doing it's own thing. (You REALLY should check your connected controller!)
2025-03-22 01:52:32 -04:00
AL2009man
aedc26bf70 Rebase PR branch
to avoid conflictions with other PRs (https://github.com/hedge-dev/UnleashedRecomp/pull/1086 and https://github.com/hedge-dev/UnleashedRecomp/pull/1045): the remaining codebae was restore to how the master build look.

the downside is that it makes it far harder to test it's behavior with Steam Input mode. but this is only temporarily until it gets added to the Master branch.
2025-03-22 01:11:08 -04:00
Al. Lopez
bbad87a0ed
Merge branch 'hedge-dev:main' into ControllerHotplugImprovements 2025-03-12 01:07:03 -04:00
Al. Lopez
5fc38a1b81
Merge branch 'hedge-dev:main' into ControllerHotplugImprovements 2025-03-07 14:36:12 -05:00
AL2009man
75dacf5578 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.
2025-03-06 20:44:15 -05:00
AL2009man
458938c2ae Attempt to reduce Input leaking
To avoid "the Controller is leaking" situation, there's now a Gamepad stat management that should reset Controller state based on connected controller.
2025-03-06 20:09:24 -05:00
AL2009man
a96fc60dcd Lightbar detection when using multiple PlayStation controllers at the same time.
An attempt to remedy the Lightbar activation. While Player 2/3/4 will override the in-game lightbar event upon connection: it'll later revert back to the in-game event.
2025-03-06 19:45:13 -05:00
AL2009man
c9b3a5e03f Initial Gamepad Hotplug Logic improvements
This changes the way how a Controller will be prioritized. By default: it'll always prioritize based on Player 1. It should play nicely with Steam Deck's internal inputs when Steam Input is active
2025-03-06 16:44:40 -05:00
Al. Lopez
a8cac8763d
Merge branch 'hedge-dev:main' into SDL2-Steam 2025-03-06 02:27:30 -05:00
AL2009man
ef4e37cb41 restoring notes for Button Labels. 2025-03-06 02:16:09 -05:00
Al. Lopez
bec2cf65ba added experimental Steam Virtual Gamepad support 2025-03-06 01:59:35 -05:00
Al. Lopez
43091838af
Merge branch 'hedge-dev:main' into main 2025-03-05 21:27:07 -05:00
Al. Lopez
90b35bc593 removing the workflows 2025-03-04 22:48:07 -05:00
Al. Lopez
9a181e0839
Create apply-patch.yml 2025-03-04 22:40:40 -05:00
Al. Lopez
176bb625e2
Create cmake-multi-platform.yml 2025-03-04 22:37:24 -05:00
Al. Lopez
07d193e229
Create c-cpp.yml 2025-03-04 22:37:09 -05:00
Al. Lopez
574afdf53d Experimenting Button Label
Experimenting a way to add a hint for Button Labels. It should attempt to fix the Nintendo Layout issue when using a Nintendo Switch controller
2025-03-04 17:03:02 -05:00

View file

@ -209,112 +209,148 @@ static void SetControllerInputDevice(Controller* controller)
}
}
static void SetControllerTimeOfDayLED(Controller& controller, bool isNight)
static void SetControllerTimeOfDayLED(Controller& ctrl, bool isNight)
{
auto r = isNight ? 22 : 0;
auto g = isNight ? 0 : 37;
auto b = isNight ? 101 : 184;
// Fetch the lightbar color based on the time of day
uint8_t r = 0, g = 0, b = 0;
controller.SetLED(r, g, b);
if (isNight)
{
r = 22; // Night: Red tone
g = 0; // Night: No green
b = 101; // Night: Cool blue
}
else
{
r = 0; // Day: No red
g = 0; // Day: No green
b = 60; // Day: Dimmer blue
}
// Apply the lightbar color to the specified controller
if (ctrl.CanPoll())
{
ctrl.SetLED(r, g, b);
}
}
int HID_OnSDLEvent(void*, SDL_Event* event)
{
switch (event->type)
{
case SDL_CONTROLLERDEVICEADDED:
case SDL_CONTROLLERDEVICEADDED:
{
const auto freeIndex = FindFreeController();
if (freeIndex != -1)
{
const auto freeIndex = FindFreeController();
// Initialize the new controller
auto controller = Controller(event->cdevice.which);
g_controllers[freeIndex] = controller;
if (freeIndex != -1)
// Assign "Player 1 LED" for Player 0 and Player 1
if (freeIndex == 0 || freeIndex == 1) // Player 0 and Player 1 both use "Player 1 LED"
{
auto controller = Controller(event->cdevice.which);
g_controllers[freeIndex] = controller;
SetControllerTimeOfDayLED(controller, App::s_isWerehog);
SDL_GameControllerSetPlayerIndex(controller.controller, 1); // Force Player LED to "Player 1"
}
else // Additional external controllers (Player 2+)
{
SDL_GameControllerSetPlayerIndex(controller.controller, freeIndex); // Assign correct LED for Player 2+
}
break;
}
// Apply lightbar settings immediately for the new controller
SetControllerTimeOfDayLED(controller, App::s_isWerehog);
case SDL_CONTROLLERDEVICEREMOVED:
{
auto* controller = FindController(event->cdevice.which);
if (controller)
controller->Close();
break;
}
case SDL_CONTROLLERBUTTONDOWN:
case SDL_CONTROLLERBUTTONUP:
case SDL_CONTROLLERAXISMOTION:
case SDL_CONTROLLERTOUCHPADDOWN:
{
auto* controller = FindController(event->cdevice.which);
if (!controller)
break;
if (event->type == SDL_CONTROLLERAXISMOTION)
// Refresh LEDs for all connected controllers
for (auto& ctrl : g_controllers)
{
if (abs(event->caxis.value) > 8000)
if (ctrl.CanPoll())
{
SDL_ShowCursor(SDL_DISABLE);
SetControllerInputDevice(controller);
SDL_GameControllerSetPlayerIndex(ctrl.controller, ctrl.index); // Ensure correct LED updates
}
controller->PollAxis();
}
else
}
break;
}
case SDL_CONTROLLERDEVICEREMOVED:
{
auto* controller = FindController(event->cdevice.which);
if (controller)
{
controller->Close();
// If Player 1 disconnects, promote the next available controller to Player 1
if (controller == &g_controllers[1]) // Player 1 removed
{
for (auto& ctrl : g_controllers)
{
if (ctrl.CanPoll() && &ctrl != &g_controllers[0]) // Skip Player 0
{
g_controllers[1] = ctrl; // Promote next available controller to Player 1
SDL_GameControllerSetPlayerIndex(ctrl.controller, 1); // Reflect Player 1 LED
SetControllerTimeOfDayLED(ctrl, App::s_isWerehog); // Update lightbar
break;
}
}
}
// Update Player LED indices for all controllers immediately
for (std::size_t i = 2; i < g_controllers.size(); ++i) // Start from Player 2 onward
{
if (g_controllers[i].CanPoll())
{
SDL_GameControllerSetPlayerIndex(g_controllers[i].controller, static_cast<int>(i)); // Assign correct LED index
SetControllerTimeOfDayLED(g_controllers[i], App::s_isWerehog); // Update lightbars
}
}
// Refresh lightbar settings for all connected controllers
for (auto& ctrl : g_controllers)
{
if (ctrl.CanPoll())
{
SetControllerTimeOfDayLED(ctrl, App::s_isWerehog);
}
}
}
break;
}
case SDL_CONTROLLERBUTTONDOWN:
case SDL_CONTROLLERBUTTONUP:
case SDL_CONTROLLERAXISMOTION:
case SDL_CONTROLLERTOUCHPADDOWN:
{
auto* controller = FindController(event->cdevice.which);
if (!controller)
break;
// Process input
if (event->type == SDL_CONTROLLERAXISMOTION)
{
if (abs(event->caxis.value) > 8000)
{
SDL_ShowCursor(SDL_DISABLE);
SetControllerInputDevice(controller);
controller->Poll();
}
break;
controller->PollAxis();
}
case SDL_KEYDOWN:
case SDL_KEYUP:
hid::g_inputDevice = hid::EInputDevice::Keyboard;
break;
case SDL_MOUSEMOTION:
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP:
else
{
if (!GameWindow::IsFullscreen() || GameWindow::s_isFullscreenCursorVisible)
SDL_ShowCursor(SDL_ENABLE);
SDL_ShowCursor(SDL_DISABLE);
SetControllerInputDevice(controller);
hid::g_inputDevice = hid::EInputDevice::Mouse;
break;
controller->Poll();
}
case SDL_WINDOWEVENT:
{
if (event->window.event == SDL_WINDOWEVENT_FOCUS_LOST)
{
// Stop vibrating controllers on focus lost.
for (auto& controller : g_controllers)
controller.SetVibration({ 0, 0 });
}
break;
}
case SDL_USER_EVILSONIC:
{
for (auto& controller : g_controllers)
SetControllerTimeOfDayLED(controller, event->user.code);
break;
}
// Instantly apply updated lightbar settings during input
SetControllerTimeOfDayLED(*controller, App::s_isWerehog);
break;
}
}
return 0;