Continuing the discussion from Let’s discuss jMonkeyEngine 3.4:
So, as I’ve continued to try to get my gamepad to work on Linux, I’ve been developing some optimizations for the gamepad remapping UI in particular, with the goal of allowing for better handling of weird gamepads. So far, I’ve come up with two main changes:
First of all, joypad mapping files can now support differentiations between axis mappings and button mappings. Simply add “axis.” or “button.” before the property name to specify whether a mapping is for the former or the latter.
button.Xbox\ 360\ Wireless\ Receiver.6=8
This change is mostly useful for gamepads where buttons and axis may share the same name (for example, my right trigger and my right bumper on my wireless Xbox 360 gamepad on Linux are both named “5”).
The second allows for the scaling of axes. Adding a bracketed tupple of two floats allows for the specification of an effective range. For example, with this:
axis.Xbox\ 360\ Wireless\ Receiver.z=rx[0.0,1.0]
The rx axis will convert all its values that were on a scale of -1 to 1 to a scale of 0 to 1 (0 would become 0.5, -0.5 would become 0.25, etc). Note that the “axis.” prefix is optional when specifying a scale.
This change has three benefits: first of all, it can be used to lock one-way trigger axes so that they don’t use negative numbers when at rest. Secondly, using a positive number for the lower bound and a negative number for the upper bound allows for a really easy way to invert an axis when it is outputting unexpected values (this shouldn’t be a substitute for inverted axes for those players who have really weird preferences for their Halo controls, though). Finally, it can be useful for compensating for worn-down joysticks that can’t reach the full 1.0 value like they used to (should be done on a case-by-case basis as specified by the end user).
Note that these features are completely optional when composing a mappings file, and jmonkey would remain fully backwards-compatible with existing mappings files.
Some of the major code changes:
JoystickCompatabilityMappings
now has hashmaps devoted to mappings that specifically specify themselves as button or axis mappings, with methods remapAxis
and remapButton
specifically looking there first before looking to the existing hashmap. The existing remapComponent
method still behaves mostly the same, skipping over entries stored in the new hashmaps. The 3 joystick managers, AndroidJoystickJoyInput14
for Android, JInputJoyInput
for LWJGL 2, and GlfwJoystickInput
for LWJGL 3, will call one of the new remap methods depending on what element they are remapping.
There is also the remapAxisRange
method. This is where the raw axis data that the joystick manager retrieves is scaled as specified by whatever scaling was in the remap file, if any. This remapped file is what is provided as the value for JoyAxisEvent
. With that said, you can still access the original unscaled value with the new method getRawValue
. I mostly included that one so that the calibrator in my Controller Config application can properly create mapping files, but I feel like it may have other uses as well.