Converted the raw input listener loop to use a
cached array copy of the raw input listener list. This prevents the whole thing from blowing up if a RawInputListener is removed as the result of a raw input event. It's also ever so slightly faster. git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7543 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
0248e92e3c
commit
85d711ccd2
@ -86,6 +86,7 @@ public class InputManager implements RawInputListener {
|
||||
private final IntMap<Long> pressedButtons = new IntMap<Long>();
|
||||
private final IntMap<Float> axisValues = new IntMap<Float>();
|
||||
private ArrayList<RawInputListener> rawListeners = new ArrayList<RawInputListener>();
|
||||
private RawInputListener[] rawListenerArray = null;
|
||||
private ArrayList<InputEvent> inputQueue = new ArrayList<InputEvent>();
|
||||
|
||||
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();
|
||||
RawInputListener[] array = getRawListenerArray();
|
||||
|
||||
for (int i = 0; i < numRawListeners; i++) {
|
||||
RawInputListener listener = rawListeners.get(i);
|
||||
for (RawInputListener listener : array) {
|
||||
listener.beginInput();
|
||||
|
||||
for (int j = 0; j < queueSize; j++) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user