mirror of
https://github.com/moonlight-stream/moonlight-embedded.git
synced 2026-02-16 10:30:47 +00:00
more controller stuff
-new controller listener to be a singleton thread that listens for controller input even when not streaming, then sends input when streaming.\ -main frame will stop controller listener when closing -gamepads should now use the gamepad config settings (WIP)
This commit is contained in:
@@ -5,62 +5,60 @@ import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
|
||||
import com.limelight.input.Gamepad.ControllerType;
|
||||
import com.limelight.nvstream.NvConnection;
|
||||
|
||||
import net.java.games.input.Controller;
|
||||
|
||||
public class GamepadHandler {
|
||||
private static LinkedList<Gamepad> gamepads = new LinkedList<Gamepad>();
|
||||
private static GamepadHandler singleton;
|
||||
private static NvConnection conn;
|
||||
private static Thread handler;
|
||||
|
||||
public static void addGamepads(List<Controller> pads, NvConnection conn) {
|
||||
if (singleton == null) {
|
||||
singleton = new GamepadHandler();
|
||||
singleton.startUp();
|
||||
}
|
||||
public static void addGamepads(List<Controller> pads) {
|
||||
|
||||
gamepads.clear();
|
||||
|
||||
for (Controller pad : pads) {
|
||||
|
||||
gamepads.add(Gamepad.createInstance(conn, pad, getType(pad)));
|
||||
|
||||
gamepads.add(new Gamepad(pad, null)); //TODO: need to create/get the settings for this controller
|
||||
}
|
||||
}
|
||||
|
||||
private static ControllerType getType(Controller pad) {
|
||||
if (pad.getType() == Controller.Type.GAMEPAD) {
|
||||
return ControllerType.XBOX;
|
||||
}
|
||||
if (pad.getName().contains("PLAYSTATION")) {
|
||||
return ControllerType.PS3;
|
||||
}
|
||||
return null;
|
||||
public static void setConnection(NvConnection connection) {
|
||||
conn = connection;
|
||||
}
|
||||
|
||||
|
||||
public static List<Gamepad> getGamepads() {
|
||||
return Collections.unmodifiableList(gamepads);
|
||||
}
|
||||
|
||||
private void startUp() {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
while (true) {
|
||||
for (Gamepad gamepad : gamepads) {
|
||||
if (!gamepad.poll()) {
|
||||
break;
|
||||
|
||||
public static void startUp() {
|
||||
if (handler == null || !handler.isAlive()) {
|
||||
handler = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
while (true) {
|
||||
for (Gamepad gamepad : gamepads) {
|
||||
if (!gamepad.poll()) {
|
||||
break;
|
||||
}
|
||||
gamepad.handleEvents(conn);
|
||||
}
|
||||
gamepad.handleEvents();
|
||||
try {
|
||||
Thread.sleep(20);
|
||||
} catch (InterruptedException e) {}
|
||||
}
|
||||
try {
|
||||
Thread.sleep(20);
|
||||
} catch (InterruptedException e) {}
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
});
|
||||
handler.start();
|
||||
}
|
||||
}
|
||||
|
||||
public static void stopHandler() {
|
||||
if (handler != null && handler.isAlive()) {
|
||||
handler.interrupt();
|
||||
conn = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user