-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add support for listening to joystick connection/disconnection. #1087
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
Conversation
Fixes bug causing NullPointerException when removing joysticks. Allows adding joysticks after the application has started.
|
Thanks @jayfella jmonkeyengine/jme3-lwjgl3/src/main/java/com/jme3/input/lwjgl/GlfwJoystickInput.java Line 52 in 318d6d0
it should be
|
jme3-lwjgl3/src/main/java/com/jme3/input/lwjgl/GlfwJoystickInput.java
Outdated
Show resolved
Hide resolved
|
Also, on quick glance, it's a little weird to embed lwjgl3-specific magic numbers into a core class rather than translating them into something more general in the implementation layer. That means every other joystick layer that wanted to implement this would have to mimic lwjgl3 constants. Just define the Connected/Disconnected enum (enum values should not be all caps) and translate that in the glfw layer. |
|
Also the print line to system.out. should it go to logger debug instead?
…On Sat, 11 May 2019, 21:22 Paul Speed, ***@***.***> wrote:
Also, on quick glance, it's a little weird to embed lwjgl3-specific magic
numbers into a core class rather than translating them into something more
general in the implementation layer. That means every other joystick layer
that wanted to implement this would have to mimic lwjgl3 constants. Just
define the Connected/Disconnected enum (enum values should not be all caps)
and translate that in the glfw layer.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#1087 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AB7VJPSLBOJTGDRPAKO2UITPU4FGFANCNFSM4HMIHXFQ>
.
|
Set the logger to the correct class
Set methods to use JoystickState enum instead of event integers.
|
Ok.
@tonihele the listener code in the comments is just an example written here of the JoystickConnectionListener entry point - unless I missed a line somwehere? |
|
The first time I read JoystickState I wondered why you were making an app state. That's an unfortunate name collision. Not really sure I have a better idea (though a boolean "connected" might also work instead of an enum.). Hmmm... |
|
Yes, I also think a boolean would be better here. |
|
Yep. Makes sense. Done. |
|
Are we all good with this now? |
|
Looks fine to me. |
|
It's going to sound like I'm being nit-picky but this is going to become part of the public API and we will be stuck with it forever. So I gave it a little more thought and I'm sorry I didn't do that earlier when you were already making changes. JME seems to follow a couple different patterns: 1) pass an event object that can be interrogated and have fewer listener methods (for example, we don't have separate pressed/released button listener methods), or 2) pass the raw event pieces and have more methods... (for example: ClientStateListener.onConnect()/onDisconnect(), ConnectionListener.connectionAdded()/connectionRemoved())... sometimes both. (CinematicListener.onPlay()/onPause()/onStop()) In that light, even if we only keep one method on the JoystickConnectionListener, I think it should pass the Joystick and not the joystick ID. It would better fit all of the other joystick listener methods to pass the actual object instead of making the listener look it up. It's also nice that one of the parameters would be strong-type tied to joysticks just from an idiomatic perspective for some wierdo who tries to implement a lot of interfaces on one object. I don't have a strong opinion on JoystickConnectionListener.onConnect()/onDisconnect() versus a boolean... just something to think about. I think the Joystick versus ID thing is important, though. |
Use separate connection methods (onConnected/onDisconnected).
|
No not at all. I'd rather it be as it should be. Referencing the joystick makes sense - from a user point of view the code seems a lot more descriptive. getInputManager().addJoystickConnectionListener(new JoystickConnectionListener() {
@Override
public void onConnected(Joystick joystick) {
System.out.println("Joystick connected: " + joystick.getName());
}
@Override
public void onDisconnected(Joystick joystick) {
System.out.println("Joystick disconnected: " + joystick.getName());
}
});I actually went with separate methods because I think in the case of buttons it usually follows the same pattern (move left, move -left or whatever) but in a connection state it's a separate flow direction completely - it would need to follow a recovery or pause phase on disconnection. In my experience each method should only do one thing to keep code maintainable - and this way keeps in line with that. |
|
I agree. I like separate methods better for all of the reasons you listed... I just didn't want to send you back to the drawing board if you weren't feeling it. It wasn't worth the argument when I really really wanted to have the Joystick parameter. :) Changes look good to me... I'll let them percolate a little longer in case someone else wants to review the latest changes. |
|
@stephengold are you alright with this PR? |
|
I'm unfamiliar with JME's support for joysticks and therefore unqualified to review this PR. |
|
I guess no one else but me and Jayfella are going to look at it so might as well just push it through. Open the gates, guys, I think I'm just going to start blind-merging everything. lol. |
|
Master is not stable, so go ahead, in the worst case it can always be reverted :) |
Further to thread: https://hub.jmonkeyengine.org/t/gamepad-disconnect-re-connect/41822
This PR changes the following: