From 1186fb209c5c5caa458c9ec760ccb8af7ded2a88 Mon Sep 17 00:00:00 2001 From: endolf Date: Mon, 21 Jun 2004 21:44:16 +0000 Subject: Possible fix for sigfault on linux, need to test more git-svn-id: file:///home/sven/projects/JOGL/git-svn/svn-server-sync/jinput/trunk@80 e343933a-64c8-49c5-92b1-88f2ce3e89e8 --- .../src/java/net/java/games/input/LinuxDevice.java | 10 ++ .../java/games/input/LinuxEnvironmentPlugin.java | 2 +- .../java/net/java/games/input/LinuxKeyboard.java | 147 +++------------------ .../net/java/games/input/LinuxNativeTypesMap.java | 1 - 4 files changed, 26 insertions(+), 134 deletions(-) diff --git a/plugins/linux/src/java/net/java/games/input/LinuxDevice.java b/plugins/linux/src/java/net/java/games/input/LinuxDevice.java index 0ed7c98..7233ce4 100644 --- a/plugins/linux/src/java/net/java/games/input/LinuxDevice.java +++ b/plugins/linux/src/java/net/java/games/input/LinuxDevice.java @@ -407,6 +407,10 @@ public class LinuxDevice extends AbstractController { private LinuxAxis createButton(int buttonNumber, int nativeButtonType) { Axis.Identifier id = LinuxNativeTypesMap.getButtonID(nativeButtonType); String name = LinuxNativeTypesMap.getButtonName(nativeButtonType); + System.out.println("native button type: " + nativeButtonType + " id: " + id + " name: " + name); + if(id!=null) { + System.out.println("id.name: " + id.getName()); + } if(name == null) { name = "Uknown button"; id = new ButtonID(name); @@ -463,6 +467,12 @@ public class LinuxDevice extends AbstractController { private LinuxHat createHat(String name, int xAxisID, int yAxisID) { return new LinuxHat(this, name, xAxisID, yAxisID); } + + public Axis[] getButtons() { + Axis[] buttonsCopy = new Axis[buttons.length]; + System.arraycopy(buttons, 0, buttonsCopy, 0, buttons.length); + return buttonsCopy; + } /** Polls axes for data. Returns false if the controller is no longer valid. * Polling reflects the current state of the device when polled. diff --git a/plugins/linux/src/java/net/java/games/input/LinuxEnvironmentPlugin.java b/plugins/linux/src/java/net/java/games/input/LinuxEnvironmentPlugin.java index 09bbfec..88ea81c 100644 --- a/plugins/linux/src/java/net/java/games/input/LinuxEnvironmentPlugin.java +++ b/plugins/linux/src/java/net/java/games/input/LinuxEnvironmentPlugin.java @@ -113,7 +113,7 @@ public class LinuxEnvironmentPlugin extends ControllerEnvironment implements Plu if((mouseCharacteristic > keyboardCharacteristic) && (mouseCharacteristic > joystickCharacteristic)) { device = new LinuxMouse(new LinuxDevice(deviceNumber, name, numButtons, numRelAxes, numAbsAxes)); } else if((keyboardCharacteristic > mouseCharacteristic) && (keyboardCharacteristic > joystickCharacteristic)) { - device = new LinuxKeyboard(deviceNumber, name, numButtons, numRelAxes, numAbsAxes); + device = new LinuxKeyboard(new LinuxDevice(deviceNumber, name, numButtons, numRelAxes, numAbsAxes)); } else if((joystickCharacteristic > keyboardCharacteristic) && (joystickCharacteristic > mouseCharacteristic)) { device = new LinuxDevice(deviceNumber, name, numButtons, numRelAxes, numAbsAxes); } else { diff --git a/plugins/linux/src/java/net/java/games/input/LinuxKeyboard.java b/plugins/linux/src/java/net/java/games/input/LinuxKeyboard.java index f03d81d..cddb5c8 100644 --- a/plugins/linux/src/java/net/java/games/input/LinuxKeyboard.java +++ b/plugins/linux/src/java/net/java/games/input/LinuxKeyboard.java @@ -25,35 +25,15 @@ */ package net.java.games.input; +import java.util.HashMap; + /** Class that represents a keyboard under linux * @author Jeremy Booth (jeremy@newdawnsoftware.com) */ public class LinuxKeyboard extends StandardKeyboard { - /** Values for the keys - */ - private int keyData[]; - /** Needed for the polling methods - */ - private int dummyRelAxesData[]; - /** Needed for the polling methods - */ - private int dummyAbsAxesData[]; - /** Map of native key numbers from jinput key id key indexes. - */ - private int keyMap[]; - /** List of keys this keyboard supports - */ - private int supportedKeys[]; - /** Number of keys this keyboard has - */ - private int numKeys; - /** Port type that this keyboard is connected to. - */ - private PortType portType; - /** The native device id - */ - private int nativeID; + private HashMap keyMap = new HashMap(); + private LinuxDevice realController; /** Creates a new instance of LinuxKeyboard * @param nativeID Native device id @@ -62,34 +42,11 @@ public class LinuxKeyboard extends StandardKeyboard { * @param numRelAxes Number of relative axes (you never know) * @param numAbsAxes Number of absolute axes (you never know) */ - public LinuxKeyboard(int nativeID, String name, int numButtons, int numRelAxes, int numAbsAxes) { - super(name); - - children = NO_CONTROLLERS; - rumblers = NO_RUMBLERS; - - if((numRelAxes > 0) || (numAbsAxes > 0)) { - children = new Controller[1]; - children[0] = new LinuxDevice(nativeID, name + " axis", 0, numRelAxes, numAbsAxes); - } - - this.nativeID = nativeID; - - portType = LinuxNativeTypesMap.getPortType(getNativePortType(nativeID)); - - dummyRelAxesData = new int[numRelAxes]; - dummyAbsAxesData = new int[numAbsAxes]; - - this.numKeys = numButtons; - keyData = new int[numButtons+1]; - supportedKeys = new int[numButtons+1]; - keyMap = new int[KeyID.LAST.getKeyIndex()]; - - getSupportedButtons(supportedKeys); - supportedKeys[numKeys] = NativeDefinitions.KEY_UNKNOWN; + public LinuxKeyboard(LinuxDevice realController) { + super(realController.getName()); + this.realController = realController; setupKeyMap(); - renameKeys(); } /** Returns whether or not the given key has been pressed since the last @@ -98,19 +55,8 @@ public class LinuxKeyboard extends StandardKeyboard { * @return the value fo the key */ protected boolean isKeyPressed(Key key) { - /*if(((Keyboard.KeyID) key.getIdentifier()).getKeyIndex() == StandardKeyboard.KeyID.ESCAPE.getKeyIndex()) { - System.out.println("Asked if key " + key + " was pressed"); - System.out.println("key id " + key.getIdentifier()); - System.out.println("keyIndex " + ((Keyboard.KeyID) key.getIdentifier()).getKeyIndex()); - System.out.println("keyMap for index is " + keyMap[((Keyboard.KeyID) key.getIdentifier()).getKeyIndex()]); - System.out.println("name for supportedKeys index is " + LinuxNativeTypesMap.getButtonName(supportedKeys[keyMap[((Keyboard.KeyID) key.getIdentifier()).getKeyIndex()]])); - System.out.println("id for supportedKeys index is " + LinuxNativeTypesMap.getButtonID(supportedKeys[keyMap[((Keyboard.KeyID) key.getIdentifier()).getKeyIndex()]])); - System.out.flush(); - }*/ - if(keyData[keyMap[((Keyboard.KeyID) key.getIdentifier()).getKeyIndex()]] > 0) { - return true; - } - return false; + Axis button = (Axis)keyMap.get(key.getIdentifier()); + if(button.getPollData()!=0) return true; else return false; } /** Polls axes for data. Returns false if the controller is no longer valid. @@ -118,82 +64,19 @@ public class LinuxKeyboard extends StandardKeyboard { * @return False if this device is invalid. */ public boolean poll() { - int retval = nativePoll(nativeID, keyData, dummyRelAxesData, dummyAbsAxesData); - if(retval>=0) return true; - return false; + return realController.poll(); } /** Goes through every key to initialise the key map */ private void setupKeyMap() { - for(int i=0;i