From fb21ddce9a484d39f05ae98af5ae7fdba2939261 Mon Sep 17 00:00:00 2001 From: SerpentSpirale Date: Fri, 26 Nov 2021 00:06:40 +0100 Subject: [PATCH] Reduce gamepad mouse latency by one frame --- .../customcontrols/gamepad/Gamepad.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/gamepad/Gamepad.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/gamepad/Gamepad.java index 75a7bb5ad..7988680f1 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/gamepad/Gamepad.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/gamepad/Gamepad.java @@ -206,11 +206,24 @@ public class Gamepad { private void updateMouseJoystick(MotionEvent event){ GamepadJoystick currentJoystick = lastGrabbingState ? rightJoystick : leftJoystick; - lastHorizontalValue = currentJoystick.getHorizontalAxis(event); - lastVerticalValue = currentJoystick.getVerticalAxis(event); + float horizontalValue = currentJoystick.getHorizontalAxis(event); + float verticalValue = currentJoystick.getVerticalAxis(event); + if(horizontalValue != lastHorizontalValue || verticalValue != lastVerticalValue){ + lastHorizontalValue = horizontalValue; + lastVerticalValue = verticalValue; + + mouseMagnitude = currentJoystick.getMagnitude(event); + mouseAngle = currentJoystick.getAngleRadian(event); + + tick(System.nanoTime()); + return; + } + lastHorizontalValue = horizontalValue; + lastVerticalValue = verticalValue; mouseMagnitude = currentJoystick.getMagnitude(event); mouseAngle = currentJoystick.getAngleRadian(event); + } private void updateDirectionalJoystick(MotionEvent event){