Simplify and document vibration pattern logic.

This commit is contained in:
player-03
2024-07-07 13:53:16 -04:00
committed by GitHub
parent 99ff0afeab
commit 1e6fdee508

View File

@@ -380,7 +380,7 @@ public class GameActivity extends SDLActivity {
public static void vibrate (int period, int duration) {
if (vibrator == null || !vibrator.hasVibrator ()) {
if (vibrator == null || !vibrator.hasVibrator () || period < 0 || duration <= 0) {
return;
@@ -400,8 +400,9 @@ public class GameActivity extends SDLActivity {
} else {
int periodMS = Math.max (1, (int)Math.ceil (period / 2.0));
int count = Math.max (1, (int)Math.ceil ((duration / (double) period) * 2));
// each period has two halves (vibrator off/vibrator on), and each half requires a separate entry in the array
int periodMS = (int)Math.ceil (period / 2.0);
int count = (int)Math.ceil (duration / (double) periodMS);
long[] pattern = new long[count];
for (int i = 0; i < count; i++) {