Modified to pay attention to the joystick axis'
dead zone if it is larger than the globally defined dead zone.
This commit is contained in:
parent
84ccd71873
commit
2a2c71dadf
@ -96,7 +96,7 @@ public class InputManager implements RawInputListener {
|
||||
private boolean eventsPermitted = false;
|
||||
private boolean mouseVisible = true;
|
||||
private boolean safeMode = false;
|
||||
private float axisDeadZone = 0.05f;
|
||||
private float globalAxisDeadZone = 0.05f;
|
||||
private Vector2f cursorPos = new Vector2f();
|
||||
private Joystick[] joysticks;
|
||||
private final IntMap<ArrayList<Mapping>> bindings = new IntMap<ArrayList<Mapping>>();
|
||||
@ -248,8 +248,8 @@ public class InputManager implements RawInputListener {
|
||||
}
|
||||
}
|
||||
|
||||
private void invokeAnalogsAndActions(int hash, float value, boolean applyTpf) {
|
||||
if (value < axisDeadZone) {
|
||||
private void invokeAnalogsAndActions(int hash, float value, float effectiveDeadZone, boolean applyTpf) {
|
||||
if (value < effectiveDeadZone) {
|
||||
invokeAnalogs(hash, value, !applyTpf);
|
||||
return;
|
||||
}
|
||||
@ -304,17 +304,18 @@ public class InputManager implements RawInputListener {
|
||||
int joyId = evt.getJoyIndex();
|
||||
int axis = evt.getAxisIndex();
|
||||
float value = evt.getValue();
|
||||
if (value < axisDeadZone && value > -axisDeadZone) {
|
||||
float effectiveDeadZone = Math.max(globalAxisDeadZone, evt.getAxis().getDeadZone());
|
||||
if (value < effectiveDeadZone && value > -effectiveDeadZone) {
|
||||
int hash1 = JoyAxisTrigger.joyAxisHash(joyId, axis, true);
|
||||
int hash2 = JoyAxisTrigger.joyAxisHash(joyId, axis, false);
|
||||
|
||||
Float val1 = axisValues.get(hash1);
|
||||
Float val2 = axisValues.get(hash2);
|
||||
|
||||
if (val1 != null && val1.floatValue() > axisDeadZone) {
|
||||
if (val1 != null && val1.floatValue() > effectiveDeadZone) {
|
||||
invokeActions(hash1, false);
|
||||
}
|
||||
if (val2 != null && val2.floatValue() > axisDeadZone) {
|
||||
if (val2 != null && val2.floatValue() > effectiveDeadZone) {
|
||||
invokeActions(hash2, false);
|
||||
}
|
||||
|
||||
@ -328,11 +329,11 @@ public class InputManager implements RawInputListener {
|
||||
// Clear the reverse direction's actions in case we
|
||||
// crossed center too quickly
|
||||
Float otherVal = axisValues.get(otherHash);
|
||||
if (otherVal != null && otherVal.floatValue() > axisDeadZone) {
|
||||
if (otherVal != null && otherVal.floatValue() > effectiveDeadZone) {
|
||||
invokeActions(otherHash, false);
|
||||
}
|
||||
|
||||
invokeAnalogsAndActions(hash, -value, true);
|
||||
invokeAnalogsAndActions(hash, -value, effectiveDeadZone, true);
|
||||
axisValues.put(hash, -value);
|
||||
axisValues.remove(otherHash);
|
||||
} else {
|
||||
@ -342,11 +343,11 @@ public class InputManager implements RawInputListener {
|
||||
// Clear the reverse direction's actions in case we
|
||||
// crossed center too quickly
|
||||
Float otherVal = axisValues.get(otherHash);
|
||||
if (otherVal != null && otherVal.floatValue() > axisDeadZone) {
|
||||
if (otherVal != null && otherVal.floatValue() > effectiveDeadZone) {
|
||||
invokeActions(otherHash, false);
|
||||
}
|
||||
|
||||
invokeAnalogsAndActions(hash, value, true);
|
||||
invokeAnalogsAndActions(hash, value, effectiveDeadZone, true);
|
||||
axisValues.put(hash, value);
|
||||
axisValues.remove(otherHash);
|
||||
}
|
||||
@ -391,15 +392,15 @@ public class InputManager implements RawInputListener {
|
||||
|
||||
if (evt.getDX() != 0) {
|
||||
float val = Math.abs(evt.getDX()) / 1024f;
|
||||
invokeAnalogsAndActions(MouseAxisTrigger.mouseAxisHash(MouseInput.AXIS_X, evt.getDX() < 0), val, false);
|
||||
invokeAnalogsAndActions(MouseAxisTrigger.mouseAxisHash(MouseInput.AXIS_X, evt.getDX() < 0), val, globalAxisDeadZone, false);
|
||||
}
|
||||
if (evt.getDY() != 0) {
|
||||
float val = Math.abs(evt.getDY()) / 1024f;
|
||||
invokeAnalogsAndActions(MouseAxisTrigger.mouseAxisHash(MouseInput.AXIS_Y, evt.getDY() < 0), val, false);
|
||||
invokeAnalogsAndActions(MouseAxisTrigger.mouseAxisHash(MouseInput.AXIS_Y, evt.getDY() < 0), val, globalAxisDeadZone, false);
|
||||
}
|
||||
if (evt.getDeltaWheel() != 0) {
|
||||
float val = Math.abs(evt.getDeltaWheel()) / 100f;
|
||||
invokeAnalogsAndActions(MouseAxisTrigger.mouseAxisHash(MouseInput.AXIS_WHEEL, evt.getDeltaWheel() < 0), val, false);
|
||||
invokeAnalogsAndActions(MouseAxisTrigger.mouseAxisHash(MouseInput.AXIS_WHEEL, evt.getDeltaWheel() < 0), val, globalAxisDeadZone, false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -477,7 +478,7 @@ public class InputManager implements RawInputListener {
|
||||
* @param deadZone the deadzone for joystick axes.
|
||||
*/
|
||||
public void setAxisDeadZone(float deadZone) {
|
||||
this.axisDeadZone = deadZone;
|
||||
this.globalAxisDeadZone = deadZone;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -486,7 +487,7 @@ public class InputManager implements RawInputListener {
|
||||
* @return the deadzone for joystick axes.
|
||||
*/
|
||||
public float getAxisDeadZone() {
|
||||
return axisDeadZone;
|
||||
return globalAxisDeadZone;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user