[SOLVED] Alternative Controller Input Libs Injection

I look currently into SDL2GDX and that handles controller just like I want it. No matter if it is XBoxOne XBox360, Nintendo Switch or Playstation all have the buttons in the same order which is very nice and makes life a piece of cake.

I currently try to figure out how I can integrate them nicely into my jMonkeEngine game, I might just ignore what jMonkeyEngine is doing and do it myself, but that would mean no Lemur for me.

There is a way to replace the gdx controller stuff with this Sdl2Gdx but have to figure out how I could do that.

Something like this due the Sdl2Gdx README

project(":desktop") {
    dependencies {
        implementation "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
        implementation "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
        implementation "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-desktop"
-       implementation "com.badlogicgames.gdx:gdx-controllers-desktop:$gdxVersion"
-       implementation "com.badlogicgames.gdx:gdx-controllers-platform:$gdxVersion:natives-desktop"
    }
}

project(":core") {
    dependencies {
        implementation "com.badlogicgames.gdx:gdx:$gdxVersion"
        implementation "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
        implementation "com.badlogicgames.gdx:gdx-controllers:$gdxVersion"
+       implementation "uk.co.electronstudio.sdl2gdx:sdl2gdx:1.0.4"
    }
}

will see, but I think I’m mainly on my own here anyway. If I manage to get that into jMonkeyEngine, I let you know, if I just manage to use it and ignore the InputManager of jMonkeyEngine then there is not much value I can provide and I wont post an update.

As @pspeed, said it could be possible as you just use a RawInput call back. If anybody sees a simple way? Sdl2Gdx does also have an Action listener you subscribe and then get called when ever a button is pressed or the axis changes (it stops if no change).

Also not sure about the Category, maybe you want one for the Engine itself?

Note that the engine itself somehow supports writing new joystick drivers but I’ve never looked into it.

Presuming you can’t get JME to just use the new library directly (or just don’t want to), even without any Lemur changes you might be able to deliver the events directly with a little reflection.

Reflection would let you still access the private field of the input mapper instance and then deliver the raw events there directly.

The tricky part will be setting poking into the joystick map so that Lemur knows how to interpret them… and that’s probably no small effort since it built it by asking JME in the first place. Probably a few hours of intuitive hacking to make it work.

The “make JME see the libs” way is obviously the best/cleanest way… and may be an eventual improvement to the engine itself.

1 Like

Thank you for the pointers. I’ll dig into it. Would be nice if jMonkeyEngine comes with a good controller support. I think I’ll just write here as soon I find a good way to do it.

And btw. Lemur still jumps around if you try to navigate with the analog sticks, I think you need a different approach for analog sticks than for D Pad. Unfortunately I didn’t find time as I have a very tight schedule, also bc I’m a single Dad with 3 already big kids :smiley:

Did you set the deadzone?

3 Likes

Got it, that is on the jMonkeyEngine InputManager not on Lemurs, so it is a global thing. I can work with that, thank you very much (I think you already told me in another thread but somehow I didn’t get it). So when ever the menu is on I set the deadzone to 0.9f and when I leave it set it back to what it was before (probably 0).

1 Like

0.2f will suffice iirc

No if I set it to less than 0.75 it still flips back. The higher the more stable, but faraway from good. I set it to 0.99f to get a somewhat stable result. Might be my controller but even with my brand new XBox controller I had to set a high value. I think the analog handling should be smarter than what it is by now. It also bothers me that left/right also selects?

So it is much better more in the direction of useable but not really good tho.

I just set the deathzone on entering the UI and reset it if I go back to the game.

I’m on it, atm I just write my own Application instead of SimpleApplication which derives from LegacyApplication. So I can also fix the timer and use SimTime instead :sweat_smile: I just copied both and do some corrections and use that instead. It will be in my case an SdlApplication which derives from my SnafuApplication. I let you know if I end up with something useful.

1 Like

I’m a few steps further. I can now listen to a joystick button. The SDL keeps the button and the index on the same position no matter if XBox, Nintendo or Playstation which makes life a lot easier (and I know Nintendo has h A B upside down or Xbox depends the PoV :smiley:). Further more I can get the name and hence the symbols / Names for the buttons (for unknown brands I just go with the button position).

And all the work is done by SDL that one keeps the position/buttonIdx for all controller same.

Not sure how I could contribute, but probably I could make a lib out of it for ppl who want this new SdlApplication (instead of the old Legacy App).

Now I hope Lemur does not to much magic else it will mess it :sweat_smile: but I’ll have a look there.

After figuring out how lemur maps the stuff I could make it work. Works for all my controller xbox, playstation, nintendo, nameless xinput :sweat_smile: button position is fix. Except direct input, but bc I have now full control this only a matter of time :smile:

1 Like

I have a few gamepads that have a button to switch between analog and digital mode. Without fail, all of them produce really dirty chaotic wobble even at idle when in “analog mode”… because this is inherently a dirty way to do joystick signaling. Digital mode produces fine results and the only ‘wobble’ was mechanical and easily controlled by a small dead zone.

I don’t know if this is true for xbox controllers but maybe you are encountering something similar. In my experience, “analog mode” is more of a backwards compatibility thing… though these days, I don’t know “backwards compatible” with what.

In my case it’s a mechanical issue, the left joystick has tilt which constantly produces a flip back. A high deadzone makes it stable and stabilizes all of my controllers. I will have a look how celeste is doing their menu using the left analog stick instead of the d-pad. I’m not talking about an old fashion Joystick :joystick: btw just the left thumb jostick you have on all newer game controllers. At the exhibition it was painful to see people trying to navigate in our menu :joy:

Just for those who wonder what I did…

  1. I threw away this old SimpleApplication and wrote my own one.
  2. In my own Application implementation I inject an own JoyInput class (my SdlJoyInput)
  3. My SdlJoyInput binds the sdl2gdx library and uses it’s unified input system (buttons are position fixed and not all over the place for every other game controller) which even handles PlayStation and Nintendo controllers perfectly.
  4. As I have a single player game and Lemur kind of smashes together all inputs to one (I know there is somehow a way, which I still can’t get my head around, to separate that), I implemented a logic that as soon a controller button is hit that controller is the active one, you can switch to another controller by just hitting a button there.

What I can now solve as well with my own Application is this float tpf, which leads to funny visual behaviours if you have higher frequencies than 60.

I have now full freedom, kicked all those FlybyCamApps, and what not, I can even remove the keyboard entirely if I wish so or the mouse :smiley:

1 Like