1
0
forked from Clones/Controlify

🐛 fix rumble reported as unsupported if it's off

This commit is contained in:
isXander
2023-05-06 12:51:42 +01:00
parent ede64f471f
commit 9017b3008c
12 changed files with 61 additions and 23 deletions

View File

@ -256,7 +256,7 @@ public class YACLHelper {
}
private static OptionGroup makeVibrationGroup(Option<Boolean> globalVibrationOption, Controller<?, ?> controller) {
boolean canRumble = controller.canRumble();
boolean canRumble = controller.supportsRumble();
var config = controller.config();
var def = controller.defaultConfig();

View File

@ -46,7 +46,7 @@ public interface Controller<S extends ControllerState, C extends ControllerConfi
default void close() {}
RumbleManager rumbleManager();
boolean canRumble();
boolean supportsRumble();
Optional<ControllerHIDService.ControllerHIDInfo> hidInfo();
@ -104,7 +104,7 @@ public interface Controller<S extends ControllerState, C extends ControllerConfi
}
@Override
public boolean canRumble() {
public boolean supportsRumble() {
return false;
}
});
@ -196,7 +196,7 @@ public interface Controller<S extends ControllerState, C extends ControllerConfi
}
@Override
public boolean canRumble() {
public boolean supportsRumble() {
return false;
}
};

View File

@ -1,7 +1,5 @@
package dev.isxander.controlify.controller.gamepad;
import dev.isxander.controlify.InputMode;
import dev.isxander.controlify.api.ControlifyApi;
import dev.isxander.controlify.bindings.ControllerBindings;
import dev.isxander.controlify.controller.AbstractController;
import dev.isxander.controlify.controller.hid.ControllerHIDService;
@ -83,7 +81,7 @@ public class GamepadController extends AbstractController<GamepadState, GamepadC
@Override
public boolean setRumble(float strongMagnitude, float weakMagnitude, RumbleSource source) {
if (!canRumble()) return false;
if (!supportsRumble() || !config().allowVibrations) return false;
var strengthMod = config().getRumbleStrength(source);
if (source != RumbleSource.MASTER)
@ -96,9 +94,8 @@ public class GamepadController extends AbstractController<GamepadState, GamepadC
}
@Override
public boolean canRumble() {
return drivers.rumbleDriver().isRumbleSupported()
&& config().allowVibrations;
public boolean supportsRumble() {
return drivers.rumbleDriver().isRumbleSupported();
}
@Override

View File

@ -148,7 +148,7 @@ public class CompoundJoystickController implements JoystickController<JoystickCo
}
@Override
public boolean canRumble() {
public boolean supportsRumble() {
return false;
}

View File

@ -94,7 +94,7 @@ public class SingleJoystickController extends AbstractController<JoystickState,
@Override
public boolean setRumble(float strongMagnitude, float weakMagnitude, RumbleSource source) {
if (!canRumble()) return false;
if (!supportsRumble()) return false;
var strengthMod = config().getRumbleStrength(source);
if (source != RumbleSource.MASTER)
@ -113,10 +113,8 @@ public class SingleJoystickController extends AbstractController<JoystickState,
}
@Override
public boolean canRumble() {
return rumbleSupported
&& config().allowVibrations
&& ControlifyApi.get().currentInputMode() == InputMode.CONTROLLER;
public boolean supportsRumble() {
return rumbleSupported;
}
@Override

View File

@ -59,11 +59,11 @@ public class SDL2GamepadDriver implements GyroDriver, RumbleDriver {
@Override
public String getGyroDetails() {
return "SDL2 supported=%s".formatted(isGyroSupported);
return "SDL2gp supported=" + isGyroSupported();
}
@Override
public String getRumbleDetails() {
return "SDL2 supported=%s".formatted(isRumbleSupported);
return "SDL2gp supported=" + isRumbleSupported();
}
}

View File

@ -0,0 +1,44 @@
package dev.isxander.controlify.driver;
import dev.isxander.controlify.Controlify;
import org.libsdl.SDL;
public class SDL2JoystickDriver implements RumbleDriver {
private final long ptrJoystick;
private final boolean isRumbleSupported;
public SDL2JoystickDriver(int jid) {
this.ptrJoystick = SDL.SDL_JoystickOpen(jid);
this.isRumbleSupported = SDL.SDL_JoystickHasRumble(ptrJoystick);
}
@Override
public void update() {
}
@Override
public boolean rumble(float strongMagnitude, float weakMagnitude) {
// duration of 0 is infinite
if (!SDL.SDL_JoystickRumble(ptrJoystick, (int)(strongMagnitude * 65535.0F), (int)(weakMagnitude * 65535.0F), 0)) {
Controlify.LOGGER.error("Could not rumble controller: " + SDL.SDL_GetError());
return false;
}
return true;
}
@Override
public boolean isRumbleSupported() {
return isRumbleSupported;
}
@Override
public String getRumbleDetails() {
return "SDL2joy supported=" + isRumbleSupported();
}
@Override
public void close() {
SDL.SDL_JoystickClose(ptrJoystick);
}
}

View File

@ -2,7 +2,6 @@ package dev.isxander.controlify.driver;
import dev.isxander.controlify.Controlify;
import dev.isxander.controlify.controller.gamepad.GamepadState;
import dev.isxander.controlify.controller.hid.HIDIdentifier;
import org.hid4java.HidDevice;
import java.util.Arrays;

View File

@ -3,5 +3,5 @@ package dev.isxander.controlify.rumble;
public interface RumbleCapable {
boolean setRumble(float strongMagnitude, float weakMagnitude, RumbleSource source);
boolean canRumble();
boolean supportsRumble();
}

View File

@ -21,7 +21,7 @@ public class RumbleManager {
}
public void play(RumbleSource source, RumbleEffect effect) {
if (!controller.canRumble())
if (!controller.supportsRumble())
return;
effectQueue.add(new RumbleEffectInstance(source, effect));