Search in sources :

Example 1 with Type

use of net.java.games.input.Controller.Type in project litiengine by gurkenlabs.

the class GamepadManager method updateGamepads.

private void updateGamepads() {
    this.handleHotPluggedControllers = true;
    try {
        this.hackTheShitOutOfJInputBecauseItSucksHard();
        // update plugged in gamepads
        for (int i = 0; i < ControllerEnvironment.getDefaultEnvironment().getControllers().length; i++) {
            final Controller controller = ControllerEnvironment.getDefaultEnvironment().getControllers()[i];
            final Type type = controller.getType();
            if (!type.equals(Type.GAMEPAD)) {
                continue;
            }
            final IGamepad existing = Input.getGamepad(i);
            if (existing != null && existing.getName().equals(controller.getName())) {
                // already added
                continue;
            }
            // add new gamepads
            final IGamepad newGamepad = new Gamepad(i, controller);
            Input.gamepads().add(newGamepad);
            for (final Consumer<IGamepad> cons : this.gamepadAddedConsumer) {
                cons.accept(newGamepad);
            }
        }
    } catch (IllegalStateException e) {
        this.hotPlugThread.interrupt();
    } finally {
        this.handleHotPluggedControllers = false;
    }
}
Also used : Type(net.java.games.input.Controller.Type) Controller(net.java.games.input.Controller)

Aggregations

Controller (net.java.games.input.Controller)1 Type (net.java.games.input.Controller.Type)1