From cf3a6a4ca82e7abb883a4616751c3c9c6d756873 Mon Sep 17 00:00:00 2001 From: Hirek193 Date: Sun, 29 Nov 2026 19:50:21 +0100 Subject: [PATCH] feat(settings): the choice of the simulator and ray tracing in the standard mode - The exe the start button runs is chosen in a section of its own in General, not only in the developer tab: several builds may sit side by side. - Ray-traced reflections have a row of their own among the details of the picture: off, or Low, Medium, High, Very high, a level being how far the rays reach (gfx.raytracing.range 250, 500, 1000, 2000 m). No level of detail turns them on or off, as they cost far more than anything a level sets; turned off, the reach stays for the next time. A reach no level has is shown as it is and kept. Only Vulkan draws them, so with OpenGL chosen the row is dimmed. - gfx.raytracing.range is in the developer tab too, and the list follows its row. --- StarterNG.Tests/GraphicsPresetTests.cs | 52 ++++++++++++ StarterNG.Tests/SettingsUnknownValueTests.cs | 51 +++++++++++ StarterNG/Domain/Settings/RayTracing.cs | 61 ++++++++++++++ StarterNG/Domain/Settings/SimulatorKeys.cs | 1 + StarterNG/Views/Settings.axaml | 30 +++++-- StarterNG/Views/Settings.axaml.cs | 89 +++++++++++++++++++- StarterNG/Views/SimulatorKeyRows.cs | 3 + StarterNG/startercfg/lang/cz.xml | 3 + StarterNG/startercfg/lang/en.xml | 5 ++ StarterNG/startercfg/lang/hu.xml | 3 + StarterNG/startercfg/lang/pl.xml | 5 ++ StarterNG/startercfg/lang/ru.xml | 3 + StarterNG/startercfg/lang/zh.xml | 4 +- 13 files changed, 299 insertions(+), 11 deletions(-) create mode 100644 StarterNG/Domain/Settings/RayTracing.cs diff --git a/StarterNG.Tests/GraphicsPresetTests.cs b/StarterNG.Tests/GraphicsPresetTests.cs index f039a85..7298e43 100644 --- a/StarterNG.Tests/GraphicsPresetTests.cs +++ b/StarterNG.Tests/GraphicsPresetTests.cs @@ -262,6 +262,58 @@ public class GraphicsPresetTests Assert.Equal(first, installation.Files.ReadAllText(copy)); } + // ── Ray tracing ────────────────────────────────────────────────────────── + + [Theory] + [InlineData("no", "500", RayTracing.Off)] + [InlineData("no", "123", RayTracing.Off)] + [InlineData("yes", "250", 0)] + [InlineData("yes", "500", 1)] + [InlineData("yes", "1000", 2)] + [InlineData("yes", "2000", 3)] + public void Ray_tracing_is_off_or_at_the_level_of_its_reach(string enabled, string range, int level) => + Assert.Equal(level, RayTracing.LevelOf(enabled, range)); + + [Fact] + public void Ray_tracing_at_a_reach_no_level_has_is_at_none() + { + Assert.Null(RayTracing.LevelOf("yes", "750")); + } + + [Fact] + public void Ray_tracing_is_off_by_default_and_its_levels_reach_further_one_by_one() + { + Assert.Equal(RayTracing.Off, RayTracing.LevelOf(Defaults())); + var ranges = RayTracing.Levels.Select(level => level.Range).ToList(); + Assert.Equal(ranges.OrderBy(r => r).Distinct(), ranges); + var key = SimulatorKeys.Named(RayTracing.RangeKey); + Assert.All(ranges, range => Assert.InRange(range, key.Minimum, key.Maximum)); + } + + [Fact] + public void Turned_off_ray_tracing_keeps_its_reach_for_the_next_time() + { + var settings = Defaults().Copy(); + RayTracing.Apply(settings, 3); + RayTracing.Apply(settings, RayTracing.Off); + + Assert.Equal("no", settings.Extra[RayTracing.Key]); + Assert.Equal("2000", settings.Extra[RayTracing.RangeKey]); + } + + [Fact] + public void No_level_of_detail_turns_ray_tracing_on_or_off() + { + foreach (var preset in GraphicsPreset.All) + { + var settings = Defaults().Copy(); + RayTracing.Apply(settings, 2); + preset.ApplyTo(settings); + Assert.Equal(2, RayTracing.LevelOf(settings)); + Assert.Same(preset, GraphicsPreset.Matching(settings)); + } + } + // ── A level for one part ───────────────────────────────────────────────── private static GraphicsGroupLevels Groups() => new(new TestInstallation().SettingsStore); diff --git a/StarterNG.Tests/SettingsUnknownValueTests.cs b/StarterNG.Tests/SettingsUnknownValueTests.cs index 298460b..12ab51a 100644 --- a/StarterNG.Tests/SettingsUnknownValueTests.cs +++ b/StarterNG.Tests/SettingsUnknownValueTests.cs @@ -47,6 +47,10 @@ public class SettingsUnknownValueTests private static string? Shown(ComboBox list) => (list.SelectedItem as ComboBoxItem)?.Content as string; + private static SettingRow Row(StarterNG.Views.Settings page, string key) => + Avalonia.LogicalTree.LogicalExtensions.GetLogicalDescendants(page).OfType() + .First(row => row.ConfigKey == key); + private static string? Note(StarterNG.Views.Settings page, string key) => Avalonia.LogicalTree.LogicalExtensions.GetLogicalDescendants(page).OfType() .First(row => row.ConfigKey == key).UnknownValue; @@ -66,6 +70,53 @@ public class SettingsUnknownValueTests }); } + [Fact] + public void The_standard_mode_has_the_choice_of_the_simulator_and_of_ray_tracing_but_not_of_the_renderer() + { + WithPage(Standard, (page, _, _) => + { + Assert.True(Row(page, "starter.exe.path").IsEffectivelyVisible); + Assert.True(Row(page, "gfx.raytracing, gfx.raytracing.range").IsVisible); + Assert.False(Row(page, "gfxrenderer").IsVisible); + }); + } + + [Fact] + public void A_level_of_ray_tracing_picked_is_saved_as_its_reach() + { + WithPage(Standard, (page, services, saved) => + { + var list = List(page, "RayTracingCb"); + Assert.Equal(App.Loc["RayTracingOff"], Shown(list)); + + list.SelectedIndex = 3; + page.Save(); + + Assert.Contains("gfx.raytracing yes\n", saved()); + Assert.Contains("gfx.raytracing.range 1000\n", saved()); + + list.SelectedIndex = 0; + page.Save(); + + Assert.Contains("gfx.raytracing no\n", saved()); + Assert.Contains("gfx.raytracing.range 1000\n", saved()); + }); + } + + [Fact] + public void A_reach_of_ray_tracing_no_level_has_is_shown_as_it_is_and_kept() + { + WithPage(Standard + "gfx.raytracing yes\ngfx.raytracing.range 750\n", (page, _, saved) => + { + Assert.Contains("750", Shown(List(page, "RayTracingCb"))); + Assert.False(page.HasUnsavedChanges); + + page.Save(); + + Assert.Contains("gfx.raytracing.range 750\n", saved()); + }); + } + [Fact] public void Another_renderer_picked_from_the_list_replaces_it() { diff --git a/StarterNG/Domain/Settings/RayTracing.cs b/StarterNG/Domain/Settings/RayTracing.cs new file mode 100644 index 0000000..290e8d6 --- /dev/null +++ b/StarterNG/Domain/Settings/RayTracing.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; + +namespace StarterNG.Domain.Settings; + +/// +/// The ray-traced reflections as the standard mode offers them: off, or on at one of four levels, a level being how +/// far the rays reach (gfx.raytracing.range). Only the Vulkan renderer on a card with ray queries draws them. No +/// level of detail turns them on or off: they cost far more than anything a level sets, so they are the player's +/// own choice. +/// +public static class RayTracing +{ + public const string Key = "gfx.raytracing"; + + public const string RangeKey = "gfx.raytracing.range"; + + /// The levels, as the other parts of the picture name theirs, and the reach of each in metres. + public static readonly IReadOnlyList<(string NameKey, int Range)> Levels = new[] + { + ("PresetLow", 250), ("PresetMedium", 500), ("PresetHigh", 1000), ("PresetVeryHigh", 2000) + }; + + /// Off. + public const int Off = -1; + + /// + /// Where stands: , the index of its level, or null for a reach none of + /// them has. + /// + public static int? LevelOf(SimulatorSettings s) => LevelOf(SimulatorKeys.Named(Key).RawIn(s), SimulatorKeys.Named(RangeKey).RawIn(s)); + + /// The level of the two keys as the file writes them. + public static int? LevelOf(string enabled, string range) + { + if (!SimulatorKey.ParseToggle(enabled)) + return Off; + double metres = SimulatorKeys.Named(RangeKey).ParseNumber(range); + for (int i = 0; i < Levels.Count; i++) + if (Math.Abs(Levels[i].Range - metres) < 0.5) + return i; + return null; + } + + /// + /// The two keys at , in the file's words. Off leaves the reach as it is, for the next + /// time they are turned on. + /// + public static (string Enabled, string? Range) ValuesOf(int level) => + level == Off + ? (SimulatorKey.FormatToggle(false), null) + : (SimulatorKey.FormatToggle(true), Levels[level].Range.ToString(System.Globalization.CultureInfo.InvariantCulture)); + + public static void Apply(SimulatorSettings s, int level) + { + var (enabled, range) = ValuesOf(level); + s.Extra[Key] = enabled; + if (range is not null) + s.Extra[RangeKey] = range; + } +} diff --git a/StarterNG/Domain/Settings/SimulatorKeys.cs b/StarterNG/Domain/Settings/SimulatorKeys.cs index 15996b9..5c38097 100644 --- a/StarterNG/Domain/Settings/SimulatorKeys.cs +++ b/StarterNG/Domain/Settings/SimulatorKeys.cs @@ -157,6 +157,7 @@ public static class SimulatorKeys Toggle("gfx.shadow.sdsm", false, Advanced, QualitySection), Choice("gfx.ssr", "medium", QualitySection), Toggle("gfx.raytracing", false, Advanced, QualitySection), + Number("gfx.raytracing.range", 500, Advanced, QualitySection, 10, 5000, 10, " m"), Choice("gfx.cabprobe", "medium", QualitySection), Toggle("gfx.water.realistic", false, Advanced, QualitySection), Choice("gfx.postfx.ao", "gtao", QualitySection, new[] { "no", "ssao", "gtao" }), diff --git a/StarterNG/Views/Settings.axaml b/StarterNG/Views/Settings.axaml index 27967b4..2ab5355 100644 --- a/StarterNG/Views/Settings.axaml +++ b/StarterNG/Views/Settings.axaml @@ -144,6 +144,21 @@ + + + + + + +