Clearing out input mappings

Please correct me if I am mistaken but I have not seen a way to do this, and I believe it would be very useful. Basically I need a way to clear out all mappings in the InputManager. One use-case is the player choosing a different input setup (between say 3 different options) while still in game. It would seem to be easy enough to do, basically a clearAllMappings() or something method on the Input Manager which would just clear out the mappings and bindings. I could write the full code if needed.



thoughts?



~David

I was looking for something similar earlier today. Would be nice to be able to do that.

Why? They dont harm anyone?

Yah they do. If the listener is the same one used previously, those mappings will still trigger on the wrong keys. ALSO when if any of the keys are the same OR you go back to a previous input setup, since those mappings already exist you get this warning:

WARN com.jme3.input.InputManager - Attempted to add mapping {0} twice to trigger.



There should always be a way to easily ‘reset’ stuff. and the code change in minimal, and offers a big benefit.



~David



EDIT: just an FYI to avoid confusion, my log msgs might look a lil different since I am piping all of (thus including JMonkey’s) java util logging (since it has horrible flexibility) through SLF4J to the Logback framework.

You should remove the listener and not the mapping…? Anyway you’d just have to save your mappings in a list and remove them.

Sorry for the delayed response… couldn’t get on the forums yesterday for w/e reason after I got the email that you had replied.





Anyways since I went the route of having one master listener that then controls all my other listeners (because having actions mapped to a specific listener was annoying and very inflexible, this way I can manage adding and removing listeners cleanly and everything is mapped to the root listener) I can easily remove it and immediately re-add it. I would probably have to do this ANYWAYS to map everything back over to it. This does NOT solve the problem, as I said above, the mappings will throw warnings and such.



Yes I could store my mappings and remove them all, but at this point I am having to maintain so much information on my side. It is like saying that java didn’t have to add clear() method on their ArrayList object because you could clear it other ways (like hold on to the values yourself, which would mostly defeat the purpose of the ArrayList.) As I said I will write the code if you want, it wouldn’t take very long. I really think it would be useful as otherwise it makes one jump through hoops and hold on to data they normally would not need to.



~David

Ah my last post was a bit more hostile than I intended, sorry about that. I was rushing during a meeting as I knew I was going to be gone all weekend.



In any case, we still think it is needed, but obviously up to you all. Just let me know if you want me to write it. I would like to contribute back to the community if possible. My team and I figured out what we are probably going to do (for now) which involves writing it anyways. (Extend the InputManager, and use the class that already extends SimpleApplication to handle setting and retrieving of it and also saving it as the InputManager. Basically a wrapper for Input Manager) Its ugly but w/e it will work for now. I want to get out of using things like ‘SimpleApplication’ and use Application directly eventually but that’s a ways down the road.



~David

Sorry but I had very little time the last few weeks due to projects and now finals.

If you can post a diff/patch it would be very appreciated.

Oh no problem, BELIEVE ME I know how that is. Patch is below. I went with the method name ‘clearMappings()’ though I was also considering ‘clearAllMappings()’ shrugs.



EDIT: fixed the patch as I noticed you guys use spaces, not tabs. It was the one piece of formatting I forgot to check lol.



[patch]

Index: src/core/com/jme3/input/InputManager.java

===================================================================

— src/core/com/jme3/input/InputManager.java (revision 6256)

+++ src/core/com/jme3/input/InputManager.java (working copy)

@@ -412,7 +412,18 @@

maps.remove(mapping);

}

}

+

  • /**
  • * Clears all the input mappings from this InputManager. Consequently, also clears all of the<br />
    
  • * InputListeners as well.<br />
    
  • */<br />
    
  • public void clearMappings() {
  •    this.mappings.clear();<br />
    
  •    this.bindings.clear();<br />
    

+ this.reset();
+ }
+
/**
* Called to reset pressed keys or buttons when focus is restored.
*/
[/patch]
2 Likes

Thanks, committed