Gamepad support

I finished the gamepad support.

1 Like

The forum thinks Iā€™m making duplicates of my topic just by repeating words. I barely can post here. Whatā€™s wrong with this new forum???

Anyways. @iwgeric how do I allow sensors and gamepad to cohabit on the code? Any suggestion?

I would go in depth about what Iā€™m asking but once I do the forum thinks Iā€™m duplicating my freaking posts and deletes it.

Edit to the Jmonkey Moderators: Yes, I know this might seem funny but Iā€™ve tried like 8 times to ask this question but the forum keeps deleting my freaking question because it thinks it is a duplicate.

Thanks for the gamepad support.

I havenā€™t noticed anything wrong with the new forum lately, but maybe itā€™s a bug similar to http://hub.jmonkeyengine.org/forum/topic/cant-reply-duplicate-reply-detected-it-looks-as-though-youve-already/

Maybe keep trying to post your message and see if a word is blocked or something ^^

This is the gamepad support. It should work correctly with the Xbox 360 controller and Ouya controller and of course with any other controller (but you know how it is).

Replace the following classes on your Jmonkey build:

OGLESContext.java
GamepadJoyInput.java

Remember to set the variable joystickEventsEnabled = true; on your android activity.

Ok here goes the full question I tried to post before.

@iwgeric How do I allow developers to choose between sensors or gamepad? Right now, due to the way the method getJoyInput under package com dot jme3 system android; you can only choose one. Either you choose sensors OR gamepad. When actually you should be able to choose anything you want (one or even both; sensors or gamepad).

I suggest moving your sensors code from the getJoyInput method into another method of different name just to keep the symmetry with the desktop counterpart.

I might think of something later but I figured I would ask you first.

Does anybody know how to make an android 4.1 requirement for this patch? Android 4.1 is required for using the gamepad support for android and I think a cannot commit this until I set a android 4.1 ā€œrequirementā€ on the Jmonkey side.

@Pixelapp said: Does anybody know how to make an android 4.1 requirement for this patch? Android 4.1 is required for using the gamepad support for android and I think a cannot commit this until I set a android 4.1 "requirement" on the Jmonkey side.

Is Android 4.1 required to compile or to run? If it is only required to run, then there is some code we can put in to only enable the code for 4.1 or higher. If it is required to compile, then we have to consider whether or not we want to add the android 4.1 jar file to the engine build system. Right now it only has the 2.2 jar file. Soon, Iā€™ll be increasing it to 2.3 and setting the minimum Android base level to 2.3.

@Pixelapp said: How do I allow developers to choose between sensors or gamepad?

I havenā€™t thought about it much. I probably need to rearrange some stuff to move sensors and gamepad into a state where they can live together. My initial thought would be another item in AppSettings, but Iā€™m not sure yet.

Curious: why would choosing between sensors and gamepad be any different than my desktop choosing between gamepad 1, 2, or 3?

To me it seems like the app can choose to do what it wants here. If the ā€œgamepad emulated by sensorsā€ is easily identified and the app sees a different gamepad then it can choose to use that instead of the sensor-emulated one. (And since I suspect the OUYA has no sensors then it wouldnā€™t even have a sensor-emulated gamepad anyway so at least on that platform it becomes more straight-forwardā€¦ just pick a gamepad.)

@iwgeric Iā€™m only interested on writing about how to RUN it. Yes please put the code or something.

@pspeed Anything is possible, we can do whatever we want. I just want to know whatā€™s the way to do it we are agreeing upon.

Here is something Iā€™ve used for choosing different audio renderers based on the android version being used:

[java]
if (Build.VERSION.SDK_INT >= 9){
logger.log(Level.INFO, ā€œEnabling OpenAL Soft Audio (Android 2.3 or higher)ā€);
audioRendererType = AppSettings.ANDROID_OPENAL_SOFT;
} else {
logger.log(Level.INFO, ā€œEnabling Android MediaPlayer/SoundPool Audio (Android 2.2)ā€);
audioRendererType = AppSettings.ANDROID_MEDIAPLAYER;
}
[/java]

@Pixelapp

Hi there! First off, sorry for bumping what is now an old topic but it is causing me a headache here, in the future. mods; feel free to split or whatever as appropriate?

I am beginning to work on a project specifically targeted at this android device: http://madcatz.com/mojo/en-aus/ (If youā€™re not familiar, it is similar to OUYA but runs a straight up version of android) and similar future android based console systems as I believe this is the start of a trend. Iā€™m hoping to base it off JME as I am already somewhat familiar with and like it!

As you can see, the controller(s) it comes with by default are also by Madcatz, the C.T.R.L.R: http://store.madcatz.com/categories/controllers-category/Mad-Catz-C-T-R-L-R-Mobile-Gamepad.html which to summarise is an XBOX-y style Bluetooth game-pad that works with either the MOJO console or any other bluetooth as an input device (supposedly with PC/Mac too). Youā€™ll notice it also has a switch on the bottom to toggle between ā€œgamesmartā€, ā€œmouseā€ and ā€œPCā€ mode. I have a pair of these bizzos, testing with both the MOJO as well as my standard galaxy smartphone. I have had a fair amount of success with regular plat-store apps and tegra games, many of which work very well with this setup.

My goal is to get the gamepads working as a traditional console device on JME. I am not interested in touch screen, orientation sensor etc as input substitutes as the console doesnā€™t even support that stuff anyhow! The game design currently hinges on this being supported OK. :blush:

Hereā€™s the issue: I cannot get the controller to work correctly with JMonkey! I have spent a few days banging my head on this problem already and seem to have hit a wall :frowning:

So far Iā€™ve got a simple test case going which just prints out diagnostics on the input event handlers. Iā€™ve tried analog and action listeners and also the raw listener in combination with various configurations. I must have read every thread on the topic 3x now. It comes to a head in this particular thread where PixelApp seems to have cracked the gamepad/android issue. But alas, the official sources do not incorporate his modifications. Are there any plans to fix this issue?

Anyway, the three modes on the controller give me different results with slightly different keyCode mappings or functionality:

  1. "GameSmart" = D-Pad, Left stick, and 3 buttons ā€˜workā€™ in as much as they generate a touch event along with two of the four triggers. All of these are seen as TouchEvents. One button and two triggers report no event and the right thumbstick is dead! I saw this mentioned earlier - why is that?
  2. Mouse mode = as above, but moving the left thumbstick whilst holding a button into the LONGPRESSED type allows for mouse events to propagate with deltas there, everything else is still a touch event.
  3. PC Mode = All buttons as well as triggers give an event, but the right thumb stick still gives nothing. No events are received whatsoever. This is a real show-stopper in the current configuration If I had the thumbstick, I would probably gloss over this issue and make do without analog reporting.

Hereā€™s the rub - with joystickEventsEnabled = true it gives me a joystick from inputmanager.getJoysticks() but itā€™s an AndroidSensorJoystick. It has 3 on the AxisCount with Orientation_X _Y and _Z and 0 on the ButtonCount.

Without the flag, I get no joystick :frowning: and am left with still touch events though, and it works similarly to aboveā€¦ still no right thumbstick and no analog goodness on the stick(s). Putting the initialization into update as hinted has no effect.

I tracked down this alternate code by PixelApp which he says allows for a gamepad to work, but I have obtained the JME sources to make changes:

  • added the GamepadJoyInput.Java
  • Replaced OGLESContext.Java but found
    it caused a bunch of deeper implications (probably due to this code
    being 1.5 years out of date) which I am not prepared/qualified to go and sort
    out and so simply replaced the getJoyInput() with his suggested
    version.
  • put in a very recent android library (20)

After compiling this all down and incorporating into my project - I get an identical result! An AndroidSensorJoystick with the same functionality/behaviour, but bogglingly with only 2 axis and 1 button counts (???). My questions are these:

  1. Have I done something mind-numbingly idiotic like left out some crucial line of code? (no one-word answers,
    please)
  2. Is there planned/intended support for actual, factual physical gamepads within JME on Android? (Please donā€™t tell me ā€œthatā€™s old tech, use a touch screen for androidā€ as I intend to target this kind of device as a casual competitor to xbox/playstation platforms)

Help and thanks!
(apologies for lengthy first post :stuck_out_tongue: )

Paging @iwgeric in here as he is currently responsible for the Android gamepad support

I actually forgot about this. Iā€™ll take a look.

Appreciated!

I just checked in an initial version that supports gamepads and orientation sensors simultaneously as separate joysticks.

Iā€™ve only done some initial testing with a Bluetooth gamepad that connects directly to the phone. I also have a Xbox360 controller that connects over USB that I plan to test, but havenā€™t got to it yet.

If it detects the physical joystick, you will end up with 2 joysticks, 1 for the sensors and 1 for the physical joystick.

3 Likes

Wow, it has been quite a while so I didnā€™t check back in time to see you replied 18 days agoā€¦ :stuck_out_tongue:

Honestly, I had shelved my project for 3 months because I didnā€™t want to have to hack in a fix of poor quality which may not be accepted back into the code base, and desperately wanted proper support in the engine by somebody who knows itā€™s ins and outs as I may want to use this feature for multiple projects in the future.

Thank you very much for your efforts, I will check this out as soon as I have time with my setup and get back to you!

Hi @iwgeric , how can I test this out? Iā€™m very interested on this feature. ( I am connecting two gamepads to my android 4.4.2 device but right now I only see the sensor. ) Thank you!