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<Long> pressedButtons = new IntMap<Long>();
|
||||||
private final IntMap<Float> axisValues = new IntMap<Float>();
|
private final IntMap<Float> axisValues = new IntMap<Float>();
|
||||||
private ArrayList<RawInputListener> rawListeners = new ArrayList<RawInputListener>();
|
private ArrayList<RawInputListener> rawListeners = new ArrayList<RawInputListener>();
|
||||||
|
private RawInputListener[] rawListenerArray = null;
|
||||||
private ArrayList<InputEvent> inputQueue = new ArrayList<InputEvent>();
|
private ArrayList<InputEvent> inputQueue = new ArrayList<InputEvent>();
|
||||||
|
|
||||||
private static class Mapping {
|
private static class Mapping {
|
||||||
@ -509,22 +510,30 @@ public class InputManager implements RawInputListener {
|
|||||||
|
|
||||||
public void addRawInputListener(RawInputListener listener) {
|
public void addRawInputListener(RawInputListener listener) {
|
||||||
rawListeners.add(listener);
|
rawListeners.add(listener);
|
||||||
|
rawListenerArray = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeRawInputListener(RawInputListener listener) {
|
public void removeRawInputListener(RawInputListener listener) {
|
||||||
rawListeners.remove(listener);
|
rawListeners.remove(listener);
|
||||||
|
rawListenerArray = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearRawInputListeners() {
|
public void clearRawInputListeners() {
|
||||||
rawListeners.clear();
|
rawListeners.clear();
|
||||||
|
rawListenerArray = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private RawInputListener[] getRawListenerArray() {
|
||||||
|
if (rawListenerArray == null)
|
||||||
|
rawListenerArray = rawListeners.toArray(new RawInputListener[rawListeners.size()]);
|
||||||
|
return rawListenerArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processQueue() {
|
private void processQueue() {
|
||||||
int queueSize = inputQueue.size();
|
int queueSize = inputQueue.size();
|
||||||
int numRawListeners = rawListeners.size();
|
RawInputListener[] array = getRawListenerArray();
|
||||||
|
|
||||||
for (int i = 0; i < numRawListeners; i++) {
|
for (RawInputListener listener : array) {
|
||||||
RawInputListener listener = rawListeners.get(i);
|
|
||||||
listener.beginInput();
|
listener.beginInput();
|
||||||
|
|
||||||
for (int j = 0; j < queueSize; j++) {
|
for (int j = 0; j < queueSize; j++) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user