diff --git a/engine/src/core/com/jme3/input/InputManager.java b/engine/src/core/com/jme3/input/InputManager.java index 850571a58..9670a39dc 100644 --- a/engine/src/core/com/jme3/input/InputManager.java +++ b/engine/src/core/com/jme3/input/InputManager.java @@ -86,6 +86,7 @@ public class InputManager implements RawInputListener { private final IntMap pressedButtons = new IntMap(); private final IntMap axisValues = new IntMap(); private ArrayList rawListeners = new ArrayList(); + private RawInputListener[] rawListenerArray = null; private ArrayList inputQueue = new ArrayList(); private static class Mapping { @@ -509,22 +510,30 @@ public class InputManager implements RawInputListener { public void addRawInputListener(RawInputListener listener) { rawListeners.add(listener); + rawListenerArray = null; } public void removeRawInputListener(RawInputListener listener) { rawListeners.remove(listener); + rawListenerArray = null; } public void clearRawInputListeners() { rawListeners.clear(); + rawListenerArray = null; + } + + private RawInputListener[] getRawListenerArray() { + if (rawListenerArray == null) + rawListenerArray = rawListeners.toArray(new RawInputListener[rawListeners.size()]); + return rawListenerArray; } private void processQueue() { int queueSize = inputQueue.size(); - int numRawListeners = rawListeners.size(); - - for (int i = 0; i < numRawListeners; i++) { - RawInputListener listener = rawListeners.get(i); + RawInputListener[] array = getRawListenerArray(); + + for (RawInputListener listener : array) { listener.beginInput(); for (int j = 0; j < queueSize; j++) {