playn icon indicating copy to clipboard operation
playn copied to clipboard

gamepad support?

Open ghost opened this issue 10 years ago • 12 comments

Is gamepad support planned for playn?

I can propose an API and work on java and html implementation...

ghost avatar May 27 '14 19:05 ghost

Nothing planned. By all means feel free to put together a pull request.

samskivert avatar May 27 '14 20:05 samskivert

Ok! I'll start to specify interfaces based on html5 gamepad API and lwjgl Controller* classes.

I saw that a google CLA notice in CONTRIBUTORS file. Is it still needed since Threerings took over playn development and it looks like google is not involved anymore?

Should I signed a CLA for Threerings? Just add my name to CONTRIBUTORS? Use a very liberal license (MIT?) that allows sublicensing and let you use whatever you want?

ghost avatar May 28 '14 07:05 ghost

I started the API specs and lwjgl based implementation last night: https://github.com/devnewton/playn/commit/1f5605f6b5fd52e17d410bba81d998086d497cae

ghost avatar May 28 '14 08:05 ghost

I made the lwjgl/jinput based gamepad support work.

I started html implementation, but gwt compiler put a lot of "null.nullMethod();" instead of methods calls. I cannot figure why...

ghost avatar May 28 '14 23:05 ghost

The general API looks reasonably as does the LWJGL implementation. I'm curious as to how dual axis controllers are exposed via this API. Is 0,1 up/down left/right for the first analog stick and then 2,3 up/down left/right for the second? It would be nice to be a bit more explicit about that, particularly if different backends make different assumptions.

Also, you should not use Java logging in the JavaGamepads init method. Just have JavaGamepads take a JavaPlatform instance (and save it), and use platform.log().warn(...) to issue the warning.

samskivert avatar May 29 '14 22:05 samskivert

Re: null.nullMethod(): that usually happens when GWT can prove that something will always be null, so you are probably failing to initialize a field somewhere or something.

samskivert avatar May 29 '14 22:05 samskivert

I'm curious as to how dual axis controllers are exposed via this API. Is 0,1 up/down left/right for the first analog stick and then 2,3 up/down left/right for the second?

I have trouble to find a portable way to do this:

  • lwjgl API has usefull accessors (getXAxis, getYAxis, getPovX..), but there is no way to tell which axis is X, Y...
  • html5 API has only recommandations that 0/1 axis should be x/y, but on my gamepad, 0/1 is the right analog stick...

I also encountered a lot of html5 API problems (no way to retrieves dead zones, on Chrome default axis values are -1, something the gamepad array list contains undefined items...).

I'll remove the Java logging uses and prepare a cleaner pull request soon.

ghost avatar May 31 '14 11:05 ghost

Ugh, sounds like a mess. I'm a little wary of providing a cross-platform API for game pads when we're not actually able to provide consistent behavior across platforms. If each platform is so full of idiosyncrasies that one has to test on all platforms they plan to support and hack in workarounds to the different types of behavior, I'd rather not provide a cross-platform API and have developers just access the native APIs in their bootstrap code because then they are forced to read the underlying platform documentation, see how it works and test what they are using.

If they're going to have to do that anyway, I'd rather save them the frustration of first writing code against an API that is either totally vague or lies to them about how it behaves, and then discover that it doesn't do what they expect and they have to test on all platforms and hack in workarounds.

samskivert avatar Jun 04 '14 17:06 samskivert

We can split Gamepad support in the following issues:

  1. retrieve gamepad list, get axis and buttons states.
  2. retrieve dead zones.
  3. provides way to find a good default input mapping.

With lwjgl controller API, html5 gamepad API and from what I've read about Android and iOS controller API, it is possible to provides a cross platform API for 1.

For 2 & 3 features some platform provides needed data, some don't. We can just do nothing or expose them as optional features (like sync i/o operations in Assets playn interface).

1 is enough to add gamepad input to a game configurable in "options menu". I think this will please 99% players.

ghost avatar Jun 04 '14 22:06 ghost

Sounds good!

samskivert avatar Jun 04 '14 22:06 samskivert

Any news on this one?

ghost avatar Sep 19 '14 12:09 ghost

Hello samskivert,

I saw that you talked about my pull request on the playn google group. I'm replying here, because I don't have a google account.

There is a pending pull request for gamepad support, but I'm still not thrilled by the state of gamepad support across platforms. The pull request just sort of glosses over the fact that the behavior of gamepads for HTML5 and gamepads for LWJGL are wildly incompatible

What do you mean? What is incompatible? Both API provide ways to enumerate gamepads and query button and axis states.

(Libgdx is doing the same kind of abstraction between desktop, android and html5 controller API).

ghost avatar Oct 11 '14 09:10 ghost