diff options
Diffstat (limited to 'ardor3d-jinput/src/main/java/com')
-rw-r--r-- | ardor3d-jinput/src/main/java/com/ardor3d/input/jinput/JInputControllerWrapper.java | 43 |
1 files changed, 14 insertions, 29 deletions
diff --git a/ardor3d-jinput/src/main/java/com/ardor3d/input/jinput/JInputControllerWrapper.java b/ardor3d-jinput/src/main/java/com/ardor3d/input/jinput/JInputControllerWrapper.java index 0169090..846e4e3 100644 --- a/ardor3d-jinput/src/main/java/com/ardor3d/input/jinput/JInputControllerWrapper.java +++ b/ardor3d-jinput/src/main/java/com/ardor3d/input/jinput/JInputControllerWrapper.java @@ -3,7 +3,7 @@ * * This file is part of Ardor3D. * - * Ardor3D is free software: you can redistribute it and/or modify it + * Ardor3D is free software: you can redistribute it and/or modify it * under the terms of its license which may be found in the accompanying * LICENSE file or at <http://www.ardor3d.com/LICENSE>. */ @@ -11,9 +11,14 @@ package com.ardor3d.input.jinput; import java.util.ArrayList; -import java.util.Collections; import java.util.List; +import com.ardor3d.input.ControllerEvent; +import com.ardor3d.input.ControllerInfo; +import com.ardor3d.input.ControllerState; +import com.ardor3d.input.ControllerWrapper; +import com.ardor3d.util.PeekingIterator; + import net.java.games.input.Component; import net.java.games.input.Component.Identifier; import net.java.games.input.Controller; @@ -21,18 +26,10 @@ import net.java.games.input.Controller.Type; import net.java.games.input.ControllerEnvironment; import net.java.games.input.Event; -import com.ardor3d.input.ControllerEvent; -import com.ardor3d.input.ControllerInfo; -import com.ardor3d.input.ControllerState; -import com.ardor3d.input.ControllerWrapper; -import com.google.common.collect.AbstractIterator; -import com.google.common.collect.PeekingIterator; - public class JInputControllerWrapper implements ControllerWrapper { protected final Event _event = new Event(); - protected final List<ControllerEvent> _events = Collections.synchronizedList(new ArrayList<ControllerEvent>()); - protected JInputControllerEventIterator _eventsIt = new JInputControllerEventIterator(); + protected ControllerIterator _eventsIt = new ControllerIterator(this); protected final List<ControllerInfo> _controllers = new ArrayList<>(); protected static boolean _inited = false; @@ -40,13 +37,15 @@ public class JInputControllerWrapper implements ControllerWrapper { public PeekingIterator<ControllerEvent> getEvents() { init(); if (!_eventsIt.hasNext()) { - _eventsIt = new JInputControllerEventIterator(); + _eventsIt = new ControllerIterator(this); } for (final Controller controller : ControllerEnvironment.getDefaultEnvironment().getControllers()) { controller.poll(); while (controller.getEventQueue().getNextEvent(_event)) { if (controller.getType() != Type.KEYBOARD && controller.getType() != Type.MOUSE) { - _events.add(createControllerEvent(controller, _event)); + synchronized (JInputControllerWrapper.this) { + _upcomingEvents.add(createControllerEvent(controller, _event)); + } } } } @@ -106,21 +105,7 @@ public class JInputControllerWrapper implements ControllerWrapper { } protected ControllerEvent createControllerEvent(final Controller controller, final Event event) { - return new ControllerEvent(event.getNanos(), controller.getName(), event.getComponent().getIdentifier() - .getName(), event.getValue()); - } - - protected class JInputControllerEventIterator extends AbstractIterator<ControllerEvent> implements - PeekingIterator<ControllerEvent> { - - @Override - protected ControllerEvent computeNext() { - if (_events.size() > 0) { - final ControllerEvent controllerEvent = _events.remove(0); - return controllerEvent; - } else { - return endOfData(); - } - } + return new ControllerEvent(event.getNanos(), controller.getName(), + event.getComponent().getIdentifier().getName(), event.getValue()); } }
\ No newline at end of file |