diff --git a/common.gradle b/common.gradle old mode 100644 new mode 100755 diff --git a/jme3-android/src/main/java/com/jme3/system/android/OGLESContext.java b/jme3-android/src/main/java/com/jme3/system/android/OGLESContext.java old mode 100644 new mode 100755 index 991ad25c0ae..28122b9ca47 --- a/jme3-android/src/main/java/com/jme3/system/android/OGLESContext.java +++ b/jme3-android/src/main/java/com/jme3/system/android/OGLESContext.java @@ -57,6 +57,10 @@ import com.jme3.renderer.opengl.GLFbo; import com.jme3.renderer.opengl.GLRenderer; import com.jme3.system.*; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; import java.util.logging.Level; import java.util.logging.Logger; @@ -278,6 +282,20 @@ public TouchInput getTouchInput() { return androidInput.getTouchInput(); } + @Override + public java.util.List getInput() { + List inputs = new ArrayList<>(); + + inputs.add(getKeyInput()); + inputs.add(getMouseInput()); + if(!settings.getBoolean("DisableJoysticks")) { + inputs.add(getJoyInput()); + } + inputs.add(getTouchInput()); + inputs.removeAll(Collections.singleton(null)); + + return inputs; + } @Override public Timer getTimer() { return timer; diff --git a/jme3-core/src/main/java/com/jme3/app/Application.java b/jme3-core/src/main/java/com/jme3/app/Application.java index 475193bfe52..b0802bd87af 100755 --- a/jme3-core/src/main/java/com/jme3/app/Application.java +++ b/jme3-core/src/main/java/com/jme3/app/Application.java @@ -48,6 +48,7 @@ import com.jme3.system.JmeContext.Type; import java.net.MalformedURLException; import java.net.URL; +import java.util.List; import java.util.concurrent.Callable; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.Future; @@ -86,10 +87,8 @@ public class Application implements SystemListener { protected LostFocusBehavior lostFocusBehavior = LostFocusBehavior.ThrottleOnLostFocus; protected float speed = 1f; protected boolean paused = false; - protected MouseInput mouseInput; - protected KeyInput keyInput; - protected JoyInput joyInput; - protected TouchInput touchInput; + + protected List inputs; protected InputManager inputManager; protected AppStateManager stateManager; @@ -173,6 +172,10 @@ public void setAssetManager(AssetManager assetManager){ this.assetManager = assetManager; } + public void setInputManager(InputManager inputManager) { + this.inputManager = inputManager; + } + private void initAssetManager(){ URL assetCfgUrl = null; @@ -306,25 +309,8 @@ private void initCamera(){ * AppSettings. */ protected void initInput(){ - mouseInput = context.getMouseInput(); - if (mouseInput != null) - mouseInput.initialize(); - - keyInput = context.getKeyInput(); - if (keyInput != null) - keyInput.initialize(); - - touchInput = context.getTouchInput(); - if (touchInput != null) - touchInput.initialize(); - - if (!settings.getBoolean("DisableJoysticks")){ - joyInput = context.getJoyInput(); - if (joyInput != null) - joyInput.initialize(); - } - - inputManager = new InputManager(mouseInput, keyInput, joyInput, touchInput); + inputs = context.getInput(); + inputManager = new InputManager(inputs); } private void initStateManager(){ @@ -715,18 +701,7 @@ public void update(){ } protected void destroyInput(){ - if (mouseInput != null) - mouseInput.destroy(); - - if (keyInput != null) - keyInput.destroy(); - - if (joyInput != null) - joyInput.destroy(); - - if (touchInput != null) - touchInput.destroy(); - + inputManager.destroyInput(); inputManager = null; } diff --git a/jme3-core/src/main/java/com/jme3/input/InputManager.java b/jme3-core/src/main/java/com/jme3/input/InputManager.java old mode 100644 new mode 100755 index b21d225bbc2..79af9511b34 --- a/jme3-core/src/main/java/com/jme3/input/InputManager.java +++ b/jme3-core/src/main/java/com/jme3/input/InputManager.java @@ -42,6 +42,7 @@ import com.jme3.util.SafeArrayList; import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; @@ -89,6 +90,7 @@ public class InputManager implements RawInputListener { private final MouseInput mouse; private final JoyInput joystick; private final TouchInput touch; + private final List inputs; private float frameTPF; private long lastLastUpdateTime = 0; private long lastUpdateTime = 0; @@ -123,32 +125,43 @@ public Mapping(String name) { * *

This should only be called internally in {@link Application}. * - * @param mouse - * @param keys - * @param joystick - * @param touch + * @param inputs * @throws IllegalArgumentException If either mouseInput or keyInput are null. */ - public InputManager(MouseInput mouse, KeyInput keys, JoyInput joystick, TouchInput touch) { + public InputManager(List inputs) { + KeyInput keys = null; + MouseInput mouse = null; + JoyInput joystick = null; + TouchInput touch = null; + + for (Input input : inputs) { + input.initialize(); + if(input instanceof MouseInput) { + mouse = (MouseInput) input; + mouse.setInputListener(this); + } else if (input instanceof KeyInput) { + keys = (KeyInput) input; + keys.setInputListener(this); + } else if (input instanceof JoyInput) { + joystick = (JoyInput) input; + joystick.setInputListener(this); + joysticks = joystick.loadJoysticks(this); + } else if (input instanceof TouchInput) { + touch = (TouchInput) input; + touch.setInputListener(this); + } + } + if (keys == null || mouse == null) { throw new IllegalArgumentException("Mouse or keyboard cannot be null"); } + this.inputs = inputs; this.keys = keys; this.mouse = mouse; this.joystick = joystick; this.touch = touch; - keys.setInputListener(this); - mouse.setInputListener(this); - if (joystick != null) { - joystick.setInputListener(this); - joysticks = joystick.loadJoysticks(this); - } - if (touch != null) { - touch.setInputListener(this); - } - firstTime = keys.getInputTimeNanos(); } @@ -893,13 +906,8 @@ public void update(float tpf) { eventsPermitted = true; - keys.update(); - mouse.update(); - if (joystick != null) { - joystick.update(); - } - if (touch != null) { - touch.update(); + for(Input input : inputs){ + input.update(); } eventsPermitted = false; @@ -946,4 +954,30 @@ public void onTouchEvent(TouchEvent evt) { cursorPos.set(evt.getX(), evt.getY()); inputQueue.add(evt); } + + public void destroyInput() { + for(Input input : inputs){ + input.destroy(); + } + } + + public List getInputs() { + return inputs; + } + + public TouchInput getTouch() { + return touch; + } + + public JoyInput getJoystick() { + return joystick; + } + + public MouseInput getMouse() { + return mouse; + } + + public KeyInput getKeys() { + return keys; + } } diff --git a/jme3-core/src/main/java/com/jme3/system/AppSettings.java b/jme3-core/src/main/java/com/jme3/system/AppSettings.java old mode 100644 new mode 100755 diff --git a/jme3-core/src/main/java/com/jme3/system/JmeContext.java b/jme3-core/src/main/java/com/jme3/system/JmeContext.java old mode 100644 new mode 100755 index f4f47ae679d..cda9ac7211f --- a/jme3-core/src/main/java/com/jme3/system/JmeContext.java +++ b/jme3-core/src/main/java/com/jme3/system/JmeContext.java @@ -31,17 +31,15 @@ */ package com.jme3.system; -import com.jme3.input.JoyInput; -import com.jme3.input.KeyInput; -import com.jme3.input.MouseInput; -import com.jme3.input.TouchInput; +import com.jme3.input.*; import com.jme3.renderer.Renderer; +import java.util.List; + /** * Represents a rendering context within the engine. */ public interface JmeContext { - /** * The type of context. */ @@ -110,6 +108,11 @@ public enum Type { */ public Renderer getRenderer(); + /** + * @return All input implementations. May be empty if not available. + */ + public List getInput(); + /** * @return Mouse input implementation. May be null if not available. */ diff --git a/jme3-core/src/main/java/com/jme3/system/NullContext.java b/jme3-core/src/main/java/com/jme3/system/NullContext.java old mode 100644 new mode 100755 index 41204e6c98d..0b9c4ac1777 --- a/jme3-core/src/main/java/com/jme3/system/NullContext.java +++ b/jme3-core/src/main/java/com/jme3/system/NullContext.java @@ -31,13 +31,14 @@ */ package com.jme3.system; -import com.jme3.input.JoyInput; -import com.jme3.input.KeyInput; -import com.jme3.input.MouseInput; -import com.jme3.input.TouchInput; +import com.jme3.input.*; import com.jme3.input.dummy.DummyKeyInput; import com.jme3.input.dummy.DummyMouseInput; import com.jme3.renderer.Renderer; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; import java.util.logging.Level; import java.util.logging.Logger; @@ -58,6 +59,8 @@ public class NullContext implements JmeContext, Runnable { protected SystemListener listener; protected NullRenderer renderer; + protected List inputs; + public Type getType() { return Type.Headless; } @@ -175,6 +178,20 @@ public JoyInput getJoyInput() { return null; } + public java.util.List getInput() { + if(inputs == null) { + inputs = new ArrayList<>(); + inputs.add(getKeyInput()); + inputs.add(getMouseInput()); + if(!settings.getBoolean("DisableJoysticks")) { + inputs.add(getJoyInput()); + } + inputs.add(getTouchInput()); + inputs.removeAll(Collections.singleton(null)); + } + return inputs; + } + public TouchInput getTouchInput() { return null; } diff --git a/jme3-core/src/main/java/com/jme3/texture/image/DefaultImageRaster.java b/jme3-core/src/main/java/com/jme3/texture/image/DefaultImageRaster.java old mode 100644 new mode 100755 index 55f1c77ac74..cd824c0ee8e --- a/jme3-core/src/main/java/com/jme3/texture/image/DefaultImageRaster.java +++ b/jme3-core/src/main/java/com/jme3/texture/image/DefaultImageRaster.java @@ -34,18 +34,17 @@ import com.jme3.math.ColorRGBA; import com.jme3.math.FastMath; import com.jme3.texture.Image; -import org.fest.util.VisibleForTesting; import java.nio.ByteBuffer; public class DefaultImageRaster extends ImageRaster { - @VisibleForTesting + protected final int[] components = new int[4]; private ByteBuffer buffer; - @VisibleForTesting + protected final Image image; - @VisibleForTesting + protected final ImageCodec codec; private final int width; private final int height; @@ -55,7 +54,7 @@ public class DefaultImageRaster extends ImageRaster { private int slice; - @VisibleForTesting + protected void rangeCheck(int x, int y) { if (x < 0 || y < 0 || x >= width || y >= height) { throw new IllegalArgumentException("x and y must be inside the image dimensions:" @@ -133,19 +132,19 @@ public void setPixel(int x, int y, ColorRGBA color) { * Input is linear, needs to be converted to sRGB before writing into image. * @param color */ - @VisibleForTesting + protected void getSRGB(ColorRGBA color) { if (convertToLinear) { color = color.getAsSrgb(); } } - @VisibleForTesting + protected void writeComponents(int x, int y) { codec.writeComponents(getBuffer(), x, y, width, offset, components, temp); } - @VisibleForTesting + protected void readComponents(int x, int y) { codec.readComponents(getBuffer(), x, y, width, offset, components, temp); } @@ -171,7 +170,7 @@ public ColorRGBA getPixel(int x, int y, ColorRGBA store) { return store; } - @VisibleForTesting + protected void setSRGB(ColorRGBA store) { if (convertToLinear) { // Input image is sRGB, need to convert to linear. diff --git a/jme3-core/src/main/java/com/jme3/texture/image/ImageRaster.java b/jme3-core/src/main/java/com/jme3/texture/image/ImageRaster.java old mode 100644 new mode 100755 index 121bab62ef6..e3f3e08f589 --- a/jme3-core/src/main/java/com/jme3/texture/image/ImageRaster.java +++ b/jme3-core/src/main/java/com/jme3/texture/image/ImageRaster.java @@ -35,7 +35,6 @@ import com.jme3.math.FastMath; import com.jme3.system.JmeSystem; import com.jme3.texture.Image; -import org.fest.util.VisibleForTesting; /** * Utility class for reading and writing from jME3 {@link Image images}. @@ -210,7 +209,6 @@ public ColorRGBA getPixel(int x, int y) { * Check flags for grayscale * @param color */ - @VisibleForTesting protected void grayscaleCheck(ColorRGBA color, ImageCodec codec) { if (codec.isGray) { float gray = color.r * 0.27f + color.g * 0.67f + color.b * 0.06f; @@ -218,7 +216,6 @@ protected void grayscaleCheck(ColorRGBA color, ImageCodec codec) { } } - @VisibleForTesting protected void setComponents(ColorRGBA color, ImageCodec codec, int[] components) { switch (codec.type) { case ImageCodec.FLAG_F16: @@ -247,7 +244,6 @@ protected void setImageUpdateNeeded(Image image) { image.setUpdateNeeded(); } - @VisibleForTesting protected void setStoreComponents(ColorRGBA store, ImageCodec codec, int[] components) { switch (codec.type) { case ImageCodec.FLAG_F16: @@ -272,7 +268,6 @@ protected void setStoreComponents(ColorRGBA store, ImageCodec codec, int[] compo } } - @VisibleForTesting protected void setStoreRGBA(ColorRGBA store, ImageCodec codec) { if (codec.isGray) { store.g = store.b = store.r; diff --git a/jme3-core/src/main/java/com/jme3/texture/image/MipMapImageRaster.java b/jme3-core/src/main/java/com/jme3/texture/image/MipMapImageRaster.java old mode 100644 new mode 100755 index eda9e02605c..bb2402f62a5 --- a/jme3-core/src/main/java/com/jme3/texture/image/MipMapImageRaster.java +++ b/jme3-core/src/main/java/com/jme3/texture/image/MipMapImageRaster.java @@ -34,18 +34,17 @@ import com.jme3.math.ColorRGBA; import com.jme3.math.FastMath; import com.jme3.texture.Image; -import org.fest.util.VisibleForTesting; import java.nio.ByteBuffer; public class MipMapImageRaster extends ImageRaster { - @VisibleForTesting + protected final int[] components = new int[4]; private ByteBuffer buffer; - @VisibleForTesting + protected final Image image; - @VisibleForTesting + protected final ImageCodec codec; private int width[]; private int height[]; @@ -54,7 +53,7 @@ public class MipMapImageRaster extends ImageRaster { private int mipLevel; private int[] offsets; - @VisibleForTesting + protected void rangeCheck(int x, int y) { if (x < 0 || y < 0 || x >= width[mipLevel] || y >= height[mipLevel]) { throw new IllegalArgumentException("x and y must be inside the image dimensions"); @@ -111,12 +110,12 @@ public void setPixel(int x, int y, ColorRGBA color) { setImageUpdateNeeded(image); } - @VisibleForTesting + protected void writeComponents(int x, int y) { codec.writeComponents(getBuffer(), x, y, width[mipLevel], offsets[mipLevel], components, temp); } - @VisibleForTesting + protected void readComponents(int x, int y) { codec.readComponents(getBuffer(), x, y, width[mipLevel], offsets[mipLevel], components, temp); } diff --git a/jme3-core/src/main/resources/com/jme3/system/version.properties b/jme3-core/src/main/resources/com/jme3/system/version.properties index 6a18aebb503..11ba02daf24 100644 --- a/jme3-core/src/main/resources/com/jme3/system/version.properties +++ b/jme3-core/src/main/resources/com/jme3/system/version.properties @@ -1,23 +1,12 @@ # THIS IS AN AUTO-GENERATED FILE.. # DO NOT MODIFY! -<<<<<<< 9873a76327519d60380864617c1c74f58802b99c -build.date=2016-03-21 -git.revision=5389 -git.branch=test-texture -git.hash=b99b43942ed5cf2b922c2268161efb413cc721d6 -git.hash.short=b99b439 -git.tag=v3.1-alpha1-231-gb99b439 -name.full=jMonkeyEngine 3.1-test-texture-5389 -version.full=3.1-test-texture-5389 -======= -build.date=2016-03-22 -git.revision=5475 -git.branch=master -git.hash=10947e8b5096f6d7e2bf0e327faa43b275adeb34 -git.hash.short=10947e8 +build.date=2016-04-03 +git.revision=5496 +git.branch=application-input-DIP +git.hash=85ccf353a95329daff30dc60304532fcc63a5f4b +git.hash.short=85ccf35 git.tag=null -name.full=jMonkeyEngine 3.1-5475 -version.full=3.1-5475 ->>>>>>> Init input Application tests +name.full=jMonkeyEngine 3.1-application-input-DIP-5496 +version.full=3.1-application-input-DIP-5496 version.number=3.1.0 version.tag=SNAPSHOT \ No newline at end of file diff --git a/jme3-core/src/test/java/com/jme3/app/ApplicationTest.java b/jme3-core/src/test/java/com/jme3/app/ApplicationTest.java index 43abdb4705b..4c8cfa7f870 100755 --- a/jme3-core/src/test/java/com/jme3/app/ApplicationTest.java +++ b/jme3-core/src/test/java/com/jme3/app/ApplicationTest.java @@ -1,113 +1 @@ -package com.jme3.app; - -import com.jme3.input.JoyInput; -import com.jme3.input.KeyInput; -import com.jme3.input.MouseInput; -import com.jme3.input.TouchInput; -import com.jme3.input.dummy.DummyKeyInput; -import com.jme3.input.dummy.DummyMouseInput; -import com.jme3.system.AppSettings; -import com.jme3.system.NullContext; -import com.jme3.texture.Texture; -import org.junit.Before; -import org.junit.Test; -import static org.mockito.Mockito.*; -import java.io.IOException; -import java.security.Key; - -import static org.junit.Assert.*; - - -public class ApplicationTest { - - Application app; - - @Before - public void setUp() { - app = new TestApplication(); - } - - @Test - public void testDestroyInput() throws Exception { - - } - - @Test - public void testInitInputWithJoyStick() throws Exception { - //setup settings - AppSettings settings = new AppSettings(true); - settings.setUseJoysticks(true); - app.setSettings(settings); - - //setup app - Application spyApp = spy(app); - assertNull(spyApp.getInputManager()); - - //setup context - NullContext spyContext = spy(new NullContext()); - MouseInput spyMouseInput = spy(new DummyMouseInput()); - KeyInput spyKeyInput = spy(new DummyKeyInput()); - TouchInput spyTouchInput = spy(new TestTouchInput()); - JoyInput spyJoyInput = spy(new TestJoyInput()); - doReturn(spyMouseInput).when(spyContext).getMouseInput(); - doReturn(spyKeyInput).when(spyContext).getKeyInput(); - doReturn(spyTouchInput).when(spyContext).getTouchInput(); - doReturn(spyJoyInput).when(spyContext).getJoyInput(); - spyApp.context = spyContext; - - spyApp.initInput(); - - verify(spyContext, times(1)).getMouseInput(); - verify(spyMouseInput, times(1)).initialize(); - verify(spyContext, times(1)).getKeyInput(); - verify(spyKeyInput, times(1)).initialize(); - verify(spyContext, times(1)).getTouchInput(); - verify(spyTouchInput, times(1)).initialize(); - verify(spyContext, times(1)).getJoyInput(); - verify(spyJoyInput, times(1)).initialize(); - - //verify(spyContext, times(1)).getJoyInput(); - - assertNotNull(spyApp.getInputManager()); - } - - @Test - public void testInitInputNoJoyStick() throws Exception { - //setup settings - AppSettings settings = new AppSettings(true); - settings.setUseJoysticks(false); - app.setSettings(settings); - - //setup app - Application spyApp = spy(app); - assertNull(spyApp.getInputManager()); - - //setup context - NullContext spyContext = spy(new NullContext()); - MouseInput spyMouseInput = spy(new DummyMouseInput()); - KeyInput spyKeyInput = spy(new DummyKeyInput()); - TouchInput spyTouchInput = spy(new TestTouchInput()); - JoyInput spyJoyInput = spy(new TestJoyInput()); - doReturn(spyMouseInput).when(spyContext).getMouseInput(); - doReturn(spyKeyInput).when(spyContext).getKeyInput(); - doReturn(spyTouchInput).when(spyContext).getTouchInput(); - doReturn(spyJoyInput).when(spyContext).getJoyInput(); - spyApp.context = spyContext; - - spyApp.initInput(); - - verify(spyContext, times(1)).getMouseInput(); - verify(spyMouseInput, times(1)).initialize(); - verify(spyContext, times(1)).getKeyInput(); - verify(spyKeyInput, times(1)).initialize(); - verify(spyContext, times(1)).getTouchInput(); - verify(spyTouchInput, times(1)).initialize(); - verify(spyContext, times(0)).getJoyInput(); - verify(spyJoyInput, times(0)).initialize(); - - //verify(spyContext, times(1)).getJoyInput(); - - assertNotNull(spyApp.getInputManager()); - } - -} \ No newline at end of file +package com.jme3.app; import com.jme3.input.*; import com.jme3.input.dummy.DummyKeyInput; import com.jme3.input.dummy.DummyMouseInput; import com.jme3.system.AppSettings; import com.jme3.system.NullContext; import org.junit.Before; import org.junit.Test; import java.util.List; import static org.hamcrest.core.Is.is; import static org.mockito.Mockito.*; import static org.junit.Assert.*; public class ApplicationTest { Application app; @Before public void setUp() { app = new TestApplication(); } @Test public void testInitInput() throws Exception { //setup settings AppSettings settings = new AppSettings(true); app.setSettings(settings); //setup app Application spyApp = spy(app); assertNull(spyApp.getInputManager()); //setup context NullContext spyContext = spy(new NullContext()); spyApp.context = spyContext; List expectedInputs = spyContext.getInput(); spyApp.initInput(); //verify InputManager actualInputManager = spyApp.getInputManager(); List actualInputs = actualInputManager.getInputs(); assertNotNull(actualInputManager); assertThat(actualInputs, is(expectedInputs)); } /** * Test from before the refactor. Should still pass * @throws Exception */ @Test public void testInitInputNoJoyStick() throws Exception { //setup settings AppSettings settings = new AppSettings(true); settings.setUseJoysticks(false); app.setSettings(settings); //setup app Application spyApp = spy(app); assertNull(spyApp.getInputManager()); //setup context NullContext spyContext = spy(new NullContext()); MouseInput spyMouseInput = spy(new DummyMouseInput()); KeyInput spyKeyInput = spy(new DummyKeyInput()); TouchInput spyTouchInput = spy(new TestTouchInput()); JoyInput spyJoyInput = spy(new TestJoyInput()); doReturn(spyMouseInput).when(spyContext).getMouseInput(); doReturn(spyKeyInput).when(spyContext).getKeyInput(); doReturn(spyTouchInput).when(spyContext).getTouchInput(); doReturn(spyJoyInput).when(spyContext).getJoyInput(); spyApp.context = spyContext; spyApp.initInput(); verify(spyContext, times(1)).getMouseInput(); verify(spyMouseInput, times(1)).initialize(); verify(spyContext, times(1)).getKeyInput(); verify(spyKeyInput, times(1)).initialize(); verify(spyContext, times(1)).getTouchInput(); verify(spyTouchInput, times(1)).initialize(); verify(spyContext, times(0)).getJoyInput(); verify(spyJoyInput, times(0)).initialize(); assertNotNull(spyApp.getInputManager()); } /** * Test from before the refactor. Should still pass * @throws Exception */ @Test public void testInitInputWithJoyStick() throws Exception { //setup settings AppSettings settings = new AppSettings(true); settings.setUseJoysticks(true); app.setSettings(settings); //setup app Application spyApp = spy(app); assertNull(spyApp.getInputManager()); //setup context NullContext spyContext = spy(new NullContext()); MouseInput spyMouseInput = spy(new DummyMouseInput()); KeyInput spyKeyInput = spy(new DummyKeyInput()); TouchInput spyTouchInput = spy(new TestTouchInput()); JoyInput spyJoyInput = spy(new TestJoyInput()); doReturn(spyMouseInput).when(spyContext).getMouseInput(); doReturn(spyKeyInput).when(spyContext).getKeyInput(); doReturn(spyTouchInput).when(spyContext).getTouchInput(); doReturn(spyJoyInput).when(spyContext).getJoyInput(); spyApp.context = spyContext; spyContext.setSettings(settings); spyApp.initInput(); verify(spyContext, times(1)).getMouseInput(); verify(spyMouseInput, times(1)).initialize(); verify(spyContext, times(1)).getKeyInput(); verify(spyKeyInput, times(1)).initialize(); verify(spyContext, times(1)).getTouchInput(); verify(spyTouchInput, times(1)).initialize(); verify(spyContext, times(1)).getJoyInput(); verify(spyJoyInput, times(1)).initialize(); assertNotNull(spyApp.getInputManager()); } @Test public void testDestroyInput() throws Exception { //setup settings AppSettings settings = new AppSettings(true); app.setSettings(settings); //setup app app.context = new NullContext(); InputManager spyInputManager = spy(new InputManager(app.getContext().getInput())); app.setInputManager(spyInputManager); assertNotNull(app.getInputManager()); app.destroyInput(); verify(spyInputManager, times(1)).destroyInput(); assertNull(app.getInputManager()); } } \ No newline at end of file diff --git a/jme3-core/src/main/java/com/jme3/app/TestApplication.java b/jme3-core/src/test/java/com/jme3/app/TestApplication.java similarity index 100% rename from jme3-core/src/main/java/com/jme3/app/TestApplication.java rename to jme3-core/src/test/java/com/jme3/app/TestApplication.java diff --git a/jme3-core/src/test/java/com/jme3/input/InputManagerTest.java b/jme3-core/src/test/java/com/jme3/input/InputManagerTest.java new file mode 100755 index 00000000000..4e89aaa6dae --- /dev/null +++ b/jme3-core/src/test/java/com/jme3/input/InputManagerTest.java @@ -0,0 +1,94 @@ +package com.jme3.input; + +import com.jme3.app.TestJoyInput; +import com.jme3.app.TestTouchInput; +import com.jme3.input.dummy.DummyKeyInput; +import com.jme3.input.dummy.DummyMouseInput; +import org.junit.Before; +import org.junit.Test; + +import java.util.ArrayList; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +public class InputManagerTest { + + private MouseInput mouseSpy; + private KeyInput keySpy; + private TouchInput touchSpy; + private JoyInput joySpy; + private ArrayList inputs; + + @Before + public void setupInputs(){ + mouseSpy = spy(new DummyMouseInput()); + keySpy = spy(new DummyKeyInput()); + touchSpy = spy(new TestTouchInput()); + joySpy = spy(new TestJoyInput()); + + inputs = new ArrayList<>(); + inputs.add(mouseSpy); + inputs.add(keySpy); + inputs.add(touchSpy); + inputs.add(joySpy); + } + + @Test(expected = IllegalArgumentException.class) + public void testInitializationNoKey() { + inputs.remove(keySpy); + + new InputManager(inputs); + } + + @Test(expected = IllegalArgumentException.class) + public void testInitializationNoMouse() { + inputs.remove(mouseSpy); + + new InputManager(inputs); + } + + @Test + public void testInitializationListenersSet() { + InputManager inputManager = new InputManager(inputs); + + verify(mouseSpy, times(1)).setInputListener(inputManager); + verify(keySpy, times(1)).setInputListener(inputManager); + verify(touchSpy, times(1)).setInputListener(inputManager); + verify(joySpy, times(1)).setInputListener(inputManager); + } + + @Test + public void testInitializationInputInitialization() { + new InputManager(inputs); + + verify(mouseSpy, times(1)).initialize(); + verify(keySpy, times(1)).initialize(); + verify(touchSpy, times(1)).initialize(); + verify(joySpy, times(1)).initialize(); + } + + @Test + public void testInitializationInputAssignments() { + InputManager inputManager = new InputManager(inputs); + + assertNotNull(inputManager.getJoystick()); + assertNotNull(inputManager.getMouse()); + assertNotNull(inputManager.getKeys()); + assertNotNull(inputManager.getTouch()); + } + + @Test + public void testDestroyInput() throws Exception { + InputManager inputManager = new InputManager(inputs); + + inputManager.destroyInput(); + + for(Input input : inputs) { + verify(input, times(1)).destroy(); + } + + } +} \ No newline at end of file diff --git a/jme3-core/src/test/java/com/jme3/system/NullContextTest.java b/jme3-core/src/test/java/com/jme3/system/NullContextTest.java new file mode 100755 index 00000000000..a2835a0e0cb --- /dev/null +++ b/jme3-core/src/test/java/com/jme3/system/NullContextTest.java @@ -0,0 +1,61 @@ +package com.jme3.system; + +import com.jme3.input.Input; +import org.junit.Test; + +import java.util.List; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.*; + +public class NullContextTest { + + @Test + public void testGetInputNotNull() throws Exception { + JmeContext spy = spy(new NullContext()); + + List inputs = spy.getInput(); + + assertNotNull(inputs); + } + + @Test + public void testGetInputWithoutJoystick() throws Exception { + AppSettings settings = new AppSettings(true); + settings.setUseJoysticks(false); + JmeContext spy = spy(new NullContext()); + spy.setSettings(settings); + + spy.getInput(); + + verify(spy, times(1)).getKeyInput(); + verify(spy, times(1)).getMouseInput(); + verify(spy, times(0)).getJoyInput(); + verify(spy, times(1)).getTouchInput(); + } + + @Test + public void testGetInputNoNullWithoutJoystick() throws Exception { + AppSettings settings = new AppSettings(true); + settings.setUseJoysticks(false); + JmeContext spy = spy(new NullContext()); + spy.setSettings(settings); + + List inputs = spy.getInput(); + + assertFalse(inputs.contains(null)); + } + + @Test + public void testGetInputNoNullWithJoystick() throws Exception { + AppSettings settings = new AppSettings(true); + settings.setUseJoysticks(true); + JmeContext spy = spy(new NullContext()); + spy.setSettings(settings); + + List inputs = spy.getInput(); + + assertFalse(inputs.contains(null)); + } + +} \ No newline at end of file diff --git a/jme3-desktop/src/main/java/com/jme3/system/awt/AwtPanelsContext.java b/jme3-desktop/src/main/java/com/jme3/system/awt/AwtPanelsContext.java old mode 100644 new mode 100755 index 897632a0091..86fc3104da2 --- a/jme3-desktop/src/main/java/com/jme3/system/awt/AwtPanelsContext.java +++ b/jme3-desktop/src/main/java/com/jme3/system/awt/AwtPanelsContext.java @@ -31,15 +31,14 @@ */ package com.jme3.system.awt; -import com.jme3.input.JoyInput; -import com.jme3.input.KeyInput; -import com.jme3.input.MouseInput; -import com.jme3.input.TouchInput; +import com.jme3.input.*; import com.jme3.input.awt.AwtKeyInput; import com.jme3.input.awt.AwtMouseInput; import com.jme3.renderer.Renderer; import com.jme3.system.*; import java.util.ArrayList; +import java.util.Collections; +import java.util.List; public class AwtPanelsContext implements JmeContext { @@ -49,6 +48,7 @@ public class AwtPanelsContext implements JmeContext { protected ArrayList panels = new ArrayList(); protected AwtPanel inputSource; + protected List inputs; protected AwtMouseInput mouseInput = new AwtMouseInput(); protected AwtKeyInput keyInput = new AwtKeyInput(); @@ -133,6 +133,20 @@ public TouchInput getTouchInput() { return null; } + public java.util.List getInput() { + if(inputs == null) { + inputs = new ArrayList<>(); + inputs.add(getKeyInput()); + inputs.add(getMouseInput()); + if(!settings.getBoolean("DisableJoysticks")) { + inputs.add(getJoyInput()); + } + inputs.add(getTouchInput()); + inputs.removeAll(Collections.singleton(null)); + } + return inputs; + } + public Timer getTimer() { return actualContext.getTimer(); } diff --git a/jme3-examples/src/main/java/jme3test/animation/TestCinematic.java b/jme3-examples/src/main/java/jme3test/animation/TestCinematic.java old mode 100644 new mode 100755 index f0200bc9125..08665b76d71 --- a/jme3-examples/src/main/java/jme3test/animation/TestCinematic.java +++ b/jme3-examples/src/main/java/jme3test/animation/TestCinematic.java @@ -41,6 +41,7 @@ import com.jme3.cinematic.events.*; import com.jme3.font.BitmapText; import com.jme3.input.ChaseCamera; +import com.jme3.input.KeyInput; import com.jme3.input.controls.ActionListener; import com.jme3.input.controls.KeyTrigger; import com.jme3.light.DirectionalLight; @@ -245,9 +246,9 @@ private void createScene() { } private void initInputs() { - inputManager.addMapping("togglePause", new KeyTrigger(keyInput.KEY_RETURN)); - inputManager.addMapping("navFwd", new KeyTrigger(keyInput.KEY_RIGHT)); - inputManager.addMapping("navBack", new KeyTrigger(keyInput.KEY_LEFT)); + inputManager.addMapping("togglePause", new KeyTrigger(KeyInput.KEY_RETURN)); + inputManager.addMapping("navFwd", new KeyTrigger(KeyInput.KEY_RIGHT)); + inputManager.addMapping("navBack", new KeyTrigger(KeyInput.KEY_LEFT)); ActionListener acl = new ActionListener() { public void onAction(String name, boolean keyPressed, float tpf) { diff --git a/jme3-examples/src/main/java/jme3test/helloworld/HelloInput.java b/jme3-examples/src/main/java/jme3test/helloworld/HelloInput.java old mode 100644 new mode 100755 index 4cf09fe6ec3..88c95666569 --- a/jme3-examples/src/main/java/jme3test/helloworld/HelloInput.java +++ b/jme3-examples/src/main/java/jme3test/helloworld/HelloInput.java @@ -69,7 +69,7 @@ public void simpleInitApp() { /** Custom Keybinding: Map named actions to inputs. */ private void initKeys() { /** You can map one or several inputs to one named mapping. */ - inputManager.addMapping("Pause", new KeyTrigger(keyInput.KEY_P)); + inputManager.addMapping("Pause", new KeyTrigger(KeyInput.KEY_P)); inputManager.addMapping("Left", new KeyTrigger(KeyInput.KEY_J)); inputManager.addMapping("Right", new KeyTrigger(KeyInput.KEY_K)); inputManager.addMapping("Rotate", new KeyTrigger(KeyInput.KEY_SPACE), // spacebar! diff --git a/jme3-examples/src/main/java/jme3test/input/TestCameraNode.java b/jme3-examples/src/main/java/jme3test/input/TestCameraNode.java old mode 100644 new mode 100755 index c1ebfeb8f70..853defe0628 --- a/jme3-examples/src/main/java/jme3test/input/TestCameraNode.java +++ b/jme3-examples/src/main/java/jme3test/input/TestCameraNode.java @@ -30,6 +30,7 @@ package jme3test.input; import com.jme3.app.SimpleApplication; +import com.jme3.input.KeyInput; import com.jme3.input.MouseInput; import com.jme3.input.controls.*; import com.jme3.material.Material; @@ -99,10 +100,10 @@ public void simpleInitApp() { } public void registerInput() { - inputManager.addMapping("moveForward", new KeyTrigger(keyInput.KEY_UP), new KeyTrigger(keyInput.KEY_W)); - inputManager.addMapping("moveBackward", new KeyTrigger(keyInput.KEY_DOWN), new KeyTrigger(keyInput.KEY_S)); - inputManager.addMapping("moveRight", new KeyTrigger(keyInput.KEY_RIGHT), new KeyTrigger(keyInput.KEY_D)); - inputManager.addMapping("moveLeft", new KeyTrigger(keyInput.KEY_LEFT), new KeyTrigger(keyInput.KEY_A)); + inputManager.addMapping("moveForward", new KeyTrigger(KeyInput.KEY_UP), new KeyTrigger(KeyInput.KEY_W)); + inputManager.addMapping("moveBackward", new KeyTrigger(KeyInput.KEY_DOWN), new KeyTrigger(KeyInput.KEY_S)); + inputManager.addMapping("moveRight", new KeyTrigger(KeyInput.KEY_RIGHT), new KeyTrigger(KeyInput.KEY_D)); + inputManager.addMapping("moveLeft", new KeyTrigger(KeyInput.KEY_LEFT), new KeyTrigger(KeyInput.KEY_A)); inputManager.addMapping("toggleRotate", new MouseButtonTrigger(MouseInput.BUTTON_LEFT)); inputManager.addMapping("rotateRight", new MouseAxisTrigger(MouseInput.AXIS_X, true)); inputManager.addMapping("rotateLeft", new MouseAxisTrigger(MouseInput.AXIS_X, false)); diff --git a/jme3-examples/src/main/java/jme3test/input/TestChaseCamera.java b/jme3-examples/src/main/java/jme3test/input/TestChaseCamera.java old mode 100644 new mode 100755 index b6041a51971..b4465b17740 --- a/jme3-examples/src/main/java/jme3test/input/TestChaseCamera.java +++ b/jme3-examples/src/main/java/jme3test/input/TestChaseCamera.java @@ -33,6 +33,7 @@ import com.jme3.app.SimpleApplication; import com.jme3.input.ChaseCamera; +import com.jme3.input.KeyInput; import com.jme3.input.controls.ActionListener; import com.jme3.input.controls.AnalogListener; import com.jme3.input.controls.KeyTrigger; @@ -107,11 +108,11 @@ public void simpleInitApp() { } public void registerInput() { - inputManager.addMapping("moveForward", new KeyTrigger(keyInput.KEY_UP), new KeyTrigger(keyInput.KEY_W)); - inputManager.addMapping("moveBackward", new KeyTrigger(keyInput.KEY_DOWN), new KeyTrigger(keyInput.KEY_S)); - inputManager.addMapping("moveRight", new KeyTrigger(keyInput.KEY_RIGHT), new KeyTrigger(keyInput.KEY_D)); - inputManager.addMapping("moveLeft", new KeyTrigger(keyInput.KEY_LEFT), new KeyTrigger(keyInput.KEY_A)); - inputManager.addMapping("displayPosition", new KeyTrigger(keyInput.KEY_P)); + inputManager.addMapping("moveForward", new KeyTrigger(KeyInput.KEY_UP), new KeyTrigger(KeyInput.KEY_W)); + inputManager.addMapping("moveBackward", new KeyTrigger(KeyInput.KEY_DOWN), new KeyTrigger(KeyInput.KEY_S)); + inputManager.addMapping("moveRight", new KeyTrigger(KeyInput.KEY_RIGHT), new KeyTrigger(KeyInput.KEY_D)); + inputManager.addMapping("moveLeft", new KeyTrigger(KeyInput.KEY_LEFT), new KeyTrigger(KeyInput.KEY_A)); + inputManager.addMapping("displayPosition", new KeyTrigger(KeyInput.KEY_P)); inputManager.addListener(this, "moveForward", "moveBackward", "moveRight", "moveLeft"); inputManager.addListener(this, "displayPosition"); } diff --git a/jme3-examples/src/main/java/jme3test/post/TestDepthOfField.java b/jme3-examples/src/main/java/jme3test/post/TestDepthOfField.java old mode 100644 new mode 100755 index 9966adc617c..1fd7a28a4f2 --- a/jme3-examples/src/main/java/jme3test/post/TestDepthOfField.java +++ b/jme3-examples/src/main/java/jme3test/post/TestDepthOfField.java @@ -3,6 +3,7 @@ import com.jme3.app.SimpleApplication; import com.jme3.collision.CollisionResult; import com.jme3.collision.CollisionResults; +import com.jme3.input.KeyInput; import com.jme3.input.controls.ActionListener; import com.jme3.input.controls.AnalogListener; import com.jme3.input.controls.KeyTrigger; @@ -129,13 +130,13 @@ public void onAnalog(String name, float value, float tpf) { }, "blurScaleUp", "blurScaleDown", "focusRangeUp", "focusRangeDown", "focusDistanceUp", "focusDistanceDown"); - inputManager.addMapping("toggle", new KeyTrigger(keyInput.KEY_SPACE)); - inputManager.addMapping("blurScaleUp", new KeyTrigger(keyInput.KEY_U)); - inputManager.addMapping("blurScaleDown", new KeyTrigger(keyInput.KEY_J)); - inputManager.addMapping("focusRangeUp", new KeyTrigger(keyInput.KEY_I)); - inputManager.addMapping("focusRangeDown", new KeyTrigger(keyInput.KEY_K)); - inputManager.addMapping("focusDistanceUp", new KeyTrigger(keyInput.KEY_O)); - inputManager.addMapping("focusDistanceDown", new KeyTrigger(keyInput.KEY_L)); + inputManager.addMapping("toggle", new KeyTrigger(KeyInput.KEY_SPACE)); + inputManager.addMapping("blurScaleUp", new KeyTrigger(KeyInput.KEY_U)); + inputManager.addMapping("blurScaleDown", new KeyTrigger(KeyInput.KEY_J)); + inputManager.addMapping("focusRangeUp", new KeyTrigger(KeyInput.KEY_I)); + inputManager.addMapping("focusRangeDown", new KeyTrigger(KeyInput.KEY_K)); + inputManager.addMapping("focusDistanceUp", new KeyTrigger(KeyInput.KEY_O)); + inputManager.addMapping("focusDistanceDown", new KeyTrigger(KeyInput.KEY_L)); } diff --git a/jme3-examples/src/main/java/jme3test/water/TestPostWaterLake.java b/jme3-examples/src/main/java/jme3test/water/TestPostWaterLake.java old mode 100644 new mode 100755 index e178c12ac39..1e9e026b507 --- a/jme3-examples/src/main/java/jme3test/water/TestPostWaterLake.java +++ b/jme3-examples/src/main/java/jme3test/water/TestPostWaterLake.java @@ -34,6 +34,7 @@ import com.jme3.app.SimpleApplication; import com.jme3.asset.plugins.HttpZipLocator; import com.jme3.asset.plugins.ZipLocator; +import com.jme3.input.KeyInput; import com.jme3.input.controls.ActionListener; import com.jme3.input.controls.KeyTrigger; import com.jme3.light.DirectionalLight; @@ -117,6 +118,6 @@ public void onAction(String name, boolean isPressed, float tpf) { } }, "HQ"); - inputManager.addMapping("HQ", new KeyTrigger(keyInput.KEY_SPACE)); + inputManager.addMapping("HQ", new KeyTrigger(KeyInput.KEY_SPACE)); } } diff --git a/jme3-ios/src/main/java/com/jme3/system/ios/IGLESContext.java b/jme3-ios/src/main/java/com/jme3/system/ios/IGLESContext.java old mode 100644 new mode 100755 index 2d046550ec1..9b27458fa35 --- a/jme3-ios/src/main/java/com/jme3/system/ios/IGLESContext.java +++ b/jme3-ios/src/main/java/com/jme3/system/ios/IGLESContext.java @@ -42,6 +42,10 @@ import com.jme3.renderer.opengl.GLExt; import com.jme3.renderer.opengl.GLFbo; import com.jme3.renderer.opengl.GLRenderer; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; import java.util.logging.Level; import java.util.logging.Logger; @@ -120,6 +124,20 @@ public JoyInput getJoyInput() { return null;// new DummySensorJoyInput(); } + public java.util.List getInput() { + List inputs = new ArrayList<>(); + + inputs.add(getKeyInput()); + inputs.add(getMouseInput()); + if(!settings.getBoolean("DisableJoysticks")) { + inputs.add(getJoyInput()); + } + inputs.add(getTouchInput()); + inputs.removeAll(Collections.singleton(null)); + + return inputs; + } + @Override public TouchInput getTouchInput() { return input; diff --git a/jme3-jogl/src/main/java/com/jme3/system/jogl/JoglAbstractDisplay.java b/jme3-jogl/src/main/java/com/jme3/system/jogl/JoglAbstractDisplay.java old mode 100644 new mode 100755 index 3b468f1aa45..59d6e1cd1ad --- a/jme3-jogl/src/main/java/com/jme3/system/jogl/JoglAbstractDisplay.java +++ b/jme3-jogl/src/main/java/com/jme3/system/jogl/JoglAbstractDisplay.java @@ -32,6 +32,7 @@ package com.jme3.system.jogl; +import com.jme3.input.Input; import com.jme3.input.KeyInput; import com.jme3.input.MouseInput; import com.jme3.input.TouchInput; @@ -44,6 +45,8 @@ import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; +import java.util.ArrayList; +import java.util.Collections; import java.util.concurrent.atomic.AtomicBoolean; import java.util.logging.Logger; @@ -164,7 +167,8 @@ public MouseInput getMouseInput() { } return mouseInput; } - + + @Override public TouchInput getTouchInput() { return null; } diff --git a/jme3-jogl/src/main/java/com/jme3/system/jogl/JoglContext.java b/jme3-jogl/src/main/java/com/jme3/system/jogl/JoglContext.java old mode 100644 new mode 100755 index 3ed543bc94e..10ce28d7057 --- a/jme3-jogl/src/main/java/com/jme3/system/jogl/JoglContext.java +++ b/jme3-jogl/src/main/java/com/jme3/system/jogl/JoglContext.java @@ -32,6 +32,7 @@ package com.jme3.system.jogl; +import com.jme3.input.Input; import com.jme3.input.JoyInput; import com.jme3.input.KeyInput; import com.jme3.input.MouseInput; @@ -59,6 +60,9 @@ import com.jme3.system.Timer; import java.nio.IntBuffer; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; import java.util.logging.Level; import java.util.logging.Logger; @@ -82,6 +86,7 @@ public abstract class JoglContext implements JmeContext { protected Timer timer; protected SystemListener listener; + protected List inputs; protected KeyInput keyInput; protected MouseInput mouseInput; protected JoyInput joyInput; @@ -133,6 +138,20 @@ public JoyInput getJoyInput() { return joyInput; } + @Override + public java.util.List getInput() { + if(inputs == null) { + inputs = new ArrayList<>(); + inputs.add(getKeyInput()); + inputs.add(getMouseInput()); + if(!settings.getBoolean("DisableJoysticks")) { + inputs.add(getJoyInput()); + } + inputs.add(getTouchInput()); + inputs.removeAll(Collections.singleton(null)); + } + return inputs; + } @Override public Timer getTimer() { return timer; diff --git a/jme3-jogl/src/main/java/com/jme3/system/jogl/JoglNewtAbstractDisplay.java b/jme3-jogl/src/main/java/com/jme3/system/jogl/JoglNewtAbstractDisplay.java old mode 100644 new mode 100755 index 9c7a49d173e..05ac839d400 --- a/jme3-jogl/src/main/java/com/jme3/system/jogl/JoglNewtAbstractDisplay.java +++ b/jme3-jogl/src/main/java/com/jme3/system/jogl/JoglNewtAbstractDisplay.java @@ -32,6 +32,7 @@ package com.jme3.system.jogl; +import com.jme3.input.Input; import com.jme3.input.KeyInput; import com.jme3.input.MouseInput; import com.jme3.input.TouchInput; @@ -43,6 +44,8 @@ import com.jogamp.opengl.util.AnimatorBase; import com.jogamp.opengl.util.FPSAnimator; +import java.util.ArrayList; +import java.util.Collections; import java.util.concurrent.atomic.AtomicBoolean; import java.util.logging.Logger; @@ -141,7 +144,8 @@ public MouseInput getMouseInput() { } return mouseInput; } - + + @Override public TouchInput getTouchInput() { return null; } diff --git a/jme3-jogl/src/main/java/com/jme3/system/jogl/JoglOffscreenBuffer.java b/jme3-jogl/src/main/java/com/jme3/system/jogl/JoglOffscreenBuffer.java old mode 100644 new mode 100755 index 56aa2d53fc5..63c16e7ca32 --- a/jme3-jogl/src/main/java/com/jme3/system/jogl/JoglOffscreenBuffer.java +++ b/jme3-jogl/src/main/java/com/jme3/system/jogl/JoglOffscreenBuffer.java @@ -31,13 +31,12 @@ */ package com.jme3.system.jogl; -import com.jme3.input.JoyInput; -import com.jme3.input.KeyInput; -import com.jme3.input.MouseInput; -import com.jme3.input.TouchInput; +import com.jme3.input.*; import com.jme3.input.dummy.DummyKeyInput; import com.jme3.input.dummy.DummyMouseInput; +import java.util.ArrayList; +import java.util.Collections; import java.util.concurrent.atomic.AtomicBoolean; import java.util.logging.Level; import java.util.logging.Logger; diff --git a/jme3-lwjgl/src/main/java/com/jme3/system/lwjgl/LwjglAbstractDisplay.java b/jme3-lwjgl/src/main/java/com/jme3/system/lwjgl/LwjglAbstractDisplay.java old mode 100644 new mode 100755 index 802b12a0fa1..93bd0c929cd --- a/jme3-lwjgl/src/main/java/com/jme3/system/lwjgl/LwjglAbstractDisplay.java +++ b/jme3-lwjgl/src/main/java/com/jme3/system/lwjgl/LwjglAbstractDisplay.java @@ -32,15 +32,15 @@ package com.jme3.system.lwjgl; -import com.jme3.input.JoyInput; -import com.jme3.input.KeyInput; -import com.jme3.input.MouseInput; -import com.jme3.input.TouchInput; +import com.jme3.input.*; import com.jme3.input.lwjgl.JInputJoyInput; import com.jme3.input.lwjgl.LwjglKeyInput; import com.jme3.input.lwjgl.LwjglMouseInput; import com.jme3.system.AppSettings; import com.jme3.system.JmeSystem; + +import java.util.ArrayList; +import java.util.Collections; import java.util.concurrent.atomic.AtomicBoolean; import java.util.logging.Level; import java.util.logging.Logger; diff --git a/jme3-lwjgl/src/main/java/com/jme3/system/lwjgl/LwjglContext.java b/jme3-lwjgl/src/main/java/com/jme3/system/lwjgl/LwjglContext.java old mode 100644 new mode 100755 index 3f113988658..1692241082c --- a/jme3-lwjgl/src/main/java/com/jme3/system/lwjgl/LwjglContext.java +++ b/jme3-lwjgl/src/main/java/com/jme3/system/lwjgl/LwjglContext.java @@ -31,6 +31,7 @@ */ package com.jme3.system.lwjgl; +import com.jme3.input.Input; import com.jme3.input.lwjgl.JInputJoyInput; import com.jme3.input.lwjgl.LwjglKeyInput; import com.jme3.input.lwjgl.LwjglMouseInput; @@ -54,6 +55,9 @@ import com.jme3.system.*; import java.io.File; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; import java.util.logging.Level; import java.util.logging.Logger; @@ -76,6 +80,7 @@ public abstract class LwjglContext implements JmeContext { protected AppSettings settings = new AppSettings(true); protected Renderer renderer; + protected List inputs; protected LwjglKeyInput keyInput; protected LwjglMouseInput mouseInput; protected JInputJoyInput joyInput; @@ -114,6 +119,20 @@ protected ContextAttribs createContextAttribs() { } } + public java.util.List getInput() { + if(inputs == null) { + inputs = new ArrayList<>(); + inputs.add(getKeyInput()); + inputs.add(getMouseInput()); + if(!settings.getBoolean("DisableJoysticks")) { + inputs.add(getJoyInput()); + } + inputs.add(getTouchInput()); + inputs.removeAll(Collections.singleton(null)); + } + return inputs; + } + protected int determineMaxSamples(int requestedSamples) { try { // If we already have a valid context, determine samples using current diff --git a/jme3-lwjgl/src/main/java/com/jme3/system/lwjgl/LwjglOffscreenBuffer.java b/jme3-lwjgl/src/main/java/com/jme3/system/lwjgl/LwjglOffscreenBuffer.java old mode 100644 new mode 100755 index ddfb8b62bc7..ac462eee64c --- a/jme3-lwjgl/src/main/java/com/jme3/system/lwjgl/LwjglOffscreenBuffer.java +++ b/jme3-lwjgl/src/main/java/com/jme3/system/lwjgl/LwjglOffscreenBuffer.java @@ -32,10 +32,7 @@ package com.jme3.system.lwjgl; -import com.jme3.input.JoyInput; -import com.jme3.input.KeyInput; -import com.jme3.input.MouseInput; -import com.jme3.input.TouchInput; +import com.jme3.input.*; import com.jme3.input.dummy.DummyKeyInput; import com.jme3.input.dummy.DummyMouseInput; import java.util.concurrent.atomic.AtomicBoolean; diff --git a/jme3-lwjgl3/src/main/java/com/jme3/system/lwjgl/LwjglContext.java b/jme3-lwjgl3/src/main/java/com/jme3/system/lwjgl/LwjglContext.java old mode 100644 new mode 100755 index 0fe8a7b23ea..abec6fa6983 --- a/jme3-lwjgl3/src/main/java/com/jme3/system/lwjgl/LwjglContext.java +++ b/jme3-lwjgl3/src/main/java/com/jme3/system/lwjgl/LwjglContext.java @@ -32,6 +32,7 @@ package com.jme3.system.lwjgl; +import com.jme3.input.Input; import com.jme3.input.lwjgl.GlfwJoystickInput; import com.jme3.input.lwjgl.GlfwKeyInput; import com.jme3.input.lwjgl.GlfwMouseInput; @@ -48,6 +49,9 @@ import org.lwjgl.opengl.EXTFramebufferMultisample; import org.lwjgl.opengl.GLCapabilities; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; import java.util.logging.Level; import java.util.logging.Logger; @@ -72,6 +76,7 @@ public abstract class LwjglContext implements JmeContext { protected AppSettings settings = new AppSettings(true); protected Renderer renderer; + protected List inputs; protected GlfwKeyInput keyInput; protected GlfwMouseInput mouseInput; protected GlfwJoystickInput joyInput; @@ -116,6 +121,20 @@ protected int getNumSamplesToUse() { return samples; } + public java.util.List getInput() { + if(inputs == null) { + inputs = new ArrayList<>(); + inputs.add(getKeyInput()); + inputs.add(getMouseInput()); + if(!settings.getBoolean("DisableJoysticks")) { + inputs.add(getJoyInput()); + } + inputs.add(getTouchInput()); + inputs.removeAll(Collections.singleton(null)); + } + return inputs; + } + protected void loadNatives() { if (JmeSystem.isLowPermissions()) { return; diff --git a/jme3-lwjgl3/src/main/java/com/jme3/system/lwjgl/LwjglWindow.java b/jme3-lwjgl3/src/main/java/com/jme3/system/lwjgl/LwjglWindow.java old mode 100644 new mode 100755 index aaa24ce423f..749b8df51f7 --- a/jme3-lwjgl3/src/main/java/com/jme3/system/lwjgl/LwjglWindow.java +++ b/jme3-lwjgl3/src/main/java/com/jme3/system/lwjgl/LwjglWindow.java @@ -32,10 +32,7 @@ package com.jme3.system.lwjgl; -import com.jme3.input.JoyInput; -import com.jme3.input.KeyInput; -import com.jme3.input.MouseInput; -import com.jme3.input.TouchInput; +import com.jme3.input.*; import com.jme3.input.lwjgl.GlfwJoystickInput; import com.jme3.input.lwjgl.GlfwKeyInput; import com.jme3.input.lwjgl.GlfwMouseInput;