@Override public boolean awaitControllerSelection() { Controllers.clearEvents(); while(!controllerSelected) { Controllers.poll(); if(Controllers.next()) { if(Controllers.isEventButton()) { controllerSelected = true; selectedController = Controllers.getEventSource(); int selectedButton = Controllers.getEventControlIndex(); while(selectedController.isButtonPressed(selectedButton))selectedController.poll(); return true; } } } return false; }
/** * */ private void logAllControllers() { for (int i = 0; i < Controllers.getControllerCount(); i++) { final Controller controller = Controllers.getController(i); Log.debug(controller.getName()); final int controllerAxisCount = controller.getAxisCount(); Log.debug("org.lwjgl.input.Controller#getAxisName"); for (int j = 0; j < controllerAxisCount; j++) { Log.debug(controller.getAxisName(j)); } final int controllerButtonCount = controller.getButtonCount(); Log.debug("org.lwjgl.input.Controller#getButtonCount"); Log.debug(String.valueOf(controllerButtonCount)); Log.debug("org.lwjgl.input.Controller#getButtonName"); for (int j = 0; j < controllerButtonCount; j++) { Log.debug(controller.getButtonName(j)); } final int controllerRumblerCount = controller.getRumblerCount(); Log.debug("org.lwjgl.input.Controller#getRumblerName"); for (int j = 0; j < controllerRumblerCount; j++) { Log.debug(controller.getRumblerName(j)); } controllers.add(controller); } }
public RemoteController(ChessbotCommunicator comm, int botID) { PropertyConfigurator.configure("log/log4j.properties"); this.comm = comm; this.botID = botID; try { Controllers.create(); } catch (LWJGLException e) { log.info("Exception", e); } Controllers.poll(); if (Controllers.getControllerCount() != 0) { controller = Controllers.getController(0); log.info("Found controller"); } else log.info("Could not find any controllers"); }
@Override public ByteBuf getControllerData() { Controllers.poll(); ByteBuf buf = SerializationHelper.serializeControllerData(Unpooled.buffer(), selectedController); if(debug)debug(); Controllers.clearEvents(); return buf; }
private void debug() { while(Controllers.next()) { if(Controllers.isEventButton() && Controllers.getEventButtonState()) { System.out.println(String.format("Button '%s' was pressed!", Controllers.getEventControlIndex())); } else if(Controllers.isEventAxis() && Controllers.getEventSource().getAxisValue(Controllers.getEventControlIndex()) != 0.0) { System.out.println(String.format("Axis '%s' was moved!", Controllers.getEventControlIndex())); } else if(Controllers.isEventPovX() || Controllers.isEventPovY()) { System.out.println("POV-Action!"); } } }
static void pollDevices() { // Poll the input devices while we're here if ( Mouse.isCreated() ) { Mouse.poll(); Mouse.updateCursor(); } if ( Keyboard.isCreated() ) { Keyboard.poll(); } if ( Controllers.isCreated() ) { Controllers.poll(); } }
public void start() { try { Controllers.create(); } catch (LWJGLException e) { e.printStackTrace(); return; } System.out.println("Controllers.getControllerCount() = " + Controllers.getControllerCount()); }
public void tick(GameContainer gc, long delta) { for (int i = 0; i < Controllers.getControllerCount(); i++) { if (Controllers.getController(i).getName().startsWith("Controller")) { xAxis = Controllers.getController(i).getXAxisValue(); yAxis = Controllers.getController(i).getYAxisValue(); xSecondAxis = Controllers.getController(i).getAxisValue(3); ySecondAxis = Controllers.getController(i).getAxisValue(2); if (xAxis != -1) xChange = true; if (yAxis != -1) yChange = true; if (xSecondAxis != -1) xSecondChange = true; if (ySecondAxis != -1) ySecondChange = true; if (xAxis == -1 && !xChange) xAxis = 0; if (yAxis == -1 && !yChange) yAxis = 0; if (xSecondAxis == -1 && !xSecondChange) xSecondAxis = 0; if (ySecondAxis == -1 && !ySecondChange) ySecondAxis = 0; } } ScreenshotTaker.tick(gc); if (paused) return; Entity.staticTick(delta); Animation.staticTick(); gsm.tick(); Editor.tick(); }
/** * */ @SuppressWarnings("unused") private void logFirstController() { if(controllers.size() >= 1) { final Controller firstController = controllers.get(0); while(Controllers.next()) { if(Controllers.getEventSource().equals(firstController)) { if(Controllers.isEventAxis()) { Log.debug("isEventAxis"); if(Controllers.isEventXAxis()) { Log.debug("isEventXAxis"); } if(Controllers.isEventYAxis()) { Log.debug("isEventYAxis"); } } if(Controllers.isEventButton()) { final int eventControlIndex = Controllers.getEventControlIndex(); final Xbox360ControllerButton xbox360ControllerButton = valueOf(eventControlIndex); final ButtonState buttonState = ButtonState.valueOf(Controllers.getEventButtonState()); buttonStateMap.put(xbox360ControllerButton, buttonState); final Set<Map.Entry<Xbox360ControllerButton, ButtonState>> entrySet = buttonStateMap.entrySet(); for (Map.Entry<Xbox360ControllerButton, ButtonState> entry: entrySet) { Log.debug(entry.getKey().name() + entry.getValue().name()); } } if(Controllers.isEventPovX()) { Log.debug("isEventPovX"); } if(Controllers.isEventPovY()) { Log.debug("isEventPovY"); } } } } }
@Override public Control[] getPossibleControls() { List<Control> possibleControls = new ArrayList<Control>(); try { if (!Controllers.isCreated()) { Controllers.create(); } for (int c = 0; c < Controllers.getControllerCount(); ++c) { Controller pad = Controllers.getController(c); for (int a = 0; a < pad.getAxisCount(); ++a) { possibleControls.add(new GamepadAxisControl(pad, a, true)); possibleControls.add(new GamepadAxisControl(pad, a, false)); } for (int b = 0; b < pad.getButtonCount(); ++b) { possibleControls.add(new GamepadButtonControl(pad, b)); } } } catch (LWJGLException ex) { Logger.getLogger(LwjglNuitControls.class.getName()).log(Level.SEVERE, null, ex); } for (Field field : Keyboard.class.getFields()) { String name = field.getName(); if (name.startsWith("KEY_")) { try { int key = field.getInt(null); possibleControls.add(new KeyControl(key)); } catch (Exception e) { Logger.getLogger(ControlsConfigurator.class.getName()).log(Level.SEVERE, "error retrieving key", e); } } } for (int m = 0; m < Mouse.getButtonCount(); ++m) { possibleControls.add(new MouseButtonControl(m)); } return possibleControls.toArray(new Control[possibleControls.size()]); }
@Override public Control[] getDefaultMenuUpControls() { Control[] controls = new Control[2]; controls[0] = new KeyControl(Keyboard.KEY_UP); controls[1] = NullControl.INSTANCE; for (int c = 0; c < Controllers.getControllerCount(); ++c) { Controller pad = Controllers.getController(c); if (pad.getAxisCount() >= 2) { controls[1] = new GamepadAxisControl(pad, 1, true); } } return controls; }
@Override public Control[] getDefaultMenuDownControls() { Control[] controls = new Control[2]; controls[0] = new KeyControl(Keyboard.KEY_DOWN); controls[1] = NullControl.INSTANCE; for (int c = 0; c < Controllers.getControllerCount(); ++c) { Controller pad = Controllers.getController(c); if (pad.getAxisCount() >= 2) { controls[1] = new GamepadAxisControl(pad, 1, false); } } return controls; }
@Override public Control[] getDefaultMenuLeftControls() { Control[] controls = new Control[2]; controls[0] = new KeyControl(Keyboard.KEY_LEFT); controls[1] = NullControl.INSTANCE; for (int c = 0; c < Controllers.getControllerCount(); ++c) { Controller pad = Controllers.getController(c); if (pad.getAxisCount() >= 1) { controls[1] = new GamepadAxisControl(pad, 0, false); } } return controls; }
@Override public Control[] getDefaultMenuRightControls() { Control[] controls = new Control[2]; controls[0] = new KeyControl(Keyboard.KEY_RIGHT); controls[1] = NullControl.INSTANCE; for (int c = 0; c < Controllers.getControllerCount(); ++c) { Controller pad = Controllers.getController(c); if (pad.getAxisCount() >= 1) { controls[1] = new GamepadAxisControl(pad, 0, true); } } return controls; }
@Override public Control[] getDefaultMenuOkControls() { Control[] controls = new Control[2]; controls[0] = new KeyControl(Keyboard.KEY_RETURN); controls[1] = NullControl.INSTANCE; for (int c = 0; c < Controllers.getControllerCount(); ++c) { Controller pad = Controllers.getController(c); if (pad.getButtonCount() >= 1) { controls[1] = new GamepadButtonControl(pad, 0); } } return controls; }
@Override public Control[] getDefaultMenuCancelControls() { Control[] controls = new Control[2]; controls[0] = new KeyControl(Keyboard.KEY_ESCAPE); controls[1] = NullControl.INSTANCE; for (int c = 0; c < Controllers.getControllerCount(); ++c) { Controller pad = Controllers.getController(c); if (pad.getButtonCount() >= 2) { controls[1] = new GamepadButtonControl(pad, 1); } } return controls; }
public void tick() { game.setDelta(1.0f / 60.0f); game.process(); Display.update(false); Display.sync(60); Display.processMessages(); Mouse.poll(); Keyboard.poll(); Controllers.poll(); }
private void initGamepads() { try { Controllers.create(); } catch (LWJGLException ex) { logger.log(Level.SEVERE, "Cannot init gamepad support", ex); } }
public static void update() { if (Keyboard.isCreated()) Keyboard.poll(); if (Mouse.isCreated()) Mouse.poll(); if (Controllers.isCreated()) Controllers.poll(); for (Control c : controls.values()) c.update(); }
@Override public float getX() { if (!Controllers.isCreated()) return 0; return Controllers.getController(target).getAxisValue(xAxis); }
@Override public float getY() { if (!Controllers.isCreated()) return 0; return Controllers.getController(target).getAxisValue(yAxis); }
public static void main(String[] args) { try { Controllers.create(); } catch (LWJGLException e) { e.printStackTrace(); } for(String s : args) { if(s.equals("debugControllerInput")) { debug = true; System.out.println("Debugging!"); } } int port = Integer.parseInt(args[0]); System.out.println("Starting IPC-Server, Port: " + port); handler = new NetworkHandler(); IPCMethodProvider provider = new IPCMethodProvider(ProvidedMethods.class, new DaemonMain(), handler); handler.setProvider(provider); EventLoopGroup eventGroup = new NioEventLoopGroup(); Bootstrap b = new Bootstrap(); b.group(eventGroup); b.channel(NioDatagramChannel.class); b.handler(handler); System.out.println("About to start bootstrap..."); ChannelFuture future = b.bind("localhost", port).syncUninterruptibly(); if(future.cause() instanceof BindException) { future.channel().close().syncUninterruptibly(); b.group().shutdownGracefully(); Controllers.destroy(); } Runtime.getRuntime().addShutdownHook(new Thread(() -> { future.channel().close(); Controllers.destroy(); })); future.channel().closeFuture().syncUninterruptibly(); b.group().shutdownGracefully(); }
@Override public boolean hasControllers() { return Controllers.getControllerCount() != 0; }
public void update() { while(Controllers.next()) { handleInput(); } }
@Override public boolean isTriggered() { return Controllers.isCreated() && Controllers.getController(target).isButtonPressed(button); }