mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-16 08:05:34 -04:00
Revert "Revert "light optimisation of motion events on Gamepad.java""
This reverts commit ebf90783117db65c097f4626e900cf241a60a2a4.
This commit is contained in:
parent
284d0f207d
commit
5855b1ef93
@ -7,6 +7,7 @@ import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.core.math.MathUtils;
|
||||
|
||||
@ -54,6 +55,7 @@ public class Gamepad {
|
||||
private GamepadMap currentMap = gameMap;
|
||||
|
||||
private boolean lastGrabbingState = true;
|
||||
private MotionEvent lastMotionEvent = null;
|
||||
|
||||
|
||||
private final Thread mouseThread;
|
||||
@ -61,6 +63,8 @@ public class Gamepad {
|
||||
private final Runnable switchStateRunnable;
|
||||
|
||||
public Gamepad(BaseMainActivity gameActivity, InputDevice inputDevice){
|
||||
Toast.makeText(gameActivity.getApplicationContext(),"GAMEPAD CREATED", Toast.LENGTH_LONG).show();
|
||||
|
||||
leftJoystick = new GamepadJoystick(MotionEvent.AXIS_X, MotionEvent.AXIS_Y, inputDevice);
|
||||
rightJoystick = new GamepadJoystick(MotionEvent.AXIS_Z, MotionEvent.AXIS_RZ, inputDevice);
|
||||
|
||||
@ -103,6 +107,12 @@ public class Gamepad {
|
||||
}
|
||||
|
||||
private void tick(){
|
||||
if(lastMotionEvent != null){
|
||||
updateDirectionalJoystick(lastMotionEvent);
|
||||
updateMouseJoystick(lastMotionEvent);
|
||||
updateAnalogTriggers(lastMotionEvent);
|
||||
}
|
||||
|
||||
if(lastHorizontalValue != 0 || lastVerticalValue != 0){
|
||||
GamepadJoystick currentJoystick = CallbackBridge.isGrabbing() ? leftJoystick : rightJoystick;
|
||||
|
||||
@ -234,10 +244,9 @@ public class Gamepad {
|
||||
}
|
||||
|
||||
public void update(MotionEvent event){
|
||||
gamepadDpad.update(event);
|
||||
updateDirectionalJoystick(event);
|
||||
updateMouseJoystick(event);
|
||||
updateAnalogTriggers(event);
|
||||
lastMotionEvent = event;
|
||||
if(gamepadDpad.update(event) != -1) return;
|
||||
//The rest of events are now sent each 1/60 second.
|
||||
}
|
||||
|
||||
private void updateMouseJoystick(MotionEvent event){
|
||||
@ -401,12 +410,12 @@ public class Gamepad {
|
||||
break;
|
||||
|
||||
case LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_RIGHT:
|
||||
CallbackBridge.putMouseEventWithCoords(LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_RIGHT, isDown?1:0, CallbackBridge.mouseX, CallbackBridge.mouseY);
|
||||
//MainActivity.sendMouseButton(LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_RIGHT, isDown);
|
||||
//CallbackBridge.putMouseEventWithCoords(LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_RIGHT, isDown?1:0, CallbackBridge.mouseX, CallbackBridge.mouseY);
|
||||
MainActivity.sendMouseButton(LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_RIGHT, isDown);
|
||||
break;
|
||||
case LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_LEFT:
|
||||
CallbackBridge.putMouseEventWithCoords(LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_LEFT, isDown?1:0, CallbackBridge.mouseX, CallbackBridge.mouseY);
|
||||
//MainActivity.sendMouseButton(LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_LEFT, isDown);
|
||||
//CallbackBridge.putMouseEventWithCoords(LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_LEFT, isDown?1:0, CallbackBridge.mouseX, CallbackBridge.mouseY);
|
||||
MainActivity.sendMouseButton(LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_LEFT, isDown);
|
||||
break;
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user