forked from Clones/Controlify
➕ Experimental anti-snapback
This commit is contained in:
@ -5,9 +5,11 @@ import dev.isxander.controlify.bindings.ControllerBindings;
|
||||
import dev.isxander.controlify.controller.AbstractController;
|
||||
import dev.isxander.controlify.controller.BatteryLevel;
|
||||
import dev.isxander.controlify.controller.hid.ControllerHIDService;
|
||||
import dev.isxander.controlify.debug.DebugProperties;
|
||||
import dev.isxander.controlify.driver.*;
|
||||
import dev.isxander.controlify.rumble.RumbleManager;
|
||||
import dev.isxander.controlify.rumble.RumbleSource;
|
||||
import dev.isxander.controlify.utils.ControllerUtils;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
@ -23,6 +25,8 @@ public class GamepadController extends AbstractController<GamepadState, GamepadC
|
||||
private final GamepadDrivers drivers;
|
||||
private final Set<Driver> uniqueDrivers;
|
||||
|
||||
private int antiSnapbackTicksL, antiSnapbackTicksR;
|
||||
|
||||
public GamepadController(int joystickId, ControllerHIDService.ControllerHIDInfo hidInfo) {
|
||||
super(joystickId, hidInfo);
|
||||
if (!GLFW.glfwJoystickIsGamepad(joystickId))
|
||||
@ -64,6 +68,23 @@ public class GamepadController extends AbstractController<GamepadState, GamepadC
|
||||
.leftJoystickDeadZone(config().leftStickDeadzoneX, config().leftStickDeadzoneY)
|
||||
.rightJoystickDeadZone(config().rightStickDeadzoneX, config().rightStickDeadzoneY);
|
||||
|
||||
if (DebugProperties.USE_SNAPBACK) {
|
||||
if (antiSnapbackTicksL > 0) {
|
||||
deadzoneAxesState = deadzoneAxesState.neutraliseLeft();
|
||||
antiSnapbackTicksL--;
|
||||
} else if (ControllerUtils.shouldApplyAntiSnapBack(deadzoneAxesState.leftStickX(), deadzoneAxesState.leftStickY(), prevState.gamepadAxes().leftStickX(), prevState.gamepadAxes().leftStickY(), 0.08f)) {
|
||||
antiSnapbackTicksL = 2;
|
||||
deadzoneAxesState = deadzoneAxesState.neutraliseLeft();
|
||||
}
|
||||
if (antiSnapbackTicksR > 0) {
|
||||
deadzoneAxesState = deadzoneAxesState.neutraliseRight();
|
||||
antiSnapbackTicksR--;
|
||||
} else if (ControllerUtils.shouldApplyAntiSnapBack(deadzoneAxesState.rightStickX(), deadzoneAxesState.rightStickY(), prevState.gamepadAxes().rightStickX(), prevState.gamepadAxes().rightStickY(), 0.08f)) {
|
||||
antiSnapbackTicksR = 2;
|
||||
deadzoneAxesState = deadzoneAxesState.neutraliseRight();
|
||||
}
|
||||
}
|
||||
|
||||
GamepadState.GyroState gyroState = drivers.gyroDriver().getGyroState();
|
||||
|
||||
state = new GamepadState(deadzoneAxesState, basicState.axes(), basicState.buttons(), gyroState, absoluteGyro);
|
||||
|
@ -177,6 +177,14 @@ public final class GamepadState implements ControllerState {
|
||||
ControllerUtils.deadzone(rightTrigger, deadZone)
|
||||
);
|
||||
}
|
||||
|
||||
public AxesState neutraliseLeft() {
|
||||
return new AxesState(0, 0, rightStickX, rightStickY, leftTrigger, rightTrigger);
|
||||
}
|
||||
|
||||
public AxesState neutraliseRight() {
|
||||
return new AxesState(leftStickX, leftStickY, 0, 0, leftTrigger, rightTrigger);
|
||||
}
|
||||
}
|
||||
|
||||
public record ButtonState(
|
||||
|
@ -80,6 +80,7 @@ public class SDL2NativesManager {
|
||||
// without calling JoystickUpdate, which we don't do.
|
||||
SDL.SDL_SetHint(SDL_HINT_JOYSTICK_RAWINPUT, "0");
|
||||
// better rumble
|
||||
SDL.SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI, "1");
|
||||
SDL.SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE, "1");
|
||||
SDL.SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS5_RUMBLE, "1");
|
||||
SDL.SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_STEAM, "1");
|
||||
|
Reference in New Issue
Block a user