Skip to content

Controller Hotplug/Swap Handling Improvements #1188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 22 commits into
base: main
Choose a base branch
from

Conversation

AL2009man
Copy link
Contributor

@AL2009man AL2009man commented Mar 8, 2025

during the work from #1086, @protocultor has been providing guidance on how some of the code works. But, they wonder if the current HID Driver handles Controller Slot. Given Sonic Unleashed is a Single-player game, it would make more sense to have a connected controller be Player 1, given Sonic Unleashed is a single-player only game.

After investigation, it turns out: there wasn't one in place. So, I've spent most of the day investing and troubleshooting it in between adding Steam Virtual Gamepad.

Originally: I looked at a SDL_CONTROLLER_TYPE_VIRTUAL setup, but ultimately went with a more semi-complicated FindFreeController / Controller State management setup that aims to prioritized Player 1 whenever Player 2/3/4 is connected.

This method ensures that Steam Deck's docked users are able to get a more seamless experience if they decided switching to a Docked setup while in-game.

But given this is a more involved process that requires multiple controllers (ideally: controllers that has RGB Lightbars like DualShock 4 and DualSense controllers...and maybe Xbox Elite Series 2?), This is the part where I'll need help conducting a series of test to ensure it goes smoothly before I make it ready for a review.

the Steam Deck portion is the one I have access to, and I can test it myself once the flatpak file gets added to GitHub Actions. The others: I'll need help from contributers on testing them out.

AL2009man added 14 commits March 4, 2025 17:03
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
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
… 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.
To avoid "the Controller is leaking" situation, there's now a Gamepad stat management that should reset Controller state based on connected controller.
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.
to avoid conflictions with other PRs (hedge-dev#1086 and hedge-dev#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.
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!)
@AL2009man AL2009man marked this pull request as ready for review March 22, 2025 05:54
@AL2009man
Copy link
Contributor Author

AL2009man commented Mar 22, 2025

I rebase the entire PR in order to ensure any changes from Steam Virtual Gamepad and Face Button layouts aren't affected. That being said: the good news is that this PR will be ready for review.

this PR now has a Virtual Controller setup (it's not a TRUE Virtutal Gamepad type, for obvious reasons), where Player 0 is detected: Player LED should not turn your Gamepad into "Player 2". It play nicely with Steam Deck's onboard inputs and easier controller swapping controllers mid-game. It's not exactly perfect, but it should do the job's done.

additionally: PlayStation Lightbar will now play nicely with Player Indexs beyond Player 1. it should now change the lightbar color that corresponds to the game, this is a very hacky workaround due to Lightbar changes being tied to Player 1.

I could try else method like this code session:

    // Fetch the lightbar color for Player 1
    uint8_t r = 0, g = 0, b = 0;
    if (App::s_isWerehog)
    {
        r = 22; g = 0; b = 101; // Night color
    }
    else
    {
        r = 0; g = 37; b = 184; // Day color
    }

but I have noticed that the Day color's lightbar color isn't consistent, as it makes the Lightbar color far more brighter. I don't know the exact Lightbar color it really uses for "isDayTime".

As outlined in the thread: I'm still requesting additional testings.

this is to ensure there isn't any conflictions with other PRs
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.
@AL2009man AL2009man marked this pull request as draft March 25, 2025 16:57
@AL2009man
Copy link
Contributor Author

AL2009man commented Mar 25, 2025

temporarily revert back to Draft PR. will need Steam Virtual Gamepad PR to be merged first. Makes it a lot easier to verify the Hotswap changes on Steam Deck.

Since then: I added a fallback lightbar mechanic. During Day-Time: the lightbar will be more consistently blue, while simultaneously ensuring that all Controllers with RGB Lightbar functions will follow and respect it. it's more of a hacky workaround for the time being.

Right now: Cutscene portions (the part where Sonic turns into Werehog or revert back) will need to be tested. I actually got to test it in my end, and the cutscene didn't change my PlayStation's lightbar right away.

@hyperbx
Copy link
Member

hyperbx commented Apr 12, 2025

I'm not really sure of the point of this PR? We don't directly use the g_controllers array for input access, that's more of a leftover from an earlier implementation.

What's really being polled is g_activeController, so the events for controllers connecting and disconnecting should probably just overwrite that single instance and the array should be omitted outright. Then for fixing the LED problem, you could just turn off the LED on the disconnect event and refresh it on the connect event instead.

@AL2009man
Copy link
Contributor Author

I'm not really sure of the point of this PR? We don't directly use the g_controllers array for input access, that's more of a leftover from an earlier implementation.

What's really being polled is g_activeController, so the events for controllers connecting and disconnecting should probably just overwrite that single instance and the array should be omitted outright. Then for fixing the LED problem, you could just turn off the LED on the disconnect event and refresh it on the connect event instead.

as stated: it's meant to improve Controller Detection, especially on Steam Deck's docked setup while addressing the Lightbar function (not to be confused with Player LED of Xbox 360/DualSense).

That being said: I did gave it a shot on making g_activeController the primary setup, but went thru a couple of issues that makes it a no-go. (one of them breaks button prompt detection when Steam Input is in use). I'll give it a shot again at some point-- got occupied with other stuffs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants