New Input system remarks

Hi, fellows monkeys!!



I changed my source code to fit the new input manager system and came accross some troubles :

let's say you add a key mapping called "doStuff" on the D key in a class and "assign" it to an ActionListener called actionListener .

Then …time pass…you work late…you're tired…you forgot…and you append to implement another class which bind the D key as well with a "doStuff" mapping attached to another ActionListener called actionListenerFoo.



In that case this code from Controls.java will trigger the onAnalog event twice on each listener.


 private void invokeAnalogsAndActions(int hash, float value){
        if (value < axisDeadZone){
            invokeAnalogs(hash, value, true);
            return;
        }

        ArrayList<Mapping> maps = bindings.get(hash);
        if (maps == null)
            return;

        int size = maps.size();
        for (int i = size - 1; i >= 0; i--){
            Mapping mapping = maps.get(i);
            ArrayList<InputListener> listeners = mapping.listeners;
            int listenerSize = listeners.size();
            for (int j = listenerSize - 1; j >= 0; j--){
                InputListener listener = listeners.get(j);
               
                if (listener instanceof ActionListener)
                    ((ActionListener)listener).onAction(mapping.name, true, frameTPF);

                if (listener instanceof AnalogListener)
                    ((AnalogListener)listener).onAnalog(mapping.name, value, frameTPF);
               
            }
        }
    }



A code exemple



        inputManager.addMapping("doStuff", new KeyTrigger(KeyInput.KEY_D));
        ActionListener a =new ActionListener() {

            public void onAction(String name, boolean pressed, float tpf) {
                if(pressed)
                    System.out.println("A");
            }
        };
        inputManager.addListener(a, "doStuff");

       //...
       // time pass....
       //....
     
      
       inputManager.addMapping("doStuff", new KeyTrigger(KeyInput.KEY_D));
       ActionListener b =new ActionListener() {

            public void onAction(String name, boolean pressed, float tpf) {
                 if(pressed)
                  System.out.println("B");
            }
        };
        inputManager.addListener(b, "doStuff");



the output is


B
A
B
A



should be


B
A



I think you should forbid mapping the same String to the same input more than once, or at least raise a warning at runtime.

What do you think?
I think you should forbid mapping the same String to the same input more than once, or at least raise a warning at runtime.

Okay I fixed it in SVN. Thanks :)