Add controller's status to event buffer
This commit is contained in:
parent
e5aada8c45
commit
a9e492d93a
|
@ -31,6 +31,8 @@
|
|||
*/
|
||||
package org.lwjgl.input;
|
||||
|
||||
import org.lwjgl.Sys;
|
||||
|
||||
/**
|
||||
* An event occuring on a controller.
|
||||
*
|
||||
|
@ -52,12 +54,18 @@ class ControllerEvent {
|
|||
private int index;
|
||||
/** Type of control that generated the event */
|
||||
private int type;
|
||||
/** True when a button is pressed, if this event was caused by the button */
|
||||
private boolean buttonState;
|
||||
/** True if this event was caused by the x axis */
|
||||
private boolean xaxis;
|
||||
/** True if this event was caused by the y axis */
|
||||
private boolean yaxis;
|
||||
/** The time stamp of this event */
|
||||
private long timeStamp;
|
||||
/** The value on a specified axis, if this event was caused by the x-axis */
|
||||
private float xaxisValue;
|
||||
/** The value on a specified axis, if this event was caused by the y-axis */
|
||||
private float yaxisValue;
|
||||
|
||||
/**
|
||||
* Create a new event
|
||||
|
@ -70,12 +78,32 @@ class ControllerEvent {
|
|||
* @param yaxis True if this event was caused by the y-axis
|
||||
*/
|
||||
ControllerEvent(Controller source,long timeStamp, int type,int index,boolean xaxis,boolean yaxis) {
|
||||
this(source, timeStamp, type, index, false, xaxis, yaxis, 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new event
|
||||
*
|
||||
* @param source The source of the event
|
||||
* @param timeStamp The time stamp given for this event
|
||||
* @param type The type of control generating this event
|
||||
* @param index The index of the input that generated the event
|
||||
* @param buttonState True when a button is pressed, if this event was caused by the button
|
||||
* @param xaxis True if this event was caused by the x-axis
|
||||
* @param yaxis True if this event was caused by the y-axis
|
||||
* @param xaxisValue The value on a specified axis, if this event was caused by the x-axis
|
||||
* @param yaxisValue The value on a specified axis, if this event was caused by the y-axis
|
||||
*/
|
||||
ControllerEvent(Controller source,long timeStamp, int type,int index,boolean buttonState,boolean xaxis,boolean yaxis,float xaxisValue,float yaxisValue) {
|
||||
this.source = source;
|
||||
this.timeStamp = timeStamp;
|
||||
this.type = type;
|
||||
this.index = index;
|
||||
this.buttonState = buttonState;
|
||||
this.xaxis = xaxis;
|
||||
this.yaxis = yaxis;
|
||||
this.xaxisValue = xaxisValue;
|
||||
this.yaxisValue = yaxisValue;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -115,6 +143,15 @@ class ControllerEvent {
|
|||
return type == BUTTON;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the button is pressed or not, when this event was caused
|
||||
*
|
||||
* @return True when a button is pressed, if this event was caused by the button
|
||||
*/
|
||||
public boolean getButtonState() {
|
||||
return buttonState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this event was generated by a axis
|
||||
*
|
||||
|
@ -159,6 +196,24 @@ class ControllerEvent {
|
|||
public boolean isYAxis() {
|
||||
return yaxis;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value on an X axis when this event was caused
|
||||
*
|
||||
* @return The value on a specified axis, if this event was caused by the x-axis
|
||||
*/
|
||||
public float getXAxisValue() {
|
||||
return xaxisValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value on an Y axis when this event was caused
|
||||
*
|
||||
* @return The value on a specified axis, if this event was caused by the y-axis
|
||||
*/
|
||||
public float getYAxisValue() {
|
||||
return yaxisValue;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see java.lang.Object#toString()
|
||||
|
|
|
@ -262,12 +262,39 @@ public class Controllers {
|
|||
/**
|
||||
* Get the timestamp assigned to the current event
|
||||
*
|
||||
* @return The timestamp assigned ot the current event
|
||||
* @return The timestamp assigned at the current event
|
||||
*/
|
||||
public static long getEventNanoseconds() {
|
||||
return event.getTimeStamp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the button is pressed or not at the current event
|
||||
*
|
||||
* @return True when a button is pressed at the current event
|
||||
*/
|
||||
public static boolean getEventButtonStatus() {
|
||||
return event.getButtonState();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value on an X axis of the current event
|
||||
*
|
||||
* @return The value on a x axis of the current event
|
||||
*/
|
||||
public static float getEventXAxisValue() {
|
||||
return event.getXAxisValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value on an Y axis of the current event
|
||||
*
|
||||
* @return The value on a y axis of the current event
|
||||
*/
|
||||
public static float getEventYAxisValue() {
|
||||
return event.getYAxisValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an event to the stack of events that have been caused
|
||||
*
|
||||
|
|
|
@ -208,7 +208,7 @@ class JInputController implements Controller {
|
|||
buttonState[buttonIndex] = event.getValue() != 0;
|
||||
|
||||
// fire button pressed event
|
||||
Controllers.addEvent(new ControllerEvent(this,event.getNanos(),ControllerEvent.BUTTON,buttonIndex,false,false));
|
||||
Controllers.addEvent(new ControllerEvent(this,event.getNanos(),ControllerEvent.BUTTON,buttonIndex,buttonState[buttonIndex],false,false,0,0));
|
||||
}
|
||||
|
||||
// handle pov events
|
||||
|
@ -232,6 +232,8 @@ class JInputController implements Controller {
|
|||
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]) {
|
||||
|
@ -246,9 +248,17 @@ class JInputController implements Controller {
|
|||
|
||||
// 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,
|
||||
axisIndex == xaxis,axisIndex == yaxis));
|
||||
Controllers.addEvent(new ControllerEvent(this,event.getNanos(),ControllerEvent.AXIS,axisIndex,false,
|
||||
axisIndex == xaxis,axisIndex == yaxis,xaxisValue,yaxisValue));
|
||||
axesValue[axisIndex] = value;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue