diff --git a/StarterNG.Tests/ExternalIniTests.cs b/StarterNG.Tests/ExternalIniTests.cs index 7086035..55a4655 100644 --- a/StarterNG.Tests/ExternalIniTests.cs +++ b/StarterNG.Tests/ExternalIniTests.cs @@ -71,17 +71,17 @@ public class ExternalIniTests [Fact] public void A_renderer_written_in_by_hand_while_the_starter_runs_survives_its_save() { - // Notepad: "gfxrenderer vulkan", a word the starter does not offer. + // Notepad: "gfxrenderer null", a word the starter does not offer. var installation = WithIni("gfxrenderer default\nfieldofview 45\n"); - Edited(installation, "gfxrenderer vulkan\nfieldofview 45\n"); + Edited(installation, "gfxrenderer null\nfieldofview 45\n"); installation.SettingsStore.Settings.FieldOfView = 60; installation.SettingsStore.Save(); string saved = installation.Files.ReadAllText(UserIni); - Assert.Contains("gfxrenderer vulkan", saved); + Assert.Contains("gfxrenderer null", saved); Assert.Contains("fieldofview 60", saved); - Assert.Equal("vulkan", installation.SettingsStore.Settings.RendererWord); + Assert.Equal("null", installation.SettingsStore.Settings.RendererWord); } [Fact] @@ -188,8 +188,9 @@ public class ExternalIniTests string saved = installation.Files.ReadAllText(UserIni); Assert.Contains("maxcabtexturesize 4096", saved); Assert.Contains("shadowtune 4096 250 400 300", saved); - Assert.Contains("gfx.framebuffer.width 1920", saved); - Assert.Contains("gfx.framebuffer.height 1080", saved); + // The render scale is the simulator's own key now, at the whole window. + Assert.Contains("gfx.buffer.percent 1", saved); + Assert.DoesNotContain("\ngfx.framebuffer.width", "\n" + saved); Assert.Contains("fieldofview 50", saved); } diff --git a/StarterNG.Tests/GraphicsPresetTests.cs b/StarterNG.Tests/GraphicsPresetTests.cs index 6de00f4..f039a85 100644 --- a/StarterNG.Tests/GraphicsPresetTests.cs +++ b/StarterNG.Tests/GraphicsPresetTests.cs @@ -13,98 +13,199 @@ public class GraphicsPresetTests return installation.SettingsStore.Settings; } - private static SimulatorSettings AtHigh() + private static SimulatorSettings At(GraphicsPreset preset) { var settings = Defaults().Copy(); - GraphicsPreset.High.ApplyTo(settings); + preset.ApplyTo(settings); return settings; } + private static SimulatorSettings AtHigh() => At(GraphicsPreset.High); + + /// The keys two renderings give different values, a key one leaves out at its default. + private static IEnumerable Differing(IReadOnlyDictionary one, IReadOnlyDictionary other) + { + string? Value(IReadOnlyDictionary keys, string key) => + keys.TryGetValue(key, out string? value) ? value : SimulatorKeys.All.FirstOrDefault(k => k.Key == key)?.Default; + return one.Keys.Union(other.Keys).Where(key => Value(one, key) != Value(other, key)); + } + [Fact] - public void The_keys_named_are_the_keys_a_level_sets() + public void A_level_sets_no_key_but_those_it_names() { var store = new TestInstallation().SettingsStore; - var low = Defaults().Copy(); - var top = Defaults().Copy(); - (GraphicsPreset.Minimal with { Extras = null }).ApplyTo(low); - (GraphicsPreset.Ultra with { Extras = null, Top = null }).ApplyTo(top); + var own = store.Render(Defaults()); + foreach (var preset in GraphicsPreset.All) + Assert.Empty(Differing(own, store.Render(At(preset))).Except(GraphicsPreset.AllKeys)); + } - var lowKeys = store.Render(low); - var topKeys = store.Render(top); - var differing = lowKeys.Keys.Union(topKeys.Keys) - .Where(key => lowKeys.GetValueOrDefault(key) != topKeys.GetValueOrDefault(key)); + [Fact] + public void Every_key_of_a_level_belongs_to_one_part_or_to_the_anti_aliasing() + { + var inGroups = GraphicsGroup.All.SelectMany(group => group.Keys).ToList(); - Assert.Equal(GraphicsPreset.Keys.OrderBy(k => k), differing.OrderBy(k => k)); + Assert.Equal(inGroups.Distinct(), inGroups); + Assert.Empty(GraphicsPreset.All.SelectMany(preset => preset.Keys.Keys).Except(inGroups)); } // ── The scale ──────────────────────────────────────────────────────────── - private static void Climbs(Func value, int repeatsAllowed) + private static void Climbs(Func value) { var values = GraphicsPreset.All.Select(value).ToList(); - Assert.Equal(values.OrderBy(v => v), values); - Assert.True(values.Count - values.Distinct().Count() <= repeatsAllowed, string.Join(", ", values)); } [Fact] - public void Every_slider_moves_from_level_to_level_as_far_as_it_has_steps_for_six() + public void Every_part_of_the_picture_gets_better_or_stays_from_level_to_level() { - // Sizes and filtering run out of steps above High. - Climbs(p => p.TextureSize, 1); - Climbs(p => p.CabTextureSize, 2); - Climbs(p => p.Anisotropy, 1); + Climbs(p => p.TextureSize); + Climbs(p => p.CabTextureSize); + Climbs(p => p.Anisotropy); + Climbs(p => p.ShadowMap); + Climbs(p => p.ShadowRange); + Climbs(p => p.ShadowRank); + Climbs(p => p.ReflectionsFidelity); + Climbs(p => p.ReflectionsRate); + Climbs(p => p.SplineFidelity); + Climbs(p => p.DrawRangeFactor); + Climbs(p => p.SmokeFidelity); - // Four steps or three for six levels. - Climbs(p => (int)p.AntiAliasing, 2); - Climbs(p => p.SmokeFidelity, 2); - Climbs(p => p.SplineFidelity, 2); - Climbs(p => p.ReflectionsFidelity, 3); - Climbs(p => p.ShadowRank, 3); - - // The simulator takes no more than its own 7 lights. - Climbs(p => p.DynamicLights, 2); - Climbs(p => p.DrawRangeFactor, 3); - Climbs(p => p.CabShadowsRange, 1); - - Climbs(p => p.ShadowMap, 2); - Climbs(p => p.ShadowRange, 1); - // The old starter's steps begin at once a second: the lower levels share it. - Climbs(p => p.ReflectionsRate, 2); - } - - [Fact] - public void No_step_up_a_scale_is_more_than_a_few_steps_of_its_slider() - { - // In steps of what the screen offers, so Ultra does not jump to the top from far below. - var rates = GraphicsPreset.All.Select(p => Steps.IndexOf(SliderRanges.ReflectionUpdates, p.ReflectionsRate)).ToList(); - Assert.All(rates.Zip(rates.Skip(1)), step => Assert.InRange(step.Second - step.First, 0, 2)); - - foreach (Func fidelity in new Func[] { p => p.SmokeFidelity, p => p.SplineFidelity }) + foreach (string name in GraphicsPreset.Low.Keys.Keys) { - var levels = GraphicsPreset.All.Select(fidelity).ToList(); - Assert.All(levels.Zip(levels.Skip(1)), step => Assert.InRange(step.Second - step.First, 0, 1)); + var key = SimulatorKeys.Named(name); + Climbs(p => key.Kind switch + { + SimulatorKeyKind.Choice => key.ChoiceIndex(p.Keys[name]), + SimulatorKeyKind.Toggle => SimulatorKey.ParseToggle(p.Keys[name]) ? 1 : 0, + _ => key.ParseNumber(p.Keys[name]) + }); } } [Fact] - public void High_is_the_simulators_own_but_where_that_is_the_bottom_of_a_scale() + public void Every_level_sets_the_same_keys() { - var store = new TestInstallation().SettingsStore; - var own = store.Render(Defaults()); - var high = store.Render(AtHigh()); - - var differing = own.Keys.Union(high.Keys) - .Where(key => own.GetValueOrDefault(key) != high.GetValueOrDefault(key)); - - Assert.Equal(new[] { "gfx.reflections.fidelity", "gfx.reflections.framerate", "gfx.shadows.cab.range", - "gfx.smoke.fidelity", "splinefidelity" }, differing.OrderBy(k => k)); - Assert.Equal(1, Defaults().SmokeFidelity); - Assert.Equal(1, Defaults().SplineFidelity); + foreach (var preset in GraphicsPreset.All) + Assert.Equal(GraphicsPreset.High.Keys.Keys.OrderBy(k => k), preset.Keys.Keys.OrderBy(k => k)); } [Fact] - public void A_player_with_no_settings_of_their_own_starts_at_high() + public void Every_value_of_a_level_is_one_its_row_offers() + { + foreach (var preset in GraphicsPreset.All) + foreach (var (name, value) in preset.Keys) + { + var key = SimulatorKeys.Named(name); + switch (key.Kind) + { + case SimulatorKeyKind.Choice: + Assert.True(key.ChoiceIndex(value) >= 0, $"{preset.NameKey} {name} {value}"); + break; + case SimulatorKeyKind.Number: + Assert.InRange(key.ParseNumber(value), key.Minimum, key.Maximum); + break; + } + } + } + + [Fact] + public void High_is_the_simulators_own_but_for_the_smoke_and_the_track_curves() + { + var store = new TestInstallation().SettingsStore; + + var differing = Differing(store.Render(Defaults()), store.Render(AtHigh())); + + Assert.Equal(new[] { "gfx.smoke.fidelity", "splinefidelity" }, differing.OrderBy(k => k, StringComparer.Ordinal)); + } + + [Fact] + public void Very_high_is_not_everything_at_its_top() + { + var top = GraphicsPreset.VeryHigh; + + Assert.True(top.AntiAliasing <= AntiAliasingMode.Msaa4); + Assert.True(top.ShadowMap <= 4096); + Assert.False(top.Keys.ContainsKey("gfx.raytracing")); + Assert.NotEqual("ultra", top.Keys["gfx.clouds"]); + Assert.NotEqual("ultra", top.Keys["gfx.fog.quality"]); + } + + [Fact] + public void Low_draws_no_screen_space_effects() + { + Assert.Equal(AntiAliasingMode.Off, GraphicsPreset.Low.AntiAliasing); + Assert.Equal("no", GraphicsPreset.Low.Keys["gfx.ssr"]); + Assert.Equal("no", GraphicsPreset.Low.Keys["gfx.postfx.ao"]); + Assert.Equal("no", GraphicsPreset.Low.Keys["gfx.contactshadows"]); + } + + [Fact] + public void Every_level_sits_on_the_steps_the_screen_offers() + { + foreach (var preset in GraphicsPreset.All) + { + Assert.True(Steps.IndexOf(Steps.Anisotropy, preset.Anisotropy) >= 0, preset.NameKey); + Assert.True(Steps.IndexOf(SliderRanges.ReflectionUpdates, preset.ReflectionsRate) >= 0, preset.NameKey); + Assert.True(Steps.IndexOf(SliderRanges.DrawRangeFactors, preset.DrawRangeFactor) >= 0, preset.NameKey); + foreach (int size in new[] { preset.TextureSize, preset.CabTextureSize, preset.ShadowMap }) + Assert.True(size is >= 512 and <= 8192 && (size & (size - 1)) == 0, preset.NameKey); + Assert.True(preset.CabTextureSize <= GraphicsRules.MaxCabTextureSize, preset.NameKey); + Assert.True(preset.ShadowRange >= SimulatorSettings.ShadowRangeFloor(preset.ShadowMap), preset.NameKey); + Assert.True(preset.ShadowRange <= GraphicsRules.MaxShadowRange, preset.NameKey); + } + } + + [Fact] + public void A_level_leaves_the_screen_and_the_matters_of_taste_as_they_are() + { + var settings = Defaults().Copy(); + settings.MotionBlur = false; + settings.ChromaticAberration = false; + settings.Smoke = false; + settings.PythonScreens = false; + settings.FieldOfView = 60; + settings.BufferScalePercent = 75; + settings.Backend = GraphicsBackend.OpenGL; + + GraphicsPreset.VeryHigh.ApplyTo(settings); + + Assert.False(settings.MotionBlur); + Assert.False(settings.ChromaticAberration); + Assert.False(settings.Smoke); + Assert.False(settings.PythonScreens); + Assert.Equal(60, settings.FieldOfView); + Assert.Equal(75, settings.BufferScalePercent); + Assert.Equal(GraphicsBackend.OpenGL, settings.Backend); + } + + [Fact] + public void A_level_applied_is_recognised_until_one_value_moves() + { + foreach (var preset in GraphicsPreset.All) + { + var settings = At(preset); + Assert.Same(preset, GraphicsPreset.Matching(settings)); + + settings.Extra["gfx.ssr"] = preset.Keys["gfx.ssr"] == "high" ? "low" : "high"; + Assert.Null(GraphicsPreset.Matching(settings)); + } + } + + [Fact] + public void A_level_is_recognised_with_its_words_written_as_numbers() + { + var settings = AtHigh(); + settings.Extra["gfx.ssr"] = "2"; + settings.Extra["gfx.lights.shadows"] = "2"; + + Assert.Same(GraphicsPreset.High, GraphicsPreset.Matching(settings)); + } + + // ── The first start ────────────────────────────────────────────────────── + + [Fact] + public void A_player_with_no_settings_of_their_own_starts_at_high_on_vulkan() { var installation = new TestInstallation(); var store = installation.SettingsStore; @@ -118,8 +219,10 @@ public class GraphicsPresetTests var again = new TestInstallation(installation.Files).SettingsStore; again.Load(); Assert.Same(GraphicsPreset.High, GraphicsPreset.Matching(again.Settings)); - // Nothing of an older starter to bring into the standard mode. + Assert.Equal(GraphicsBackend.Vulkan, again.Settings.Backend); + // Nothing of an older starter to bring into the standard mode, nor of an older layout. Assert.True(again.Settings.MovedToStandard); + Assert.Equal(SimulatorSettings.CurrentRevision, again.Settings.Revision); } [Fact] @@ -159,369 +262,10 @@ public class GraphicsPresetTests Assert.Equal(first, installation.Files.ReadAllText(copy)); } - [Fact] - public void Ultra_is_the_top_of_what_the_old_starter_offered() - { - var ultra = GraphicsPreset.Ultra; - - Assert.Equal(8192, ultra.TextureSize); - Assert.Equal(GraphicsRules.MaxCabTextureSize, ultra.CabTextureSize); - Assert.Equal(8192, ultra.ShadowMap); - Assert.Equal(GraphicsRules.MaxShadowRange, ultra.ShadowRange); - Assert.Equal(Steps.Anisotropy.Max(), ultra.Anisotropy); - Assert.Equal(AntiAliasingMode.Msaa8, ultra.AntiAliasing); - Assert.Equal(SliderRanges.ReflectionUpdates.Max(), ultra.ReflectionsRate); - Assert.Equal(4, ultra.SmokeFidelity); - Assert.Equal(4, ultra.SplineFidelity); - Assert.Equal(SliderRanges.DrawRangeFactors.Max(), ultra.DrawRangeFactor); - Assert.Equal(100, ultra.CabShadowsRange); - - var extras = ultra.Extras!; - Assert.Equal(200, extras.PythonUpdateMs); - Assert.True(extras.MotionBlur && extras.ChromaticAberration && extras.Smoke); - - Assert.True(ultra.Top!.Screens); - } - - [Fact] - public void No_level_goes_past_what_the_old_starter_gave() - { - foreach (var preset in GraphicsPreset.All) - { - Assert.True(preset.ShadowRange <= GraphicsRules.MaxShadowRange, preset.NameKey); - Assert.True(preset.CabTextureSize <= GraphicsRules.MaxCabTextureSize, preset.NameKey); - } - } - - [Fact] - public void No_level_sets_what_only_the_advanced_mode_shows() - { - var set = GraphicsPreset.Keys.Concat(GraphicsExtras.Keys).Concat(GraphicsTop.Keys).ToList(); - - // The rows of keys by name, the buffer and the resources are all the advanced mode's. - Assert.Empty(set.Intersect(SimulatorKeys.All.Select(key => key.Key))); - Assert.Empty(set.Intersect(new[] { "starter.bufferscale", "gfx.framebuffer.width", "gfx.framebuffer.height", - "compresstex", "python.mipmaps", "gfx.skippipeline" })); - } - - [Fact] - public void A_level_leaves_what_only_the_advanced_mode_shows_as_it_is() - { - foreach (var preset in GraphicsPreset.All) - { - var settings = Defaults().Copy(); - settings.BufferScalePercent = 80; - settings.CompressTextures = false; - settings.ScreenMipmaps = false; - settings.Extra["basedrawrange"] = "3000"; - settings.Extra["targetfps"] = "60"; - - preset.ApplyTo(settings); - - Assert.Equal(80, settings.BufferScalePercent); - Assert.False(settings.CompressTextures); - Assert.False(settings.ScreenMipmaps); - Assert.Equal("3000", settings.Extra["basedrawrange"]); - Assert.Equal("60", settings.Extra["targetfps"]); - Assert.Same(preset, GraphicsPreset.Matching(settings)); - } - } - - [Fact] - public void At_ultra_the_shadows_are_longest() - { - // The bottom of that scale. - Assert.Equal(0.2, GraphicsPreset.Ultra.Top!.ShadowAngleLimit); - } - - [Fact] - public void Ultra_undoes_what_was_moved_earlier() - { - var settings = Defaults().Copy(); - settings.ShadowAngleLimit = 0.8; - settings.IgnoreIrrelevantTrains = true; - settings.PythonScreens = false; - - GraphicsPreset.Ultra.ApplyTo(settings); - - Assert.Same(GraphicsPreset.Ultra, GraphicsPreset.Matching(settings)); - Assert.Equal(0.2, settings.ShadowAngleLimit); - Assert.True(settings.PythonScreens); - Assert.True(settings.IgnoreIrrelevantTrains); - } - - [Fact] - public void Ultra_leaves_the_screens_in_their_own_windows_to_the_player() - { - var settings = Defaults().Copy(); - settings.Extra["python.displaywindows"] = "yes"; - - GraphicsPreset.Ultra.ApplyTo(settings); - - Assert.Equal("yes", settings.Extra["python.displaywindows"]); - Assert.Same(GraphicsPreset.Ultra, GraphicsPreset.Matching(settings)); - } - - [Fact] - public void The_other_levels_leave_what_only_ultra_sets() - { - foreach (var preset in GraphicsPreset.All.Where(preset => preset != GraphicsPreset.Ultra)) - { - var settings = Defaults().Copy(); - settings.IgnoreIrrelevantTrains = true; - settings.ShadowAngleLimit = 0.8; - - preset.ApplyTo(settings); - - Assert.True(settings.IgnoreIrrelevantTrains, preset.NameKey); - Assert.Equal(0.8, settings.ShadowAngleLimit); - Assert.Same(preset, GraphicsPreset.Matching(settings)); - } - } - - [Fact] - public void Ultra_is_not_recognised_with_one_of_its_values_moved() - { - var settings = Defaults().Copy(); - GraphicsPreset.Ultra.ApplyTo(settings); - Assert.Same(GraphicsPreset.Ultra, GraphicsPreset.Matching(settings)); - - settings.ReflectionsFramerate = 25; - - Assert.Null(GraphicsPreset.Matching(settings)); - } - - [Fact] - public void Shadows_reach_further_with_every_level_that_has_them() - { - static double Reach(GraphicsPreset preset) => - SimulatorSettings.ShadowReach(preset.ShadowRange, preset.ShadowMap, legacyRenderer: false); - - var reaches = GraphicsPreset.All.Where(preset => preset.Shadows).Select(Reach).ToList(); - - Assert.Equal(reaches.Distinct().OrderBy(reach => reach), reaches); - Assert.Equal(250, Reach(GraphicsPreset.High)); - Assert.Equal(800, Reach(GraphicsPreset.VeryHigh)); - } - - [Fact] - public void Without_extras_the_settings_are_what_the_simulator_goes_by() - { - Assert.Equal(GraphicsExtras.None, GraphicsExtras.Of(Defaults())); - Assert.Equal(GraphicsTop.None, GraphicsTop.Of(Defaults())); - } - - [Fact] - public void A_level_leaves_what_only_the_lowest_one_sets() - { - var settings = Defaults().Copy(); - settings.MotionBlur = false; - - GraphicsPreset.Low.ApplyTo(settings); - - Assert.False(settings.MotionBlur); - Assert.Same(GraphicsPreset.Low, GraphicsPreset.Matching(settings)); - } - - [Fact] - public void Every_level_is_within_what_the_sliders_offer() - { - foreach (var preset in GraphicsPreset.All) - { - Assert.True(preset.TextureSize >= SliderRanges.MinTextureSize, preset.NameKey); - Assert.True(preset.ShadowMap >= SliderRanges.MinShadowMap, preset.NameKey); - Assert.True(preset.DynamicLights >= SliderRanges.MinDynamicLights, preset.NameKey); - Assert.Contains(preset.ReflectionsRate, SliderRanges.ReflectionUpdates); - } - } - - [Fact] - public void The_lowest_level_is_not_recognised_with_one_of_its_extras_undone() - { - var settings = Defaults().Copy(); - GraphicsPreset.Minimal.ApplyTo(settings); - - settings.Smoke = true; - - Assert.Null(GraphicsPreset.Matching(settings)); - } - - [Fact] - public void The_extras_sit_on_the_steps_the_screen_offers() - { - foreach (var extras in new[] { GraphicsPreset.Minimal.Extras!, GraphicsPreset.Ultra.Extras! }) - Assert.Contains(extras.PythonUpdateMs, new[] { 200, 400, 800, 1600 }); - } - - // ── Leaving an end of the scale ────────────────────────────────────────── - - [Fact] - public void A_level_between_the_ends_chooses_only_its_own_keys() - { - var settings = Defaults().Copy(); - settings.MotionBlur = false; - settings.ShadowAngleLimit = 0.8; - - var applied = new GraphicsPresetMemory().Apply(GraphicsPreset.Medium, settings); - - Assert.Same(GraphicsPreset.Medium, GraphicsPreset.Matching(settings)); - Assert.False(settings.MotionBlur); - Assert.Equal(0.8, settings.ShadowAngleLimit); - Assert.Equal(GraphicsPreset.Keys, applied.ChosenKeys); - } - - [Fact] - public void Leaving_the_lowest_level_brings_back_what_was_there_before_it() - { - var memory = new GraphicsPresetMemory(); - var settings = Defaults().Copy(); - settings.MotionBlur = false; - var before = GraphicsExtras.Of(settings); - - var entering = memory.Apply(GraphicsPreset.Minimal, settings); - Assert.Equal(GraphicsPreset.Minimal.Extras, GraphicsExtras.Of(settings)); - Assert.Equal(GraphicsPreset.Keys.Concat(GraphicsExtras.Keys), entering.ChosenKeys); - - var leaving = memory.Apply(GraphicsPreset.Medium, settings); - - Assert.Equal(before, GraphicsExtras.Of(settings)); - Assert.Same(GraphicsPreset.Medium, GraphicsPreset.Matching(settings)); - Assert.Equal(GraphicsPreset.Keys.Concat(GraphicsExtras.Keys), leaving.ChosenKeys); - } - - [Fact] - public void Leaving_ultra_brings_back_what_was_there_before_it() - { - var memory = new GraphicsPresetMemory(); - var settings = Defaults().Copy(); - settings.MotionBlur = false; - settings.ShadowAngleLimit = 0.8; - var extras = GraphicsExtras.Of(settings); - var top = GraphicsTop.Of(settings); - - memory.Apply(GraphicsPreset.Ultra, settings); - var applied = memory.Apply(GraphicsPreset.VeryHigh, settings); - - Assert.Equal(extras, GraphicsExtras.Of(settings)); - Assert.Equal(top, GraphicsTop.Of(settings)); - Assert.Same(GraphicsPreset.VeryHigh, GraphicsPreset.Matching(settings)); - Assert.Equal(GraphicsPreset.Keys.Concat(GraphicsExtras.Keys).Concat(GraphicsTop.Keys), applied.ChosenKeys); - } - - [Fact] - public void Leaving_an_end_chosen_before_this_run_gives_the_simulators_own_values() - { - var settings = Defaults().Copy(); - GraphicsPreset.Ultra.ApplyTo(settings); - - new GraphicsPresetMemory().Apply(GraphicsPreset.Low, settings); - - Assert.Equal(GraphicsExtras.None, GraphicsExtras.Of(settings)); - Assert.Equal(GraphicsTop.None, GraphicsTop.Of(settings)); - Assert.Same(GraphicsPreset.Low, GraphicsPreset.Matching(settings)); - } - - [Fact] - public void One_end_to_the_other_keeps_what_was_there_before_either() - { - var memory = new GraphicsPresetMemory(); - var settings = Defaults().Copy(); - settings.MotionBlur = false; - settings.ShadowAngleLimit = 0.8; - var extras = GraphicsExtras.Of(settings); - var top = GraphicsTop.Of(settings); - - memory.Apply(GraphicsPreset.Minimal, settings); - memory.Apply(GraphicsPreset.Ultra, settings); - Assert.Same(GraphicsPreset.Ultra, GraphicsPreset.Matching(settings)); - - memory.Apply(GraphicsPreset.Minimal, settings); - Assert.Same(GraphicsPreset.Minimal, GraphicsPreset.Matching(settings)); - // Ultra's own values go, Minimal has no say over them. - Assert.Equal(top, GraphicsTop.Of(settings)); - - memory.Apply(GraphicsPreset.Medium, settings); - Assert.Equal(extras, GraphicsExtras.Of(settings)); - } - - [Fact] - public void What_was_remembered_comes_back_only_once() - { - var memory = new GraphicsPresetMemory(); - var settings = Defaults().Copy(); - settings.MotionBlur = false; - - memory.Apply(GraphicsPreset.Minimal, settings); - memory.Apply(GraphicsPreset.Medium, settings); - Assert.False(settings.MotionBlur); - - // Moved since, and no end left behind this time: it stays as moved. - settings.MotionBlur = true; - var applied = memory.Apply(GraphicsPreset.High, settings); - - Assert.True(settings.MotionBlur); - Assert.Equal(GraphicsPreset.Keys, applied.ChosenKeys); - } - - [Fact] - public void A_level_applied_twice_at_an_end_remembers_what_came_before_the_first() - { - var memory = new GraphicsPresetMemory(); - var settings = Defaults().Copy(); - settings.MotionBlur = false; - var before = GraphicsExtras.Of(settings); - - memory.Apply(GraphicsPreset.Minimal, settings); - memory.Apply(GraphicsPreset.Minimal, settings); - memory.Apply(GraphicsPreset.Low, settings); - - Assert.Equal(before, GraphicsExtras.Of(settings)); - } - - [Fact] - public void A_level_applied_is_recognised_until_one_value_moves() - { - foreach (var preset in GraphicsPreset.All) - { - var settings = Defaults().Copy(); - preset.ApplyTo(settings); - Assert.Same(preset, GraphicsPreset.Matching(settings)); - - settings.DynamicLights = 6; - Assert.Null(GraphicsPreset.Matching(settings)); - } - } - - [Fact] - public void Every_level_sits_on_the_steps_the_screen_offers() - { - foreach (var preset in GraphicsPreset.All) - { - Assert.True(Steps.IndexOf(Steps.Anisotropy, preset.Anisotropy) >= 0, preset.NameKey); - Assert.True(Steps.IndexOf(SliderRanges.ReflectionUpdates, preset.ReflectionsRate) >= 0, preset.NameKey); - Assert.True(Steps.IndexOf(SliderRanges.DrawRangeFactors, preset.DrawRangeFactor) >= 0, preset.NameKey); - foreach (int size in new[] { preset.TextureSize, preset.CabTextureSize, preset.ShadowMap }) - Assert.True(size is >= 512 and <= 8192 && (size & (size - 1)) == 0, preset.NameKey); - Assert.True(preset.ShadowRange >= SimulatorSettings.ShadowRangeFloor(preset.ShadowMap), preset.NameKey); - Assert.True(Steps.IndexOf(SliderRanges.CabShadowRanges, preset.CabShadowsRange) >= 0, preset.NameKey); - } - } - // ── A level for one part ───────────────────────────────────────────────── private static GraphicsGroupLevels Groups() => new(new TestInstallation().SettingsStore); - [Fact] - public void Every_key_a_level_sets_but_those_of_the_whole_belongs_to_one_part() - { - var inGroups = GraphicsGroup.All.SelectMany(group => group.Keys).ToList(); - - Assert.Equal(inGroups.Distinct(), inGroups); - Assert.Empty(inGroups.Except(GraphicsPreset.Keys).Except(GraphicsExtras.Keys).Except(GraphicsTop.Keys)); - Assert.Equal(new[] { "dynamiclights", "gfx.extraeffects", "gfx.smoke.fidelity", "multisampling" }, - GraphicsPreset.Keys.Except(inGroups).OrderBy(key => key, StringComparer.Ordinal)); - } - [Fact] public void One_part_moves_alone() { @@ -533,9 +277,10 @@ public class GraphicsPresetTests Assert.Equal(GraphicsPreset.Low.ShadowMap, moved.ShadowMapResolution); Assert.Equal(GraphicsPreset.Low.ShadowRange, moved.ShadowProjectionRange); Assert.Equal(GraphicsPreset.Low.ShadowRank, moved.ShadowRankCutoff); + Assert.Equal("low", moved.Extra["gfx.lights.shadows"]); Assert.Equal(settings.MaxTextureSize, moved.MaxTextureSize); - Assert.Equal(settings.DynamicLights, moved.DynamicLights); - Assert.Equal(settings.BufferScalePercent, moved.BufferScalePercent); + Assert.Equal(settings.Extra["gfx.ssr"], moved.Extra["gfx.ssr"]); + Assert.Equal(settings.AntiAliasing, moved.AntiAliasing); var levels = groups.LevelsOf(moved); Assert.Same(GraphicsPreset.Low, levels[GraphicsGroup.Shadows]); @@ -544,12 +289,10 @@ public class GraphicsPresetTests } [Fact] - public void Every_part_shows_ultra_when_the_whole_is_at_ultra() + public void Every_part_shows_the_level_the_whole_is_at() { - var settings = Defaults().Copy(); - GraphicsPreset.Ultra.ApplyTo(settings); - - Assert.All(Groups().LevelsOf(settings).Values, level => Assert.Same(GraphicsPreset.Ultra, level)); + foreach (var preset in GraphicsPreset.All) + Assert.All(Groups().LevelsOf(At(preset)).Values, level => Assert.Same(preset, level)); } [Fact] @@ -565,17 +308,15 @@ public class GraphicsPresetTests } [Fact] - public void Every_part_at_a_level_and_the_rest_with_it_is_that_level() + public void Every_part_at_a_level_and_the_anti_aliasing_with_it_is_that_level() { var groups = Groups(); - foreach (var level in GraphicsPreset.All.Where(level => level.Extras is null)) + foreach (var level in GraphicsPreset.All) { var settings = Defaults().Copy(); foreach (var group in GraphicsGroup.All) settings = groups.Apply(group, level, settings); settings.AntiAliasing = level.AntiAliasing; - settings.DynamicLights = level.DynamicLights; - settings.SmokeFidelity = level.SmokeFidelity; Assert.Same(level, GraphicsPreset.Matching(settings)); } @@ -589,34 +330,4 @@ public class GraphicsPresetTests foreach (var level in GraphicsPreset.All) Assert.Same(level, groups.LevelsOf(groups.Apply(group, level, Defaults()))[group]); } - - [Fact] - public void Leaving_an_end_in_a_part_gives_the_simulators_own_for_what_only_the_end_sets() - { - var groups = Groups(); - var settings = AtHigh(); - settings.ShadowAngleLimit = 0.8; - - var ultra = groups.Apply(GraphicsGroup.Shadows, GraphicsPreset.Ultra, settings); - Assert.Equal(0.2, ultra.ShadowAngleLimit); - Assert.Same(GraphicsPreset.Ultra, groups.LevelsOf(ultra)[GraphicsGroup.Shadows]); - - var back = groups.Apply(GraphicsGroup.Shadows, GraphicsPreset.High, ultra); - Assert.Equal(GraphicsTop.None.ShadowAngleLimit, back.ShadowAngleLimit); - Assert.Same(GraphicsPreset.High, groups.LevelsOf(back)[GraphicsGroup.Shadows]); - } - - [Fact] - public void A_level_in_a_part_between_the_ends_leaves_what_only_an_end_sets() - { - var settings = AtHigh(); - settings.MotionBlur = false; - - settings.Smoke = false; - - var shadows = Groups().Apply(GraphicsGroup.Shadows, GraphicsPreset.VeryHigh, settings); - Assert.False(shadows.Smoke); - Assert.False(shadows.MotionBlur); - Assert.Equal(GraphicsPreset.VeryHigh.ShadowMap, shadows.ShadowMapResolution); - } } diff --git a/StarterNG.Tests/GraphicsSettingsTests.cs b/StarterNG.Tests/GraphicsSettingsTests.cs index 1ac97dd..985207b 100644 --- a/StarterNG.Tests/GraphicsSettingsTests.cs +++ b/StarterNG.Tests/GraphicsSettingsTests.cs @@ -37,88 +37,95 @@ public class GraphicsSettingsTests private static string? Line(string text, string key) => Lines(text).FirstOrDefault(l => l == key || l.StartsWith(key + " ", StringComparison.Ordinal)); - // As application.cpp on master has them; a word the starter does not know is the file's own, written back as it is. + // As utilities/Globals.cpp has them; a word the simulator does not know is the file's own, written back as it is. [Theory] - [InlineData("default", "default")] - [InlineData("full", "full")] - [InlineData("gl46", "gl46")] [InlineData("vulkan", "vulkan")] - [InlineData("vulkan14", "vulkan14")] - [InlineData("legacy", "legacy")] - [InlineData("simpleshader", "legacy")] - [InlineData("off", "legacy")] - [InlineData("simple", "simple")] - [InlineData("experimental", "experimental")] - public void A_renderer_is_written_by_the_name_master_knows(string read, string written) + [InlineData("VULKAN14", "vulkan")] + [InlineData("default", "default")] + [InlineData("full", "default")] + [InlineData("gl46", "default")] + [InlineData("opengl", "default")] + [InlineData("legacy", "default")] + [InlineData("simple", "default")] + [InlineData("experimental", "default")] + [InlineData("null", "null")] + public void A_renderer_is_written_by_the_name_the_simulator_reads_it_as(string read, string written) { Assert.Equal($"gfxrenderer {written}", Line(Write(Read($"gfxrenderer {read}\n")), "gfxrenderer")); } [Fact] - public void Without_a_renderer_in_the_file_the_full_one_is_chosen() + public void Without_a_renderer_in_the_file_vulkan_is_chosen_and_written() { - Assert.Equal(0, Read("").RenderEngine); - Assert.Equal("gfxrenderer default", Line(Write(Read("")), "gfxrenderer")); + // The simulator's own is OpenGL: the starter writes Vulkan whatever the file had. + Assert.Equal(GraphicsBackend.Vulkan, Read("").Backend); + Assert.Equal("gfxrenderer vulkan", Line(Write(Read("")), "gfxrenderer")); } [Fact] - public void An_older_renderer_stays_chosen_and_can_be_chosen_again() + public void Opengl_stays_chosen_and_vulkan_can_be_chosen_again() { - var installation = WithIni("gfxrenderer legacy\n"); + var installation = WithIni("gfxrenderer default\n"); var store = installation.SettingsStore; + Assert.Equal(GraphicsBackend.OpenGL, store.Settings.Backend); store.Settings.FieldOfView = 50; store.Save(); - Assert.Contains("gfxrenderer legacy", installation.Files.ReadAllText(UserIni)); + Assert.Contains("gfxrenderer default", installation.Files.ReadAllText(UserIni)); - store.Settings.RenderEngine = SimulatorSettings.RenderEngineOf("simple"); + store.Settings.Backend = GraphicsBackend.Vulkan; store.Save(); - Assert.Contains("gfxrenderer simple", installation.Files.ReadAllText(UserIni)); + Assert.Equal("gfxrenderer vulkan", Line(installation.Files.ReadAllText(UserIni), "gfxrenderer")); } [Fact] - public void Keys_only_the_legacy_renderer_or_windows_read_stay_in_the_file() + public void Keys_the_simulator_no_longer_goes_by_are_taken_out_on_a_save() { string[] old = { - "usevbo no", "gfx.angleplatform vulkan", "gfx.usegles yes", "gfx.shadows.cab.range 20" + "usevbo no", "gfx.angleplatform vulkan", "gfx.usegles yes", "gfx.shadows.cab.range 20", "shadows yes", + "skyenabled yes", "smoothtraction yes", "gfx.framebuffer.width 1280", "gfx.framebuffer.height 720", + "starter.bufferscale 100" }; var installation = WithIni(string.Join("\n", old) + "\n"); - installation.SettingsStore.Settings.FieldOfView = 50; installation.SettingsStore.Save(); string saved = installation.Files.ReadAllText(UserIni); - Assert.All(old, line => Assert.Contains(line, saved)); + Assert.All(old, line => Assert.Null(Line(saved, line.Split(' ')[0]))); } [Fact] - public void Keys_of_the_vulkan_renderer_master_does_not_have_stay_on_a_save() + public void Keys_of_the_new_renderers_are_kept_as_the_file_has_them() { string[] vulkan = { "gfx.antialiasing dlss", "gfx.dlss.preset k", "gfx.framegeneration x2", "gfx.reflex on", "gfx.raytracing yes", "gfx.ssr high", "gfx.postfx.ao gtao", "gfx.clouds ultra", "gfx.grass yes", - "gfx.buffer.percent 0.67", "gfx.vulkan.device RTX", "gfx.fog yes", "gfx.cabprobe medium" + "gfx.buffer.percent 0.67", "gfx.vulkan.device RTX", "gfx.fog yes", "gfx.cabprobe medium", "gfx.gpucull no" }; - var installation = WithIni("calibratein 0 0 0 0\n" + string.Join("\n", vulkan) + "\n"); + var installation = WithIni("calibratein 0 0 0 0\nmultisampling 0\n" + string.Join("\n", vulkan) + "\n"); installation.SettingsStore.Save(); string saved = installation.Files.ReadAllText(UserIni); Assert.Contains("calibratein 0 0 0 0", saved); - // Written in by hand for a build that has that renderer: the starter does not know them, and leaves them. Assert.All(vulkan, line => Assert.Equal(line, Line(saved, line.Split(' ')[0]))); + Assert.Equal(AntiAliasingMode.Dlss, installation.SettingsStore.Settings.AntiAliasing); + Assert.Equal(67, installation.SettingsStore.Settings.BufferScalePercent); } [Fact] - public void Levels_leave_the_switches_only_an_older_simulator_reads() + public void The_faster_choices_the_simulator_does_not_make_itself_are_written() { - var s = new SimulatorSettings { UseVbo = false, UseGLES = true, RenderAngleVulkan = true }; + var installation = WithIni("width 1280\n"); - GraphicsPreset.Ultra.ApplyTo(s); + installation.SettingsStore.Save(); - Assert.Equal((false, true, true), (s.UseVbo, s.UseGLES, s.RenderAngleVulkan)); + string saved = installation.Files.ReadAllText(UserIni); + foreach (var key in SimulatorKeys.All.Where(key => key.Writes)) + Assert.Equal($"{key.Key} {key.Default}", Line(saved, key.Key)); + Assert.Equal("gfx.gpucull yes", Line(saved, "gfx.gpucull")); } [Theory] @@ -127,20 +134,40 @@ public class GraphicsSettingsTests [InlineData("multisampling 2\n", AntiAliasingMode.Msaa4)] [InlineData("multisampling 3\n", AntiAliasingMode.Msaa8)] [InlineData("", AntiAliasingMode.Msaa4)] - public void Multisampling_is_read_as_master_reads_it(string text, AntiAliasingMode expected) + [InlineData("gfx.antialiasing taa\n", AntiAliasingMode.Taa)] + [InlineData("multisampling 3\ngfx.antialiasing taa\n", AntiAliasingMode.Taa)] + [InlineData("gfx.antialiasing taa\nmultisampling 3\n", AntiAliasingMode.Msaa8)] + [InlineData("multisampling 2\ngfx.antialiasing dlaa\n", AntiAliasingMode.Dlaa)] + [InlineData("multisampling 1\ngfx.antialiasing off\n", AntiAliasingMode.Off)] + public void The_anti_aliasing_is_read_from_the_key_further_down(string text, AntiAliasingMode expected) { Assert.Equal(expected, Read(text).AntiAliasing); } - [Fact] - public void Multisampling_is_written_to_its_own_key_only() + [Theory] + [InlineData(AntiAliasingMode.Msaa2, "1", "msaax2")] + [InlineData(AntiAliasingMode.Taa, "0", "taa")] + [InlineData(AntiAliasingMode.Dlss, "0", "dlss")] + [InlineData(AntiAliasingMode.Off, "0", "off")] + public void The_anti_aliasing_is_written_to_both_keys(AntiAliasingMode mode, string multisampling, string word) { - var s = Read("multisampling 1\n"); + string text = Write(new SimulatorSettings { AntiAliasing = mode }); - string text = Write(s); + Assert.Equal($"multisampling {multisampling}", Line(text, "multisampling")); + Assert.Equal($"gfx.antialiasing {word}", Line(text, "gfx.antialiasing")); + } - Assert.Equal("multisampling 1", Line(text, "multisampling")); - Assert.Null(Line(text, "gfx.antialiasing")); + [Fact] + public void A_save_puts_the_newer_anti_aliasing_key_below_the_older() + { + var installation = WithIni("gfx.antialiasing msaax4\nwidth 1280\nmultisampling 2\n"); + installation.SettingsStore.Settings.AntiAliasing = AntiAliasingMode.Taa; + + installation.SettingsStore.Save(); + + var lines = Lines(installation.Files.ReadAllText(UserIni)).ToList(); + Assert.True(lines.IndexOf("gfx.antialiasing taa") > lines.IndexOf("multisampling 0")); + Assert.Equal(AntiAliasingMode.Taa, Read(installation.Files.ReadAllText(UserIni)).AntiAliasing); } [Fact] @@ -154,113 +181,37 @@ public class GraphicsSettingsTests } [Fact] - public void The_render_scale_is_the_starters_own_key_or_the_framebuffer_against_the_window() + public void The_render_scale_is_the_buffer_percent_or_what_an_older_starter_left() { + Assert.Equal(50, Read("gfx.buffer.percent 0.5\n").BufferScalePercent); + Assert.Equal(75, Read("gfx.buffer.percent 75\n").BufferScalePercent); Assert.Equal(75, Read("starter.bufferscale 75\n").BufferScalePercent); Assert.Equal(50, Read("width 1920\ngfx.framebuffer.width 960\n").BufferScalePercent); Assert.Equal(100, Read("").BufferScalePercent); } [Fact] - public void The_render_scale_is_written_as_the_framebuffer_master_reads() + public void The_render_scale_is_written_as_the_buffer_percent() { var s = Read("width 1920\nheight 1080\nstarter.bufferscale 50\n"); string text = Write(s); - Assert.Equal("gfx.framebuffer.width 960", Line(text, "gfx.framebuffer.width")); - Assert.Equal("gfx.framebuffer.height 540", Line(text, "gfx.framebuffer.height")); - Assert.Null(Line(text, "gfx.buffer.percent")); - } - - // Borderless, the simulator takes the window's size from the monitor (application.cpp) and - // leaves width and height unread; -1 is its own word for a buffer of the window's size - // (opengl33renderer.cpp). - [Fact] - public void A_borderless_screen_draws_into_a_buffer_of_the_windows_own_size() - { - var s = Read("fullscreenwindowed yes\nwidth 1280\nheight 720\n"); - - string text = Write(s); - - Assert.Equal("gfx.framebuffer.width -1", Line(text, "gfx.framebuffer.width")); - Assert.Equal("gfx.framebuffer.height -1", Line(text, "gfx.framebuffer.height")); - Assert.Equal("width 1280", Line(text, "width")); - Assert.Equal(100, Read(text).BufferScalePercent); - } - - [Fact] - public void A_borderless_screen_with_a_smaller_buffer_takes_its_part_of_the_monitor() - { - var s = Read("fullscreenwindowed yes\nfullscreenmonitor HDMI-1:1920,0\nwidth 1280\nheight 720\nstarter.bufferscale 50\n"); - var asked = new List(); - var serializer = new SettingsSerializer(id => - { - asked.Add(id); - return (2560, 1440); - }); - var c = new ConfigFile(); - - serializer.Write(s, c); - - Assert.Equal("1280", c.GetRaw("gfx.framebuffer.width")); - Assert.Equal("720", c.GetRaw("gfx.framebuffer.height")); - Assert.Equal("50", c.GetRaw("starter.bufferscale")); - Assert.Equal(new[] { "HDMI-1:1920,0" }, asked.Distinct()); - var read = new SimulatorSettings(); - serializer.Read(read, c); - Assert.Equal(50, read.BufferScalePercent); - } - - [Fact] - public void A_borderless_screen_on_a_monitor_of_unknown_size_keeps_the_windows_own_buffer() - { - var s = Read("fullscreenwindowed yes\nwidth 1280\nheight 720\nstarter.bufferscale 50\n"); - var c = new ConfigFile(); - - new SettingsSerializer(_ => null).Write(s, c); - - Assert.Equal("-1", c.GetRaw("gfx.framebuffer.width")); - Assert.Equal("-1", c.GetRaw("gfx.framebuffer.height")); - } - - [Fact] - public void A_buffer_of_the_window_left_in_a_borderless_file_goes_on_a_save() - { - // As this starter wrote it before: the size of the resolution row, which borderless does not use. - var installation = WithIni("fullscreenwindowed yes\nwidth 1280\nheight 720\nstarter.bufferscale 100\n" + - "gfx.framebuffer.width 1280\ngfx.framebuffer.height 720\n"); - - installation.SettingsStore.Save(); - - string saved = installation.Files.ReadAllText(UserIni); - Assert.Equal("gfx.framebuffer.width -1", Line(saved, "gfx.framebuffer.width")); - Assert.Equal("gfx.framebuffer.height -1", Line(saved, "gfx.framebuffer.height")); - } - - [Fact] - public void A_buffer_the_file_has_for_a_window_or_a_full_screen_stays_until_changed() - { - var installation = WithIni("fullscreenwindowed no\nwidth 1280\nheight 720\nstarter.bufferscale 100\n" + - "gfx.framebuffer.width 1280\ngfx.framebuffer.height 720\n"); - - installation.SettingsStore.Save(); - - string saved = installation.Files.ReadAllText(UserIni); - Assert.Equal("gfx.framebuffer.width 1280", Line(saved, "gfx.framebuffer.width")); - Assert.Equal("gfx.framebuffer.height 720", Line(saved, "gfx.framebuffer.height")); + Assert.Equal("gfx.buffer.percent 0.5", Line(text, "gfx.buffer.percent")); + Assert.Null(Line(text, "gfx.framebuffer.width")); + Assert.Null(Line(text, "starter.bufferscale")); } [Fact] public void A_level_is_recognised_after_it_is_applied_and_survives_a_save() { - for (int engine = 0; engine < SimulatorSettings.RenderEngines.Length; engine++) + foreach (var backend in new[] { GraphicsBackend.Vulkan, GraphicsBackend.OpenGL }) { foreach (var level in GraphicsPreset.All) { var installation = WithIni(""); var store = installation.SettingsStore; - store.Settings.RenderEngine = engine; + store.Settings.Backend = backend; level.ApplyTo(store.Settings); Assert.Same(level, GraphicsPreset.Matching(store.Settings)); @@ -270,6 +221,7 @@ public class GraphicsSettingsTests again.Environment.With("HOME", "/home/kolejarz"); again.SettingsStore.Load(); Assert.Same(level, GraphicsPreset.Matching(again.SettingsStore.Settings)); + Assert.Equal(backend, again.SettingsStore.Settings.Backend); } } } @@ -279,7 +231,7 @@ public class GraphicsSettingsTests { var s = new SimulatorSettings(); GraphicsPreset.High.ApplyTo(s); - s.DynamicLights = 2; + s.ShadowRankCutoff = 1; Assert.Null(GraphicsPreset.Matching(s)); } @@ -318,7 +270,7 @@ public class GraphicsSettingsTests Assert.True(installation.SettingsStore.ImportFrom("/backup/eu07.ini")); var s = installation.SettingsStore.Settings; Assert.Equal(60, s.FieldOfView); - Assert.Equal(SimulatorSettings.RenderEngineOf("legacy"), s.RenderEngine); + Assert.Equal(GraphicsBackend.OpenGL, s.Backend); Assert.Equal("eu07_local.exe", s.ExecutablePath); // Nothing is written until saved, and the save keeps the user's own lines. diff --git a/StarterNG.Tests/LocalizationTests.cs b/StarterNG.Tests/LocalizationTests.cs index cdb5b90..46cf1cf 100644 --- a/StarterNG.Tests/LocalizationTests.cs +++ b/StarterNG.Tests/LocalizationTests.cs @@ -31,9 +31,13 @@ public class LocalizationTests var english = Strings(all.Single(l => l.Code == "en").Path); var other = Strings(all.Single(l => l.Code == code).Path); + // The developer tab's rows (Ini.*) and the words of their lists (Choice.*) come in English where a + // language lacks them (SimulatorKeyRows), as the descriptions do. var missing = english.Keys .Where(key => !key.EndsWith("Desc", StringComparison.Ordinal) && - !key.StartsWith("Cmd.", StringComparison.Ordinal)) + !key.StartsWith("Cmd.", StringComparison.Ordinal) && + !key.StartsWith("Ini.", StringComparison.Ordinal) && + !key.StartsWith("Choice.", StringComparison.Ordinal)) .Where(key => !other.ContainsKey(key)); Assert.Empty(missing); diff --git a/StarterNG.Tests/RenderersTests.cs b/StarterNG.Tests/RenderersTests.cs deleted file mode 100644 index 589a1f4..0000000 --- a/StarterNG.Tests/RenderersTests.cs +++ /dev/null @@ -1,17 +0,0 @@ -using StarterNG.Domain.Settings; - -namespace StarterNG.Tests; - -public class RenderersTests -{ - [Theory] - [InlineData("default", RendererKind.Modern)] - [InlineData("full", RendererKind.Modern)] - [InlineData("vulkan", RendererKind.Modern)] - [InlineData("legacy", RendererKind.Legacy)] - [InlineData("simple", RendererKind.Legacy)] - [InlineData("simpleshader", RendererKind.Legacy)] - [InlineData("OFF", RendererKind.Legacy)] - public void A_renderer_word_draws_with_the_renderer_master_gives_it(string word, RendererKind kind) => - Assert.Equal(kind, Renderers.KindOf(word)); -} diff --git a/StarterNG.Tests/SettingsStoreTests.cs b/StarterNG.Tests/SettingsStoreTests.cs index e9be865..25c5bbf 100644 --- a/StarterNG.Tests/SettingsStoreTests.cs +++ b/StarterNG.Tests/SettingsStoreTests.cs @@ -951,13 +951,12 @@ public class SettingsStoreTests Assert.Equal(floor, SimulatorSettings.ShadowRangeFloor(mapSize)); [Theory] - [InlineData(150, 1024, false, 150)] - [InlineData(150, 4096, false, 300)] - [InlineData(150, 4096, true, 150)] - [InlineData(100, 8192, false, 1200)] - [InlineData(400, 8192, false, 1600)] - public void Shadows_reach_as_far_as_the_renderer_stretches_them(int range, int mapSize, bool legacy, int reach) => - Assert.Equal(reach, SimulatorSettings.ShadowReach(range, mapSize, legacy)); + [InlineData(150, 1024, 150)] + [InlineData(150, 4096, 300)] + [InlineData(100, 8192, 1200)] + [InlineData(400, 8192, 1600)] + public void Shadows_reach_as_far_as_the_renderer_stretches_them(int range, int mapSize, int reach) => + Assert.Equal(reach, SimulatorSettings.ShadowReach(range, mapSize)); [Theory] [InlineData("anisotropicfiltering 12")] @@ -975,10 +974,15 @@ public class SettingsStoreTests [Theory] [InlineData("default")] + [InlineData("full")] + [InlineData("opengl")] + [InlineData("gl46")] + [InlineData("vulkan14")] [InlineData("simpleshader")] [InlineData("off")] [InlineData("legacy")] [InlineData("simple")] + [InlineData("experimental")] public void A_renderer_word_the_simulator_reads_as_another_stays_until_changed(string word) { var installation = WithHome(new InMemoryFileSystem().WithFile(UserIni, $"gfxrenderer {word}\n")); @@ -989,16 +993,11 @@ public class SettingsStoreTests Assert.Contains($"gfxrenderer {word}\n", SavedLines(installation)); } - // A word the starter does not know is written in by hand for a build that has it, such as one with Vulkan: - // shown, and left as it is until another renderer is chosen. + // A word the starter does not know is written in by hand: "null" of the test runs, or one of a newer simulator. + // Shown, and left as it is until another renderer is chosen. [Theory] - [InlineData("full")] - [InlineData("opengl")] - [InlineData("gl46")] - [InlineData("vulkan")] - [InlineData("vulkan14")] - [InlineData("experimental")] [InlineData("null")] + [InlineData("whatever")] public void A_renderer_word_the_starter_does_not_know_stays_until_another_is_chosen(string word) { var installation = WithHome(new InMemoryFileSystem().WithFile(UserIni, $"gfxrenderer {word}\nfieldofview 45\n")); @@ -1011,60 +1010,61 @@ public class SettingsStoreTests store.Save(); Assert.Contains($"gfxrenderer {word}\n", SavedLines(installation)); - // Picking one from the list, even the full renderer it runs as, is a choice. + // Picking one from the list, even the renderer it runs as, is a choice. store.Settings.RendererWord = null; - store.Settings.RenderEngine = 0; + store.Settings.Backend = GraphicsBackend.Vulkan; store.Save(); - Assert.Contains("gfxrenderer default\n", SavedLines(installation)); + Assert.Contains("gfxrenderer vulkan\n", SavedLines(installation)); Assert.False(store.UnreadableValues().ContainsKey("gfxrenderer")); } [Theory] - [InlineData(0, "default")] - [InlineData(1, "legacy")] - [InlineData(2, "simple")] - public void A_chosen_renderer_is_saved_as_the_simulator_reads_it(int engine, string saved) + [InlineData(GraphicsBackend.Vulkan, "vulkan")] + [InlineData(GraphicsBackend.OpenGL, "default")] + public void A_chosen_renderer_is_saved_as_the_simulator_reads_it(GraphicsBackend backend, string saved) { - // application.cpp on master knows default, legacy and simple; "simpleshader" and "off" - // from older starters are legacy, and any other word gets the full renderer. + // utilities/Globals.cpp knows default (OpenGL 4.6) and vulkan; the words of the renderers it no longer has + // it reads as default. var installation = WithHome(new InMemoryFileSystem().WithFile(UserIni, "gfxrenderer simpleshader\n")); installation.SettingsStore.Load(); - installation.SettingsStore.Settings.RenderEngine = engine == 1 ? 0 : engine; + installation.SettingsStore.Settings.Backend = backend == GraphicsBackend.Vulkan ? GraphicsBackend.OpenGL : GraphicsBackend.Vulkan; installation.SettingsStore.Save(); - installation.SettingsStore.Settings.RenderEngine = engine; + installation.SettingsStore.Settings.Backend = backend; installation.SettingsStore.Save(); Assert.Contains($"gfxrenderer {saved}\n", SavedLines(installation)); } [Theory] - [InlineData("full", 0)] - [InlineData("gl46", 0)] - [InlineData("opengl", 0)] - [InlineData("vulkan", 0)] - [InlineData("VULKAN14", 0)] - [InlineData("whatever", 0)] - [InlineData("experimental", 0)] - [InlineData("simpleshader", 1)] - public void A_renderer_word_stands_where_the_simulator_reads_it(string word, int engine) + [InlineData("full", GraphicsBackend.OpenGL)] + [InlineData("gl46", GraphicsBackend.OpenGL)] + [InlineData("opengl", GraphicsBackend.OpenGL)] + [InlineData("default", GraphicsBackend.OpenGL)] + [InlineData("vulkan", GraphicsBackend.Vulkan)] + [InlineData("VULKAN14", GraphicsBackend.Vulkan)] + [InlineData("whatever", GraphicsBackend.OpenGL)] + [InlineData("experimental", GraphicsBackend.OpenGL)] + [InlineData("simpleshader", GraphicsBackend.OpenGL)] + public void A_renderer_word_stands_where_the_simulator_reads_it(string word, GraphicsBackend backend) { - Assert.Equal(engine, SimulatorSettings.RenderEngineOf(word)); + Assert.Equal(backend, SimulatorSettings.BackendOf(word)); } [Fact] - public void The_buffer_is_written_as_the_framebuffer_master_reads() + public void The_buffer_is_written_as_the_simulator_reads_it() { - var installation = WithHome(new InMemoryFileSystem().WithFile(UserIni, "width 1000\nheight 500\n")); + var installation = WithHome(new InMemoryFileSystem().WithFile(UserIni, + "width 1000\nheight 500\ngfx.framebuffer.width 1000\ngfx.framebuffer.height 500\n")); installation.SettingsStore.Load(); installation.SettingsStore.Settings.BufferScalePercent = 50; installation.SettingsStore.Save(); string saved = SavedLines(installation); - Assert.DoesNotContain("gfx.buffer.percent", saved); - Assert.Contains("gfx.framebuffer.width 500\n", saved); - Assert.Contains("gfx.framebuffer.height 250\n", saved); + Assert.Contains("gfx.buffer.percent 0.5\n", saved); + Assert.DoesNotContain("\ngfx.framebuffer.width", saved); + Assert.DoesNotContain("\ngfx.framebuffer.height", saved); } [Theory] @@ -1074,8 +1074,9 @@ public class SettingsStoreTests [InlineData("gfx.framebuffer.width 500\n", 100)] [InlineData("starter.bufferscale 60\n", 60)] [InlineData("starter.bufferscale 60\nwidth 1000\ngfx.framebuffer.width 800\n", 60)] - [InlineData("gfx.buffer.percent 0.5\n", 100)] - public void The_buffer_is_read_from_the_starters_key_or_the_framebuffer(string ini, int percent) + [InlineData("gfx.buffer.percent 0.5\n", 50)] + [InlineData("gfx.buffer.percent 0.6\nstarter.bufferscale 80\n", 60)] + public void The_buffer_is_read_from_the_simulators_key_or_what_an_older_starter_left(string ini, int percent) { var installation = WithHome(new InMemoryFileSystem().WithFile(UserIni, ini)); @@ -1285,26 +1286,23 @@ public class SettingsStoreTests Assert.Equal(60, store.Settings.FieldOfView); } - // The move to the standard mode puts back the keys of the rows it hides: the row of the - // render scale has the frame buffer's two, and the percent it is worked out from is the starter's own. + // The render scale put back is the whole window, whichever way the file had it. [Theory] - [InlineData("width 1920\nheight 1080\nstarter.bufferscale 50\ngfx.framebuffer.width 960\ngfx.framebuffer.height 540\n")] + [InlineData("width 1920\nheight 1080\ngfx.buffer.percent 0.5\n")] + [InlineData("width 1920\nheight 1080\nstarter.bufferscale 50\n")] [InlineData("width 1920\nheight 1080\ngfx.framebuffer.width 960\ngfx.framebuffer.height 540\n")] - public void The_frame_buffer_put_back_takes_the_render_scale_with_it(string ini) + public void The_render_scale_put_back_is_the_whole_window(string ini) { var installation = WithHome(new InMemoryFileSystem().WithFile(UserIni, ini)); var store = installation.SettingsStore; store.Load(); Assert.Equal(50, store.Settings.BufferScalePercent); - var reset = store.WithDefaults(store.Settings, new[] { "gfx.framebuffer.width", "gfx.framebuffer.height" }); + var reset = store.WithDefaults(store.Settings, new[] { "gfx.buffer.percent" }); Assert.Equal(100, reset.BufferScalePercent); Assert.Equal(1920, reset.Width); - var written = store.Render(reset); - Assert.Equal("100", written["starter.bufferscale"]); - Assert.Equal("1920", written["gfx.framebuffer.width"]); - Assert.Equal("1080", written["gfx.framebuffer.height"]); + Assert.Equal("1", store.Render(reset)["gfx.buffer.percent"]); } // ── What the screen shows otherwise ────────────────────────────────────── @@ -1610,7 +1608,6 @@ public class SettingsStoreTests [Theory] [InlineData("starter.gpu")] - [InlineData("gfx.usegles")] public void The_move_to_the_standard_mode_keeps_what_lets_a_machine_run_the_simulator(string key) => Assert.Contains(key, StarterNG.Application.SettingsStore.KeptOnMoveToStandard); diff --git a/StarterNG.Tests/SettingsUnknownValueTests.cs b/StarterNG.Tests/SettingsUnknownValueTests.cs index 760829e..298460b 100644 --- a/StarterNG.Tests/SettingsUnknownValueTests.cs +++ b/StarterNG.Tests/SettingsUnknownValueTests.cs @@ -54,24 +54,24 @@ public class SettingsUnknownValueTests [Fact] public void A_renderer_word_is_on_the_list_chosen_and_saved_as_it_is() { - WithPage(Standard + "gfxrenderer vulkan\nfieldofview 45\n", (page, _, saved) => + WithPage(Standard + "gfxrenderer null\nfieldofview 45\n", (page, _, saved) => { - Assert.Equal("vulkan", Shown(List(page, "RenderEngineCb"))); - Assert.Contains("vulkan", Note(page, "gfxrenderer")); + Assert.Equal("null", Shown(List(page, "RenderEngineCb"))); + Assert.Contains("null", Note(page, "gfxrenderer")); Assert.False(page.HasUnsavedChanges); page.Save(); - Assert.Contains("gfxrenderer vulkan\n", saved()); + Assert.Contains("gfxrenderer null\n", saved()); }); } [Fact] public void Another_renderer_picked_from_the_list_replaces_it() { - WithPage(Standard + "gfxrenderer vulkan\n", (page, services, saved) => + WithPage(Standard + "gfxrenderer null\n", (page, services, saved) => { - List(page, "RenderEngineCb").SelectedIndex = 0; + List(page, "RenderEngineCb").SelectedIndex = 1; page.Save(); @@ -165,18 +165,67 @@ public class SettingsUnknownValueTests [Fact] public void The_move_to_the_standard_mode_puts_values_of_the_file_right() { - WithPage("gfxrenderer vulkan\nstarter.batterydefault 7\nvsync moze\ngfx.usegles yes\n", (page, _, saved) => + WithPage("gfxrenderer null\nstarter.batterydefault 7\nvsync moze\nstarter.gpu system\n", (page, _, saved) => + { + page.MoveToStandardOnce(); + + string text = saved(); + Assert.Contains("gfxrenderer vulkan\n", text); + Assert.Contains("starter.batterydefault 0\n", text); + Assert.Contains("vsync no\n", text); + // What lets some machines run the simulator at all stays. + Assert.Contains("starter.gpu system\n", text); + Assert.Null(Note(page, "gfxrenderer")); + Assert.NotEqual("7", Shown(List(page, "ReadyOverrideCb"))); + }); + } + + // A player of the standard mode of an older starter: Vulkan, every optimisation on and the developer's settings + // at the starter's own values, the picture's level and what the player chose in the standard mode as it was. + [Fact] + public void The_standard_mode_of_an_older_layout_moves_to_vulkan_and_the_fast_choices() + { + WithPage(Standard + "gfxrenderer default\ngfx.gpucull no\nphysicslog yes\nfriction 2\nmaxtexturesize 1024\n" + + "fieldofview 60\ngfx.ssr low\nblackbox yes\n", (page, services, saved) => + { + page.MoveToStandardOnce(); + + string text = saved(); + Assert.Contains("gfxrenderer vulkan\n", text); + Assert.Contains("gfx.gpucull yes\n", text); + Assert.Contains("physicslog no\n", text); + Assert.Contains("friction 1\n", text); + Assert.Contains("maxtexturesize 1024\n", text); + Assert.Contains("gfx.ssr low\n", text); + Assert.Contains("fieldofview 60\n", text); + Assert.Contains("blackbox yes\n", text); + Assert.Contains($"starter.settings.revision {StarterNG.Domain.Settings.SimulatorSettings.CurrentRevision}\n", text); + }); + } + + [Fact] + public void The_advanced_mode_of_an_older_layout_keeps_what_its_developer_chose() + { + WithPage(Standard + "starter.settings.advanced yes\ngfxrenderer default\ngfx.gpucull no\n", (page, services, saved) => { page.MoveToStandardOnce(); string text = saved(); Assert.Contains("gfxrenderer default\n", text); - Assert.Contains("starter.batterydefault 0\n", text); - Assert.Contains("vsync no\n", text); - // What lets some machines run the simulator at all stays. - Assert.Contains("gfx.usegles yes\n", text); - Assert.Null(Note(page, "gfxrenderer")); - Assert.NotEqual("7", Shown(List(page, "ReadyOverrideCb"))); + Assert.Contains("gfx.gpucull no\n", text); + Assert.True(services.Settings.AdvancedSettings); + Assert.Equal(StarterNG.Domain.Settings.SimulatorSettings.CurrentRevision, services.Settings.Revision); + }); + } + + [Fact] + public void The_layout_of_this_starter_is_moved_to_once_only() + { + WithPage(Standard + "starter.settings.revision 2\ngfxrenderer default\n", (page, _, saved) => + { + page.MoveToStandardOnce(); + + Assert.Contains("gfxrenderer default\n", saved()); }); } } diff --git a/StarterNG.Tests/SliderStepsTests.cs b/StarterNG.Tests/SliderStepsTests.cs index 5fb853b..61d2e6a 100644 --- a/StarterNG.Tests/SliderStepsTests.cs +++ b/StarterNG.Tests/SliderStepsTests.cs @@ -10,10 +10,10 @@ public class SliderStepsTests public void The_old_starters_steps_are_offered_and_a_value_outside_them_stays() { var slider = new Avalonia.Controls.Slider(); - var steps = new SliderSteps(slider, SliderRanges.ReflectionUpdates) { Value = 1 / 300.0 }; + var steps = new SliderSteps(slider, SliderRanges.ReflectionUpdates) { Value = 0.5 }; - // The simulator's own once in five minutes, shown before the old starter's 1 to 60. - Assert.Equal(1 / 300.0, steps.Value); + // Twice a second is none of the steps: shown among them, between once in five seconds and once a second. + Assert.Equal(0.5, steps.Value); Assert.Equal(SliderRanges.ReflectionUpdates.Length, slider.Maximum); slider.Value = slider.Maximum; @@ -44,11 +44,11 @@ public class SliderStepsTests public void Clamping_leaves_a_value_between_two_steps_where_it_is() { var slider = new Avalonia.Controls.Slider(); - var steps = new SliderSteps(slider, SliderRanges.CabShadowRanges) { Clamps = true, Value = 15 }; + var steps = new SliderSteps(slider, SliderRanges.DrawRangeFactors) { Clamps = true, Value = 1.5 }; - Assert.Equal(15, steps.Value); + Assert.Equal(1.5, steps.Value); steps.Value = -5; - Assert.Equal(0, steps.Value); + Assert.Equal(1, steps.Value); } } diff --git a/StarterNG.Tests/StartSimulationTests.cs b/StarterNG.Tests/StartSimulationTests.cs index b291945..e34c29f 100644 --- a/StarterNG.Tests/StartSimulationTests.cs +++ b/StarterNG.Tests/StartSimulationTests.cs @@ -152,12 +152,12 @@ public class StartSimulationTests } [Theory] - [InlineData(0)] - [InlineData(3)] - public void Any_renderer_is_left_for_the_simulator_to_take(int renderer) + [InlineData(StarterNG.Domain.Settings.GraphicsBackend.Vulkan)] + [InlineData(StarterNG.Domain.Settings.GraphicsBackend.OpenGL)] + public void Any_renderer_is_left_for_the_simulator_to_take(StarterNG.Domain.Settings.GraphicsBackend renderer) { var (start, launcher, installation) = Rig(files => files.WithExecutable(Build, "\u007fELF binary")); - installation.SettingsStore.Settings.RenderEngine = renderer; + installation.SettingsStore.Settings.Backend = renderer; Assert.Equal(SimulationStartOutcome.Started, start.Execute(freeFly: true, saveSettings: false).Outcome); Assert.NotNull(launcher.Executable); diff --git a/StarterNG/Application/AppServices.cs b/StarterNG/Application/AppServices.cs index 3639820..e4948f1 100644 --- a/StarterNG/Application/AppServices.cs +++ b/StarterNG/Application/AppServices.cs @@ -65,10 +65,7 @@ public sealed class AppServices SceneryFiles = new SceneryFileWatch(files, Sceneries, Library, State); Executables = new ExecutableLocator(files, paths, environment, log); - // Read when a borderless screen with a smaller buffer is first written, and once. - var monitors = new Lazy>(() => Monitors.List(environment)); - SettingsStore = new SettingsStore(files, clock, log, settingsPaths, - new SettingsSerializer(id => Monitors.SizeOf(monitors.Value, id)), Executables); + SettingsStore = new SettingsStore(files, clock, log, settingsPaths, new SettingsSerializer(), Executables); MissingVehicleLog = new MissingVehicleLog(SettingsStore.Settings, missingAssets, Library, log); Favorites = new FavoriteSceneries(files, log, settingsPaths.FavoritesPath()); Tapes = new HaslerTapes(files, paths, log, clock, Timetables, () => State.SimulatorRunning); diff --git a/StarterNG/Application/GraphicsGroupLevels.cs b/StarterNG/Application/GraphicsGroupLevels.cs index 4d7937a..2fbf114 100644 --- a/StarterNG/Application/GraphicsGroupLevels.cs +++ b/StarterNG/Application/GraphicsGroupLevels.cs @@ -12,10 +12,7 @@ public sealed class GraphicsGroupLevels public GraphicsGroupLevels(SettingsStore store) => _store = store; - /// - /// The level each group is at in , null where it is at none. At - /// Ultra the level under it fits too, as it leaves alone what only Ultra sets: the highest counts. - /// + /// The level each group is at in , null where it is at none. public IReadOnlyDictionary LevelsOf(SimulatorSettings settings) { var now = _store.Render(settings); @@ -24,18 +21,10 @@ public sealed class GraphicsGroupLevels (GraphicsPreset?)rendered.LastOrDefault(level => Same(group, level.Keys, now)).Level); } - /// - /// A copy of with the group at . What only - /// an end of the scale sets goes back to the simulator's own on leaving that end. - /// + /// A copy of with the group at . public SimulatorSettings Apply(GraphicsGroup group, GraphicsPreset level, SimulatorSettings settings) { - var current = LevelsOf(settings)[group]; var source = settings.Copy(); - if (level.Extras is null && current?.Extras is not null) - GraphicsExtras.None.ApplyTo(source); - if (level.Top is null && current?.Top is not null) - GraphicsTop.None.ApplyTo(source); level.ApplyTo(source); return _store.WithKeysOf(settings, source, group.Keys); } diff --git a/StarterNG/Application/SettingsStore.cs b/StarterNG/Application/SettingsStore.cs index 566d9b3..b404211 100644 --- a/StarterNG/Application/SettingsStore.cs +++ b/StarterNG/Application/SettingsStore.cs @@ -131,8 +131,9 @@ public sealed class SettingsStore return; GraphicsPreset.High.ApplyTo(Settings); - // Nothing of an older starter to bring over: the settings start in the standard mode. + // Nothing of an older starter to bring over: the settings start in the standard mode, of this layout. Settings.MovedToStandard = true; + Settings.Revision = SimulatorSettings.CurrentRevision; Save(); } @@ -181,12 +182,11 @@ public sealed class SettingsStore } /// - /// What lets some machines run the simulator at all: the card it is put on (offloading - /// to the discrete one fails with some drivers) and OpenGL ES where desktop OpenGL does - /// not work. The move to the standard mode, done without asking, leaves them as they are. + /// What lets some machines run the simulator at all: the card it is put on (offloading to the discrete one + /// fails with some drivers). The move to the standard mode, done without asking, leaves it as it is. /// public static readonly IReadOnlySet KeptOnMoveToStandard = - new HashSet(StringComparer.OrdinalIgnoreCase) { "starter.gpu", "gfx.usegles" }; + new HashSet(StringComparer.OrdinalIgnoreCase) { "starter.gpu" }; /// /// The mode is this installation's, like its simulator and its card: another file, a @@ -268,6 +268,7 @@ public sealed class SettingsStore ApplyChanges(_config, Changes(Settings)); RemoveDuplicates(_config, path); + KeepAntiAliasingLast(_config); if (merged) { // What is held follows the file: the player's changes and the others' together. @@ -312,6 +313,12 @@ public sealed class SettingsStore Save(); } + /// + /// Of gfx.antialiasing and the older multisampling the simulator heeds the one further down, so the newer goes + /// below the older, which only the simulators before it read. + /// + private static void KeepAntiAliasingLast(ConfigFile config) => config.MoveAfter("gfx.antialiasing", "multisampling"); + private static void ApplyChanges(ConfigFile config, IReadOnlyList changes) { foreach (var change in changes) @@ -379,6 +386,7 @@ public sealed class SettingsStore var copy = ConfigFile.Parse(_config.ToText()); ApplyChanges(copy, Changes(settings ?? Settings)); copy.RemoveDuplicates(SettingsSerializer.RepeatableKeys); + KeepAntiAliasingLast(copy); try { @@ -437,6 +445,7 @@ public sealed class SettingsStore bool readable = key.Kind switch { SimulatorKeyKind.Toggle => Bool(first) is not null, + SimulatorKeyKind.Choice => key.ChoiceIndex(first) >= 0, SimulatorKeyKind.Number => double.TryParse(first, NumberStyles.Float, CultureInfo.InvariantCulture, out _), _ => true }; @@ -453,7 +462,7 @@ public sealed class SettingsStore // Written from other keys, or rewritten on purpose whatever they say: what they hold is no setting of their own. private static readonly HashSet NotReadAlone = new(StringComparer.OrdinalIgnoreCase) { - "mousescale", "gfxrenderer", "gfx.shadowmap.enabled", "gfx.framebuffer.width", "gfx.framebuffer.height" + "mousescale", "gfxrenderer", "multisampling" }; private SimulatorSettings WithFile(ConfigFile config) @@ -542,9 +551,9 @@ public sealed class SettingsStore return false; if (overCap.Contains(key)) return false; - // The simulator goes by these to the letter: a buffer of a window's size stretched - // over the monitor, a monitor's name it does not find. The file's own is no choice to keep. - if (AsWritten(key) && _config.GetRaw(key) != value) + // The simulator goes by this to the letter: a monitor's name it does not find. The file's own is no + // choice to keep. + if (string.Equals(key, "fullscreenmonitor", StringComparison.OrdinalIgnoreCase) && _config.GetRaw(key) != value) return false; string? synced = _synced.GetValueOrDefault(key); if (shown.TryGetValue(key, out var onScreen) && onScreen.Shown == value && onScreen.Held == synced) @@ -552,11 +561,6 @@ public sealed class SettingsStore return _config.Has(key) && synced == value; } - bool AsWritten(string key) => - string.Equals(key, "fullscreenmonitor", StringComparison.OrdinalIgnoreCase) || - (settings.FullscreenWindowed && - SettingsSerializer.FramebufferKeys.Contains(key, StringComparer.OrdinalIgnoreCase)); - void Add(string key, string? value) { // To the simulator a key past endconfig is not set yet, whatever it says. diff --git a/StarterNG/Domain/Settings/GraphicsPreset.cs b/StarterNG/Domain/Settings/GraphicsPreset.cs index 4d6af06..9188821 100644 --- a/StarterNG/Domain/Settings/GraphicsPreset.cs +++ b/StarterNG/Domain/Settings/GraphicsPreset.cs @@ -5,208 +5,139 @@ using System.Linq; namespace StarterNG.Domain.Settings; /// -/// What only the two ends of the scale touch: the effects left to taste at every other -/// level and how often the screens refresh. The lowest level gives them up, the highest -/// takes the most there is. -/// -/// python.updatetime, one of the steps of its list. -public sealed record GraphicsExtras( - bool MotionBlur, - bool ChromaticAberration, - bool Smoke, - int PythonUpdateMs) -{ - /// The eu07.ini keys these values live in. - public static readonly IReadOnlyList Keys = new[] - { - "gfx.postfx.motionblur.enabled", "gfx.postfx.chromaticaberration.enabled", - "gfx.smoke", "python.updatetime" - }; - - /// The simulator's own, for leaving a level chosen before this run: what was there earlier is gone. - public static readonly GraphicsExtras None = new(true, true, true, 200); - - public static GraphicsExtras Of(SimulatorSettings s) => - new(s.MotionBlur, s.ChromaticAberration, s.Smoke, s.PythonScreenUpdateRate); - - public void ApplyTo(SimulatorSettings s) - { - s.MotionBlur = MotionBlur; - s.ChromaticAberration = ChromaticAberration; - s.Smoke = Smoke; - s.PythonScreenUpdateRate = PythonUpdateMs; - } -} - -/// -/// What only Ultra sets, with no scale to climb: the longest shadows, at the bottom of their -/// limit, and the screens drawn. What only the advanced mode shows no level sets. -/// -/// gfx.shadow.angle.min: how low the sun counts for shadows, so how long they -/// get: up to 5× the height of what casts them at 0.2, no longer than it at 1 (opengl33renderer.cpp). -/// python.enabled. -public sealed record GraphicsTop(double ShadowAngleLimit, bool Screens) -{ - /// The eu07.ini keys these values live in. - public static readonly IReadOnlyList Keys = new[] { "gfx.shadow.angle.min", "python.enabled" }; - - /// What they are with nothing set, as . - public static readonly GraphicsTop None = new(0.2, true); - - public static GraphicsTop Of(SimulatorSettings s) => new(s.ShadowAngleLimit, s.PythonScreens); - - public void ApplyTo(SimulatorSettings s) - { - s.ShadowAngleLimit = ShadowAngleLimit; - s.PythonScreens = Screens; - } -} - -/// -/// A level of detail set in one go: what weighs on the graphics card. Every scale climbs in -/// even steps from to , as far as it has steps for six -/// levels. A level sets only what the standard mode shows, and only to what its sliders offer -/// (, the old starter's ranges): never past the old starter. The screen -/// (resolution, buffer, field of view), the frame pacing and the effects that are a matter of -/// taste - motion blur, chromatic aberration - stay as they are, except at the two ends of the -/// scale, which have . +/// A level of detail set in one go, as games offer them: what weighs on the graphics card, from Low for a weak or +/// old card to Very high for a strong one. High is about the simulator's own values, the start of a player with no +/// settings of their own; Very high is the most worth having, not everything at its top - ray tracing, MSAA x8 and +/// the largest shadow maps cost far more than they show, and stay for the developer tab. The screen (resolution, +/// render scale, field of view), the frame pacing and the effects that are a matter of taste - motion blur, +/// chromatic aberration - are no level's. /// /// Its name's translation key. -/// gfx.shadows.cab.range, in metres, read only by the legacy renderer. -/// multisampling. -/// gfx.reflections.framerate, in updates a second, one of the old starter's steps. +/// gfx.reflections.framerate, in updates a second. /// gfx.drawrange.factor.max: how far the regulator may stretch the draw range. +/// The it sets, in the file's words. public sealed record GraphicsPreset( string NameKey, int TextureSize, int CabTextureSize, double Anisotropy, + bool ExtraEffects, AntiAliasingMode AntiAliasing, - int DynamicLights, - int SmokeFidelity, - bool Shadows, int ShadowMap, int ShadowRange, int ShadowRank, - bool EnvMap, int ReflectionsFidelity, double ReflectionsRate, - bool ExtraEffects, int SplineFidelity, double DrawRangeFactor, - int CabShadowsRange, - GraphicsExtras? Extras = null, - GraphicsTop? Top = null) + int SmokeFidelity, + IReadOnlyDictionary Keys) { + /// The simulator's own rate of the reflections: once in five minutes, or a kilometre on. + public const double ReflectionsSeldom = 1 / 300.0; + /// The eu07.ini keys a level sets. - public static readonly IReadOnlyList Keys = new[] - { - "maxtexturesize", "maxcabtexturesize", "anisotropicfiltering", "multisampling", "dynamiclights", - "gfx.smoke.fidelity", "shadows", "gfx.shadowmap.enabled", "shadowtune", "gfx.shadow.rank.cutoff", - "gfx.envmap.enabled", "gfx.reflections.fidelity", "gfx.reflections.framerate", "gfx.extraeffects", - "splinefidelity", "gfx.drawrange.factor.max", "gfx.shadows.cab.range" - }; + public static IReadOnlyList AllKeys => + GraphicsGroup.All.SelectMany(group => group.Keys).Concat(GraphicsGroup.AntiAliasingKeys).ToList(); - /// The last resort: no shadows, no reflections, no effects, no smoke. - public static readonly GraphicsPreset Minimal = new( - "PresetMinimal", TextureSize: 512, CabTextureSize: 512, Anisotropy: 1, AntiAliasing: AntiAliasingMode.Off, - DynamicLights: 1, SmokeFidelity: 1, Shadows: false, ShadowMap: 1024, ShadowRange: 75, ShadowRank: 1, - EnvMap: false, ReflectionsFidelity: 0, ReflectionsRate: 1, ExtraEffects: false, - SplineFidelity: 1, DrawRangeFactor: 1, CabShadowsRange: 0, - Extras: new GraphicsExtras(MotionBlur: false, ChromaticAberration: false, Smoke: false, PythonUpdateMs: 800)); + private static Dictionary Values(params (string Key, string Value)[] values) => + values.ToDictionary(pair => pair.Key, pair => pair.Value, StringComparer.OrdinalIgnoreCase); + /// For a weak or old card, or a laptop on its own graphics: the shadows short, no screen-space effects. public static readonly GraphicsPreset Low = new( - "PresetLow", TextureSize: 1024, CabTextureSize: 1024, Anisotropy: 2, AntiAliasing: AntiAliasingMode.Off, - DynamicLights: 3, SmokeFidelity: 1, Shadows: true, ShadowMap: 1024, ShadowRange: 125, ShadowRank: 2, - EnvMap: true, ReflectionsFidelity: 0, ReflectionsRate: 1, ExtraEffects: true, - SplineFidelity: 2, DrawRangeFactor: 1, CabShadowsRange: 0); + "PresetLow", TextureSize: 1024, CabTextureSize: 1024, Anisotropy: 4, ExtraEffects: false, + AntiAliasing: AntiAliasingMode.Off, ShadowMap: 1024, ShadowRange: 125, ShadowRank: 1, + ReflectionsFidelity: 0, ReflectionsRate: ReflectionsSeldom, SplineFidelity: 1, DrawRangeFactor: 1, + SmokeFidelity: 1, + Values(("gfx.lights.shadows", "low"), ("gfx.contactshadows", "no"), ("gfx.ssr", "no"), ("gfx.cabprobe", "low"), + ("gfx.postfx.ao", "no"), ("gfx.fog.quality", "low"), ("gfx.clouds", "low"), + ("gfx.grass", "yes"), ("gfx.grass.distance", "40"), ("gfx.grass.fadedistance", "50"), + ("gfx.grass.density", "0.5"), ("gfx.precipitation.particles", "16384"))); public static readonly GraphicsPreset Medium = new( - "PresetMedium", TextureSize: 2048, CabTextureSize: 2048, Anisotropy: 4, AntiAliasing: AntiAliasingMode.Msaa2, - DynamicLights: 5, SmokeFidelity: 2, Shadows: true, ShadowMap: 1024, ShadowRange: 175, ShadowRank: 2, - EnvMap: true, ReflectionsFidelity: 1, ReflectionsRate: 1, ExtraEffects: true, - SplineFidelity: 2, DrawRangeFactor: 2, CabShadowsRange: 20); + "PresetMedium", TextureSize: 2048, CabTextureSize: 2048, Anisotropy: 8, ExtraEffects: true, + AntiAliasing: AntiAliasingMode.Msaa2, ShadowMap: 2048, ShadowRange: 175, ShadowRank: 2, + ReflectionsFidelity: 1, ReflectionsRate: ReflectionsSeldom, SplineFidelity: 2, DrawRangeFactor: 2, + SmokeFidelity: 1, + Values(("gfx.lights.shadows", "low"), ("gfx.contactshadows", "no"), ("gfx.ssr", "low"), ("gfx.cabprobe", "low"), + ("gfx.postfx.ao", "ssao"), ("gfx.fog.quality", "medium"), ("gfx.clouds", "low"), + ("gfx.grass", "yes"), ("gfx.grass.distance", "60"), ("gfx.grass.fadedistance", "70"), + ("gfx.grass.density", "1"), ("gfx.precipitation.particles", "32768"))); - /// - /// Where a player with no settings of their own starts. The simulator's own values (Globals.h), - /// but for smoke, track curves, reflections and cab shadows: theirs are the bottom of a scale - /// with levels to go under this one, or below what the old starter offered. - /// + /// Where a player with no settings of their own starts: about the simulator's own values. public static readonly GraphicsPreset High = new( - "PresetHigh", TextureSize: 4096, CabTextureSize: 4096, Anisotropy: 8, AntiAliasing: AntiAliasingMode.Msaa4, - DynamicLights: 7, SmokeFidelity: 2, Shadows: true, ShadowMap: 2048, ShadowRange: 250, ShadowRank: 3, - EnvMap: true, ReflectionsFidelity: 1, ReflectionsRate: 3, ExtraEffects: true, - SplineFidelity: 2, DrawRangeFactor: 3, CabShadowsRange: 30); + "PresetHigh", TextureSize: 4096, CabTextureSize: 4096, Anisotropy: 8, ExtraEffects: true, + AntiAliasing: AntiAliasingMode.Msaa4, ShadowMap: 2048, ShadowRange: 250, ShadowRank: 3, + ReflectionsFidelity: 2, ReflectionsRate: ReflectionsSeldom, SplineFidelity: 2, DrawRangeFactor: 3, + SmokeFidelity: 2, + Values(("gfx.lights.shadows", "medium"), ("gfx.contactshadows", "no"), ("gfx.ssr", "medium"), + ("gfx.cabprobe", "medium"), ("gfx.postfx.ao", "gtao"), ("gfx.fog.quality", "medium"), + ("gfx.clouds", "medium"), ("gfx.grass", "yes"), ("gfx.grass.distance", "60"), + ("gfx.grass.fadedistance", "70"), ("gfx.grass.density", "1"), ("gfx.precipitation.particles", "65536"))); /// - /// For a strong card. A map of 4096 doubles the cascades, so the range here reaches 800 m. - /// Filtering stays as High's, so the textures tell this level from Ultra. + /// For a strong card. A map of 4096 doubles the cascades, so the range here reaches 600 m; the textures of the + /// cab stay at 4096, the most the starter gives them. /// public static readonly GraphicsPreset VeryHigh = new( - "PresetVeryHigh", TextureSize: 8192, CabTextureSize: 4096, Anisotropy: 8, AntiAliasing: AntiAliasingMode.Msaa8, - DynamicLights: 7, SmokeFidelity: 3, Shadows: true, ShadowMap: 4096, ShadowRange: 400, ShadowRank: 3, - EnvMap: true, ReflectionsFidelity: 2, ReflectionsRate: 10, ExtraEffects: true, - SplineFidelity: 3, DrawRangeFactor: 3, CabShadowsRange: 50); + "PresetVeryHigh", TextureSize: 8192, CabTextureSize: 4096, Anisotropy: 16, ExtraEffects: true, + AntiAliasing: AntiAliasingMode.Msaa4, ShadowMap: 4096, ShadowRange: 300, ShadowRank: 3, + ReflectionsFidelity: 2, ReflectionsRate: 1, SplineFidelity: 3, DrawRangeFactor: 3, + SmokeFidelity: 3, + Values(("gfx.lights.shadows", "high"), ("gfx.contactshadows", "low"), ("gfx.ssr", "high"), + ("gfx.cabprobe", "high"), ("gfx.postfx.ao", "gtao"), ("gfx.fog.quality", "high"), + ("gfx.clouds", "high"), ("gfx.grass", "yes"), ("gfx.grass.distance", "100"), + ("gfx.grass.fadedistance", "120"), ("gfx.grass.density", "1.25"), ("gfx.precipitation.particles", "65536"))); - /// - /// The top of every slider, which is the most the old starter gave. Not the best picture - /// throughout: a map of 8192 stretches the cascades fourfold, so shadows reach 1600 m but are - /// coarser up close than at . - /// - public static readonly GraphicsPreset Ultra = new( - "PresetUltra", TextureSize: 8192, CabTextureSize: 4096, Anisotropy: 16, AntiAliasing: AntiAliasingMode.Msaa8, - DynamicLights: 7, SmokeFidelity: 4, Shadows: true, ShadowMap: 8192, ShadowRange: 400, ShadowRank: 3, - EnvMap: true, ReflectionsFidelity: 2, ReflectionsRate: 60, ExtraEffects: true, - SplineFidelity: 4, DrawRangeFactor: 3, CabShadowsRange: 100, - Extras: new GraphicsExtras(MotionBlur: true, ChromaticAberration: true, Smoke: true, PythonUpdateMs: 200), - Top: new GraphicsTop(ShadowAngleLimit: 0.2, Screens: true)); - - public static readonly IReadOnlyList All = new[] { Minimal, Low, Medium, High, VeryHigh, Ultra }; + public static readonly IReadOnlyList All = new[] { Low, Medium, High, VeryHigh }; public void ApplyTo(SimulatorSettings s) { s.MaxTextureSize = TextureSize; s.MaxCabTextureSize = CabTextureSize; s.TextureFiltering = Anisotropy; + s.ExtraEffects = ExtraEffects; s.AntiAliasing = AntiAliasing; - s.CabShadowsRange = CabShadowsRange; - s.DynamicLights = DynamicLights; - s.SmokeFidelity = SmokeFidelity; - s.RenderShadows = Shadows; + s.RenderShadows = true; s.ShadowMapResolution = ShadowMap; s.ShadowProjectionRange = ShadowRange; s.ShadowRankCutoff = ShadowRank; - s.EnvMap = EnvMap; + s.EnvMap = true; s.ReflectionsFidelity = ReflectionsFidelity; s.ReflectionsFramerate = ReflectionsRate; - s.ExtraEffects = ExtraEffects; s.SplineFidelity = SplineFidelity; s.DrawRangeFactor = DrawRangeFactor; - Extras?.ApplyTo(s); - Top?.ApplyTo(s); + s.SmokeFidelity = SmokeFidelity; + foreach (var (key, value) in Keys) + s.Extra[key] = value; } /// Whether is at this level throughout. public bool Matches(SimulatorSettings s) => s.MaxTextureSize == TextureSize && s.MaxCabTextureSize == CabTextureSize && - Near(s.TextureFiltering, Anisotropy) && s.AntiAliasing == AntiAliasing && - s.DynamicLights == DynamicLights && s.SmokeFidelity == SmokeFidelity && - s.RenderShadows == Shadows && s.ShadowMapResolution == ShadowMap && + Near(s.TextureFiltering, Anisotropy) && s.ExtraEffects == ExtraEffects && s.AntiAliasing == AntiAliasing && + s.RenderShadows && s.ShadowMapResolution == ShadowMap && s.ShadowProjectionRange == ShadowRange && s.ShadowRankCutoff == ShadowRank && - s.EnvMap == EnvMap && s.ReflectionsFidelity == ReflectionsFidelity && - Near(s.ReflectionsFramerate, ReflectionsRate) && s.ExtraEffects == ExtraEffects && + s.EnvMap && s.ReflectionsFidelity == ReflectionsFidelity && + Near(s.ReflectionsFramerate, ReflectionsRate) && s.SplineFidelity == SplineFidelity && Near(s.DrawRangeFactor, DrawRangeFactor) && - s.CabShadowsRange == CabShadowsRange && - (Extras is null || GraphicsExtras.Of(s) == Extras) && - (Top is null || GraphicsTop.Of(s) == Top); + s.SmokeFidelity == SmokeFidelity && + Keys.All(pair => SameValue(SimulatorKeys.Named(pair.Key), pair.Value, s)); /// The level is at throughout, if any. public static GraphicsPreset? Matching(SimulatorSettings s) => All.FirstOrDefault(preset => preset.Matches(s)); - internal static double NumberOf(SimulatorSettings s, string name) + /// Whether gives the key the value means, written its own way. + private static bool SameValue(SimulatorKey key, string value, SimulatorSettings s) { - var key = SimulatorKeys.Named(name); - return key.ParseNumber(key.RawIn(s)); + string raw = key.RawIn(s); + return key.Kind switch + { + SimulatorKeyKind.Toggle => SimulatorKey.ParseToggle(raw) == SimulatorKey.ParseToggle(value), + SimulatorKeyKind.Number => Near(key.ParseNumber(raw), key.ParseNumber(value)), + SimulatorKeyKind.Choice => key.ChoiceIndex(raw) == key.ChoiceIndex(value), + _ => string.Equals(raw.Trim(), value, StringComparison.OrdinalIgnoreCase) + }; } // As the file rounds it. @@ -215,69 +146,49 @@ public sealed record GraphicsPreset( } /// -/// A part of the picture with a level of its own, as its section on the screen has it. The rest -/// of a level - the anti-aliasing, the post-processing switches, the dynamic lights and the smoke - goes only with the whole. +/// A part of the picture with a level of its own: one row of the standard mode, which the levels set in one go and +/// the player can take further up or down. The anti-aliasing has a row of its own. /// +/// Its row's translation key. /// The eu07.ini keys it sets. -public sealed record GraphicsGroup(IReadOnlyList Keys) +public sealed record GraphicsGroup(string NameKey, IReadOnlyList Keys) { - public static readonly GraphicsGroup DrawRange = new(new[] { "splinefidelity", "gfx.drawrange.factor.max" }); + /// The keys of the anti-aliasing, which a level sets too. + public static readonly IReadOnlyList AntiAliasingKeys = new[] { "gfx.antialiasing", "multisampling" }; - public static readonly GraphicsGroup Textures = new(new[] + public static readonly GraphicsGroup Textures = new("GroupTextures", new[] { - "maxtexturesize", "maxcabtexturesize", "anisotropicfiltering" + "maxtexturesize", "maxcabtexturesize", "anisotropicfiltering", "gfx.extraeffects" }); - public static readonly GraphicsGroup Shadows = new(new[] + public static readonly GraphicsGroup Shadows = new("GroupShadows", new[] { - "shadows", "gfx.shadowmap.enabled", "shadowtune", "gfx.shadow.rank.cutoff", "gfx.shadow.angle.min", "gfx.shadows.cab.range" + "gfx.shadowmap.enabled", "shadowtune", "gfx.shadow.rank.cutoff", "gfx.lights.shadows", "gfx.contactshadows" }); - public static readonly GraphicsGroup Reflections = new(new[] + public static readonly GraphicsGroup Reflections = new("GroupReflections", new[] { - "gfx.envmap.enabled", "gfx.reflections.fidelity", "gfx.reflections.framerate" + "gfx.envmap.enabled", "gfx.reflections.fidelity", "gfx.reflections.framerate", "gfx.ssr", "gfx.cabprobe" + }); + + public static readonly GraphicsGroup Lighting = new("GroupLighting", new[] + { + "gfx.postfx.ao", "gfx.fog.quality", "gfx.clouds" + }); + + public static readonly GraphicsGroup DrawRange = new("GroupDrawRange", new[] + { + "splinefidelity", "gfx.drawrange.factor.max", "gfx.grass", "gfx.grass.distance", "gfx.grass.fadedistance", + "gfx.grass.density" + }); + + public static readonly GraphicsGroup Particles = new("GroupParticles", new[] + { + "gfx.smoke.fidelity", "gfx.precipitation.particles" }); public static readonly IReadOnlyList All = new[] { - DrawRange, Textures, Shadows, Reflections + Textures, Shadows, Reflections, Lighting, DrawRange, Particles }; } - -/// What applying a level touched. -/// The eu07.ini keys it chose as a whole. -public sealed record PresetApplied(IReadOnlyList ChosenKeys); - -/// -/// Remembers what was there before an end of the scale, which comes back with any level -/// between. Leaving one chosen before this run, what was there earlier is gone, so the -/// simulator's own values take its place. -/// -public sealed class GraphicsPresetMemory -{ - private GraphicsExtras? _beforeExtras; - - private GraphicsTop? _beforeTop; - - /// Puts in , with what an end of the scale left behind. - public PresetApplied Apply(GraphicsPreset preset, SimulatorSettings settings) - { - var current = GraphicsPreset.Matching(settings); - var coming = preset.Extras is not null ? null - : _beforeExtras ?? (current?.Extras is not null ? GraphicsExtras.None : null); - _beforeExtras = preset.Extras is not null ? _beforeExtras ?? GraphicsExtras.Of(settings) : null; - var comingTop = preset.Top is not null ? null - : _beforeTop ?? (current?.Top is not null ? GraphicsTop.None : null); - _beforeTop = preset.Top is not null ? _beforeTop ?? GraphicsTop.Of(settings) : null; - coming?.ApplyTo(settings); - comingTop?.ApplyTo(settings); - preset.ApplyTo(settings); - - var chosen = new List(GraphicsPreset.Keys); - if (preset.Extras is not null || coming is not null) - chosen.AddRange(GraphicsExtras.Keys); - if (preset.Top is not null || comingTop is not null) - chosen.AddRange(GraphicsTop.Keys); - return new PresetApplied(chosen); - } -} diff --git a/StarterNG/Domain/Settings/Renderers.cs b/StarterNG/Domain/Settings/Renderers.cs deleted file mode 100644 index e47ec98..0000000 --- a/StarterNG/Domain/Settings/Renderers.cs +++ /dev/null @@ -1,14 +0,0 @@ -namespace StarterNG.Domain.Settings; - -/// The renderers a gfxrenderer word picks, as application.cpp tells them apart. -public enum RendererKind { Modern, Legacy } - -public static class Renderers -{ - /// "legacy", "simple", "simpleshader" and "off" draw with the legacy renderer, any other word with the full one. - public static RendererKind KindOf(string renderer) => renderer.ToLowerInvariant() switch - { - "legacy" or "simple" or "simpleshader" or "off" => RendererKind.Legacy, - _ => RendererKind.Modern - }; -} diff --git a/StarterNG/Domain/Settings/SimulatorKeys.cs b/StarterNG/Domain/Settings/SimulatorKeys.cs index f0d53c7..15996b9 100644 --- a/StarterNG/Domain/Settings/SimulatorKeys.cs +++ b/StarterNG/Domain/Settings/SimulatorKeys.cs @@ -5,13 +5,14 @@ using System.Linq; namespace StarterNG.Domain.Settings; -public enum SimulatorKeyKind { Toggle, Number, Text } +public enum SimulatorKeyKind { Toggle, Number, Text, Choice } /// /// An eu07.ini key the simulator reads that needs no logic of the starter's own: -/// a switch, a number or a word, shown as one row of the settings. The default -/// is the simulator's own, from Globals.h, used while the file does not carry -/// the key. +/// a switch, a number, a word or one of a few words, shown as one row of the settings. +/// The default is the simulator's own, from Globals.h, used while the file does not +/// carry the key - but for a key the starter , where it is the +/// starter's own: the faster choice the simulator does not make by itself. /// public sealed record SimulatorKey( string Key, @@ -24,7 +25,9 @@ public sealed record SimulatorKey( double Step = 1, string Unit = "", bool ZeroIsOff = false, - int Repeat = 1) + int Repeat = 1, + bool Writes = false, + IReadOnlyList? Choices = null) { /// The label's translation key; the explanation's adds "Desc". public string LabelKey => "Ini." + Key; @@ -36,6 +39,31 @@ public sealed record SimulatorKey( public static string FormatToggle(bool value) => value ? "yes" : "no"; + /// The words of a level the simulator takes for 0 to 3 as well. + public static readonly IReadOnlyList Levels = new[] { "no", "low", "medium", "high" }; + + /// + /// Where stands among the : its word, or the number the simulator + /// takes for a level (gfx.ssr 2 is medium); -1 for one it is not. + /// + public int ChoiceIndex(string raw) + { + if (Choices is null) + return -1; + string word = FirstToken(raw); + for (int i = 0; i < Choices.Count; i++) + if (string.Equals(Choices[i], word, StringComparison.OrdinalIgnoreCase)) + return i; + if (ReferenceEquals(Choices, Levels) && + int.TryParse(word, NumberStyles.Integer, CultureInfo.InvariantCulture, out int level) && + level >= 0 && level < Choices.Count) + return level; + return -1; + } + + /// The label's translation key of the word . + public static string ChoiceLabelKey(string choice) => "Choice." + choice; + /// The key's value in , in the file's words: what is set, or else the default. public string RawIn(SimulatorSettings s) => s.Extra.TryGetValue(Key, out string? raw) ? raw : Default; @@ -64,10 +92,13 @@ public sealed record SimulatorKey( public static class SimulatorKeys { /// - /// The keys a player sees in the standard mode, which has what the old starter had. It had - /// none of these: they are all for the advanced mode. + /// The keys a player sees in the standard mode. The rest are the developer tab's, which only the advanced + /// mode shows: a player in the standard mode has them at their defaults, the fast choice. /// - public static readonly IReadOnlySet Standard = new HashSet(StringComparer.OrdinalIgnoreCase); + public static readonly IReadOnlySet Standard = new HashSet(StringComparer.OrdinalIgnoreCase) + { + "ui.scale" + }; public const string General = "general"; public const string Graphics = "graphics"; @@ -75,8 +106,13 @@ public static class SimulatorKeys public const string Physics = "physics"; public const string Advanced = "advanced"; - private static SimulatorKey Toggle(string key, bool value, string category, string section) => - new(key, SimulatorKeyKind.Toggle, SimulatorKey.FormatToggle(value), category, section); + public const string RendererSection = "IniSectionRenderer"; + public const string QualitySection = "IniSectionQuality"; + public const string PerformanceSection = "IniSectionPerformance"; + public const string LogsSection = "IniSectionLogs"; + + private static SimulatorKey Toggle(string key, bool value, string category, string section, bool writes = false) => + new(key, SimulatorKeyKind.Toggle, SimulatorKey.FormatToggle(value), category, section, Writes: writes); private static SimulatorKey Number(string key, double value, string category, string section, double min, double max, double step, string unit = "", @@ -87,47 +123,98 @@ public static class SimulatorKeys private static SimulatorKey Text(string key, string category, string section) => new(key, SimulatorKeyKind.Text, string.Empty, category, section); + private static SimulatorKey Choice(string key, string value, string section, IReadOnlyList? choices = null) => + new(key, SimulatorKeyKind.Choice, value, Advanced, section, Choices: choices ?? SimulatorKey.Levels); + public static SimulatorKey Named(string key) => All.First(k => k.Key == key); public static IReadOnlyList All { get; } = new[] { Number("ui.scale", 1, General, "IniSectionInterface", 0.5, 3, 0.05, "×"), - Number("ui.fontsize", 13, General, "IniSectionInterface", 8, 32, 1, " px"), - Number("ui.bg.opacity", 0.94, General, "IniSectionInterface", 0.1, 1, 0.05), - Toggle("gui.defaultwindows", true, General, "IniSectionInterface"), - Toggle("gui.trainingdefault", false, General, "IniSectionInterface"), - Toggle("gui.showtranscripts", true, General, "IniSectionInterface"), - Toggle("loadinglog", false, General, "IniSectionInterface"), - Toggle("captureonstart", true, General, "IniSectionInterface"), - Toggle("mousecontrol", true, General, "IniSectionInterface"), - Text("screenshotsdir", General, "IniSectionInterface"), + Number("ui.fontsize", 13, Advanced, "IniSectionInterface", 8, 32, 1, " px"), + Number("ui.bg.opacity", 0.94, Advanced, "IniSectionInterface", 0.1, 1, 0.05), + Toggle("gui.defaultwindows", true, Advanced, "IniSectionInterface"), + Toggle("gui.trainingdefault", false, Advanced, "IniSectionInterface"), + Toggle("gui.showtranscripts", true, Advanced, "IniSectionInterface"), + Toggle("captureonstart", true, Advanced, "IniSectionInterface"), + Toggle("mousecontrol", true, Advanced, "IniSectionInterface"), + Text("screenshotsdir", Advanced, "IniSectionInterface"), - Number("basedrawrange", 2500, Graphics, "IniSectionRanges", 500, 10000, 250, " m"), - Number("heightbase", 1, Graphics, "IniSectionRanges", 0.5, 3, 0.05, "×"), - Number("targetfps", 0, Graphics, "IniSectionRanges", 0, 240, 5, " FPS", zeroIsOff: true), - Number("sleeperdistance", 250, Graphics, "IniSectionRanges", 0, 1000, 50, " m", zeroIsOff: true), - Number("gfx.reflections.range_instances", 750, Graphics, "IniSectionRanges", 0, 3000, 50, " m"), - Number("gfx.reflections.range_vehicles", 250, Graphics, "IniSectionRanges", 0, 2000, 50, " m"), - Toggle("gfx.textures.streaming", false, Graphics, "IniSectionRanges"), - Number("gfx.textures.releasedistance", 0, Graphics, "IniSectionRanges", 0, 10, 0.5, "×", zeroIsOff: true), - Toggle("skyenabled", true, Graphics, "IniSectionRanges"), - Toggle("rendercab", true, Graphics, "IniSectionRanges"), - Number("gfx.postfx.motionblur.shutter", 0.01, Graphics, "IniSectionRanges", 0.001, 0.1, 0.001, " s"), - Number("python.fpslimit", 100, Graphics, "IniSectionRanges", 5, 200, 5, " FPS"), - Toggle("python.vsync", true, Graphics, "IniSectionRanges"), - Toggle("python.displaywindows", false, Graphics, "IniSectionRanges"), - Toggle("newaircouplers", true, Graphics, "IniSectionRanges"), - Toggle("smoothtraction", true, Graphics, "IniSectionRanges"), + // The renderer: what only Vulkan reads, and the shaders of either. + Text("gfx.vulkan.device", Advanced, RendererSection), + Toggle("gfx.vulkan.renderthread", true, Advanced, RendererSection), + Number("gfx.threads", 0, Advanced, RendererSection, 0, 64, 1, zeroIsOff: true), + Toggle("gfx.vulkan.asyncresources", true, Advanced, RendererSection), + Toggle("gfx.vulkan.parallelpasses", true, Advanced, RendererSection), + Toggle("gfx.vulkan.parallelmodels", true, Advanced, RendererSection), + Toggle("gfx.vulkan.asynccompute", false, Advanced, RendererSection), + Number("gfx.vulkan.framesinflight", 2, Advanced, RendererSection, 2, 3, 1), + Toggle("gfx.shaders.binaries", true, Advanced, RendererSection), - Number("sound.maxsources", 30, Sound, "IniSectionAudio", 8, 256, 8), - Toggle("sound.asyncload", false, Sound, "IniSectionAudio"), + // The parts of the picture of the OpenGL 4.6 and Vulkan renderers the levels set, one by one. + Choice("gfx.lights.shadows", "medium", QualitySection), + Choice("gfx.contactshadows", "no", QualitySection), + Toggle("gfx.shadow.sdsm", false, Advanced, QualitySection), + Choice("gfx.ssr", "medium", QualitySection), + Toggle("gfx.raytracing", false, Advanced, QualitySection), + Choice("gfx.cabprobe", "medium", QualitySection), + Toggle("gfx.water.realistic", false, Advanced, QualitySection), + Choice("gfx.postfx.ao", "gtao", QualitySection, new[] { "no", "ssao", "gtao" }), + Choice("gfx.fog.quality", "medium", QualitySection, new[] { "low", "medium", "high", "ultra" }), + Choice("gfx.clouds", "medium", QualitySection, new[] { "no", "low", "medium", "high", "ultra" }), + Toggle("gfx.postfx.bloom", true, Advanced, QualitySection), + Toggle("gfx.grass", true, Advanced, QualitySection), + Number("gfx.grass.distance", 60, Advanced, QualitySection, 5, 500, 5, " m"), + Number("gfx.grass.fadedistance", 70, Advanced, QualitySection, 5, 600, 5, " m"), + Number("gfx.grass.density", 1, Advanced, QualitySection, 0, 4, 0.25, "×"), + Number("gfx.precipitation.particles", 65536, Advanced, QualitySection, 0, 262144, 4096), + Choice("gfx.dlss.preset", "default", QualitySection, new[] { "default", "j", "k", "l", "m" }), + Choice("gfx.framegeneration", "off", QualitySection, new[] { "off", "x2", "x3", "x4" }), + Choice("gfx.reflex", "off", QualitySection, new[] { "off", "on", "boost" }), - Toggle("loadtraction", true, Physics, "IniSectionPhysics"), - Toggle("rollfix", true, Physics, "IniSectionPhysics"), - Number("shakefactor", 1, Physics, "IniSectionPhysics", 0, 3, 0.1, "×", repeat: 3), - Toggle("map.manualswitchcontrol", false, Physics, "IniSectionPhysics"), - Number("map.highlightdistance", 3000, Physics, "IniSectionPhysics", 0, 10000, 250, " m", zeroIsOff: true), + Number("basedrawrange", 2500, Advanced, "IniSectionRanges", 500, 10000, 250, " m"), + Number("heightbase", 1, Advanced, "IniSectionRanges", 0.5, 3, 0.05, "×"), + Number("targetfps", 0, Advanced, "IniSectionRanges", 0, 240, 5, " FPS", zeroIsOff: true), + Number("sleeperdistance", 250, Advanced, "IniSectionRanges", 0, 1000, 50, " m", zeroIsOff: true), + Number("gfx.reflections.range_instances", 750, Advanced, "IniSectionRanges", 0, 3000, 50, " m"), + Number("gfx.reflections.range_vehicles", 250, Advanced, "IniSectionRanges", 0, 2000, 50, " m"), + Toggle("rendercab", true, Advanced, "IniSectionRanges"), + Number("gfx.postfx.motionblur.shutter", 0.01, Advanced, "IniSectionRanges", 0.001, 0.1, 0.001, " s"), + Number("python.fpslimit", 100, Advanced, "IniSectionRanges", 5, 200, 5, " FPS"), + Toggle("python.vsync", true, Advanced, "IniSectionRanges"), + Toggle("python.displaywindows", false, Advanced, "IniSectionRanges"), + Toggle("newaircouplers", true, Advanced, "IniSectionRanges"), - Toggle("showsystemconsole", false, Advanced, "IniSectionConsole"), + // What makes the simulator faster at no cost to the picture. Where the simulator's own default is the + // slower one, the starter writes its own: the standard mode keeps them all on. + Toggle("gfx.gpucull", true, Advanced, PerformanceSection, writes: true), + Toggle("gfx.gpucull.occlusion", true, Advanced, PerformanceSection), + Toggle("gfx.depthprepass", true, Advanced, PerformanceSection), + Toggle("gfx.textures.streaming", true, Advanced, PerformanceSection, writes: true), + Number("gfx.textures.releasedistance", 0, Advanced, PerformanceSection, 0, 10, 0.5, "×", zeroIsOff: true), + Toggle("sound.asyncload", true, Advanced, PerformanceSection, writes: true), + Toggle("physics.sleepheld", true, Advanced, PerformanceSection, writes: true), + Toggle("physics.roadlod", true, Advanced, PerformanceSection, writes: true), + Toggle("performance.multithreading", true, Advanced, PerformanceSection), + Toggle("file.binary.terrain", true, Advanced, PerformanceSection), + Toggle("gfx.smoke.gpu", true, Advanced, PerformanceSection), + Toggle("gfx.weather.occlusion", true, Advanced, PerformanceSection), + Toggle("gfx.clouds.interleave", true, Advanced, PerformanceSection), + Toggle("screens.gpupost", true, Advanced, PerformanceSection), + Number("screens.cabframes", 4, Advanced, PerformanceSection, 1, 60, 1), + Number("screens.externalframes", 30, Advanced, PerformanceSection, 1, 120, 1), + + Number("sound.maxsources", 30, Advanced, "IniSectionAudio", 8, 256, 8), + + Toggle("loadtraction", true, Advanced, "IniSectionPhysics"), + Toggle("rollfix", true, Advanced, "IniSectionPhysics"), + Number("shakefactor", 1, Advanced, "IniSectionPhysics", 0, 3, 0.1, "×", repeat: 3), + Toggle("map.manualswitchcontrol", false, Advanced, "IniSectionPhysics"), + Number("map.highlightdistance", 3000, Advanced, "IniSectionPhysics", 0, 10000, 250, " m", zeroIsOff: true), + + Toggle("loadinglog", false, Advanced, LogsSection), + Toggle("showsystemconsole", false, Advanced, LogsSection), + Number("debug.perflog", 0, Advanced, LogsSection, 0, 60, 1, " s", zeroIsOff: true), + Toggle("crashdump.full", false, Advanced, LogsSection), }; } diff --git a/StarterNG/Domain/Settings/SimulatorSettings.cs b/StarterNG/Domain/Settings/SimulatorSettings.cs index b29c218..49b6cc3 100644 --- a/StarterNG/Domain/Settings/SimulatorSettings.cs +++ b/StarterNG/Domain/Settings/SimulatorSettings.cs @@ -8,8 +8,13 @@ public enum ConsistReadyOverride { Scenery = 0, AlwaysCold = 1, AlwaysReady = 2 public enum ExeProblem { None, NotFound, NotExecutable, WrongPlatform, NotAProgram } -// multisampling: 0 off, then 2, 4 and 8 samples. -public enum AntiAliasingMode { Off, Msaa2, Msaa4, Msaa8 } +// gfx.antialiasing (and the older multisampling, 0 off, then 2, 4 and 8 samples). Dlss and Dlaa are the Vulkan +// renderer's only, on an NVIDIA RTX card with a build that has DLSS; the simulator falls back to TAA elsewhere. +public enum AntiAliasingMode { Off, Msaa2, Msaa4, Msaa8, Msaa16, Taa, Dlss, Dlaa } + +// gfxrenderer: the Vulkan 1.4 renderer, which the simulator leaves for the OpenGL one where it cannot run, or the +// OpenGL 4.6 one ("default"). +public enum GraphicsBackend { Vulkan, OpenGL } public sealed class SimulatorSettings { @@ -52,16 +57,19 @@ public sealed class SimulatorSettings public bool VirtualShunting = true; public bool LogMissingVehicleFiles; - public int RenderEngine; + /// The renderer: Vulkan unless the advanced mode chose OpenGL. + public GraphicsBackend Backend = GraphicsBackend.Vulkan; /// - /// The file's gfxrenderer word where it is none the starter knows - vulkan, written in by - /// hand for a build that has it: written back as it is until another renderer is chosen. + /// The file's gfxrenderer word where it is none the starter knows - "null" of the test runs, or one of a + /// newer simulator: written back as it is until another renderer is chosen. /// public string? RendererWord; public int Width = 1280; public int Height = 720; + + /// gfx.buffer.percent, in percent: the part of the window the picture is drawn at, then stretched to it. public int BufferScalePercent = 100; public int MaxTextureSize = 4096; public int MaxCabTextureSize = 4096; @@ -78,19 +86,13 @@ public sealed class SimulatorSettings public bool EnvMap = true; public bool RenderShadows = true; - // Only the legacy renderer, or only Windows builds, read these. - public bool UseVbo = true; - public bool RenderAngleVulkan; - public bool UseGLES; - public int CabShadowsRange; - /// Updates of the reflections a second; the simulator's own is one in five minutes. public double ReflectionsFramerate = 1 / 300.0; public int ShadowMapResolution = 2048; /// The third number of shadowtune; the second and fourth go unread. public int ShadowProjectionRange = 250; public int ShadowRankCutoff = 3; - public int ReflectionsFidelity; + public int ReflectionsFidelity = 2; public int FieldOfView = 45; public bool PythonScreens = true; public bool PythonThreadedUpload = true; @@ -165,6 +167,16 @@ public sealed class SimulatorSettings /// public bool MovedToStandard; + /// + /// starter.settings.revision: the layout of the settings this file was last brought to. Below + /// , a player in the standard mode is moved to it once: the renderer and what + /// only the developer tab shows at the starter's own values, the fast ones. + /// + public int Revision; + + /// The layout of this starter: the standard mode on Vulkan, the rest in the developer tab. + public const int CurrentRevision = 2; + /// Warn at start when the processor cannot run the official simulator builds. public bool CpuNotice = true; @@ -197,26 +209,20 @@ public sealed class SimulatorSettings } /// - /// The gfxrenderer words the starter offers. "default" is the full renderer, the one to use - /// wherever it runs; the other two draw with the legacy one. The experimental renderer is - /// not offered: the simulator a player has is built without it. - /// - public static readonly string[] RenderEngines = { "default", "legacy", "simple" }; - - /// - /// The words the starter places among : those application.cpp on - /// master knows, but "experimental". Any other word is kept as . + /// The gfxrenderer words the simulator knows (utilities/Globals.cpp): the Vulkan ones, the OpenGL ones and + /// those of the renderers it no longer has, which it reads as OpenGL. Any other word is kept as + /// . /// public static bool KnownRendererWord(string? word) => - word?.Trim().ToLowerInvariant() is "default" or "legacy" or "simple" or "simpleshader" or "off"; + word?.Trim().ToLowerInvariant() is "vulkan" or "vulkan14" or "default" or "full" or "opengl" or "gl46" + or "legacy" or "simple" or "simpleshader" or "off" or "experimental"; - /// Where stands among , as the simulator reads it. - public static int RenderEngineOf(string word) => word.Trim().ToLowerInvariant() switch - { - "legacy" or "simpleshader" or "off" => 1, - "simple" => 2, - _ => 0 - }; + /// The renderer picks, as the simulator reads it. + public static GraphicsBackend BackendOf(string word) => + word.Trim().ToLowerInvariant() is "vulkan" or "vulkan14" ? GraphicsBackend.Vulkan : GraphicsBackend.OpenGL; + + /// The gfxrenderer word of . + public static string WordOf(GraphicsBackend backend) => backend == GraphicsBackend.Vulkan ? "vulkan" : "default"; /// /// The least shadow range the simulator keeps for a map size: a map above @@ -225,14 +231,13 @@ public sealed class SimulatorSettings public static int ShadowRangeFloor(int mapSize) => mapSize <= 2048 ? 75 : 75 * mapSize / 2048; /// - /// How far shadows actually reach. The full renderer's cascades stretch with a - /// map above 2048 px (opengl33renderer.cpp), on top of the floor; the legacy - /// one draws a single map out to the range itself. + /// How far shadows actually reach: the cascades stretch with a map above 2048 px + /// (rendering/common/shadowfit.cpp), on top of the floor. /// - public static int ShadowReach(int range, int mapSize, bool legacyRenderer) + public static int ShadowReach(int range, int mapSize) { int reach = Math.Max(range, ShadowRangeFloor(mapSize)); - return legacyRenderer || mapSize <= 2048 ? reach : reach * (mapSize / 2048); + return mapSize <= 2048 ? reach : reach * (mapSize / 2048); } /// diff --git a/StarterNG/Domain/Settings/SliderRanges.cs b/StarterNG/Domain/Settings/SliderRanges.cs index 2c18853..f4d9aba 100644 --- a/StarterNG/Domain/Settings/SliderRanges.cs +++ b/StarterNG/Domain/Settings/SliderRanges.cs @@ -16,15 +16,15 @@ public static class SliderRanges /// dynamiclights: 1 to 7. public const int MinDynamicLights = 1; - /// gfx.reflections.framerate, in updates a second. - public static readonly double[] ReflectionUpdates = { 1, 3, 10, 25, 60 }; + /// + /// gfx.reflections.framerate, in updates a second: from the simulator's own once in five minutes, which the + /// levels below Very high keep, up to every frame. + /// + public static readonly double[] ReflectionUpdates = { 1 / 300.0, 1 / 60.0, 0.2, 1, 3, 10, 25, 60 }; /// gfx.drawrange.factor.max: normal, high and very high. public static readonly double[] DrawRangeFactors = { 1, 2, 3 }; - /// gfx.shadows.cab.range, in metres: off, then 10 to 100. - public static readonly double[] CabShadowRanges = { 0, 10, 20, 30, 50, 100 }; - /// fpslimit: none, or up to 240, where the fastest usual monitors run. public static readonly double[] FrameRateLimits = { 0, 20, 25, 30, 40, 45, 50, 60, 72, 75, 90, 100, 120, 144, 165, 180, 200, 240 }; diff --git a/StarterNG/Infrastructure/Settings/SettingsSerializer.cs b/StarterNG/Infrastructure/Settings/SettingsSerializer.cs index 5939b33..4097a34 100644 --- a/StarterNG/Infrastructure/Settings/SettingsSerializer.cs +++ b/StarterNG/Infrastructure/Settings/SettingsSerializer.cs @@ -11,15 +11,6 @@ namespace StarterNG.Infrastructure.Settings; public sealed class SettingsSerializer { - private readonly Func? _monitorSize; - - /// - /// The size of the monitor a full screen of the simulator goes to, by what fullscreenmonitor - /// says; null where it is not known. - /// - public SettingsSerializer(Func? monitorSize = null) => - _monitorSize = monitorSize; - /// /// An ini of before the tapes of the trains, its recording turned on ("blackbox yes", with the physics log of every /// vehicle, hundreds of files on a big scenery): moved to the tapes of the trains, the log of every vehicle off. @@ -91,8 +82,9 @@ public sealed class SettingsSerializer s.VirtualShunting = c.GetBool("ai.trainman", true); s.LogMissingVehicleFiles = c.GetBool("starter.logmissingvehicles", false); - string renderer = c.GetString("gfxrenderer", "default").Trim(); - s.RenderEngine = SimulatorSettings.RenderEngineOf(renderer); + // Vulkan unless the file says otherwise: the simulator's own is OpenGL, so the starter always writes it. + string renderer = c.GetString("gfxrenderer", SimulatorSettings.WordOf(GraphicsBackend.Vulkan)).Trim(); + s.Backend = SimulatorSettings.BackendOf(renderer); s.RendererWord = renderer.Length > 0 && !SimulatorSettings.KnownRendererWord(renderer) ? renderer : null; s.Width = c.GetInt("width", 1280); s.Height = c.GetInt("height", 720); @@ -110,8 +102,7 @@ public sealed class SettingsSerializer s.MotionBlur = c.GetBool("gfx.postfx.motionblur.enabled", true); s.ExtraEffects = c.GetBool("gfx.extraeffects", true); s.EnvMap = c.GetBool("gfx.envmap.enabled", true); - s.UseVbo = c.GetBool("usevbo", true); - s.RenderShadows = c.GetBool("shadows", true); + s.RenderShadows = c.GetBool("gfx.shadowmap.enabled", true); // A negative rate counts as its size; none at all, as never. double reflections = Math.Abs(c.GetDouble("gfx.reflections.framerate", 1 / 300.0)); s.ReflectionsFramerate = reflections > 0 ? reflections : 1 / 300.0; @@ -123,9 +114,9 @@ public sealed class SettingsSerializer if (shadowTune.Length >= 2) s.ShadowTuneUnused[0] = shadowTune[1]; if (shadowTune.Length >= 4) s.ShadowTuneUnused[1] = shadowTune[3]; - s.CabShadowsRange = (int)Math.Round(c.GetDouble("gfx.shadows.cab.range", 0)); s.ShadowRankCutoff = c.GetInt("gfx.shadow.rank.cutoff", 3); - s.ReflectionsFidelity = Clamp(c.GetInt("gfx.reflections.fidelity", 0), 0, 2); + // the simulator's own: track sections, models and vehicles (Globals.h) + s.ReflectionsFidelity = Clamp(c.GetInt("gfx.reflections.fidelity", 2), 0, 2); s.FieldOfView = Clamp((int)Math.Round(c.GetDouble("fieldofview", 45)), 10, 75); s.PythonScreens = c.GetBool("python.enabled", true); s.PythonThreadedUpload = c.GetBool("python.threadedupload", true); @@ -136,7 +127,6 @@ public sealed class SettingsSerializer s.ShadowAngleLimit = c.GetDouble("gfx.shadow.angle.min", 0.2); s.FullscreenWindowed = c.GetBool("fullscreenwindowed", false); s.FullscreenMonitor = LegacyText.Utf8From1250(c.GetString("fullscreenmonitor", "").Trim()); - s.RenderAngleVulkan = string.Equals(c.GetString("gfx.angleplatform", ""), "vulkan", StringComparison.OrdinalIgnoreCase); s.SplineFidelity = Clamp(c.GetInt("splinefidelity", 1), 1, 4); s.FullPhysics = c.GetBool("fullphysics", true); @@ -172,7 +162,6 @@ public sealed class SettingsSerializer s.CompressTextures = c.GetBool("compresstex", true); s.ScaleSpeculars = c.GetBool("scalespeculars", true); - s.UseGLES = c.GetBool("gfx.usegles", false); s.ShaderGamma = c.GetBool("gfx.shadergamma", false); s.ScreenMipmaps = c.GetBool("python.mipmaps", true); s.ExtendedModelConversion = c.GetInt("convertmodels", 0) != 0; @@ -186,6 +175,7 @@ public sealed class SettingsSerializer s.AutoExpandSceneryTree = c.GetBool("starter.expandtree", false); s.AdvancedSettings = c.GetBool("starter.settings.advanced", false); s.MovedToStandard = c.GetBool("starter.settings.standard", false); + s.Revision = c.GetInt("starter.settings.revision", 0); s.CpuNotice = c.GetBool("starter.cpunotice", true); s.Gpu = string.Equals(c.GetString("starter.gpu", "discrete"), "system", StringComparison.OrdinalIgnoreCase) ? GpuPreference.System @@ -209,6 +199,9 @@ public sealed class SettingsSerializer foreach (var key in SimulatorKeys.All) if (c.Has(key.Key)) s.Extra[key.Key] = c.GetRaw(key.Key) ?? string.Empty; + // the faster choice the simulator's own default is not: written whether or not the file had it + else if (key.Writes) + s.Extra[key.Key] = key.Default; GraphicsRules.Normalize(s); } @@ -227,15 +220,29 @@ public sealed class SettingsSerializer public static readonly string[] RepeatableKeys = { "network.server", "python.viewport", "extraviewport", "test.vehicle" }; /// Keys written only when they say something, besides those of . - public static readonly string[] OptionalKeys = { "fpslimit", "gfx.angleplatform", "fullscreenmonitor" }; + public static readonly string[] OptionalKeys = { "fpslimit", "fullscreenmonitor" }; - /// Keys no simulator reads any more, taken out of the file on a save. + /// + /// Keys the simulator no longer goes by, taken out of the file on a save: those of the renderers it has no more, + /// which it logs as unsupported (usevbo, gfx.usegles, gfx.angleplatform, the frame buffer's size in pixels in + /// place of gfx.buffer.percent), those it reads and does nothing with, and the starter's own of before. + /// public static readonly string[] ObsoleteKeys = { "gfx.postfx.tonemapping", "starter.developertools", - // The keys of the OpenGL 4.6 and Vulkan renderers (gfx.vulkan.device, gfx.raytracing...) are not here: - // written in by hand for a build that has them, they stay as the file has them. + "usevbo", + "gfx.usegles", + "gfx.angleplatform", + "gfx.framebuffer.width", + "gfx.framebuffer.height", + "starter.bufferscale", + "shadows", + "gfx.shadows.cab.range", + "smoothtraction", + "skyenabled", + "hideconsole", + "slowmotion", }; /// @@ -289,18 +296,18 @@ public sealed class SettingsSerializer c.SetBool("ai.trainman", s.VirtualShunting); c.SetBool("starter.logmissingvehicles", s.LogMissingVehicleFiles); - c.Set("gfxrenderer", s.RendererWord ?? SimulatorSettings.RenderEngines[Clamp(s.RenderEngine, 0, SimulatorSettings.RenderEngines.Length - 1)]); + c.Set("gfxrenderer", s.RendererWord ?? SimulatorSettings.WordOf(s.Backend)); c.SetInt("width", s.Width); c.SetInt("height", s.Height); - c.SetInt("starter.bufferscale", s.BufferScalePercent); - // The simulator draws into a buffer of this size and stretches it to the window. - var (bufferWidth, bufferHeight) = FramebufferSize(s); - c.SetInt("gfx.framebuffer.width", bufferWidth); - c.SetInt("gfx.framebuffer.height", bufferHeight); + // The simulator draws at this part of the window and stretches it to the window. + c.SetDouble("gfx.buffer.percent", s.BufferScalePercent / 100.0); c.SetInt("maxtexturesize", s.MaxTextureSize); c.SetInt("maxcabtexturesize", s.MaxCabTextureSize); c.SetDouble("anisotropicfiltering", s.TextureFiltering); + // The older key for the simulators before gfx.antialiasing; of the two, the simulator heeds the one further + // down, which SettingsStore keeps gfx.antialiasing. c.SetInt("multisampling", MultisamplingLevel(s.AntiAliasing)); + c.Set("gfx.antialiasing", AntiAliasingWord(s.AntiAliasing)); c.SetInt("dynamiclights", s.DynamicLights); c.SetDouble("gfx.drawrange.factor.max", s.DrawRangeFactor); c.SetBool("vsync", s.VSync); @@ -310,14 +317,11 @@ public sealed class SettingsSerializer c.SetBool("gfx.postfx.motionblur.enabled", s.MotionBlur); c.SetBool("gfx.extraeffects", s.ExtraEffects); c.SetBool("gfx.envmap.enabled", s.EnvMap); - c.SetBool("usevbo", s.UseVbo); - c.SetBool("shadows", s.RenderShadows); c.SetBool("gfx.shadowmap.enabled", s.RenderShadows); c.Set("gfx.reflections.framerate", s.ReflectionsFramerate.ToString("0.######", CultureInfo.InvariantCulture)); c.Set("shadowtune", $"{s.ShadowMapResolution} {s.ShadowTuneUnused[0]} " + $"{s.ShadowProjectionRange} {s.ShadowTuneUnused[1]}"); - c.SetInt("gfx.shadows.cab.range", s.CabShadowsRange); c.SetInt("gfx.shadow.rank.cutoff", s.ShadowRankCutoff); c.SetInt("gfx.reflections.fidelity", s.ReflectionsFidelity); c.SetInt("fieldofview", s.FieldOfView); @@ -329,7 +333,6 @@ public sealed class SettingsSerializer // The simulator compares the word with GLFW's name of the monitor, which is UTF-8. if (!string.IsNullOrWhiteSpace(s.FullscreenMonitor)) c.Set("fullscreenmonitor", LegacyText.Utf8As1250(s.FullscreenMonitor.Trim())); - if (s.RenderAngleVulkan) c.Set("gfx.angleplatform", "vulkan"); c.SetInt("splinefidelity", s.SplineFidelity); c.SetBool("fullphysics", s.FullPhysics); @@ -363,7 +366,6 @@ public sealed class SettingsSerializer c.SetBool("compresstex", s.CompressTextures); c.SetBool("scalespeculars", s.ScaleSpeculars); - c.SetBool("gfx.usegles", s.UseGLES); c.SetBool("gfx.shadergamma", s.ShaderGamma); c.SetBool("python.mipmaps", s.ScreenMipmaps); c.Set("convertmodels", s.ExtendedModelConversion ? "143" : "0"); @@ -377,6 +379,7 @@ public sealed class SettingsSerializer c.SetBool("starter.expandtree", s.AutoExpandSceneryTree); c.SetBool("starter.settings.advanced", s.AdvancedSettings); c.SetBool("starter.settings.standard", s.MovedToStandard); + c.SetInt("starter.settings.revision", s.Revision); c.SetBool("starter.cpunotice", s.CpuNotice); c.Set("starter.gpu", s.Gpu == GpuPreference.System ? "system" : "discrete"); c.SetInt("starter.batterydefault", (int)s.ReadyOverride); @@ -395,49 +398,33 @@ public sealed class SettingsSerializer c.Set(key.Key, value.Trim()); } - /// The keys of the frame buffer's size. - public static readonly string[] FramebufferKeys = { "gfx.framebuffer.width", "gfx.framebuffer.height" }; - - /// What the simulator takes for "as large as the window" (opengl33renderer.cpp), its own default. - public const int FramebufferOfWindow = -1; - /// - /// The frame buffer of : its part of the window. Borderless, the window - /// is the monitor whatever width and height say (application.cpp), so the buffer is the - /// window's own, or its part of the monitor's size where that is known. - /// - private (int Width, int Height) FramebufferSize(SimulatorSettings s) - { - if (!s.FullscreenWindowed) - return (Part(s.Width, s.BufferScalePercent), Part(s.Height, s.BufferScalePercent)); - if (s.BufferScalePercent < 100 && - _monitorSize?.Invoke(s.FullscreenMonitor.Trim()) is { Width: > 0, Height: > 0 } monitor) - return (Part(monitor.Width, s.BufferScalePercent), Part(monitor.Height, s.BufferScalePercent)); - return (FramebufferOfWindow, FramebufferOfWindow); - } - - private static int Part(int size, int percent) => (int)Math.Round(size * percent / 100.0); - - /// - /// with the keys that say the same setting along with them: the - /// starter's own percent goes wherever the frame buffer's size does, or it would stand - /// when the size is put back. + /// with the keys that say the same setting along with them: the anti-aliasing is + /// written in two keys, the older for the simulators before the newer one. /// public static IReadOnlyCollection WithCompanions(IReadOnlyCollection keys) { - if (!keys.Intersect(FramebufferKeys, StringComparer.OrdinalIgnoreCase).Any()) + if (!keys.Intersect(GraphicsGroup.AntiAliasingKeys, StringComparer.OrdinalIgnoreCase).Any()) return keys; - var all = new HashSet(keys, StringComparer.OrdinalIgnoreCase) { "starter.bufferscale" }; - all.UnionWith(FramebufferKeys); + var all = new HashSet(keys, StringComparer.OrdinalIgnoreCase); + all.UnionWith(GraphicsGroup.AntiAliasingKeys); return all; } private static int ReadBufferScale(ConfigFile c) => Clamp(BufferScaleIn(c), 25, GraphicsRules.MaxBufferScale); - // The starter's own percent, or the framebuffer the file sets against its window. + /// + /// The render scale in percent: gfx.buffer.percent as the simulator reads it (a fraction, or above 4 a percent), + /// else what a starter of before left - its own percent, or the frame buffer the file set against its window. + /// private static int BufferScaleIn(ConfigFile c) { + if (c.Has("gfx.buffer.percent")) + { + double part = c.GetDouble("gfx.buffer.percent", 1); + return (int)Math.Round(part > 4 ? part : part * 100); + } if (c.Has("starter.bufferscale")) return c.GetInt("starter.bufferscale", 100); int width = c.GetInt("width", 0); @@ -458,16 +445,53 @@ public sealed class SettingsSerializer if (shadowTune.Length >= 3 && ParseDouble(shadowTune[2], 0) > GraphicsRules.MaxShadowRange) keys.Add("shadowtune"); if (BufferScaleIn(c) > GraphicsRules.MaxBufferScale) - keys.UnionWith(new[] { "starter.bufferscale", "gfx.framebuffer.width", "gfx.framebuffer.height" }); + keys.Add("gfx.buffer.percent"); return keys; } - private static AntiAliasingMode ReadAntiAliasing(ConfigFile c) => c.GetInt("multisampling", 2) switch + /// + /// The anti-aliasing as the simulator reads it: of gfx.antialiasing and the older multisampling, the one further + /// down the file, and with neither its own MSAA x4. + /// + private static AntiAliasingMode ReadAntiAliasing(ConfigFile c) { - <= 0 => AntiAliasingMode.Off, - 1 => AntiAliasingMode.Msaa2, - 2 => AntiAliasingMode.Msaa4, - _ => AntiAliasingMode.Msaa8 + if (c.Has("gfx.antialiasing") && c.LineOf("gfx.antialiasing") > c.LineOf("multisampling") && + AntiAliasingOfWord(c.GetString("gfx.antialiasing", "")) is { } mode) + return mode; + return c.GetInt("multisampling", 2) switch + { + <= 0 => AntiAliasingMode.Off, + 1 => AntiAliasingMode.Msaa2, + 2 => AntiAliasingMode.Msaa4, + 3 => AntiAliasingMode.Msaa8, + _ => AntiAliasingMode.Msaa16 + }; + } + + /// The mode of a gfx.antialiasing word; null for one the simulator does not know. + private static AntiAliasingMode? AntiAliasingOfWord(string word) => word.Trim().ToLowerInvariant() switch + { + "off" or "no" or "none" or "0" => AntiAliasingMode.Off, + "msaax2" => AntiAliasingMode.Msaa2, + "msaax4" => AntiAliasingMode.Msaa4, + "msaax8" => AntiAliasingMode.Msaa8, + "msaax16" => AntiAliasingMode.Msaa16, + "taa" => AntiAliasingMode.Taa, + "dlss" => AntiAliasingMode.Dlss, + "dlaa" => AntiAliasingMode.Dlaa, + _ => null + }; + + public static string AntiAliasingWord(AntiAliasingMode mode) => mode switch + { + AntiAliasingMode.Msaa2 => "msaax2", + AntiAliasingMode.Msaa4 => "msaax4", + AntiAliasingMode.Msaa8 => "msaax8", + AntiAliasingMode.Msaa16 => "msaax16", + AntiAliasingMode.Taa => "taa", + AntiAliasingMode.Dlss => "dlss", + AntiAliasingMode.Dlaa => "dlaa", + _ => "off" }; private static int MultisamplingLevel(AntiAliasingMode mode) => mode switch @@ -475,6 +499,7 @@ public sealed class SettingsSerializer AntiAliasingMode.Msaa2 => 1, AntiAliasingMode.Msaa4 => 2, AntiAliasingMode.Msaa8 => 3, + AntiAliasingMode.Msaa16 => 4, _ => 0 }; diff --git a/StarterNG/Views/SettingTexts.cs b/StarterNG/Views/SettingTexts.cs index 3a730fe..7017c2c 100644 --- a/StarterNG/Views/SettingTexts.cs +++ b/StarterNG/Views/SettingTexts.cs @@ -23,14 +23,6 @@ internal static class SettingTexts public static string Anisotropy(double value) => "x" + value.ToString("0.#", CultureInfo.CurrentCulture); - public static string AntiAliasing(AntiAliasingMode mode) => mode switch - { - AntiAliasingMode.Msaa2 => "MSAA x2", - AntiAliasingMode.Msaa4 => "MSAA x4", - AntiAliasingMode.Msaa8 => "MSAA x8", - _ => App.Loc["MsaaNone"] - }; - public static string TwoDecimals(double value) => value.ToString("0.00", CultureInfo.CurrentCulture); /// A rate below one a second reads better as the time between updates. diff --git a/StarterNG/Views/Settings.Graphics.cs b/StarterNG/Views/Settings.Graphics.cs index fbe9065..54f3226 100644 --- a/StarterNG/Views/Settings.Graphics.cs +++ b/StarterNG/Views/Settings.Graphics.cs @@ -8,6 +8,7 @@ using Avalonia.Platform.Storage; using StarterNG.Application; using StarterNG.Domain.Settings; using StarterNG.Infrastructure; +using StarterNG.Infrastructure.Settings; namespace StarterNG.Views; @@ -37,12 +38,11 @@ public partial class Settings { if (_fileRendererItem is not null && ReferenceEquals(RenderEngineCb.SelectedItem, _fileRendererItem)) { - s.RenderEngine = 0; s.RendererWord = _fileRendererItem.Tag as string; } else { - s.RenderEngine = Math.Max(0, RenderEngineCb.SelectedIndex); + s.Backend = SelectedBackend(); s.RendererWord = null; } if (!ShowsFileValue(AntiAliasingCb)) @@ -78,7 +78,7 @@ public partial class Settings RenderEngineCb.SelectedItem = _fileRendererItem; } else - RenderEngineCb.SelectedIndex = s.RenderEngine; + SelectTag(RenderEngineCb, SimulatorSettings.WordOf(s.Backend)); } // ── How the simulator shows: full screen, borderless or in a window ────── @@ -252,19 +252,18 @@ public partial class Settings cb.SelectedIndex = index; } - private static string AntiAliasingTag(AntiAliasingMode mode) => mode switch - { - AntiAliasingMode.Msaa2 => "msaax2", - AntiAliasingMode.Msaa4 => "msaax4", - AntiAliasingMode.Msaa8 => "msaax8", - _ => "off" - }; + // The list's tags are the gfx.antialiasing words. + private static string AntiAliasingTag(AntiAliasingMode mode) => SettingsSerializer.AntiAliasingWord(mode); private static AntiAliasingMode AntiAliasingFromTag(string? tag) => tag switch { "msaax2" => AntiAliasingMode.Msaa2, "msaax4" => AntiAliasingMode.Msaa4, "msaax8" => AntiAliasingMode.Msaa8, + "msaax16" => AntiAliasingMode.Msaa16, + "taa" => AntiAliasingMode.Taa, + "dlss" => AntiAliasingMode.Dlss, + "dlaa" => AntiAliasingMode.Dlaa, _ => AntiAliasingMode.Off }; } diff --git a/StarterNG/Views/Settings.axaml b/StarterNG/Views/Settings.axaml index be974fa..27967b4 100644 --- a/StarterNG/Views/Settings.axaml +++ b/StarterNG/Views/Settings.axaml @@ -80,12 +80,11 @@ SelectionChanged="CategoryList_OnSelectionChanged"> - - + @@ -119,30 +118,34 @@ VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled"> + + - - - -