mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-14 23:28:52 -04:00
Fix[gamepad]: better gamepad support
This commit is contained in:
parent
b2f2cbfa5c
commit
751ade3340
@ -198,7 +198,7 @@ dependencies {
|
|||||||
implementation 'com.github.PojavLauncherTeam:portrait-sdp:ed33e89cbc'
|
implementation 'com.github.PojavLauncherTeam:portrait-sdp:ed33e89cbc'
|
||||||
implementation 'com.github.PojavLauncherTeam:portrait-ssp:6c02fd739b'
|
implementation 'com.github.PojavLauncherTeam:portrait-ssp:6c02fd739b'
|
||||||
implementation 'com.github.Mathias-Boulay:ExtendedView:1.0.0'
|
implementation 'com.github.Mathias-Boulay:ExtendedView:1.0.0'
|
||||||
implementation 'com.github.Mathias-Boulay:android_gamepad_remapper:eb92e3a5bb'
|
implementation 'com.github.Mathias-Boulay:android_gamepad_remapper:67b4fd4448'
|
||||||
implementation 'com.github.Mathias-Boulay:virtual-joystick-android:2e7aa25e50'
|
implementation 'com.github.Mathias-Boulay:virtual-joystick-android:2e7aa25e50'
|
||||||
|
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@ import androidx.core.math.MathUtils;
|
|||||||
import net.kdt.pojavlaunch.GrabListener;
|
import net.kdt.pojavlaunch.GrabListener;
|
||||||
import net.kdt.pojavlaunch.LwjglGlfwKeycode;
|
import net.kdt.pojavlaunch.LwjglGlfwKeycode;
|
||||||
import net.kdt.pojavlaunch.R;
|
import net.kdt.pojavlaunch.R;
|
||||||
|
import net.kdt.pojavlaunch.Tools;
|
||||||
import net.kdt.pojavlaunch.prefs.LauncherPreferences;
|
import net.kdt.pojavlaunch.prefs.LauncherPreferences;
|
||||||
import net.kdt.pojavlaunch.utils.MCOptionUtils;
|
import net.kdt.pojavlaunch.utils.MCOptionUtils;
|
||||||
|
|
||||||
@ -43,11 +44,13 @@ import static net.kdt.pojavlaunch.customcontrols.gamepad.GamepadJoystick.DIRECTI
|
|||||||
import static net.kdt.pojavlaunch.customcontrols.gamepad.GamepadJoystick.DIRECTION_SOUTH_WEST;
|
import static net.kdt.pojavlaunch.customcontrols.gamepad.GamepadJoystick.DIRECTION_SOUTH_WEST;
|
||||||
import static net.kdt.pojavlaunch.customcontrols.gamepad.GamepadJoystick.DIRECTION_WEST;
|
import static net.kdt.pojavlaunch.customcontrols.gamepad.GamepadJoystick.DIRECTION_WEST;
|
||||||
import static net.kdt.pojavlaunch.customcontrols.gamepad.GamepadJoystick.isJoystickEvent;
|
import static net.kdt.pojavlaunch.customcontrols.gamepad.GamepadJoystick.isJoystickEvent;
|
||||||
|
import static net.kdt.pojavlaunch.prefs.LauncherPreferences.PREF_DEADZONE_SCALE;
|
||||||
import static net.kdt.pojavlaunch.utils.MCOptionUtils.getMcScale;
|
import static net.kdt.pojavlaunch.utils.MCOptionUtils.getMcScale;
|
||||||
import static org.lwjgl.glfw.CallbackBridge.sendKeyPress;
|
import static org.lwjgl.glfw.CallbackBridge.sendKeyPress;
|
||||||
import static org.lwjgl.glfw.CallbackBridge.sendMouseButton;
|
import static org.lwjgl.glfw.CallbackBridge.sendMouseButton;
|
||||||
|
|
||||||
import fr.spse.gamepad_remapper.GamepadHandler;
|
import fr.spse.gamepad_remapper.GamepadHandler;
|
||||||
|
import fr.spse.gamepad_remapper.Settings;
|
||||||
|
|
||||||
public class Gamepad implements GrabListener, GamepadHandler {
|
public class Gamepad implements GrabListener, GamepadHandler {
|
||||||
|
|
||||||
@ -89,6 +92,8 @@ public class Gamepad implements GrabListener, GamepadHandler {
|
|||||||
private final MCOptionUtils.MCOptionListener mGuiScaleListener = () -> notifyGUISizeChange(getMcScale());
|
private final MCOptionUtils.MCOptionListener mGuiScaleListener = () -> notifyGUISizeChange(getMcScale());
|
||||||
|
|
||||||
public Gamepad(View contextView, InputDevice inputDevice){
|
public Gamepad(View contextView, InputDevice inputDevice){
|
||||||
|
Settings.setDeadzoneScale(PREF_DEADZONE_SCALE);
|
||||||
|
|
||||||
mScreenChoreographer = Choreographer.getInstance();
|
mScreenChoreographer = Choreographer.getInstance();
|
||||||
Choreographer.FrameCallback frameCallback = new Choreographer.FrameCallback() {
|
Choreographer.FrameCallback frameCallback = new Choreographer.FrameCallback() {
|
||||||
@Override
|
@Override
|
||||||
@ -185,10 +190,8 @@ public class Gamepad implements GrabListener, GamepadHandler {
|
|||||||
//update mouse position
|
//update mouse position
|
||||||
long newFrameTime = System.nanoTime();
|
long newFrameTime = System.nanoTime();
|
||||||
if(mLastHorizontalValue != 0 || mLastVerticalValue != 0){
|
if(mLastHorizontalValue != 0 || mLastVerticalValue != 0){
|
||||||
GamepadJoystick currentJoystick = isGrabbing ? mLeftJoystick : mRightJoystick;
|
|
||||||
|
|
||||||
double acceleration = (mMouseMagnitude - currentJoystick.getDeadzone()) / (1 - currentJoystick.getDeadzone());
|
double acceleration = Math.pow(mMouseMagnitude, MOUSE_MAX_ACCELERATION);
|
||||||
acceleration = Math.pow(acceleration, MOUSE_MAX_ACCELERATION);
|
|
||||||
if(acceleration > 1) acceleration = 1;
|
if(acceleration > 1) acceleration = 1;
|
||||||
|
|
||||||
// Compute delta since last tick time
|
// Compute delta since last tick time
|
||||||
|
@ -59,11 +59,11 @@ public class GamepadJoystick {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public float getVerticalAxis(){
|
public float getVerticalAxis(){
|
||||||
return applyDeadzone(mVerticalAxisValue);
|
return mVerticalAxisValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getHorizontalAxis(){
|
public float getHorizontalAxis(){
|
||||||
return applyDeadzone(mHorizontalAxisValue);
|
return mHorizontalAxisValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isJoystickEvent(MotionEvent event){
|
public static boolean isJoystickEvent(MotionEvent event){
|
||||||
@ -73,35 +73,10 @@ public class GamepadJoystick {
|
|||||||
|
|
||||||
|
|
||||||
public int getHeightDirection(){
|
public int getHeightDirection(){
|
||||||
if(getMagnitude() <= getDeadzone()) return DIRECTION_NONE;
|
if(getMagnitude() == 0) return DIRECTION_NONE;
|
||||||
return ((int) ((getAngleDegree()+22.5)/45)) % 8;
|
return ((int) ((getAngleDegree()+22.5)/45)) % 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the deadzone from the Input device linked to this joystick
|
|
||||||
* Some controller aren't supported, fallback to 0.2 if that the case.
|
|
||||||
* @return the deadzone of the joystick
|
|
||||||
*/
|
|
||||||
public float getDeadzone() {
|
|
||||||
try{
|
|
||||||
return mInputDevice.getMotionRange(mHorizontalAxis).getFlat() * PREF_DEADZONE_SCALE;
|
|
||||||
}catch (Exception e){
|
|
||||||
Log.e(GamepadJoystick.class.toString(), "Dynamic Deadzone is not supported ");
|
|
||||||
return 0.2f;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private float applyDeadzone(float value){
|
|
||||||
//This piece of code also modifies the value
|
|
||||||
//to make it seem like there was no deadzone in the first place
|
|
||||||
|
|
||||||
double magnitude = getMagnitude();
|
|
||||||
float deadzone = getDeadzone();
|
|
||||||
if (magnitude < deadzone) return 0;
|
|
||||||
|
|
||||||
return (float) ( (value / magnitude) * ((magnitude - deadzone) / (1 - deadzone)) );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Setters */
|
/* Setters */
|
||||||
public void setXAxisValue(float value){
|
public void setXAxisValue(float value){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user