joystick: use jinput backend for lwjgl3

experimental
Kirill Vainer 9 years ago
parent 87af1f30b0
commit f28d74a1f6
  1. 11
      jme3-jinput/build.gradle
  2. 49
      jme3-jinput/src/main/java/com/jme3/input/jinput/JInputJoyInput.java
  3. 1
      jme3-lwjgl/build.gradle
  4. 2
      jme3-lwjgl/src/main/java/com/jme3/system/lwjgl/LwjglAbstractDisplay.java
  5. 3
      jme3-lwjgl/src/main/java/com/jme3/system/lwjgl/LwjglContext.java
  6. 1
      jme3-lwjgl3/build.gradle
  7. 3
      jme3-lwjgl3/src/main/java/com/jme3/system/lwjgl/LwjglContext.java
  8. 3
      jme3-lwjgl3/src/main/java/com/jme3/system/lwjgl/LwjglWindow.java
  9. 1
      settings.gradle

@ -0,0 +1,11 @@
if (!hasProperty('mainClass')) {
ext.mainClass = ''
}
dependencies {
compile project(':jme3-core')
compile project(':jme3-desktop')
compile 'net.java.jinput:jinput:2.0.6'
testCompile project(path: ':jme3-core', configuration: 'testOutput')
}

@ -1,4 +1,4 @@
package com.jme3.input.lwjgl; package com.jme3.input.jinput;
import com.jme3.input.AbstractJoystick; import com.jme3.input.AbstractJoystick;
import com.jme3.input.DefaultJoystickAxis; import com.jme3.input.DefaultJoystickAxis;
@ -32,25 +32,13 @@ public class JInputJoyInput implements JoyInput {
private JInputJoystick[] joysticks; private JInputJoystick[] joysticks;
private RawInputListener listener; private RawInputListener listener;
private Map<Controller, JInputJoystick> joystickIndex = new HashMap<Controller, JInputJoystick>(); private final Map<Controller, JInputJoystick> joystickIndex = new HashMap<Controller, JInputJoystick>();
public void setJoyRumble(int joyId, float amount){
if( joyId >= joysticks.length )
throw new IllegalArgumentException();
Controller c = joysticks[joyId].controller;
for (Rumbler r : c.getRumblers()){
r.rumble(amount);
}
}
@Override
public Joystick[] loadJoysticks(InputManager inputManager){ public Joystick[] loadJoysticks(InputManager inputManager){
ControllerEnvironment ce = ControllerEnvironment ce =
ControllerEnvironment.getDefaultEnvironment(); ControllerEnvironment.getDefaultEnvironment();
Controller[] cs = ce.getControllers();
List<Joystick> list = new ArrayList<Joystick>(); List<Joystick> list = new ArrayList<Joystick>();
for( Controller c : ce.getControllers() ) { for( Controller c : ce.getControllers() ) {
if (c.getType() == Controller.Type.KEYBOARD if (c.getType() == Controller.Type.KEYBOARD
@ -82,10 +70,12 @@ public class JInputJoyInput implements JoyInput {
return joysticks; return joysticks;
} }
@Override
public void initialize() { public void initialize() {
inited = true; inited = true;
} }
@Override
public void update() { public void update() {
ControllerEnvironment ce = ControllerEnvironment ce =
ControllerEnvironment.getDefaultEnvironment(); ControllerEnvironment.getDefaultEnvironment();
@ -151,25 +141,42 @@ public class JInputJoyInput implements JoyInput {
} }
} }
@Override
public void setJoyRumble(int joyId, float amount) {
if (joyId >= joysticks.length) {
throw new IllegalArgumentException();
}
Controller c = joysticks[joyId].controller;
for (Rumbler r : c.getRumblers()) {
r.rumble(amount);
}
}
@Override
public void destroy() { public void destroy() {
inited = false; inited = false;
} }
@Override
public boolean isInitialized() { public boolean isInitialized() {
return inited; return inited;
} }
@Override
public void setInputListener(RawInputListener listener) { public void setInputListener(RawInputListener listener) {
this.listener = listener; this.listener = listener;
} }
@Override
public long getInputTimeNanos() { public long getInputTimeNanos() {
return 0; return 0;
} }
protected class JInputJoystick extends AbstractJoystick { private static class JInputJoystick extends AbstractJoystick {
private JoystickAxis nullAxis; private final JoystickAxis nullAxis;
private Controller controller; private Controller controller;
private JoystickAxis xAxis; private JoystickAxis xAxis;
private JoystickAxis yAxis; private JoystickAxis yAxis;
@ -216,8 +223,8 @@ public class JInputJoyInput implements JoyInput {
String name = comp.getName(); String name = comp.getName();
String original = id.getName(); String original = id.getName();
String logicalId = JoystickCompatibilityMappings.remapComponent( controller.getName(), original ); String logicalId = JoystickCompatibilityMappings.remapComponent( controller.getName(), original );
if( name != original ) { if (!logicalId.equals(original)) {
logger.log(Level.FINE, "Remapped:" + original + " to:" + logicalId); logger.log(Level.FINE, "Remapped:{0} to:{1}", new Object[]{original, logicalId});
} }
JoystickButton button = new DefaultJoystickButton( getInputManager(), this, getButtonCount(), JoystickButton button = new DefaultJoystickButton( getInputManager(), this, getButtonCount(),
@ -238,8 +245,8 @@ public class JInputJoyInput implements JoyInput {
String name = comp.getName(); String name = comp.getName();
String original = id.getName(); String original = id.getName();
String logicalId = JoystickCompatibilityMappings.remapComponent( controller.getName(), original ); String logicalId = JoystickCompatibilityMappings.remapComponent( controller.getName(), original );
if( name != original ) { if (!logicalId.equals(original)) {
logger.log(Level.FINE, "Remapped:" + original + " to:" + logicalId); logger.log(Level.FINE, "Remapped:{0} to:{1}", new Object[]{original, logicalId});
} }
JoystickAxis axis = new DefaultJoystickAxis( getInputManager(), JoystickAxis axis = new DefaultJoystickAxis( getInputManager(),

@ -5,6 +5,7 @@ if (!hasProperty('mainClass')) {
dependencies { dependencies {
compile project(':jme3-core') compile project(':jme3-core')
compile project(':jme3-desktop') compile project(':jme3-desktop')
compile project(':jme3-jinput')
compile 'org.lwjgl.lwjgl:lwjgl:2.9.3' compile 'org.lwjgl.lwjgl:lwjgl:2.9.3'
testCompile project(path: ':jme3-core', configuration: 'testOutput') testCompile project(path: ':jme3-core', configuration: 'testOutput')

@ -36,9 +36,9 @@ import com.jme3.input.JoyInput;
import com.jme3.input.KeyInput; import com.jme3.input.KeyInput;
import com.jme3.input.MouseInput; import com.jme3.input.MouseInput;
import com.jme3.input.TouchInput; import com.jme3.input.TouchInput;
import com.jme3.input.lwjgl.JInputJoyInput;
import com.jme3.input.lwjgl.LwjglKeyInput; import com.jme3.input.lwjgl.LwjglKeyInput;
import com.jme3.input.lwjgl.LwjglMouseInput; import com.jme3.input.lwjgl.LwjglMouseInput;
import com.jme3.input.jinput.JInputJoyInput;
import com.jme3.system.AppSettings; import com.jme3.system.AppSettings;
import com.jme3.system.JmeSystem; import com.jme3.system.JmeSystem;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;

@ -31,7 +31,7 @@
*/ */
package com.jme3.system.lwjgl; package com.jme3.system.lwjgl;
import com.jme3.input.lwjgl.JInputJoyInput; import com.jme3.input.jinput.JInputJoyInput;
import com.jme3.input.lwjgl.LwjglKeyInput; import com.jme3.input.lwjgl.LwjglKeyInput;
import com.jme3.input.lwjgl.LwjglMouseInput; import com.jme3.input.lwjgl.LwjglMouseInput;
import com.jme3.renderer.Renderer; import com.jme3.renderer.Renderer;
@ -52,7 +52,6 @@ import com.jme3.renderer.opengl.GLTiming;
import com.jme3.renderer.opengl.GLTimingState; import com.jme3.renderer.opengl.GLTimingState;
import com.jme3.renderer.opengl.GLTracer; import com.jme3.renderer.opengl.GLTracer;
import com.jme3.system.*; import com.jme3.system.*;
import java.io.File;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level; import java.util.logging.Level;

@ -7,6 +7,7 @@ def lwjglVersion = '3.0.0b'
dependencies { dependencies {
compile project(':jme3-core') compile project(':jme3-core')
compile project(':jme3-desktop') compile project(':jme3-desktop')
compile project(':jme3-jinput')
compile "org.lwjgl:lwjgl:${lwjglVersion}" compile "org.lwjgl:lwjgl:${lwjglVersion}"
compile "org.lwjgl:lwjgl-platform:${lwjglVersion}:natives-windows" compile "org.lwjgl:lwjgl-platform:${lwjglVersion}:natives-windows"

@ -32,6 +32,7 @@
package com.jme3.system.lwjgl; package com.jme3.system.lwjgl;
import com.jme3.input.jinput.JInputJoyInput;
import com.jme3.input.lwjgl.GlfwJoystickInput; import com.jme3.input.lwjgl.GlfwJoystickInput;
import com.jme3.input.lwjgl.GlfwKeyInput; import com.jme3.input.lwjgl.GlfwKeyInput;
import com.jme3.input.lwjgl.GlfwMouseInput; import com.jme3.input.lwjgl.GlfwMouseInput;
@ -74,7 +75,7 @@ public abstract class LwjglContext implements JmeContext {
protected Renderer renderer; protected Renderer renderer;
protected GlfwKeyInput keyInput; protected GlfwKeyInput keyInput;
protected GlfwMouseInput mouseInput; protected GlfwMouseInput mouseInput;
protected GlfwJoystickInput joyInput; protected JInputJoyInput joyInput;
protected Timer timer; protected Timer timer;
protected SystemListener listener; protected SystemListener listener;

@ -36,6 +36,7 @@ import com.jme3.input.JoyInput;
import com.jme3.input.KeyInput; import com.jme3.input.KeyInput;
import com.jme3.input.MouseInput; import com.jme3.input.MouseInput;
import com.jme3.input.TouchInput; import com.jme3.input.TouchInput;
import com.jme3.input.jinput.JInputJoyInput;
import com.jme3.input.lwjgl.GlfwJoystickInput; import com.jme3.input.lwjgl.GlfwJoystickInput;
import com.jme3.input.lwjgl.GlfwKeyInput; import com.jme3.input.lwjgl.GlfwKeyInput;
import com.jme3.input.lwjgl.GlfwMouseInput; import com.jme3.input.lwjgl.GlfwMouseInput;
@ -465,7 +466,7 @@ public abstract class LwjglWindow extends LwjglContext implements Runnable {
public JoyInput getJoyInput() { public JoyInput getJoyInput() {
if (joyInput == null) { if (joyInput == null) {
joyInput = new GlfwJoystickInput(); joyInput = new JInputJoyInput();
} }
return joyInput; return joyInput;
} }

@ -14,6 +14,7 @@ include 'jme3-terrain'
include 'jme3-desktop' include 'jme3-desktop'
include 'jme3-blender' include 'jme3-blender'
include 'jme3-jogl' include 'jme3-jogl'
include 'jme3-jinput'
include 'jme3-lwjgl' include 'jme3-lwjgl'
include 'jme3-lwjgl3' include 'jme3-lwjgl3'

Loading…
Cancel
Save