forked from Clones/Controlify
🐛 fix rumble reported as unsupported if it's off
This commit is contained in:
@ -13,7 +13,7 @@ quilt_mappings = "10"
|
|||||||
fabric_loader = "0.14.19"
|
fabric_loader = "0.14.19"
|
||||||
fabric_api = "0.78.0+1.19.4"
|
fabric_api = "0.78.0+1.19.4"
|
||||||
mixin_extras = "0.2.0-beta.6"
|
mixin_extras = "0.2.0-beta.6"
|
||||||
yet_another_config_lib = "2.5.0+1.19.4"
|
yet_another_config_lib = "2.5.1+1.19.4"
|
||||||
mod_menu = "6.1.0-rc.4"
|
mod_menu = "6.1.0-rc.4"
|
||||||
hid4java = "0.7.0"
|
hid4java = "0.7.0"
|
||||||
quilt_json5 = "1.0.3"
|
quilt_json5 = "1.0.3"
|
||||||
|
@ -256,7 +256,7 @@ public class YACLHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static OptionGroup makeVibrationGroup(Option<Boolean> globalVibrationOption, Controller<?, ?> controller) {
|
private static OptionGroup makeVibrationGroup(Option<Boolean> globalVibrationOption, Controller<?, ?> controller) {
|
||||||
boolean canRumble = controller.canRumble();
|
boolean canRumble = controller.supportsRumble();
|
||||||
var config = controller.config();
|
var config = controller.config();
|
||||||
var def = controller.defaultConfig();
|
var def = controller.defaultConfig();
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ public interface Controller<S extends ControllerState, C extends ControllerConfi
|
|||||||
default void close() {}
|
default void close() {}
|
||||||
|
|
||||||
RumbleManager rumbleManager();
|
RumbleManager rumbleManager();
|
||||||
boolean canRumble();
|
boolean supportsRumble();
|
||||||
|
|
||||||
Optional<ControllerHIDService.ControllerHIDInfo> hidInfo();
|
Optional<ControllerHIDService.ControllerHIDInfo> hidInfo();
|
||||||
|
|
||||||
@ -104,7 +104,7 @@ public interface Controller<S extends ControllerState, C extends ControllerConfi
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canRumble() {
|
public boolean supportsRumble() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -196,7 +196,7 @@ public interface Controller<S extends ControllerState, C extends ControllerConfi
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canRumble() {
|
public boolean supportsRumble() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package dev.isxander.controlify.controller.gamepad;
|
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.bindings.ControllerBindings;
|
||||||
import dev.isxander.controlify.controller.AbstractController;
|
import dev.isxander.controlify.controller.AbstractController;
|
||||||
import dev.isxander.controlify.controller.hid.ControllerHIDService;
|
import dev.isxander.controlify.controller.hid.ControllerHIDService;
|
||||||
@ -83,7 +81,7 @@ public class GamepadController extends AbstractController<GamepadState, GamepadC
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean setRumble(float strongMagnitude, float weakMagnitude, RumbleSource source) {
|
public boolean setRumble(float strongMagnitude, float weakMagnitude, RumbleSource source) {
|
||||||
if (!canRumble()) return false;
|
if (!supportsRumble() || !config().allowVibrations) return false;
|
||||||
|
|
||||||
var strengthMod = config().getRumbleStrength(source);
|
var strengthMod = config().getRumbleStrength(source);
|
||||||
if (source != RumbleSource.MASTER)
|
if (source != RumbleSource.MASTER)
|
||||||
@ -96,9 +94,8 @@ public class GamepadController extends AbstractController<GamepadState, GamepadC
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canRumble() {
|
public boolean supportsRumble() {
|
||||||
return drivers.rumbleDriver().isRumbleSupported()
|
return drivers.rumbleDriver().isRumbleSupported();
|
||||||
&& config().allowVibrations;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -148,7 +148,7 @@ public class CompoundJoystickController implements JoystickController<JoystickCo
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canRumble() {
|
public boolean supportsRumble() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ public class SingleJoystickController extends AbstractController<JoystickState,
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean setRumble(float strongMagnitude, float weakMagnitude, RumbleSource source) {
|
public boolean setRumble(float strongMagnitude, float weakMagnitude, RumbleSource source) {
|
||||||
if (!canRumble()) return false;
|
if (!supportsRumble()) return false;
|
||||||
|
|
||||||
var strengthMod = config().getRumbleStrength(source);
|
var strengthMod = config().getRumbleStrength(source);
|
||||||
if (source != RumbleSource.MASTER)
|
if (source != RumbleSource.MASTER)
|
||||||
@ -113,10 +113,8 @@ public class SingleJoystickController extends AbstractController<JoystickState,
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canRumble() {
|
public boolean supportsRumble() {
|
||||||
return rumbleSupported
|
return rumbleSupported;
|
||||||
&& config().allowVibrations
|
|
||||||
&& ControlifyApi.get().currentInputMode() == InputMode.CONTROLLER;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -59,11 +59,11 @@ public class SDL2GamepadDriver implements GyroDriver, RumbleDriver {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getGyroDetails() {
|
public String getGyroDetails() {
|
||||||
return "SDL2 supported=%s".formatted(isGyroSupported);
|
return "SDL2gp supported=" + isGyroSupported();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getRumbleDetails() {
|
public String getRumbleDetails() {
|
||||||
return "SDL2 supported=%s".formatted(isRumbleSupported);
|
return "SDL2gp supported=" + isRumbleSupported();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
@ -2,7 +2,6 @@ package dev.isxander.controlify.driver;
|
|||||||
|
|
||||||
import dev.isxander.controlify.Controlify;
|
import dev.isxander.controlify.Controlify;
|
||||||
import dev.isxander.controlify.controller.gamepad.GamepadState;
|
import dev.isxander.controlify.controller.gamepad.GamepadState;
|
||||||
import dev.isxander.controlify.controller.hid.HIDIdentifier;
|
|
||||||
import org.hid4java.HidDevice;
|
import org.hid4java.HidDevice;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -3,5 +3,5 @@ package dev.isxander.controlify.rumble;
|
|||||||
public interface RumbleCapable {
|
public interface RumbleCapable {
|
||||||
boolean setRumble(float strongMagnitude, float weakMagnitude, RumbleSource source);
|
boolean setRumble(float strongMagnitude, float weakMagnitude, RumbleSource source);
|
||||||
|
|
||||||
boolean canRumble();
|
boolean supportsRumble();
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ public class RumbleManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void play(RumbleSource source, RumbleEffect effect) {
|
public void play(RumbleSource source, RumbleEffect effect) {
|
||||||
if (!controller.canRumble())
|
if (!controller.supportsRumble())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
effectQueue.add(new RumbleEffectInstance(source, effect));
|
effectQueue.add(new RumbleEffectInstance(source, effect));
|
||||||
|
@ -47,7 +47,7 @@ public class FakeController implements JoystickController<JoystickConfig> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canRumble() {
|
public boolean supportsRumble() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user