Add and Remove Joysticks mid-game

Is there any way to add and remove Joysticks in the middle of a game?

@Inferno630 said: Is there any way to add and remove Joysticks in the middle of a game?

Not yet.

@pspeed @Inferno630 Yes, you can. With my android gamepad support you can, at least: http://hub.jmonkeyengine.org/forum/topic/xbox-360-controller-not-recognized-on-android-4-0/page/5/

I probably should’ve specified it’s for a computer game. Sorry. :confused:

@pspeed: Would you happen to know if it’s something that’s going to be worked on at some point? Or even if it’s possible? I suppose I could look through the source code to see if I could find anything that might check the system a second time; but it’d be nice to know if someone was already trying something with it (or if it simply can’t be done on most computers).

@Inferno630 said: I probably should've specified it's for a computer game. Sorry. :/

@pspeed: Would you happen to know if it’s something that’s going to be worked on at some point? Or even if it’s possible? I suppose I could look through the source code to see if I could find anything that might check the system a second time; but it’d be nice to know if someone was already trying something with it (or if it simply can’t be done on most computers).

It’s one of a half-dozen things I plan to look into once the release is finally done. I’m not modifying any source code right now and no one has created a branch… so we are in development limbo for the time being.

@Pixelapp said: @pspeed @Inferno630 Yes, you can. With my android gamepad support you can, at least: http://hub.jmonkeyengine.org/forum/topic/xbox-360-controller-not-recognized-on-android-4-0/page/5/

Meaning that calling InputManager.getJoysticks() may return new joysticks or meaning that you might get random joystick events from a joystick you’ve never seen before?

When you plug in the controller, it creates a new Id. After you save that Id (Jmonkey saves it for you, or you can save it yourself), you have a new controller available. In other words, what @Inferno630 is looking for.

@Pixelapp said: When you plug in the controller, it creates a new Id. After you save that Id (Jmonkey saves it for you, or you can save it yourself), you have a new controller available. In other words, what @Inferno630 is looking for.

Since that doesn’t really answer my question… I will ask again:

Does calling InputManager.getJoysticks() return NEW joysticks after a joystick is plugged in or does it keep returning the same list?

This as opposed to just getting events for a new joystick and having to somehow detect that.

I’m not trying to be mean but it seems like a really straight forward question and has not really been answered. I want to add this general support to desktop so I’m curious if you’ve done the proper solution (the first way) or the ugly hack required to get it to work with android (the second way).

It returns a new Joystick.

[Edit:] You can always check yourself, if you don’t see the answer to something.

Whenever I tried calling the app’s inputManager.getJoysticks(), it always returns the same array; probably because it’s always created from the same JoyInput, which comes from the same JmeContext, which comes from… well, there’s a large chain that I’ve tried looking through, but it never really achieved much. I could be doing something wrong, of course, but it doesn’t seem like it’s working.

Then again, I’m calling getJoysticks() from a button-esque thing (which does work, I’ve tested it), rather than in something’s update loop.

Oddly enough, trying to disable joysticks completely mid-game doesn’t seem to work either (I edited the AppSettings, set them for the app, then used app.restart, which looks like it should change the settings, but it still lets me use the joysticks. I only tried this because I hoped that by disabling then re-enabling them, I could get it to detect the new ones.

Although, to be honest, I’m not sure what part you wanted me to look at, @Pixelapp . I’m not horribly concerned if it’s a horrible hack or not (provided nothing is destroyed in the process), I just want it to work for my game. :stuck_out_tongue:

@pspeed : It’s certainly nice to know that someone plans on looking into it at some point. :slight_smile:

@Pixelapp said: It returns a new Joystick.

[Edit:] You can always check yourself, if you don’t see the answer to something.

…you mean I could go through your code to spend some 10s of minutes searching for a yes or no answer you already knew?

…man, if all forum posters did that we’d never have any questions here. :wink: Seriously, it was 1,000,000 times easier for me to ask the question and get a yes or no answer than to download and look through someone’s code. I’m not paid for this.

I think he meant you could run his code to test it, not read it. Of course, I could be wrong.

@Pixelapp So does your code make a new Id when a new controller is plugged in, or are you saying it’s something that the Input Manager (or something I’m supposed to be using) does naturally?

@pspeed @Inferno630

What we should take away from this conversation, I think is. That you should check out the Android support when I’m finish coding it. Android only gives me a set of tools to work with, so it may not satisfy everyone needs. But that doesn’t mean it is not doing things better than JInput in some areas.

Just wait till I’m done creating gamepad support on android and then just use it. We should talk about this android gamepad support after I’m finished. Otherwise these conversations are not going to take us anywhere, for now at least.

@Pixelapp said: @pspeed @Inferno630

What we should take away from this conversation, I think is. That you should check out the Android support when I’m finish coding it. Android only gives me a set of tools to work with, so it may not satisfy everyone needs. But that doesn’t mean it is not doing things better than JInput in some areas.

Just wait till I’m done creating gamepad support on android and then just use it. We should talk about this android gamepad support after I’m finished. Otherwise these conversations are not going to take us anywhere, for now at least.

I’m pretty sure the fact that JME doesn’t update the list of joysticks has nothing to do with JInput, really. It just caches the list and never resets it.

But I’m not looking at it until after the release since I’ll roll back any core changes prior to release or us just giving up on a release.

Sounds good to me.

So, in short, the answer to the question this topic is about is no. Am I correct? Because I’d rather know now that it’s something I can’t do than wait until after I dig into all the source code only to find there’s no solution to my problem yet. Chances are, waiting for another version is going to wreck all my progress anyway, so I suppose it doesn’t really make a difference. :confused:

Thanks anyway, though.

EDIT: Do either of you think it’d be possible to extend SimpleApplication into something where you can re-get the input? It looks like it gets the input stuff from the JMEContext, so do you think there’d be some way to make it reinitialize just the input stuff from that?

Please wait for the release. I really don’t know how to answer any of these questions because we are using two different gamepad-detecting (JInput and android) APIs.

@Pixelapp: If we’re using two different APIs, wouldn’t I not be able to use the release for my project anyway? Or am I misunderstanding something?

@Inferno630 said: @Pixelapp: If we're using two different APIs, wouldn't I not be able to use the release for my project anyway? Or am I misunderstanding something?

I think he’s alluding to the fact that I said I was going to look into it after the release and save you the trouble.

You are welcome to hack your local copy of JME… though I think supporting this properly is non-trivial if you aren’t already familiar with the code.

Edit: P.S.: I’d love to be wrong about that. Anyway, submitted patches won’t be added until after release anyway.

@Inferno630 Sure you would be able to use it. I the sample jmonkey projects everyday without changing them so you don’t even have to know any changes were ever made by me.

@pspeed I’m not counting on anybody to try this patch. But you are more than welcome to use it if you or the JMonkey community find it useful. I’m sure I’ll use it, it’s a freaking awesome patch!