mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-17 08:35:37 -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.view.View;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.core.math.MathUtils;
|
import androidx.core.math.MathUtils;
|
||||||
|
|
||||||
@ -54,6 +55,7 @@ public class Gamepad {
|
|||||||
private GamepadMap currentMap = gameMap;
|
private GamepadMap currentMap = gameMap;
|
||||||
|
|
||||||
private boolean lastGrabbingState = true;
|
private boolean lastGrabbingState = true;
|
||||||
|
private MotionEvent lastMotionEvent = null;
|
||||||
|
|
||||||
|
|
||||||
private final Thread mouseThread;
|
private final Thread mouseThread;
|
||||||
@ -61,6 +63,8 @@ public class Gamepad {
|
|||||||
private final Runnable switchStateRunnable;
|
private final Runnable switchStateRunnable;
|
||||||
|
|
||||||
public Gamepad(BaseMainActivity gameActivity, InputDevice inputDevice){
|
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);
|
leftJoystick = new GamepadJoystick(MotionEvent.AXIS_X, MotionEvent.AXIS_Y, inputDevice);
|
||||||
rightJoystick = new GamepadJoystick(MotionEvent.AXIS_Z, MotionEvent.AXIS_RZ, inputDevice);
|
rightJoystick = new GamepadJoystick(MotionEvent.AXIS_Z, MotionEvent.AXIS_RZ, inputDevice);
|
||||||
|
|
||||||
@ -103,6 +107,12 @@ public class Gamepad {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void tick(){
|
private void tick(){
|
||||||
|
if(lastMotionEvent != null){
|
||||||
|
updateDirectionalJoystick(lastMotionEvent);
|
||||||
|
updateMouseJoystick(lastMotionEvent);
|
||||||
|
updateAnalogTriggers(lastMotionEvent);
|
||||||
|
}
|
||||||
|
|
||||||
if(lastHorizontalValue != 0 || lastVerticalValue != 0){
|
if(lastHorizontalValue != 0 || lastVerticalValue != 0){
|
||||||
GamepadJoystick currentJoystick = CallbackBridge.isGrabbing() ? leftJoystick : rightJoystick;
|
GamepadJoystick currentJoystick = CallbackBridge.isGrabbing() ? leftJoystick : rightJoystick;
|
||||||
|
|
||||||
@ -234,10 +244,9 @@ public class Gamepad {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void update(MotionEvent event){
|
public void update(MotionEvent event){
|
||||||
gamepadDpad.update(event);
|
lastMotionEvent = event;
|
||||||
updateDirectionalJoystick(event);
|
if(gamepadDpad.update(event) != -1) return;
|
||||||
updateMouseJoystick(event);
|
//The rest of events are now sent each 1/60 second.
|
||||||
updateAnalogTriggers(event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateMouseJoystick(MotionEvent event){
|
private void updateMouseJoystick(MotionEvent event){
|
||||||
@ -401,12 +410,12 @@ public class Gamepad {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_RIGHT:
|
case LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_RIGHT:
|
||||||
CallbackBridge.putMouseEventWithCoords(LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_RIGHT, isDown?1:0, CallbackBridge.mouseX, CallbackBridge.mouseY);
|
//CallbackBridge.putMouseEventWithCoords(LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_RIGHT, isDown?1:0, CallbackBridge.mouseX, CallbackBridge.mouseY);
|
||||||
//MainActivity.sendMouseButton(LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_RIGHT, isDown);
|
MainActivity.sendMouseButton(LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_RIGHT, isDown);
|
||||||
break;
|
break;
|
||||||
case LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_LEFT:
|
case LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_LEFT:
|
||||||
CallbackBridge.putMouseEventWithCoords(LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_LEFT, isDown?1:0, CallbackBridge.mouseX, CallbackBridge.mouseY);
|
//CallbackBridge.putMouseEventWithCoords(LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_LEFT, isDown?1:0, CallbackBridge.mouseX, CallbackBridge.mouseY);
|
||||||
//MainActivity.sendMouseButton(LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_LEFT, isDown);
|
MainActivity.sendMouseButton(LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_LEFT, isDown);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user