Skip to content

Commit

Permalink
AxisToAxisAction, AxisToRelativeAxisAction: reduced nesting in doActi…
Browse files Browse the repository at this point in the history
…on()
  • Loading branch information
bwRavencl committed Dec 22, 2023
1 parent 0c97a00 commit 24cf22f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,28 +42,30 @@ public class AxisToAxisAction extends ToAxisAction<Float> implements IAxisToActi

@Override
public void doAction(final Input input, final int component, Float value) {
if (!input.isAxisSuspended(component)) {
if (Math.abs(value) <= deadZone) {
value = 0f;
if (input.isAxisSuspended(component)) {
return;
}

if (Math.abs(value) <= deadZone) {
value = 0f;
} else {
final float inMax;
if (exponent > 1f) {
inMax = (float) Math.pow((1f - deadZone) * 100f, exponent);

value = Math.signum(value) * (float) Math.pow((Math.abs(value) - deadZone) * 100f, exponent);
} else {
final float inMax;
if (exponent > 1f) {
inMax = (float) Math.pow((1f - deadZone) * 100f, exponent);

value = Math.signum(value) * (float) Math.pow((Math.abs(value) - deadZone) * 100f, exponent);
} else {
inMax = 1f;
}

if (value >= 0f) {
value = Input.normalize(value, deadZone, inMax, 0f, 1f);
} else {
value = Input.normalize(value, -inMax, -deadZone, -1f, 0f);
}
inMax = 1f;
}

input.setAxis(virtualAxis, invert ? -value : value, false, null);
if (value >= 0f) {
value = Input.normalize(value, deadZone, inMax, 0f, 1f);
} else {
value = Input.normalize(value, -inMax, -deadZone, -1f, 0f);
}
}

input.setAxis(virtualAxis, invert ? -value : value, false, null);
}

public float getDeadZone() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,34 +44,32 @@ public final class AxisToRelativeAxisAction extends AxisToAxisAction {
public void doAction(final Input input, final int component, final Float value) {
final var absValue = Math.abs(value);

if (!input.isAxisSuspended(component) && absValue > deadZone) {
final var inMax = (float) Math.pow((1f - deadZone) * 100f, exponent);

var d = Input.normalize(
Math.signum(value) * (float) Math.pow((absValue - deadZone) * 100f, exponent),
-inMax,
inMax,
-maxRelativeSpeed,
maxRelativeSpeed)
* input.getRateMultiplier();

d += remainingD;

if (Math.abs(d) < input.getPlanckLength()) {
remainingD = d;
} else {
remainingD = 0f;

final var runMode = input.getRunMode();
final var oldValue = Input.normalize(
input.getAxes().get(virtualAxis),
runMode.getMinAxisValue(),
runMode.getMaxAxisValue(),
-1f,
1f);

input.setAxis(virtualAxis, oldValue + (invert ? -d : d), hapticFeedback, detentValue);
}
if (input.isAxisSuspended(component) || absValue <= deadZone) {
return;
}

final var inMax = (float) Math.pow((1f - deadZone) * 100f, exponent);

var d = Input.normalize(
Math.signum(value) * (float) Math.pow((absValue - deadZone) * 100f, exponent),
-inMax,
inMax,
-maxRelativeSpeed,
maxRelativeSpeed)
* input.getRateMultiplier();

d += remainingD;

if (Math.abs(d) < input.getPlanckLength()) {
remainingD = d;
} else {
remainingD = 0f;

final var runMode = input.getRunMode();
final var oldValue = Input.normalize(
input.getAxes().get(virtualAxis), runMode.getMinAxisValue(), runMode.getMaxAxisValue(), -1f, 1f);

input.setAxis(virtualAxis, oldValue + (invert ? -d : d), hapticFeedback, detentValue);
}
}

Expand Down

0 comments on commit 24cf22f

Please sign in to comment.