mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-13 06:39:54 -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-ssp:6c02fd739b'
|
||||
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'
|
||||
|
||||
|
||||
|
@ -27,6 +27,7 @@ import androidx.core.math.MathUtils;
|
||||
import net.kdt.pojavlaunch.GrabListener;
|
||||
import net.kdt.pojavlaunch.LwjglGlfwKeycode;
|
||||
import net.kdt.pojavlaunch.R;
|
||||
import net.kdt.pojavlaunch.Tools;
|
||||
import net.kdt.pojavlaunch.prefs.LauncherPreferences;
|
||||
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_WEST;
|
||||
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 org.lwjgl.glfw.CallbackBridge.sendKeyPress;
|
||||
import static org.lwjgl.glfw.CallbackBridge.sendMouseButton;
|
||||
|
||||
import fr.spse.gamepad_remapper.GamepadHandler;
|
||||
import fr.spse.gamepad_remapper.Settings;
|
||||
|
||||
public class Gamepad implements GrabListener, GamepadHandler {
|
||||
|
||||
@ -89,6 +92,8 @@ public class Gamepad implements GrabListener, GamepadHandler {
|
||||
private final MCOptionUtils.MCOptionListener mGuiScaleListener = () -> notifyGUISizeChange(getMcScale());
|
||||
|
||||
public Gamepad(View contextView, InputDevice inputDevice){
|
||||
Settings.setDeadzoneScale(PREF_DEADZONE_SCALE);
|
||||
|
||||
mScreenChoreographer = Choreographer.getInstance();
|
||||
Choreographer.FrameCallback frameCallback = new Choreographer.FrameCallback() {
|
||||
@Override
|
||||
@ -185,10 +190,8 @@ public class Gamepad implements GrabListener, GamepadHandler {
|
||||
//update mouse position
|
||||
long newFrameTime = System.nanoTime();
|
||||
if(mLastHorizontalValue != 0 || mLastVerticalValue != 0){
|
||||
GamepadJoystick currentJoystick = isGrabbing ? mLeftJoystick : mRightJoystick;
|
||||
|
||||
double acceleration = (mMouseMagnitude - currentJoystick.getDeadzone()) / (1 - currentJoystick.getDeadzone());
|
||||
acceleration = Math.pow(acceleration, MOUSE_MAX_ACCELERATION);
|
||||
double acceleration = Math.pow(mMouseMagnitude, MOUSE_MAX_ACCELERATION);
|
||||
if(acceleration > 1) acceleration = 1;
|
||||
|
||||
// Compute delta since last tick time
|
||||
|
@ -59,11 +59,11 @@ public class GamepadJoystick {
|
||||
}
|
||||
|
||||
public float getVerticalAxis(){
|
||||
return applyDeadzone(mVerticalAxisValue);
|
||||
return mVerticalAxisValue;
|
||||
}
|
||||
|
||||
public float getHorizontalAxis(){
|
||||
return applyDeadzone(mHorizontalAxisValue);
|
||||
return mHorizontalAxisValue;
|
||||
}
|
||||
|
||||
public static boolean isJoystickEvent(MotionEvent event){
|
||||
@ -73,35 +73,10 @@ public class GamepadJoystick {
|
||||
|
||||
|
||||
public int getHeightDirection(){
|
||||
if(getMagnitude() <= getDeadzone()) return DIRECTION_NONE;
|
||||
if(getMagnitude() == 0) return DIRECTION_NONE;
|
||||
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 */
|
||||
public void setXAxisValue(float value){
|
||||
|
Loading…
x
Reference in New Issue
Block a user