0
0
Fork 0

Implement analog stick range modifier (#2783)

* adjust position vector + GUI

* remove brackets

* Update configuration

* Update ConfigurationFileFormat.cs

* rebase + review changes

* spacing

* revert deletion

* fix profile loading

* spacing

* comment spacing
This commit is contained in:
MutantAura 2022-01-03 11:49:29 +00:00 committed by GitHub
parent 16c649934f
commit 686757105c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 160 additions and 5 deletions

View file

@ -24,6 +24,16 @@ namespace Ryujinx.Common.Configuration.Hid.Controller
/// </summary> /// </summary>
public float DeadzoneRight { get; set; } public float DeadzoneRight { get; set; }
/// <summary>
/// Controller Left Analog Stick Range
/// </summary>
public float RangeLeft { get; set; }
/// <summary>
/// Controller Right Analog Stick Range
/// </summary>
public float RangeRight { get; set; }
/// <summary> /// <summary>
/// Controller Trigger Threshold /// Controller Trigger Threshold
/// </summary> /// </summary>

View file

@ -196,6 +196,8 @@ namespace Ryujinx.Headless.SDL2
ControllerType = ControllerType.JoyconPair, ControllerType = ControllerType.JoyconPair,
DeadzoneLeft = 0.1f, DeadzoneLeft = 0.1f,
DeadzoneRight = 0.1f, DeadzoneRight = 0.1f,
RangeLeft = 1.0f,
RangeRight = 1.0f,
TriggerThreshold = 0.5f, TriggerThreshold = 0.5f,
LeftJoycon = new LeftJoyconCommonConfig<ConfigGamepadInputId> LeftJoycon = new LeftJoyconCommonConfig<ConfigGamepadInputId>
{ {
@ -299,6 +301,18 @@ namespace Ryujinx.Headless.SDL2
Logger.Info?.Print(LogClass.Application, $"{config.PlayerIndex} configured with {inputTypeName} \"{config.Id}\""); Logger.Info?.Print(LogClass.Application, $"{config.PlayerIndex} configured with {inputTypeName} \"{config.Id}\"");
// If both stick ranges are 0 (usually indicative of an outdated profile load) then both sticks will be set to 1.0.
if (config is StandardControllerInputConfig controllerConfig)
{
if (controllerConfig.RangeLeft <= 0.0f && controllerConfig.RangeRight <= 0.0f)
{
controllerConfig.RangeLeft = 1.0f;
controllerConfig.RangeRight = 1.0f;
Logger.Info?.Print(LogClass.Application, $"{config.PlayerIndex} stick range reset. Save the profile now to update your configuration");
}
}
return config; return config;
} }

View file

@ -381,8 +381,8 @@ namespace Ryujinx.Input.HLE
(float leftAxisX, float leftAxisY) = State.GetStick(StickInputId.Left); (float leftAxisX, float leftAxisY) = State.GetStick(StickInputId.Left);
(float rightAxisX, float rightAxisY) = State.GetStick(StickInputId.Right); (float rightAxisX, float rightAxisY) = State.GetStick(StickInputId.Right);
state.LStick = ClampToCircle(ApplyDeadzone(leftAxisX, leftAxisY, controllerConfig.DeadzoneLeft)); state.LStick = ClampToCircle(ApplyDeadzone(leftAxisX, leftAxisY, controllerConfig.DeadzoneLeft), controllerConfig.RangeLeft);
state.RStick = ClampToCircle(ApplyDeadzone(rightAxisX, rightAxisY, controllerConfig.DeadzoneRight)); state.RStick = ClampToCircle(ApplyDeadzone(rightAxisX, rightAxisY, controllerConfig.DeadzoneRight), controllerConfig.RangeRight);
} }
return state; return state;
@ -412,9 +412,9 @@ namespace Ryujinx.Input.HLE
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
private static JoystickPosition ClampToCircle(JoystickPosition position) private static JoystickPosition ClampToCircle(JoystickPosition position, float range)
{ {
Vector2 point = new Vector2(position.Dx, position.Dy); Vector2 point = new Vector2(position.Dx, position.Dy) * range;
if (point.Length() > short.MaxValue) if (point.Length() > short.MaxValue)
{ {

View file

@ -14,7 +14,7 @@ namespace Ryujinx.Configuration
/// <summary> /// <summary>
/// The current version of the file format /// The current version of the file format
/// </summary> /// </summary>
public const int CurrentVersion = 34; public const int CurrentVersion = 35;
/// <summary> /// <summary>
/// Version of the configuration file format /// Version of the configuration file format

View file

@ -975,6 +975,22 @@ namespace Ryujinx.Configuration
configurationFileUpdated = true; configurationFileUpdated = true;
} }
if (configurationFileFormat.Version < 35)
{
Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 35.");
foreach (InputConfig config in configurationFileFormat.InputConfig)
{
if (config is StandardControllerInputConfig controllerConfig)
{
controllerConfig.RangeLeft = 1.0f;
controllerConfig.RangeRight = 1.0f;
}
}
configurationFileUpdated = true;
}
Logger.EnableFileLog.Value = configurationFileFormat.EnableFileLog; Logger.EnableFileLog.Value = configurationFileFormat.EnableFileLog;
Graphics.BackendThreading.Value = configurationFileFormat.BackendThreading; Graphics.BackendThreading.Value = configurationFileFormat.BackendThreading;
Graphics.ResScale.Value = configurationFileFormat.ResScale; Graphics.ResScale.Value = configurationFileFormat.ResScale;

View file

@ -38,6 +38,8 @@ namespace Ryujinx.Ui.Windows
[GUI] Adjustment _controllerWeakRumble; [GUI] Adjustment _controllerWeakRumble;
[GUI] Adjustment _controllerDeadzoneLeft; [GUI] Adjustment _controllerDeadzoneLeft;
[GUI] Adjustment _controllerDeadzoneRight; [GUI] Adjustment _controllerDeadzoneRight;
[GUI] Adjustment _controllerRangeLeft;
[GUI] Adjustment _controllerRangeRight;
[GUI] Adjustment _controllerTriggerThreshold; [GUI] Adjustment _controllerTriggerThreshold;
[GUI] Adjustment _slotNumber; [GUI] Adjustment _slotNumber;
[GUI] Adjustment _altSlotNumber; [GUI] Adjustment _altSlotNumber;
@ -59,9 +61,11 @@ namespace Ryujinx.Ui.Windows
[GUI] Grid _leftStickKeyboard; [GUI] Grid _leftStickKeyboard;
[GUI] Grid _leftStickController; [GUI] Grid _leftStickController;
[GUI] Box _deadZoneLeftBox; [GUI] Box _deadZoneLeftBox;
[GUI] Box _rangeLeftBox;
[GUI] Grid _rightStickKeyboard; [GUI] Grid _rightStickKeyboard;
[GUI] Grid _rightStickController; [GUI] Grid _rightStickController;
[GUI] Box _deadZoneRightBox; [GUI] Box _deadZoneRightBox;
[GUI] Box _rangeRightBox;
[GUI] Grid _leftSideTriggerBox; [GUI] Grid _leftSideTriggerBox;
[GUI] Grid _rightSideTriggerBox; [GUI] Grid _rightSideTriggerBox;
[GUI] Box _triggerThresholdBox; [GUI] Box _triggerThresholdBox;
@ -316,6 +320,8 @@ namespace Ryujinx.Ui.Windows
_rightStickController.Hide(); _rightStickController.Hide();
_deadZoneLeftBox.Hide(); _deadZoneLeftBox.Hide();
_deadZoneRightBox.Hide(); _deadZoneRightBox.Hide();
_rangeLeftBox.Hide();
_rangeRightBox.Hide();
_triggerThresholdBox.Hide(); _triggerThresholdBox.Hide();
_motionBox.Hide(); _motionBox.Hide();
_rumbleBox.Hide(); _rumbleBox.Hide();
@ -416,6 +422,8 @@ namespace Ryujinx.Ui.Windows
_controllerWeakRumble.Value = 1; _controllerWeakRumble.Value = 1;
_controllerDeadzoneLeft.Value = 0; _controllerDeadzoneLeft.Value = 0;
_controllerDeadzoneRight.Value = 0; _controllerDeadzoneRight.Value = 0;
_controllerRangeLeft.Value = 1;
_controllerRangeRight.Value = 1;
_controllerTriggerThreshold.Value = 0; _controllerTriggerThreshold.Value = 0;
_mirrorInput.Active = false; _mirrorInput.Active = false;
_enableMotion.Active = false; _enableMotion.Active = false;
@ -510,12 +518,23 @@ namespace Ryujinx.Ui.Windows
_enableRumble.Active = controllerConfig.Rumble.EnableRumble; _enableRumble.Active = controllerConfig.Rumble.EnableRumble;
_controllerDeadzoneLeft.Value = controllerConfig.DeadzoneLeft; _controllerDeadzoneLeft.Value = controllerConfig.DeadzoneLeft;
_controllerDeadzoneRight.Value = controllerConfig.DeadzoneRight; _controllerDeadzoneRight.Value = controllerConfig.DeadzoneRight;
_controllerRangeLeft.Value = controllerConfig.RangeLeft;
_controllerRangeRight.Value = controllerConfig.RangeRight;
_controllerTriggerThreshold.Value = controllerConfig.TriggerThreshold; _controllerTriggerThreshold.Value = controllerConfig.TriggerThreshold;
_sensitivity.Value = controllerConfig.Motion.Sensitivity; _sensitivity.Value = controllerConfig.Motion.Sensitivity;
_gyroDeadzone.Value = controllerConfig.Motion.GyroDeadzone; _gyroDeadzone.Value = controllerConfig.Motion.GyroDeadzone;
_enableMotion.Active = controllerConfig.Motion.EnableMotion; _enableMotion.Active = controllerConfig.Motion.EnableMotion;
_enableCemuHook.Active = controllerConfig.Motion.MotionBackend == MotionInputBackendType.CemuHook; _enableCemuHook.Active = controllerConfig.Motion.MotionBackend == MotionInputBackendType.CemuHook;
// If both stick ranges are 0 (usually indicative of an outdated profile load) then both sticks will be set to 1.0.
if (_controllerRangeLeft.Value <= 0.0 && _controllerRangeRight.Value <= 0.0)
{
_controllerRangeLeft.Value = 1.0;
_controllerRangeRight.Value = 1.0;
Logger.Info?.Print(LogClass.Application, $"{config.PlayerIndex} stick range reset. Save the profile now to update your configuration");
}
if (controllerConfig.Motion is CemuHookMotionConfigController cemuHookMotionConfig) if (controllerConfig.Motion is CemuHookMotionConfigController cemuHookMotionConfig)
{ {
_slotNumber.Value = cemuHookMotionConfig.Slot; _slotNumber.Value = cemuHookMotionConfig.Slot;
@ -678,6 +697,8 @@ namespace Ryujinx.Ui.Windows
PlayerIndex = _playerIndex, PlayerIndex = _playerIndex,
DeadzoneLeft = (float)_controllerDeadzoneLeft.Value, DeadzoneLeft = (float)_controllerDeadzoneLeft.Value,
DeadzoneRight = (float)_controllerDeadzoneRight.Value, DeadzoneRight = (float)_controllerDeadzoneRight.Value,
RangeLeft = (float)_controllerRangeLeft.Value,
RangeRight = (float)_controllerRangeRight.Value,
TriggerThreshold = (float)_controllerTriggerThreshold.Value, TriggerThreshold = (float)_controllerTriggerThreshold.Value,
LeftJoycon = new LeftJoyconCommonConfig<ConfigGamepadInputId> LeftJoycon = new LeftJoyconCommonConfig<ConfigGamepadInputId>
{ {
@ -1013,6 +1034,8 @@ namespace Ryujinx.Ui.Windows
ControllerType = ControllerType.JoyconPair, ControllerType = ControllerType.JoyconPair,
DeadzoneLeft = 0.1f, DeadzoneLeft = 0.1f,
DeadzoneRight = 0.1f, DeadzoneRight = 0.1f,
RangeLeft = 1.0f,
RangeRight = 1.0f,
TriggerThreshold = 0.5f, TriggerThreshold = 0.5f,
LeftJoycon = new LeftJoyconCommonConfig<ConfigGamepadInputId> LeftJoycon = new LeftJoyconCommonConfig<ConfigGamepadInputId>
{ {

View file

@ -33,6 +33,18 @@
<property name="step_increment">0.01</property> <property name="step_increment">0.01</property>
<property name="page_increment">0.10000000000000001</property> <property name="page_increment">0.10000000000000001</property>
</object> </object>
<object class="GtkAdjustment" id="_controllerRangeLeft">
<property name="upper">2</property>
<property name="value">1.000000000000000003</property>
<property name="step_increment">0.01</property>
<property name="page_increment">0.10000000000000001</property>
</object>
<object class="GtkAdjustment" id="_controllerRangeRight">
<property name="upper">2</property>
<property name="value">1.000000000000000003</property>
<property name="step_increment">0.01</property>
<property name="page_increment">0.10000000000000001</property>
</object>
<object class="GtkAdjustment" id="_controllerTriggerThreshold"> <object class="GtkAdjustment" id="_controllerTriggerThreshold">
<property name="upper">1</property> <property name="upper">1</property>
<property name="value">0.5</property> <property name="value">0.5</property>
@ -775,6 +787,46 @@
<property name="position">4</property> <property name="position">4</property>
</packing> </packing>
</child> </child>
<child>
<object class="GtkBox" id="_rangeLeftBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_top">10</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Range Left</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkScale">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="adjustment">_controllerRangeLeft</property>
<property name="round_digits">2</property>
<property name="digits">2</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">5</property>
</packing>
</child>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
@ -1692,6 +1744,46 @@
<property name="position">4</property> <property name="position">4</property>
</packing> </packing>
</child> </child>
<child>
<object class="GtkBox" id="_rangeRightBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_top">10</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Range Right</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkScale">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="adjustment">_controllerRangeRight</property>
<property name="round_digits">2</property>
<property name="digits">2</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">5</property>
</packing>
</child>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>