fix(settings): the cursor's speed is read and written as the old starter did, its four levels

The old starter (src/uSettings.pas) showed a mousescale as one of four levels - low below 1.3, high above 1.9, very high above 2.7, standard between - and wrote 1.0, 1.5, 2.3 or 3.2 for them, with 0.5 after it, the signs being the inversions. The slider had three whole steps instead, so a 3.2 was the top only by rounding and anything above 3 was cut to 3 on the move to the standard mode.
This commit is contained in:
maj00r
2026-11-22 14:47:05 +01:00
parent 34beec588d
commit 77b0c23cea
6 changed files with 111 additions and 73 deletions

View File

@@ -492,10 +492,8 @@ public class SettingsStoreTests
[InlineData("mousescale 1.5 0.5", false, true, "mousescale 1.5 -0.5")]
[InlineData("mousescale 1.5 0.5", true, false, "mousescale -1.5 0.5")]
[InlineData("mousescale -1.5 -0.5", false, false, "mousescale 1.5 0.5")]
[InlineData("mousescale 2.5 0.5", false, true, "mousescale 2.5 -0.5")]
// Further than the slider goes.
[InlineData("mousescale 12 0.5", true, false, "mousescale -12 0.5")]
public void A_mouse_scale_keeps_its_numbers_when_an_axis_is_inverted(
[InlineData("mousescale 3.2 0.5", true, true, "mousescale -3.2 -0.5")]
public void An_inverted_axis_is_the_sign_of_its_number(
string line, bool invertX, bool invertY, string written)
{
var installation = WithHome(new InMemoryFileSystem().WithFile(UserIni, line + "\n"));
@@ -508,10 +506,69 @@ public class SettingsStoreTests
Assert.Equal(written, LineFor(installation, "mousescale"));
}
[Fact]
public void A_mouse_scale_nobody_changed_stays_as_the_file_has_it()
[Theory]
[InlineData("mousescale 1.0 0.5")]
[InlineData("mousescale 1 0.5")]
[InlineData("mousescale 1.5 0.5")]
[InlineData("mousescale -2.3 0.5")]
[InlineData("mousescale 3.2 -0.5")]
public void A_mouse_scale_of_the_old_starter_stays_as_the_file_has_it(string line)
{
var installation = WithHome(new InMemoryFileSystem().WithFile(UserIni, "mousescale 1.5 0.5\n"));
var installation = WithHome(new InMemoryFileSystem().WithFile(UserIni, line + "\n"));
installation.SettingsStore.Load();
installation.SettingsStore.Save();
Assert.Equal(line, LineFor(installation, "mousescale"));
}
[Theory]
// The old starter's four speeds (src/uSettings.pas): low, standard, high, very high.
[InlineData(1, "mousescale 1.0 0.5")]
[InlineData(2, "mousescale 1.5 0.5")]
[InlineData(3, "mousescale 2.3 0.5")]
[InlineData(4, "mousescale 3.2 0.5")]
public void The_sensitivity_is_written_as_the_old_starter_wrote_it(int level, string written)
{
var installation = WithHome(new InMemoryFileSystem().WithFile(UserIni, "mousescale 12 0.5\n"));
installation.SettingsStore.Load();
installation.SettingsStore.Settings.CursorSensitivity = level;
installation.SettingsStore.Save();
Assert.Equal(written, LineFor(installation, "mousescale"));
}
[Theory]
// Low below 1.3, high above 1.9, very high above 2.7, standard between - whatever the sign.
[InlineData("0", 1)]
[InlineData("0.2", 1)]
[InlineData("1.29", 1)]
[InlineData("1.3", 2)]
[InlineData("1.5", 2)]
[InlineData("1.9", 2)]
[InlineData("2", 3)]
[InlineData("-2.3", 3)]
[InlineData("2.7", 3)]
[InlineData("3", 4)]
[InlineData("-3.2", 4)]
[InlineData("12", 4)]
// Not a number the old starter could read: its list stayed at standard.
[InlineData("Infinity", 2)]
[InlineData("fast", 2)]
public void The_sensitivity_is_read_as_the_old_starter_read_it(string x, int level)
{
var installation = WithHome(new InMemoryFileSystem().WithFile(UserIni, $"mousescale {x} 0.5\n"));
installation.SettingsStore.Load();
Assert.Equal(level, installation.SettingsStore.Settings.CursorSensitivity);
}
[Fact]
public void Without_a_mouse_scale_the_old_starters_standard_is_written()
{
var installation = WithHome();
installation.SettingsStore.Load();
installation.SettingsStore.Save();
@@ -519,49 +576,28 @@ public class SettingsStoreTests
Assert.Equal("mousescale 1.5 0.5", LineFor(installation, "mousescale"));
}
[Fact]
public void Moving_the_sensitivity_replaces_the_scale_it_stood_for()
{
var installation = WithHome(new InMemoryFileSystem().WithFile(UserIni, "mousescale 1.5 0.5\n"));
installation.SettingsStore.Load();
Assert.Equal(2, installation.SettingsStore.Settings.CursorSensitivity);
installation.SettingsStore.Settings.CursorSensitivity = 3;
installation.SettingsStore.Save();
Assert.Equal("mousescale 3 0.5", LineFor(installation, "mousescale"));
}
[Fact]
public void The_default_mouse_scale_is_written_as_before()
{
var installation = WithHome();
installation.SettingsStore.Load();
installation.SettingsStore.Save();
Assert.Equal("mousescale 2 0.5", LineFor(installation, "mousescale"));
}
[Theory]
// The second number is always 0.5, as the old starter wrote it; its sign is the inversion.
[InlineData("mousescale 1.5 0.2", "mousescale 1.5 0.5")]
[InlineData("mousescale 1.5 0.23", "mousescale 1.5 0.5")]
[InlineData("mousescale 1.5 -0.23", "mousescale 1.5 -0.5")]
[InlineData("mousescale 1.5 -2", "mousescale 1.5 -0.5")]
// A zero locks that axis in the simulator: the camera turns only left/right.
// X goes back to the default.
[InlineData("mousescale 0.5 0", "mousescale 0.5 0.5")]
[InlineData("mousescale 0.5 -0", "mousescale 0.5 0.5")]
[InlineData("mousescale 0 0.5", "mousescale 2 0.5")]
[InlineData("mousescale 0 0", "mousescale 2 0.5")]
[InlineData("mousescale 1.5 0", "mousescale 1.5 0.5")]
[InlineData("mousescale 1.5 -0", "mousescale 1.5 0.5")]
[InlineData("mousescale 1.5 NaN", "mousescale 1.5 0.5")]
[InlineData("mousescale Infinity -0.5", "mousescale 2 -0.5")]
// A decimal comma: the simulator reads "0,2" as 0.
[InlineData("mousescale 1.5 0,2", "mousescale 1.5 0.5")]
// The first is one of that starter's four speeds, the one of the level the file's number has.
[InlineData("mousescale 0.5 0.5", "mousescale 1.0 0.5")]
[InlineData("mousescale 0 0.5", "mousescale 1.0 0.5")]
[InlineData("mousescale 2 0.5", "mousescale 2.3 0.5")]
[InlineData("mousescale -3 0.5", "mousescale -3.2 0.5")]
[InlineData("mousescale 12 0.2", "mousescale 3.2 0.5")]
[InlineData("mousescale Infinity -0.5", "mousescale 1.5 -0.5")]
// One number: the simulator takes the next word of the file ("mousecontrol") for Y, and reads it as 0.
[InlineData("mousescale 1.5", "mousescale 1.5 0.5")]
[InlineData("mousescale 0.5\t// (3.2 0.5) komentarz", "mousescale 0.5 0.5\t// (3.2 0.5) komentarz")]
// A decimal comma: the simulator reads "0,2" as 0.
[InlineData("mousescale 0.5 0,2", "mousescale 0.5 0.5")]
public void A_mouse_scale_axis_that_would_not_move_gets_the_default(string line, string written)
[InlineData("mousescale 0.5\t// (3.2 0.5) komentarz", "mousescale 1.0 0.5\t// (3.2 0.5) komentarz")]
public void A_mouse_scale_the_old_starter_would_not_write_goes_on_a_save(string line, string written)
{
var installation = WithHome(new InMemoryFileSystem().WithFile(UserIni, line + "\n"));
installation.SettingsStore.Load();

View File

@@ -230,10 +230,25 @@ public sealed class SimulatorSettings
}
/// <summary>
/// The file's own first mousescale number. The slider takes whole steps: this
/// stands for as long as <see cref="CursorSensitivity"/> is the step nearest it.
/// The first mousescale number of each level of <see cref="CursorSensitivity"/>, 1 to 4, as
/// the old starter wrote them (MaSzyna-EU07/Starter, src/uSettings.pas): low, standard, high
/// and very high, negative with <see cref="InvertMouseHorizontal"/>. Whatever else the file
/// has there goes on the next save.
/// </summary>
internal double MouseScaleXMagnitude { get; set; } = 2;
internal static readonly double[] MouseScales = { 1.0, 1.5, 2.3, 3.2 };
/// <summary>The first mousescale number <paramref name="level"/> stands for.</summary>
internal static double MouseScaleOf(int level) => MouseScales[Math.Clamp(level, 1, MouseScales.Length) - 1];
/// <summary>
/// The level the old starter showed for a first mousescale number: low below 1.3, high
/// above 1.9, very high above 2.7 and standard between, whatever its sign.
/// </summary>
internal static int MouseLevelOf(double scale)
{
double size = Math.Abs(scale);
return size > 2.7 ? 4 : size > 1.9 ? 3 : size < 1.3 ? 1 : 2;
}
/// <summary>
/// The second mousescale number, as the old starter always wrote it: 0.5, or

View File

@@ -16,9 +16,6 @@ public static class SliderRanges
/// <summary>dynamiclights: 1 to 7.</summary>
public const int MinDynamicLights = 1;
/// <summary>The cursor's speed: its fastest was a mousescale of 3.2.</summary>
public const int MaxCursorSensitivity = 3;
/// <summary>gfx.reflections.framerate, in updates a second.</summary>
public static readonly double[] ReflectionUpdates = { 1, 3, 10, 25, 60 };

View File

@@ -36,16 +36,14 @@ public sealed class SettingsSerializer
s.FpsAverage = c.GetDouble("fpsaverage", 0);
s.PauseOnStart = c.GetBool("pause", false);
// A zero (or NaN/Infinity) scale locks that axis in the simulator: the
// camera then turns only one way. Nothing in the starter writes such a
// number on purpose, so X takes the default. Of Y only the sign is read:
// it is written 0.5 or -0.5, as the old starter always wrote it.
// As the old starter read it (src/uSettings.pas): of X its level and its sign, of Y
// only the sign. Both are written as that starter wrote them, one of its four speeds
// and 0.5, whatever the file had. A number that cannot be read leaves the standard level.
var mouse = c.GetTokens("mousescale");
if (mouse.Length >= 1 && TryParseMouseScale(mouse[0], out double mx))
{
s.InvertMouseHorizontal = mx < 0;
s.MouseScaleXMagnitude = Math.Abs(mx);
s.CursorSensitivity = SensitivityStep(mx);
s.CursorSensitivity = SimulatorSettings.MouseLevelOf(mx);
}
if (mouse.Length >= 1)
s.InvertMouseVertical = mouse.Length >= 2 && TryParseMouseScale(mouse[1], out double my) && my < 0;
@@ -243,14 +241,11 @@ public sealed class SettingsSerializer
c.SetBool("inactivepause", s.PauseWhenInactive);
c.SetBool("pause", s.PauseOnStart);
double magnitude = SensitivityStep(s.MouseScaleXMagnitude) == s.CursorSensitivity
? s.MouseScaleXMagnitude
: s.CursorSensitivity;
double mx = magnitude * (s.InvertMouseHorizontal ? -1 : 1);
double mx = SimulatorSettings.MouseScaleOf(s.CursorSensitivity) * (s.InvertMouseHorizontal ? -1 : 1);
double my = SimulatorSettings.MouseScaleY * (s.InvertMouseVertical ? -1 : 1);
c.Set("mousescale",
$"{mx.ToString("R", CultureInfo.InvariantCulture)} " +
$"{my.ToString("R", CultureInfo.InvariantCulture)}");
$"{mx.ToString("0.0", CultureInfo.InvariantCulture)} " +
$"{my.ToString("0.0", CultureInfo.InvariantCulture)}");
c.SetBool("input.gamepad", !s.IgnoreGamepad);
c.SetInt("feedbackmode", s.FeedbackMode);
@@ -433,25 +428,23 @@ public sealed class SettingsSerializer
private static int Clamp(int v, int lo, int hi) => v < lo ? lo : (v > hi ? hi : v);
/// <summary>
/// Whether the file's own mousescale can stay as it is: a first number neither
/// zero nor NaN/Infinity, and 0.5 or -0.5 after it. Otherwise a save writes the
/// one the starter holds.
/// Whether the file's own mousescale can stay as it is: one of the old starter's four
/// speeds, and 0.5 or -0.5 after it. Otherwise a save writes the one the starter holds,
/// as every save of the old starter did.
/// </summary>
public static bool MouseScaleStands(string? raw)
{
string[] tokens = (raw ?? "").Split((char[]?)null, StringSplitOptions.RemoveEmptyEntries);
return tokens.Length >= 2 &&
TryParseMouseScale(tokens[0], out _) &&
TryParseMouseScale(tokens[0], out double x) &&
Math.Abs(Math.Abs(x) - SimulatorSettings.MouseScaleOf(SimulatorSettings.MouseLevelOf(x))) < 1e-9 &&
TryParseMouseScale(tokens[1], out double y) &&
Math.Abs(Math.Abs(y) - SimulatorSettings.MouseScaleY) < 1e-9;
}
private static bool TryParseMouseScale(string token, out double scale) =>
double.TryParse(token, NumberStyles.Float, CultureInfo.InvariantCulture, out scale) &&
double.IsFinite(scale) && scale != 0;
private static int SensitivityStep(double mouseScale) =>
(int)Math.Clamp(Math.Round(Math.Abs(mouseScale)), 1, 5);
double.IsFinite(scale);
private static double ParseDouble(string s, double fallback) =>
double.TryParse(s, NumberStyles.Float, CultureInfo.InvariantCulture, out double d) ? d : fallback;

View File

@@ -145,8 +145,8 @@
</ctl:SettingRow>
<ctl:SettingRow ConfigKey="mousescale" x:Name="CursorSensitivityRow"
Label="{Binding [CursorSensitivity], Source={x:Static starterNg:App.Loc}}">
<ctl:ReadableSlider x:Name="CursorSensitivitySlider" Minimum="1" Maximum="3" TickFrequency="1"
IsSnapToTickEnabled="True" Value="3"
<ctl:ReadableSlider x:Name="CursorSensitivitySlider" Minimum="1" Maximum="4" TickFrequency="1"
IsSnapToTickEnabled="True" Value="2"
ValueChanged="QualitySlider_OnValueChanged" />
</ctl:SettingRow>
<ctl:SettingRow ConfigKey="mousescale">

View File

@@ -1766,9 +1766,6 @@ public partial class Settings : UserControl, ISettingsCapture
DynamicLightsSlider.Minimum = widen
? Math.Min(SliderRanges.MinDynamicLights, s.DynamicLights)
: SliderRanges.MinDynamicLights;
CursorSensitivitySlider.Maximum = widen
? Math.Max(SliderRanges.MaxCursorSensitivity, s.CursorSensitivity)
: SliderRanges.MaxCursorSensitivity;
foreach (var steps in new[] { _fpsLimit, _reflections, _anisotropy, _drawRangeFactor, _cabShadows })
steps.Clamps = _clamping;
}