From a29ec5e7879bab9058ceee1f94461d108781f642 Mon Sep 17 00:00:00 2001 From: Julien Gouesse Date: Thu, 13 Sep 2018 23:34:25 +0200 Subject: Replaces Guava's PeekingIterator --- .../input/jinput/JInputControllerWrapper.java | 43 +++++++--------------- 1 file changed, 14 insertions(+), 29 deletions(-) (limited to 'ardor3d-jinput/src/main/java/com') 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 . */ @@ -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 _events = Collections.synchronizedList(new ArrayList()); - protected JInputControllerEventIterator _eventsIt = new JInputControllerEventIterator(); + protected ControllerIterator _eventsIt = new ControllerIterator(this); protected final List _controllers = new ArrayList<>(); protected static boolean _inited = false; @@ -40,13 +37,15 @@ public class JInputControllerWrapper implements ControllerWrapper { public PeekingIterator 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 implements - PeekingIterator { - - @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 -- cgit v1.2.3