mirror of
https://github.com/moonlight-stream/moonlight-android.git
synced 2026-04-22 08:20:12 +00:00
Reduce power by avoiding resends when OSC state is not changing
This commit is contained in:
@@ -43,23 +43,12 @@ public class VirtualController {
|
|||||||
private final Context context;
|
private final Context context;
|
||||||
private final Handler handler;
|
private final Handler handler;
|
||||||
|
|
||||||
// HACK: GFE sometimes discards gamepad packets when they are received
|
private final Runnable delayedRetransmitRunnable = new Runnable() {
|
||||||
// very shortly after another. This can be critical if an axis zeroing packet
|
|
||||||
// is lost and causes an analog stick to get stuck. To avoid this, we send
|
|
||||||
// a gamepad input packet every 100 ms to ensure any loss can be recovered.
|
|
||||||
private static final int RETRANSMIT_PERIOD_MS = 100;
|
|
||||||
private final Runnable retransmitRunnable = new Runnable() {
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (hidden) {
|
sendControllerInputContextInternal();
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
sendControllerInputContext();
|
|
||||||
handler.postDelayed(this, RETRANSMIT_PERIOD_MS);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
private boolean hidden;
|
|
||||||
|
|
||||||
private FrameLayout frame_layout = null;
|
private FrameLayout frame_layout = null;
|
||||||
|
|
||||||
@@ -114,9 +103,6 @@ public class VirtualController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void hide() {
|
public void hide() {
|
||||||
hidden = true;
|
|
||||||
handler.removeCallbacks(retransmitRunnable);
|
|
||||||
|
|
||||||
for (VirtualControllerElement element : elements) {
|
for (VirtualControllerElement element : elements) {
|
||||||
element.setVisibility(View.INVISIBLE);
|
element.setVisibility(View.INVISIBLE);
|
||||||
}
|
}
|
||||||
@@ -125,15 +111,11 @@ public class VirtualController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void show() {
|
public void show() {
|
||||||
hidden = false;
|
|
||||||
|
|
||||||
for (VirtualControllerElement element : elements) {
|
for (VirtualControllerElement element : elements) {
|
||||||
element.setVisibility(View.VISIBLE);
|
element.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
buttonConfigure.setVisibility(View.VISIBLE);
|
buttonConfigure.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
handler.postDelayed(retransmitRunnable, RETRANSMIT_PERIOD_MS);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeElements() {
|
public void removeElements() {
|
||||||
@@ -196,7 +178,7 @@ public class VirtualController {
|
|||||||
return inputContext;
|
return inputContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendControllerInputContext() {
|
private void sendControllerInputContextInternal() {
|
||||||
_DBG("INPUT_MAP + " + inputContext.inputMap);
|
_DBG("INPUT_MAP + " + inputContext.inputMap);
|
||||||
_DBG("LEFT_TRIGGER " + inputContext.leftTrigger);
|
_DBG("LEFT_TRIGGER " + inputContext.leftTrigger);
|
||||||
_DBG("RIGHT_TRIGGER " + inputContext.rightTrigger);
|
_DBG("RIGHT_TRIGGER " + inputContext.rightTrigger);
|
||||||
@@ -215,4 +197,19 @@ public class VirtualController {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void sendControllerInputContext() {
|
||||||
|
// Cancel retransmissions of prior gamepad inputs
|
||||||
|
handler.removeCallbacks(delayedRetransmitRunnable);
|
||||||
|
|
||||||
|
sendControllerInputContextInternal();
|
||||||
|
|
||||||
|
// HACK: GFE sometimes discards gamepad packets when they are received
|
||||||
|
// very shortly after another. This can be critical if an axis zeroing packet
|
||||||
|
// is lost and causes an analog stick to get stuck. To avoid this, we retransmit
|
||||||
|
// the gamepad state a few times unless another input event happens before then.
|
||||||
|
handler.postDelayed(delayedRetransmitRunnable, 25);
|
||||||
|
handler.postDelayed(delayedRetransmitRunnable, 50);
|
||||||
|
handler.postDelayed(delayedRetransmitRunnable, 75);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user