PurpleKingdomGames / indigo

An FP game engine for Scala.
https://indigoengine.io/
MIT License
626 stars 58 forks source link

Support DualSense (PS5 controller) as a gamepad #517

Open kubukoz opened 1 year ago

kubukoz commented 1 year ago

I tried using a DualSense for the Pirate game demo, and to my surprise it doesn't seem to work.

I see this in the console:

image

According to the mapping, 14 is 14 D Left, which I suppose is the left arrow on the D-pad... which seems to be an axis in the DualSense layout:

MDN's demo

image

It would be great to support this gamepad as well :)

kubukoz commented 1 year ago

My guess is that, to properly handle this, GamepadInputCaptureImpl will have to dispatch to a device-specific mapping, and someone with a controller will have to implement that layout for DualSense. Happy to give it a go sometime :)

davesmith00000 commented 1 year ago

Just to echo what I said on Discord: Any and all assistance welcome here if you're interested in having a go!

I implemented PS4 gamepad support a long time ago and very quickly, and haven't revisited it since. It wouldn't surprised me if it needed a bit of a rethink!

Thanks for raising the issue.

kubukoz commented 1 year ago

OK, it's even funnier: this is only on Firefox. The d-pad is actually represented as buttons in Chrome. It still doesn't work in your demo, but apparently for another reason.

I... don't like this very much.

davesmith00000 commented 1 year ago

Frontend dev is always... exciting. Accounting for how different hardware / browsers / platforms works, getting a bit creative with how to support things. :smile:

One thing we're been discussing, is for Indigo to become a Tyrian App: https://github.com/PurpleKingdomGames/indigo/issues/506

If we do that, all the work around interacting with the browser / world (websockets, frameticks, gamepads...) becomes a Tyrian problem. There's actually nothing preventing this from happening right now as embedding Indigo into Tyrian is really easy.

Might be worth making something similar to https://luser.github.io/gamepadtest/ in Tyrian and seeing how it looks. Also has the benefit of not needing to conform to the existing Indigo implementation.

Just an idea, maybe it'll go nowhere, but it could be interesting. :shrug:

davesmith00000 commented 1 year ago

There's an example of an Indigo game inside a Tyrian App here, just if you're interested: https://github.com/PurpleKingdomGames/tyrian/blob/main/examples/indigo/src/main/scala/example/Main.scala

kubukoz commented 1 year ago

That surely seems interesting. I suppose we'd still want the button mappings to live in Indigo or a helper library, and Tyrian would only deal with the DOM nonsense... either way, I like the idea of a gamepadtest in Tyrian. Might pick this up some time.

davesmith00000 commented 1 year ago

I like the idea of a gamepadtest in Tyrian

Yeah so do I. Be good to see it working and then worry about the other details like who owns the config and so on. Let me know if you have a go. :+1: