use of net.java.games.input.Event in project Terasology by MovingBlocks.
the class JInputControllerDevice method getInputQueue.
@Override
public Queue<ControllerAction> getInputQueue() {
Queue<ControllerAction> result = new ArrayDeque<>();
Event event = new Event();
Iterator<Controller> it = controllers.iterator();
while (it.hasNext()) {
Controller c = it.next();
if (c.poll()) {
EventQueue queue = c.getEventQueue();
while (queue.getNextEvent(event)) {
ControllerAction action = convertEvent(c, event);
if (action != null) {
result.add(action);
}
}
} else {
removeController(c);
}
}
return result;
}
use of net.java.games.input.Event in project litiengine by gurkenlabs.
the class Gamepad method update.
@Override
public void update() {
final boolean couldPoll = this.controller.poll();
if (!couldPoll) {
this.dispose();
}
final Event event = new Event();
while (this.controller.getEventQueue().getNextEvent(event)) {
this.handlePollEvents(event);
}
for (Component comp : this.controller.getComponents()) {
if (Math.abs(comp.getPollData()) > getDeadZone(comp.getIdentifier())) {
this.handlePressed(comp);
} else {
this.handleRelease(comp);
}
}
}
use of net.java.games.input.Event in project j6dof-flight-sim by chris-ali.
the class JoystickVisitor method handleDeviceInput.
@Override
public void handleDeviceInput(Controller device) {
if (!canHandleDevice(device))
return;
JoystickAssignments assignments = joystickAssignments.get(device.getName());
Map<String, JoystickAxis> axisAssignments = assignments.getAxisAssignments();
Map<String, KeyCommand> buttonAssignments = assignments.getButtonAssignments();
Map<Float, KeyCommand> hatAssignments = assignments.getHatAssignments();
if (device.poll()) {
Event event = new Event();
while (device.getEventQueue().getNextEvent(event)) {
Component component = event.getComponent();
Identifier componentIdentifier = component.getIdentifier();
String componentName = componentIdentifier.getName();
float pollValue = component.getPollData();
// Buttons
if (buttonAssignments != null && componentIdentifier.getName().matches("^[0-9]*$")) {
// If the component name contains only numbers, it is a button
KeyCommand command = buttonAssignments.get(componentName);
if (command != null)
actuator.handleParameterChange(command, pollValue);
continue;
}
// Hat Switch
if (hatAssignments != null && componentIdentifier == Axis.POV) {
KeyCommand command = hatAssignments.get(pollValue);
if (command != null)
actuator.handleParameterChange(command, pollValue);
continue;
}
// Joystick Axes
if (axisAssignments != null) {
JoystickAxis axis = axisAssignments.get(componentName);
if (axis != null)
actuator.handleParameterChange(axis.getAxisAssignment(), pollValue);
continue;
}
}
}
}
use of net.java.games.input.Event in project lwjgl by LWJGL.
the class JInputController method poll.
/*
* @see org.lwjgl.input.Controller#poll()
*/
public void poll() {
target.poll();
Event event = new Event();
EventQueue queue = target.getEventQueue();
while (queue.getNextEvent(event)) {
// handle button event
if (buttons.contains(event.getComponent())) {
Component button = event.getComponent();
int buttonIndex = buttons.indexOf(button);
buttonState[buttonIndex] = event.getValue() != 0;
// fire button pressed event
Controllers.addEvent(new ControllerEvent(this, event.getNanos(), ControllerEvent.BUTTON, buttonIndex, buttonState[buttonIndex], false, false, 0, 0));
}
// handle pov events
if (pov.contains(event.getComponent())) {
Component povComponent = event.getComponent();
int povIndex = pov.indexOf(povComponent);
float prevX = getPovX();
float prevY = getPovY();
povValues[povIndex] = event.getValue();
if (prevX != getPovX()) {
Controllers.addEvent(new ControllerEvent(this, event.getNanos(), ControllerEvent.POVX, 0, false, false));
}
if (prevY != getPovY()) {
Controllers.addEvent(new ControllerEvent(this, event.getNanos(), ControllerEvent.POVY, 0, false, false));
}
}
// handle axis updates
if (axes.contains(event.getComponent())) {
Component axis = event.getComponent();
int axisIndex = axes.indexOf(axis);
float value = axis.getPollData();
float xaxisValue = 0;
float yaxisValue = 0;
// fixed dead zone since most axis don't report it :(
if (Math.abs(value) < deadZones[axisIndex]) {
value = 0;
}
if (Math.abs(value) < axis.getDeadZone()) {
value = 0;
}
if (Math.abs(value) > axesMax[axisIndex]) {
axesMax[axisIndex] = Math.abs(value);
}
// normalize the value based on maximum value read in the past
value /= axesMax[axisIndex];
if (axisIndex == xaxis) {
xaxisValue = value;
}
if (axisIndex == yaxis) {
yaxisValue = value;
}
// fire event
Controllers.addEvent(new ControllerEvent(this, event.getNanos(), ControllerEvent.AXIS, axisIndex, false, axisIndex == xaxis, axisIndex == yaxis, xaxisValue, yaxisValue));
axesValue[axisIndex] = value;
}
}
}
Aggregations