I’m giving JInput’s support for controllers a whirl, however I get a funny assertion poping up.
Triggering the assert from:
ControllerEnvironment env = ControllerEnvironment.getDefaultEnvironment();
Controller[] controllers = env.getControllers();
System.out.println("Found "+controllers.length+" controllers.");
java.lang.AssertionError
at net.java.games.input.DirectInputEnvironmentPlugin.addDevice(DirectInputEnvironmentPlugin.java:165)
at net.java.games.input.DirectInputEnvironmentPlugin.enumDevices(Native Method)
at net.java.games.input.DirectInputEnvironmentPlugin.enumControllers(DirectInputEnvironmentPlugin.java:133)
at net.java.games.input.DirectInputEnvironmentPlugin.<init>(DirectInputEnvironmentPlugin.java:113)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
at java.lang.Class.newInstance0(Class.java:296)
at java.lang.Class.newInstance(Class.java:249)
at net.java.games.input.DefaultControllerEnvironment.scanControllersAt(DefaultControllerEnvironment.java:188)
at net.java.games.input.DefaultControllerEnvironment.scanControllers(DefaultControllerEnvironment.java:169)
at net.java.games.input.DefaultControllerEnvironment.access$000(DefaultControllerEnvironment.java:57)
at net.java.games.input.DefaultControllerEnvironment$1.run(DefaultControllerEnvironment.java:108)
at java.security.AccessController.doPrivileged(Native Method)
at net.java.games.input.DefaultControllerEnvironment.getControllers(DefaultControllerEnvironment.java:106)
at com.vecript.core.entity.DefaultRootEntity.<init>(DefaultRootEntity.java:36)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
at java.lang.Class.newInstance0(Class.java:296)
at java.lang.Class.newInstance(Class.java:249)
at com.vecript.core.entity.EntityFactory.createEntity(EntityFactory.java:78)
at com.vecript.core.entity.EntityFactory.createEntity(EntityFactory.java:64)
at com.vecript.core.Scene.<init>(Scene.java:33)
at com.vecript.core.Vecript.initialise(Vecript.java:183)
at com.vecript.core.Vecript.main(Vecript.java:289)
The offending code:
private void addDevice(ArrayList list, long lpDevice,
int type, String productName, String instanceName, boolean polled) {
Controller c;
int category = GET_DIDEVICE_TYPE(type);
int subtype = GET_DIDEVICE_SUBTYPE(type);
//System.out.println("Category = "+category);
if (category == DI8DEVTYPE_MOUSE) {
c = DirectInputMouse.createMouse(lpDevice, subtype, productName,
instanceName);
} else if (category == DI8DEVTYPE_KEYBOARD) {
c = DirectInputKeyboard.createKeyboard(lpDevice, subtype,
productName, instanceName);
} else {
assert category == DI8DEVTYPE_JOYSTICK; // Asserts here!
c = DirectInputDevice.createDevice(lpDevice, subtype, productName,
instanceName,polled);
}
if (c != null) {
list.add(c);
}
}
A quick check in the debugger shows that the final else statement checks the catergory is a joystick. Well, close enough its a gamecube joypad hooked up via usb. But the actual catergory is DI8DEVTYPE_1STPERSON :o Is this possibly because its a 6-axis controller?
Running without asserts I obviously don’t get the assertion, but I also don’t get any values back All the Controller axies return 0.0 (although it gets a full 18 axies, I assumes this is 6 analog axies + 12 buttons).
Anyone any ideas?