mirror of
https://github.com/moonlight-stream/moonlight-embedded.git
synced 2026-04-05 23:46:17 +00:00
more gamepad changes
- now have a menu bar to access settings - now handle user input to assign mappings - fixed some typos - now properly shutdown controller threads on exit - renamed GamepadSettings to GamepadMapping - created a lock to ensure we do not add/remove gamepads from the list while we are handling their events - fixed settings directory booch
This commit is contained in:
@@ -4,6 +4,8 @@ package com.limelight.input;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import com.limelight.nvstream.NvConnection;
|
||||
import com.limelight.settings.GamepadSettingsManager;
|
||||
@@ -12,19 +14,23 @@ import net.java.games.input.Controller;
|
||||
|
||||
public class GamepadHandler {
|
||||
private static LinkedList<Gamepad> gamepads = new LinkedList<Gamepad>();
|
||||
private static Lock gamepadLock = new ReentrantLock();
|
||||
private static NvConnection conn;
|
||||
private static Thread handler;
|
||||
|
||||
private static boolean run = true;
|
||||
|
||||
public static void addGamepads(List<Controller> pads) {
|
||||
|
||||
gamepads.clear();
|
||||
|
||||
LinkedList<Gamepad> newPadList = new LinkedList<Gamepad>();
|
||||
|
||||
GamepadSettings settings = GamepadSettingsManager.getSettings();
|
||||
GamepadMapping settings = GamepadSettingsManager.getSettings();
|
||||
for (Controller pad : pads) {
|
||||
|
||||
gamepads.add(new Gamepad(pad, settings));
|
||||
newPadList.add(new Gamepad(pad, settings));
|
||||
}
|
||||
|
||||
gamepadLock.lock();
|
||||
gamepads = newPadList;
|
||||
gamepadLock.unlock();
|
||||
}
|
||||
|
||||
public static void setConnection(NvConnection connection) {
|
||||
@@ -37,21 +43,29 @@ public class GamepadHandler {
|
||||
|
||||
public static void startUp() {
|
||||
if (handler == null || !handler.isAlive()) {
|
||||
run = true;
|
||||
System.out.println("Gamepad Handler thread starting up");
|
||||
handler = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
while (true) {
|
||||
while (run) {
|
||||
try {
|
||||
gamepadLock.lockInterruptibly();
|
||||
} catch (InterruptedException e1) {
|
||||
run = false;
|
||||
}
|
||||
for (Gamepad gamepad : gamepads) {
|
||||
if (!gamepad.poll()) {
|
||||
break;
|
||||
}
|
||||
|
||||
gamepad.handleEvents(conn);
|
||||
}
|
||||
gamepadLock.unlock();
|
||||
try {
|
||||
Thread.sleep(20);
|
||||
} catch (InterruptedException e) {}
|
||||
} catch (InterruptedException e) {
|
||||
run = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -67,4 +81,8 @@ public class GamepadHandler {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isRunning() {
|
||||
return (handler != null && handler.isAlive());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user