diff --git a/jni/gamepad_jni/Gamepad.h b/jni/gamepad_jni/Gamepad.h deleted file mode 100644 index 3879f2a..0000000 --- a/jni/gamepad_jni/Gamepad.h +++ /dev/null @@ -1,125 +0,0 @@ -/* - Copyright (c) 2013 Alex Diener - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - Alex Diener adiener@sacredsoftware.net -*/ - -#ifndef __GAMEPAD_H__ -#define __GAMEPAD_H__ -#ifdef __cplusplus -extern "C" { -#endif - -#include - -struct Gamepad_device { - // Unique device identifier for application session, starting at 0 for the first device attached and - // incrementing by 1 for each additional device. If a device is removed and subsequently reattached - // during the same application session, it will have a new deviceID. - unsigned int deviceID; - - // Human-readable device name - const char * description; - - // USB vendor/product IDs as returned by the driver. Can be used to determine the particular model of device represented. - int vendorID; - int productID; - - // Number of axis elements belonging to the device - unsigned int numAxes; - - // Number of button elements belonging to the device - unsigned int numButtons; - - // Array[numAxes] of values representing the current state of each axis, in the range [-1..1] - float * axisStates; - - // Array[numButtons] of values representing the current state of each button - bool * buttonStates; - - // Platform-specific device data storage. Don't touch unless you know what you're doing and don't - // mind your code breaking in future versions of this library. - void * privateData; -}; - -/* Initializes gamepad library and detects initial devices. Call this before any other Gamepad_*() - function, other than callback registration functions. If you want to receive deviceAttachFunc - callbacks from devices detected in Gamepad_init(), you must call Gamepad_deviceAttachFunc() - before calling Gamepad_init(). */ -void Gamepad_init(); - -/* Tears down all data structures created by the gamepad library and releases any memory that was - allocated. It is not necessary to call this function at application termination, but it's - provided in case you want to free memory associated with gamepads at some earlier time. */ -void Gamepad_shutdown(); - -/* Returns the number of currently attached gamepad devices. */ -unsigned int Gamepad_numDevices(); - -/* Returns the specified Gamepad_device struct, or NULL if deviceIndex is out of bounds. */ -struct Gamepad_device * Gamepad_deviceAtIndex(unsigned int deviceIndex); - -/* Polls for any devices that have been attached since the last call to Gamepad_detectDevices() or - Gamepad_init(). If any new devices are found, the callback registered with - Gamepad_deviceAttachFunc() (if any) will be called once per newly detected device. - - Note that depending on implementation, you may receive button and axis event callbacks for - devices that have not yet been detected with Gamepad_detectDevices(). You can safely ignore - these events, but be aware that your callbacks might receive a device ID that hasn't been seen - by your deviceAttachFunc. */ -void Gamepad_detectDevices(); - -/* Reads pending input from all attached devices and calls the appropriate input callbacks, if any - have been registered. */ -void Gamepad_processEvents(); - -/* Registers a function to be called whenever a device is attached. The specified function will be - called only during calls to Gamepad_init() and Gamepad_detectDevices(), in the thread from - which those functions were called. Calling this function with a NULL argument will stop any - previously registered callback from being called subsequently. */ -void Gamepad_deviceAttachFunc(void (* callback)(struct Gamepad_device * device, void * context), void * context); - -/* Registers a function to be called whenever a device is detached. The specified function can be - called at any time, and will not necessarily be called from the main thread. Calling this - function with a NULL argument will stop any previously registered callback from being called - subsequently. */ -void Gamepad_deviceRemoveFunc(void (* callback)(struct Gamepad_device * device, void * context), void * context); - -/* Registers a function to be called whenever a button on any attached device is pressed. The - specified function will be called only during calls to Gamepad_processEvents(), in the - thread from which Gamepad_processEvents() was called. Calling this function with a NULL - argument will stop any previously registered callback from being called subsequently. */ -void Gamepad_buttonDownFunc(void (* callback)(struct Gamepad_device * device, unsigned int buttonID, double timestamp, void * context), void * context); - -/* Registers a function to be called whenever a button on any attached device is released. The - specified function will be called only during calls to Gamepad_processEvents(), in the - thread from which Gamepad_processEvents() was called. Calling this function with a NULL - argument will stop any previously registered callback from being called subsequently. */ -void Gamepad_buttonUpFunc(void (* callback)(struct Gamepad_device * device, unsigned int buttonID, double timestamp, void * context), void * context); - -/* Registers a function to be called whenever an axis on any attached device is moved. The - specified function will be called only during calls to Gamepad_processEvents(), in the - thread from which Gamepad_processEvents() was called. Calling this function with a NULL - argument will stop any previously registered callback from being called subsequently. */ -void Gamepad_axisMoveFunc(void (* callback)(struct Gamepad_device * device, unsigned int axisID, float value, float lastValue, double timestamp, void * context), void * context); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/jni/gamepad_jni/buildlinux.sh b/jni/gamepad_jni/buildlinux.sh deleted file mode 100755 index 82a6c73..0000000 --- a/jni/gamepad_jni/buildlinux.sh +++ /dev/null @@ -1,5 +0,0 @@ -rm *.o libgamepad_jni.so -gcc -I /usr/lib/jvm/java-7-openjdk-amd64/include/ -fPIC -c *.c -gcc -shared -Wl,-soname,libgamepad_jni.so -Wl,--no-undefined -o libgamepad_jni.so *.o -L./lin64 -lstem_gamepad -lpthread -rm *.o - diff --git a/jni/gamepad_jni/buildosx.sh b/jni/gamepad_jni/buildosx.sh deleted file mode 100644 index 6b07d63..0000000 --- a/jni/gamepad_jni/buildosx.sh +++ /dev/null @@ -1,5 +0,0 @@ -rm *.o libgamepad_jni.dylib -gcc -I /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/include/ -I /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/include/darwin -fPIC -c *.c -gcc -shared -o libgamepad_jni.dylib *.o -L./osx -lstem_gamepad -lpthread -framework IOKit -framework CoreFoundation -rm *.o - diff --git a/jni/gamepad_jni/buildwin.sh b/jni/gamepad_jni/buildwin.sh deleted file mode 100644 index 9ac9177..0000000 --- a/jni/gamepad_jni/buildwin.sh +++ /dev/null @@ -1,3 +0,0 @@ -rm gamepad_jni.dll gamepad_jni64.dll -/C/MinGW/bin/gcc -m32 -shared -Wall -I"/C/Program Files (x86)/Java/jdk1.7.0_45/include" -I"/C/Program Files (x86)/Java/jdk1.7.0_45/include/win32" *.c -L./win32 -lstem_gamepad -lxinput9_1_0 -Wl,--no-undefined -Wl,--kill-at -o gamepad_jni.dll -/C/MinGW-w64/bin/gcc -m64 -shared -Wall -I"/C/Program Files (x86)/Java/jdk1.7.0_45/include" -I"/C/Program Files (x86)/Java/jdk1.7.0_45/include/win32" *.c -L./win64 -lstem_gamepad -lxinput9_1_0 -Wl,--no-undefined -Wl,--kill-at -o gamepad_jni64.dll diff --git a/jni/gamepad_jni/gamepad_jni.c b/jni/gamepad_jni/gamepad_jni.c deleted file mode 100644 index 44b3b77..0000000 --- a/jni/gamepad_jni/gamepad_jni.c +++ /dev/null @@ -1,108 +0,0 @@ -#include -#include - -#include "Gamepad.h" - -static JavaVM *jvm; -static jclass nativeGamepadClass; -static jmethodID jdeviceAttached; -static jmethodID jdeviceRemoved; -static jmethodID jbuttonDown; -static jmethodID jbuttonUp; -static jmethodID jaxisMove; - -static JNIEnv *getThreadEnv(void) { - JNIEnv *env; - (*jvm)->GetEnv(jvm, (void**)&env, JNI_VERSION_1_6); - return env; -} - -static void invokeJavaCallback(jmethodID method, ...) { - JNIEnv *env = getThreadEnv(); - va_list args; - va_start(args, method); - (*env)->CallStaticVoidMethodV(env, nativeGamepadClass, method, args); - va_end(args); -} - -static void deviceAttachCallback(struct Gamepad_device * device, void * context) { - invokeJavaCallback(jdeviceAttached, device->deviceID, device->numButtons, device->numAxes); -} - -static void deviceRemoveCallback(struct Gamepad_device * device, void * context) { - invokeJavaCallback(jdeviceRemoved, device->deviceID); -} - -static void buttonDownCallback(struct Gamepad_device * device, unsigned int buttonID, double timestamp, void * context) { - invokeJavaCallback(jbuttonDown, device->deviceID, buttonID); -} - -static void buttonUpCallback(struct Gamepad_device * device, unsigned int buttonID, double timestamp, void * context) { - invokeJavaCallback(jbuttonUp, device->deviceID, buttonID); -} - -static void axisMoveCallback(struct Gamepad_device * device, unsigned int axisID, float value, float lastValue, double timestamp, void * context) { - invokeJavaCallback(jaxisMove, device->deviceID, axisID, value, lastValue); -} - -// This function must be called first -JNIEXPORT void JNICALL -Java_com_limelight_input_gamepad_NativeGamepad_init(JNIEnv *env, jobject this) { - Gamepad_deviceAttachFunc(deviceAttachCallback, NULL); - Gamepad_deviceRemoveFunc(deviceRemoveCallback, NULL); - Gamepad_buttonDownFunc(buttonDownCallback, NULL); - Gamepad_buttonUpFunc(buttonUpCallback, NULL); - Gamepad_axisMoveFunc(axisMoveCallback, NULL); - - Gamepad_init(); -} - -// This function must be called last -JNIEXPORT void JNICALL -Java_com_limelight_input_gamepad_NativeGamepad_shutdown(JNIEnv *env, jobject this) { - Gamepad_shutdown(); - - // Remove the class reference - (*env)->DeleteGlobalRef(env, nativeGamepadClass); -} - -// This returns the number of connected devices -JNIEXPORT jint JNICALL -Java_com_limelight_input_gamepad_NativeGamepad_numDevices(JNIEnv *env, jobject this) { - return Gamepad_numDevices(); -} - -// This triggers device detection -JNIEXPORT void JNICALL -Java_com_limelight_input_gamepad_NativeGamepad_detectDevices(JNIEnv *env, jobject this) { - Gamepad_detectDevices(); -} - -// This polls for events and calls the appropriate callbacks -JNIEXPORT void JNICALL -Java_com_limelight_input_gamepad_NativeGamepad_processEvents(JNIEnv *env, jobject this) { - Gamepad_processEvents(); -} - -// This is called when the library is first loaded -JNIEXPORT jint JNICALL -JNI_OnLoad(JavaVM *pjvm, void *reserved) { - JNIEnv *env; - - // This has to be saved before getThreadEnv() can be called - jvm = pjvm; - - env = getThreadEnv(); - - // We use a global reference to keep the class loaded - nativeGamepadClass = (*env)->NewGlobalRef(env, (*env)->FindClass(env, "com/limelight/input/gamepad/NativeGamepad")); - - // These method IDs are only valid as long as the NativeGamepad class is loaded - jdeviceAttached = (*env)->GetStaticMethodID(env, nativeGamepadClass, "deviceAttachCallback", "(III)V"); - jdeviceRemoved = (*env)->GetStaticMethodID(env, nativeGamepadClass, "deviceRemoveCallback", "(I)V"); - jbuttonDown = (*env)->GetStaticMethodID(env, nativeGamepadClass, "buttonDownCallback", "(II)V"); - jbuttonUp = (*env)->GetStaticMethodID(env, nativeGamepadClass, "buttonUpCallback", "(II)V"); - jaxisMove = (*env)->GetStaticMethodID(env, nativeGamepadClass, "axisMovedCallback", "(IIFF)V"); - - return JNI_VERSION_1_6; -} diff --git a/jni/gamepad_jni/lin32/libstem_gamepad.a b/jni/gamepad_jni/lin32/libstem_gamepad.a deleted file mode 100644 index 2ddf5f6..0000000 Binary files a/jni/gamepad_jni/lin32/libstem_gamepad.a and /dev/null differ diff --git a/jni/gamepad_jni/lin64/libstem_gamepad.a b/jni/gamepad_jni/lin64/libstem_gamepad.a deleted file mode 100644 index c78ee79..0000000 Binary files a/jni/gamepad_jni/lin64/libstem_gamepad.a and /dev/null differ diff --git a/jni/gamepad_jni/osx/libstem_gamepad.a b/jni/gamepad_jni/osx/libstem_gamepad.a deleted file mode 100644 index dff2576..0000000 Binary files a/jni/gamepad_jni/osx/libstem_gamepad.a and /dev/null differ diff --git a/jni/gamepad_jni/win32/libstem_gamepad.a b/jni/gamepad_jni/win32/libstem_gamepad.a deleted file mode 100644 index 669aa33..0000000 Binary files a/jni/gamepad_jni/win32/libstem_gamepad.a and /dev/null differ diff --git a/jni/gamepad_jni/win32/libxinput9_1_0.a b/jni/gamepad_jni/win32/libxinput9_1_0.a deleted file mode 100644 index d4bc693..0000000 Binary files a/jni/gamepad_jni/win32/libxinput9_1_0.a and /dev/null differ diff --git a/jni/gamepad_jni/win64/libstem_gamepad.a b/jni/gamepad_jni/win64/libstem_gamepad.a deleted file mode 100644 index 564b448..0000000 Binary files a/jni/gamepad_jni/win64/libstem_gamepad.a and /dev/null differ diff --git a/jni/gamepad_jni/win64/libxinput9_1_0.a b/jni/gamepad_jni/win64/libxinput9_1_0.a deleted file mode 100644 index 36923c5..0000000 Binary files a/jni/gamepad_jni/win64/libxinput9_1_0.a and /dev/null differ diff --git a/src/com/limelight/Limelight.java b/src/com/limelight/Limelight.java index ea99f3a..0936aaf 100644 --- a/src/com/limelight/Limelight.java +++ b/src/com/limelight/Limelight.java @@ -5,8 +5,6 @@ import java.io.IOException; import com.limelight.binding.LibraryHelper; import com.limelight.binding.PlatformBinding; import com.limelight.input.EvdevHandler; -import com.limelight.input.gamepad.Gamepad; -import com.limelight.input.gamepad.GamepadListener; import com.limelight.nvstream.NvConnection; import com.limelight.nvstream.NvConnectionListener; import com.limelight.nvstream.StreamConfiguration; @@ -59,8 +57,6 @@ public class Limelight implements NvConnectionListener { displayError("Input", "Input (" + input + ") could not be found"); } } - - GamepadListener.getInstance().addDeviceListener(new Gamepad(conn)); } private void pair() { diff --git a/src/com/limelight/input/gamepad/Gamepad.java b/src/com/limelight/input/gamepad/Gamepad.java deleted file mode 100644 index 96914bd..0000000 --- a/src/com/limelight/input/gamepad/Gamepad.java +++ /dev/null @@ -1,222 +0,0 @@ -package com.limelight.input.gamepad; - -import com.limelight.input.Device; -import com.limelight.input.DeviceListener; -import com.limelight.input.gamepad.GamepadMapping.Mapping; -import com.limelight.input.gamepad.SourceComponent.Type; -import com.limelight.nvstream.NvConnection; -import com.limelight.nvstream.input.ControllerPacket; -import com.limelight.settings.GamepadSettingsManager; - -/** - * Represents a gamepad connected to the system - * @author Diego Waxemberg - */ -public class Gamepad implements DeviceListener { - - private short inputMap = 0x0000; - private byte leftTrigger = 0x00; - private byte rightTrigger = 0x00; - private short rightStickX = 0x0000; - private short rightStickY = 0x0000; - private short leftStickX = 0x0000; - private short leftStickY = 0x0000; - - private NvConnection conn; - - public Gamepad(NvConnection conn) { - this.conn = conn; - } - - public Gamepad() { - this(null); - } - - public void setConnection(NvConnection conn) { - this.conn = conn; - } - - @Override - public void handleButton(Device device, int buttonId, boolean pressed) { - GamepadMapping mapping = GamepadSettingsManager.getSettings(); - - Mapping mapped = mapping.get(new SourceComponent(Type.BUTTON, buttonId)); - if (mapped == null) { - System.out.println("Unmapped button pressed: " + buttonId); - return; - } - - if (!mapped.padComp.isAnalog()) { - handleDigitalComponent(mapped, pressed); - } else { - handleAnalogComponent(mapped.padComp, sanitizeValue(mapped, pressed)); - } - - //printInfo(device, new SourceComponent(Type.BUTTON, buttonId), mapped.padComp, pressed ? 1F : 0F); - } - - @Override - public void handleAxis(Device device, int axisId, float newValue, float lastValue) { - GamepadMapping mapping = GamepadSettingsManager.getSettings(); - - Mapping mapped = mapping.get(new SourceComponent(Type.AXIS, axisId)); - if (mapped == null) { - System.out.println("Unmapped axis moved: " + axisId); - return; - } - - float value = sanitizeValue(mapped, newValue); - - if (mapped.padComp.isAnalog()) { - handleAnalogComponent(mapped.padComp, value); - } else { - handleDigitalComponent(mapped, (value > 0.5)); - } - - //printInfo(device, new SourceComponent(Type.AXIS, axisId), mapped.padComp, newValue); - } - - private float sanitizeValue(Mapping mapped, boolean value) { - if (mapped.invert) { - return value ? 0F : 1F; - } else { - return value ? 1F : 0F; - } - } - - private float sanitizeValue(Mapping mapped, float value) { - float retVal = value; - if (mapped.invert) { - retVal = -retVal; - } - if (mapped.trigger) { - retVal = (retVal + 1) / 2; - } - return retVal; - } - - private void handleAnalogComponent(GamepadComponent padComp, float value) { - switch (padComp) { - case LS_X: - leftStickX = (short)Math.round(value * 0x7FFF); - break; - case LS_Y: - leftStickY = (short)Math.round(value * 0x7FFF); - break; - case RS_X: - rightStickX = (short)Math.round(value * 0x7FFF); - break; - case RS_Y: - rightStickY = (short)Math.round(value * 0x7FFF); - break; - case LT: - leftTrigger = (byte)Math.round(value * 0xFF); - break; - case RT: - rightTrigger = (byte)Math.round(value * 0xFF); - break; - default: - System.out.println("A mapping error has occured. Ignoring: " + padComp.name()); - break; - } - if (conn != null) { - sendControllerPacket(); - } - } - - - private void handleDigitalComponent(Mapping mapped, boolean pressed) { - switch (mapped.padComp) { - case BTN_A: - toggle(ControllerPacket.A_FLAG, pressed); - break; - case BTN_X: - toggle(ControllerPacket.X_FLAG, pressed); - break; - case BTN_Y: - toggle(ControllerPacket.Y_FLAG, pressed); - break; - case BTN_B: - toggle(ControllerPacket.B_FLAG, pressed); - break; - case DPAD_UP: - toggle(ControllerPacket.UP_FLAG, pressed); - break; - case DPAD_DOWN: - toggle(ControllerPacket.DOWN_FLAG, pressed); - break; - case DPAD_LEFT: - toggle(ControllerPacket.LEFT_FLAG, pressed); - break; - case DPAD_RIGHT: - toggle(ControllerPacket.RIGHT_FLAG, pressed); - break; - case LS_THUMB: - toggle(ControllerPacket.LS_CLK_FLAG, pressed); - break; - case RS_THUMB: - toggle(ControllerPacket.RS_CLK_FLAG, pressed); - break; - case LB: - toggle(ControllerPacket.LB_FLAG, pressed); - break; - case RB: - toggle(ControllerPacket.RB_FLAG, pressed); - break; - case BTN_START: - toggle(ControllerPacket.PLAY_FLAG, pressed); - break; - case BTN_BACK: - toggle(ControllerPacket.BACK_FLAG, pressed); - break; - case BTN_SPECIAL: - toggle(ControllerPacket.SPECIAL_BUTTON_FLAG, pressed); - break; - default: - System.out.println("A mapping error has occured. Ignoring: " + mapped.padComp.name()); - return; - } - if (conn != null) { - sendControllerPacket(); - } - } - - /* - * Sends a controller packet to the specified connection containing the current gamepad values - */ - private void sendControllerPacket() { - if (conn != null) { - conn.sendControllerInput(inputMap, leftTrigger, rightTrigger, - leftStickX, leftStickY, rightStickX, rightStickY); - } - } - - /* - * Prints out the specified event information for the given gamepad - * used for debugging, normally unused. - */ - @SuppressWarnings("unused") - private void printInfo(Device device, SourceComponent sourceComp, GamepadComponent padComp, float value) { - - StringBuilder builder = new StringBuilder(); - - builder.append(sourceComp.getType().name() + ": "); - builder.append(sourceComp.getId() + " "); - builder.append("mapped to: " + padComp + " "); - builder.append("changed to "); - - System.out.println(builder.toString()); - } - - /* - * Toggles a flag that indicates the specified button was pressed or released - */ - private void toggle(short button, boolean pressed) { - if (pressed) { - inputMap |= button; - } else { - inputMap &= ~button; - } - } - -} diff --git a/src/com/limelight/input/gamepad/GamepadComponent.java b/src/com/limelight/input/gamepad/GamepadComponent.java deleted file mode 100644 index 4b47e71..0000000 --- a/src/com/limelight/input/gamepad/GamepadComponent.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.limelight.input.gamepad; - -import java.io.Serializable; - -import javax.swing.JLabel; - -/** - * Enumerator for every gamepad component GFE recognizes - * @author Diego Waxemberg - */ -public enum GamepadComponent implements Serializable { - BTN_A("Button 1 (A)", false), BTN_X("Button 2 (X)", false), BTN_Y("Button 3 (Y)", false), BTN_B("Button 4 (B)", false), - DPAD_UP("D-pad Up", false), DPAD_DOWN("D-pad Down", false), DPAD_LEFT("D-pad Left", false), DPAD_RIGHT("D-pad Right", false), - LS_X("Left Stick X", true), LS_Y("Left Stick Y", true), RS_X("Right Stick X", true), RS_Y("Right Stick Y", true), - LS_THUMB("Left Stick Button", false), RS_THUMB("Right Stick Button", false), - LT("Left Trigger", true), RT("Right Trigger", true), LB("Left Bumper", false), RB("Right Bumper", false), - BTN_START("Start Button", false), BTN_BACK("Back Button", false), BTN_SPECIAL("Special Button", false); - - private JLabel label; - private boolean analog; - - /* - * Constructs the enumerator with the given name for a label and whether it is analog or not - */ - private GamepadComponent(String name, boolean analog) { - this.label = new JLabel(name); - this.analog = analog; - } - - /** - * Gets the label for this gamepad component - * @return a label with the name of this component as the text - */ - public JLabel getLabel() { - return label; - } - - /** - * Checks if this component is analog or digital - * @return whether this component is analog - */ - public boolean isAnalog() { - return analog; - } -} diff --git a/src/com/limelight/input/gamepad/GamepadListener.java b/src/com/limelight/input/gamepad/GamepadListener.java deleted file mode 100644 index b764469..0000000 --- a/src/com/limelight/input/gamepad/GamepadListener.java +++ /dev/null @@ -1,83 +0,0 @@ -package com.limelight.input.gamepad; - -import java.util.Collections; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; - -import com.limelight.input.Device; -import com.limelight.input.DeviceListener; - -/** - * Listens to Controllers connected to this computer and gives any gamepad to the gamepad handler - * @author Diego Waxemberg - */ -public class GamepadListener implements NativeGamepadListener { - private HashMap devices; - private List listeners; - - private static GamepadListener singleton; - - public static GamepadListener getInstance() { - if (singleton == null) { - singleton = new GamepadListener(); - } - return singleton; - } - - private GamepadListener() { - devices = new HashMap(); - listeners = new LinkedList(); - } - - public int deviceCount() { - return devices.size(); - } - - public void addDeviceListener(DeviceListener listener) { - listeners.add(listener); - } - - public List getListeners() { - return Collections.unmodifiableList(listeners); - } - - public void removeListener(DeviceListener listener) { - listeners.remove(listener); - } - - @Override - public void deviceAttached(int deviceId, int numButtons, int numAxes) { - devices.put(deviceId, new Device(deviceId, numButtons, numAxes)); - } - - @Override - public void deviceRemoved(int deviceId) { - devices.remove(deviceId); - } - - @Override - public void buttonDown(int deviceId, int buttonId) { - Device dev = devices.get(deviceId); - for (DeviceListener listener : listeners) { - listener.handleButton(dev, buttonId, true); - } - } - - @Override - public void buttonUp(int deviceId, int buttonId) { - Device dev = devices.get(deviceId); - for (DeviceListener listener : listeners) { - listener.handleButton(dev, buttonId, false); - } - } - - @Override - public void axisMoved(int deviceId, int axisId, float value, float lastValue) { - Device dev = devices.get(deviceId); - for (DeviceListener listener : listeners) { - listener.handleAxis(dev, axisId, value, lastValue); - } - } - -} diff --git a/src/com/limelight/input/gamepad/GamepadMapping.java b/src/com/limelight/input/gamepad/GamepadMapping.java deleted file mode 100644 index a4f328f..0000000 --- a/src/com/limelight/input/gamepad/GamepadMapping.java +++ /dev/null @@ -1,114 +0,0 @@ -package com.limelight.input.gamepad; - -import java.io.Serializable; -import java.util.HashMap; -import java.util.Map.Entry; - -/** - * Mappings for gamepad components - * @author Diego Waxemberg - */ -public class GamepadMapping implements Serializable { - private static final long serialVersionUID = -185035113915743149L; - - private HashMap mapping; - - /** - * Constructs a new mapping that has nothing mapped. - */ - public GamepadMapping() { - mapping = new HashMap(); - } - - /** - * Inserts the specified mapping into this map - * @param toMap a Mapping that will be mapped to the specified gamepad component - * @param comp the gamepad component to map to. - */ - public void insertMapping(Mapping toMap, SourceComponent comp) { - mapping.put(comp, toMap); - } - - /** - * Gets the mapping for the specified gamepad component - * @param comp the gamepad component to get a mapping for - * @return a mapping for the requested component - */ - public Mapping get(SourceComponent comp) { - return mapping.get(comp); - } - - /** - * Removes the mapping to the specified component - * @param comp the component to no longer be mapped. - */ - public void remove(SourceComponent comp) { - mapping.remove(comp); - } - - /** - * Gets the mapped ControllerComponent for the specified ControllerComponent.
- * NOTE: Iterates a hashmap, use sparingly - * @param padComp the component to get a mapping for - * @return a mapping or an null if there is none - */ - public Mapping get(GamepadComponent padComp) { - //#allTheJank - for (Entry entry : mapping.entrySet()) { - if (entry.getValue().padComp == padComp) { - return entry.getValue(); - } - } - return null; - } - - /** - * Gets the mapping for the specified component.
- * NOTE: Iterates a hashmap, use sparingly - * @param padComp the component to get a mapping for - * @return a mapping or an empty string if there is none - */ - public SourceComponent getMapping(GamepadComponent padComp) { - for (Entry entry : mapping.entrySet()) { - if (entry.getValue().padComp == padComp) { - return entry.getKey(); - } - } - return null; - } - - /** - * Represents a mapping, that is which gamepad component, whether it is inverted, a trigger, etc. - * @author Diego Waxemberg - */ - public class Mapping implements Serializable { - private static final long serialVersionUID = -8407172977953214242L; - - /** - * The component this mapping belongs to - */ - public GamepadComponent padComp; - - /** - * Whether the value of this component should be inverted - */ - public boolean invert; - - /** - * Whether this component should be treated as a trigger - */ - public boolean trigger; - - /** - * Constructs a new mapping with the specified configuration - * @param padComp the component this mapping belongs to - * @param invert whether the value should be inverted - * @param trigger whether this component should be treated as a trigger - */ - public Mapping(GamepadComponent padComp, boolean invert, boolean trigger) { - this.padComp = padComp; - this.invert = invert; - this.trigger = trigger; - } - } -} diff --git a/src/com/limelight/input/gamepad/NativeGamepad.java b/src/com/limelight/input/gamepad/NativeGamepad.java deleted file mode 100644 index 83fa5c2..0000000 --- a/src/com/limelight/input/gamepad/NativeGamepad.java +++ /dev/null @@ -1,182 +0,0 @@ -package com.limelight.input.gamepad; - -import java.util.ArrayList; - -public class NativeGamepad { - public static final int DEFAULT_DEVICE_POLLING_INTERVAL = 1000; - public static final int DEFAULT_EVENT_POLLING_INTERVAL = 20; - - private static ArrayList listenerList = - new ArrayList(); - private static boolean running = false; - private static boolean initialized = false; - private static Thread deviceThread = null; - private static Thread eventThread = null; - private static int devicePollingIntervalMs = DEFAULT_DEVICE_POLLING_INTERVAL; - private static int eventPollingIntervalMs = DEFAULT_EVENT_POLLING_INTERVAL; - - static { - System.loadLibrary("gamepad_jni"); - } - - private static native void init(); - private static native void shutdown(); - private static native int numDevices(); - private static native void detectDevices(); - private static native void processEvents(); - - public static void addListener(NativeGamepadListener listener) { - listenerList.add(listener); - } - - public static void removeListener(NativeGamepadListener listener) { - listenerList.remove(listener); - } - - public static boolean isRunning() { - return running; - } - - public static void setDevicePollingInterval(int interval) { - devicePollingIntervalMs = interval; - } - - public static int getDevicePollingInterval() { - return devicePollingIntervalMs; - } - - public static void setEventPollingInterval(int interval) { - eventPollingIntervalMs = interval; - } - - public static int getEventPollingInterval() { - return eventPollingIntervalMs; - } - - public static void start() { - if (!initialized) { - NativeGamepad.init(); - initialized = true; - } - if (!running) { - startDevicePolling(); - startEventPolling(); - running = true; - } - } - - public static void stop() { - if (running) { - stopEventPolling(); - stopDevicePolling(); - running = false; - } - } - - public static void release() { - if (running) { - throw new IllegalStateException("Cannot release running NativeGamepad"); - } - - if (initialized) { - NativeGamepad.shutdown(); - initialized = false; - } - } - - public static int getDeviceCount() { - if (!running) { - throw new IllegalStateException("NativeGamepad not running"); - } - - return NativeGamepad.numDevices(); - } - - private static void startDevicePolling() { - deviceThread = new Thread() { - @Override - public void run() { - while (!isInterrupted()) { - NativeGamepad.detectDevices(); - - try { - Thread.sleep(devicePollingIntervalMs); - } catch (InterruptedException e) { - return; - } - } - } - }; - deviceThread.setName("Native Gamepad - Device Polling Thread"); - deviceThread.start(); - } - - private static void startEventPolling() { - eventThread = new Thread() { - @Override - public void run() { - while (!isInterrupted()) { - NativeGamepad.processEvents(); - - try { - Thread.sleep(eventPollingIntervalMs); - } catch (InterruptedException e) { - return; - } - } - } - }; - eventThread.setName("Native Gamepad - Event Polling Thread"); - eventThread.start(); - } - - private static void stopDevicePolling() { - if (deviceThread != null) { - deviceThread.interrupt(); - - try { - deviceThread.join(); - } catch (InterruptedException e) {} - } - } - - private static void stopEventPolling() { - if (eventThread != null) { - eventThread.interrupt(); - - try { - eventThread.join(); - } catch (InterruptedException e) {} - } - } - - public static void deviceAttachCallback(int deviceId, int numButtons, int numAxes) { - for (NativeGamepadListener listener : listenerList) { - listener.deviceAttached(deviceId, numButtons, numAxes); - } - } - - public static void deviceRemoveCallback(int deviceId) { - for (NativeGamepadListener listener : listenerList) { - listener.deviceRemoved(deviceId); - } - } - - public static void buttonUpCallback(int deviceId, int buttonId) { - for (NativeGamepadListener listener : listenerList) { - listener.buttonUp(deviceId, buttonId); - } - } - - public static void buttonDownCallback(int deviceId, int buttonId) { - for (NativeGamepadListener listener : listenerList) { - listener.buttonDown(deviceId, buttonId); - } - } - - public static void axisMovedCallback(int deviceId, int axisId, float value, float lastValue) { - for (NativeGamepadListener listener : listenerList) { - listener.axisMoved(deviceId, axisId, value, lastValue); - } - } -} diff --git a/src/com/limelight/input/gamepad/NativeGamepadListener.java b/src/com/limelight/input/gamepad/NativeGamepadListener.java deleted file mode 100644 index 95bbd54..0000000 --- a/src/com/limelight/input/gamepad/NativeGamepadListener.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.limelight.input.gamepad; - -public interface NativeGamepadListener { - public void deviceAttached(int deviceId, int numButtons, int numAxes); - - public void deviceRemoved(int deviceId); - - public void buttonDown(int deviceId, int buttonId); - - public void buttonUp(int deviceId, int buttonId); - - public void axisMoved(int deviceId, int axisId, float value, float lastValue); -} diff --git a/src/com/limelight/input/gamepad/SourceComponent.java b/src/com/limelight/input/gamepad/SourceComponent.java deleted file mode 100644 index fe48c1e..0000000 --- a/src/com/limelight/input/gamepad/SourceComponent.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.limelight.input.gamepad; - -import java.io.Serializable; - -public class SourceComponent implements Serializable { - private static final long serialVersionUID = 2366409458045238273L; - - public enum Type { AXIS, BUTTON } - private Type type; - private int id; - - public SourceComponent(Type type, int id) { - this.type = type; - this.id = id; - } - - public Type getType() { - return type; - } - - public int getId() { - return id; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + id; - result = prime * result + ((type == null) ? 0 : type.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null || !(obj instanceof SourceComponent)) { - return false; - } - SourceComponent other = (SourceComponent) obj; - - return id == other.id && type == other.type; - } -} diff --git a/src/com/limelight/settings/GamepadSettingsManager.java b/src/com/limelight/settings/GamepadSettingsManager.java deleted file mode 100644 index a84d9d5..0000000 --- a/src/com/limelight/settings/GamepadSettingsManager.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.limelight.settings; - -import java.io.File; - -import com.limelight.input.gamepad.GamepadMapping; - -/** - * Manages the gamepad settings - * @author Diego Waxemberg - */ -public abstract class GamepadSettingsManager { - private static GamepadMapping cachedSettings; - - /** - * Reads the gamepad settings from the gamepad file and caches the configuration - * @return the gamepad settings - */ - public static GamepadMapping getSettings() { - if (cachedSettings == null) { - System.out.println("Reading Gamepad Settings"); - File gamepadFile = SettingsManager.getInstance().getGamepadFile(); - GamepadMapping savedMapping = (GamepadMapping)SettingsManager.readSettings(gamepadFile); - cachedSettings = savedMapping; - } - if (cachedSettings == null) { - System.out.println("Unable to get gamepad settings. Using an empty mapping instead."); - cachedSettings = new GamepadMapping(); - writeSettings(cachedSettings); - } - return cachedSettings; - } - - /** - * Writes the specified mapping to the gamepad file and updates the cached settings - * @param settings the new gamepad mapping to be written out - */ - public static void writeSettings(GamepadMapping settings) { - cachedSettings = settings; - System.out.println("Writing Gamepad Settings"); - - File gamepadFile = SettingsManager.getInstance().getGamepadFile(); - - SettingsManager.writeSettings(gamepadFile, settings); - } - -}