Skip to content

Commit

Permalink
Desktop: improve accuracy of canVibrate() and isVibrating()
Browse files Browse the repository at this point in the history
  • Loading branch information
MrStahlfelge committed Jan 12, 2021
1 parent 7644413 commit 7347979
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class JamepadController implements Controller {
private final IntMap<Float> axisState = new IntMap<>();
private final String uuid;
private boolean connected = true;
private boolean canVibrate = true;
private long vibrationEndMs;

public JamepadController(ControllerIndex controllerIndex) {
Expand Down Expand Up @@ -158,7 +159,7 @@ private void initializeState() {

@Override
public boolean canVibrate() {
return true;
return canVibrate;
}

@Override
Expand All @@ -169,8 +170,12 @@ public boolean isVibrating() {
@Override
public void startVibration(int duration, float strength) {
try {
controllerIndex.doVibration(strength, strength, duration);
vibrationEndMs = TimeUtils.millis() + duration;
if (controllerIndex.doVibration(strength, strength, duration)) {
vibrationEndMs = TimeUtils.millis() + duration;
canVibrate = true;
} else {
canVibrate = false;
}
} catch (ControllerUnpluggedException e) {
setDisconnected();
}
Expand Down

0 comments on commit 7347979

Please sign in to comment.