InputMapper map, parameters question

For once I’m gonna ask a question on the forum.

I’m using Lemur InputMapper, but I have some trouble understanding some of the map method parameters, especially the bias parameter.

I was under the impression that, InputState.Positive, Axis.JOYSTICK_HAT_X);
 inputMapper.addStateListener(this, MY_FUNCTION);

would send notification only when the Axis.JOYSTICK_HAT_X value is positive.
However I rececieve events for any value (negative, off, and positive).
Also I noted no difference when setting or not this parameter. So I wonder if it’s working as intended or if I completely misunderstood the usage.

Also, the method can take an array of objects as parmeter. I figured it was the modifier keys (like ctrl, shift and all) but what kind of object should I pass? KeyInput?

All great questions!

This is one major difference with InputMapper in that it lets you treat almost anything like an axis… but in this case it actually IS an axis so you will get all values.

I’d have expected the bias to invert the values but normally the bias is used when you want to map keys to a function that wants to deal with an axis.

The classic example would be if you want your function to deal with left/right strafing. You could map the JOYSTICK_HAT_X to that function and you will automatically get left/right… but what about keys?

Well, in that case you can add another mapping for ‘D’ and one for ‘A’ but with a negative bias. So now ‘A’ and ‘S’ of WASD will trigger Negative, off, and Positive just like the hat.

The camera movement Lemur Gem tried to show some examples of this with varying success. You might find this source file useful:

Any triggerable input can go here… that includes mouse buttons, key inputs, joystick buttons, etc… When specified this way, all must be true for the action to trigger. So you could do something really convoluted and have left control + right mouse button + joystick button 5 all have to be pressed at the same time to invoke something… for three handed people. :smile:

Usually it’s for keyboard modifiers as you’ve suggested… in which case KeyInput.XXXX works. (Note: if you have multiple actions that use similar keys ctrl + left for one, ctrl + right for another, there is a specific key ordering that is preferred… but I don’t remember if it’s “common one first” or “common one last”… and maybe that was a bug and I fixed it already… fuzzy memories but it has to do with how the tree is navigated when plopping events into buckets. Ah… may only be relevant for distinguishing left from ctrl+left… in that if you had map(left) and map(left, ctrl) then it wouldn’t ever see left, ctrl because left would already be being triggered or something.)

I digress.

Anyway, in the keyboard you might use shift and control, etc… on the joystick it’s somewhat uncommon to have modifiers but not unheard of. Perhaps right trigger + button x does something different than just button x or whatever.

Hope that answered your questions.

Oh ok so the Bias is more to have buttons act like an axis “state”. I actually thought (an needed) that it was the other way around. Make an axis state work as a button.
I wanted the POV axis to be considered like 4 buttons. Idk if you’d have a solution for this.
I could test for positive values but for now the problem I have is that if I do that :, InputState.Positive, Axis.JOYSTICK_HAT_X);, InputState.Negative, Axis.JOYSTICK_HAT_X);

BUTTON2 is actually never triggered. I only have BUTTON1 with negative value when I press Left on the pov axis.

But from the answer to the second question, I may go a complete different route.
Since I want to make some quick time events, I may register/unregister a new mapping for each QTE. The function would be something like ACHIEVED_QTE and each time I would randomly pick what button/axis to press and I’d check for the positive value.
Also with the modifiers, that will allow me to even have combinations of buttons for the QTE, and the InputMapper will handle things for me, and only trigger my function when all buttons are pressed.

Yeah, the only way to treat an axis as single buttons is to filter in InputState.

Anyway, your approach sounds interesting. It will be interesting to see what you come up with.

So If anyone comes accross this issue, I tried to use the method I described in previous post : Adding and removing the mapping for each QTE. It worked somehow (though I had weird issues some time), but the code was very convoluted and I had to modify Lemur’s code to be able to delete a mapping (not implemented yet, though I guess that will change).

So in the end, and with Paul’s advice I ended up doing a trick.
I register one funcion for the 4 joystick buttons (1,2,3,4), then I register one function for each of the pov axis direction (povAxisX, povAxisY)
I used a “man in the middle” listener that is listening for the axis functions, and that dispaches the real functions (button 5,6,7,8) to the real listener, depending on the InputState value.

So in my final listener I can listen for buttons 1,2,3,4,5,6,7,8 and it works. I can also map for example keyboard inputs the the same buttons functions and it still works without changing the listener code.

Hope that helps someone, someday :wink:

Hi @nehon that is super cool.
I also added Joystick support recently and I ended up using the RawInputListener.
I then created a Class JoystickEvent which has all the button presses and axis actions in it such as up, down, left, right, button1, etc.
I then created an interface that the use have to implements which will listener for those events.

It is very basic but it works for me.

Your solution is really cool.

Yeah I started doing this too, especially because the joystick sample in the repo does that :p.
But I wanted to use the InputMapper to be able to easily be able to map a different button set for the QTE.
It’s a bit cleaner, and avoid to have too much boiler plate in my game :stuck_out_tongue:

InputMapper rocks! Ouch! Excuse me while I go have this broken arm taken a look at… patting ones’ self on the back can be dangerous. :stuck_out_tongue_winking_eye: