mirror of
https://github.com/MaSzyna-EU07/StarterNG.git
synced 2026-12-01 01:17:05 +01:00
cf3a6a4ca8
- The exe the start button runs is chosen in a section of its own in General, not only in the developer tab: several builds may sit side by side. - Ray-traced reflections have a row of their own among the details of the picture: off, or Low, Medium, High, Very high, a level being how far the rays reach (gfx.raytracing.range 250, 500, 1000, 2000 m). No level of detail turns them on or off, as they cost far more than anything a level sets; turned off, the reach stays for the next time. A reach no level has is shown as it is and kept. Only Vulkan draws them, so with OpenGL chosen the row is dimmed. - gfx.raytracing.range is in the developer tab too, and the list follows its row.
386 lines
14 KiB
C#
386 lines
14 KiB
C#
using StarterNG.Application;
|
|
using StarterNG.Domain.Settings;
|
|
using StarterNG.Tests.Fakes;
|
|
|
|
namespace StarterNG.Tests;
|
|
|
|
public class GraphicsPresetTests
|
|
{
|
|
private static SimulatorSettings Defaults()
|
|
{
|
|
var installation = new TestInstallation();
|
|
installation.SettingsStore.Load();
|
|
return installation.SettingsStore.Settings;
|
|
}
|
|
|
|
private static SimulatorSettings At(GraphicsPreset preset)
|
|
{
|
|
var settings = Defaults().Copy();
|
|
preset.ApplyTo(settings);
|
|
return settings;
|
|
}
|
|
|
|
private static SimulatorSettings AtHigh() => At(GraphicsPreset.High);
|
|
|
|
/// <summary>The keys two renderings give different values, a key one leaves out at its default.</summary>
|
|
private static IEnumerable<string> Differing(IReadOnlyDictionary<string, string> one, IReadOnlyDictionary<string, string> other)
|
|
{
|
|
string? Value(IReadOnlyDictionary<string, string> 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 A_level_sets_no_key_but_those_it_names()
|
|
{
|
|
var store = new TestInstallation().SettingsStore;
|
|
var own = store.Render(Defaults());
|
|
foreach (var preset in GraphicsPreset.All)
|
|
Assert.Empty(Differing(own, store.Render(At(preset))).Except(GraphicsPreset.AllKeys));
|
|
}
|
|
|
|
[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(inGroups.Distinct(), inGroups);
|
|
Assert.Empty(GraphicsPreset.All.SelectMany(preset => preset.Keys.Keys).Except(inGroups));
|
|
}
|
|
|
|
// ── The scale ────────────────────────────────────────────────────────────
|
|
|
|
private static void Climbs(Func<GraphicsPreset, double> value)
|
|
{
|
|
var values = GraphicsPreset.All.Select(value).ToList();
|
|
Assert.Equal(values.OrderBy(v => v), values);
|
|
}
|
|
|
|
[Fact]
|
|
public void Every_part_of_the_picture_gets_better_or_stays_from_level_to_level()
|
|
{
|
|
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);
|
|
|
|
foreach (string name in GraphicsPreset.Low.Keys.Keys)
|
|
{
|
|
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 Every_level_sets_the_same_keys()
|
|
{
|
|
foreach (var preset in GraphicsPreset.All)
|
|
Assert.Equal(GraphicsPreset.High.Keys.Keys.OrderBy(k => k), preset.Keys.Keys.OrderBy(k => k));
|
|
}
|
|
|
|
[Fact]
|
|
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;
|
|
store.Load();
|
|
|
|
store.StartAtHighWithoutOwnSettings();
|
|
|
|
Assert.Same(GraphicsPreset.High, GraphicsPreset.Matching(store.Settings));
|
|
Assert.False(store.LastSaveFailed);
|
|
|
|
var again = new TestInstallation(installation.Files).SettingsStore;
|
|
again.Load();
|
|
Assert.Same(GraphicsPreset.High, GraphicsPreset.Matching(again.Settings));
|
|
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]
|
|
public void A_player_with_settings_of_their_own_stays_as_they_are()
|
|
{
|
|
var installation = new TestInstallation();
|
|
var store = installation.SettingsStore;
|
|
store.Load();
|
|
GraphicsPreset.Low.ApplyTo(store.Settings);
|
|
store.Save();
|
|
|
|
var again = new TestInstallation(installation.Files).SettingsStore;
|
|
again.Load();
|
|
again.StartAtHighWithoutOwnSettings();
|
|
|
|
Assert.Same(GraphicsPreset.Low, GraphicsPreset.Matching(again.Settings));
|
|
Assert.False(again.Settings.MovedToStandard);
|
|
}
|
|
|
|
[Fact]
|
|
public void A_copy_of_the_file_is_kept_once_and_not_written_over()
|
|
{
|
|
var installation = new TestInstallation();
|
|
var store = installation.SettingsStore;
|
|
store.Load();
|
|
store.Settings.FieldOfView = 50;
|
|
store.Save();
|
|
string copy = store.SavePath + ".before-standard";
|
|
|
|
store.KeepCopy(".before-standard");
|
|
string first = installation.Files.ReadAllText(copy);
|
|
Assert.Equal(installation.Files.ReadAllText(store.SavePath), first);
|
|
|
|
store.Settings.FieldOfView = 60;
|
|
store.Save();
|
|
store.KeepCopy(".before-standard");
|
|
Assert.Equal(first, installation.Files.ReadAllText(copy));
|
|
}
|
|
|
|
// ── Ray tracing ──────────────────────────────────────────────────────────
|
|
|
|
[Theory]
|
|
[InlineData("no", "500", RayTracing.Off)]
|
|
[InlineData("no", "123", RayTracing.Off)]
|
|
[InlineData("yes", "250", 0)]
|
|
[InlineData("yes", "500", 1)]
|
|
[InlineData("yes", "1000", 2)]
|
|
[InlineData("yes", "2000", 3)]
|
|
public void Ray_tracing_is_off_or_at_the_level_of_its_reach(string enabled, string range, int level) =>
|
|
Assert.Equal(level, RayTracing.LevelOf(enabled, range));
|
|
|
|
[Fact]
|
|
public void Ray_tracing_at_a_reach_no_level_has_is_at_none()
|
|
{
|
|
Assert.Null(RayTracing.LevelOf("yes", "750"));
|
|
}
|
|
|
|
[Fact]
|
|
public void Ray_tracing_is_off_by_default_and_its_levels_reach_further_one_by_one()
|
|
{
|
|
Assert.Equal(RayTracing.Off, RayTracing.LevelOf(Defaults()));
|
|
var ranges = RayTracing.Levels.Select(level => level.Range).ToList();
|
|
Assert.Equal(ranges.OrderBy(r => r).Distinct(), ranges);
|
|
var key = SimulatorKeys.Named(RayTracing.RangeKey);
|
|
Assert.All(ranges, range => Assert.InRange(range, key.Minimum, key.Maximum));
|
|
}
|
|
|
|
[Fact]
|
|
public void Turned_off_ray_tracing_keeps_its_reach_for_the_next_time()
|
|
{
|
|
var settings = Defaults().Copy();
|
|
RayTracing.Apply(settings, 3);
|
|
RayTracing.Apply(settings, RayTracing.Off);
|
|
|
|
Assert.Equal("no", settings.Extra[RayTracing.Key]);
|
|
Assert.Equal("2000", settings.Extra[RayTracing.RangeKey]);
|
|
}
|
|
|
|
[Fact]
|
|
public void No_level_of_detail_turns_ray_tracing_on_or_off()
|
|
{
|
|
foreach (var preset in GraphicsPreset.All)
|
|
{
|
|
var settings = Defaults().Copy();
|
|
RayTracing.Apply(settings, 2);
|
|
preset.ApplyTo(settings);
|
|
Assert.Equal(2, RayTracing.LevelOf(settings));
|
|
Assert.Same(preset, GraphicsPreset.Matching(settings));
|
|
}
|
|
}
|
|
|
|
// ── A level for one part ─────────────────────────────────────────────────
|
|
|
|
private static GraphicsGroupLevels Groups() => new(new TestInstallation().SettingsStore);
|
|
|
|
[Fact]
|
|
public void One_part_moves_alone()
|
|
{
|
|
var groups = Groups();
|
|
var settings = AtHigh();
|
|
|
|
var moved = groups.Apply(GraphicsGroup.Shadows, GraphicsPreset.Low, settings);
|
|
|
|
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.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]);
|
|
Assert.Same(GraphicsPreset.High, levels[GraphicsGroup.Textures]);
|
|
Assert.Null(GraphicsPreset.Matching(moved));
|
|
}
|
|
|
|
[Fact]
|
|
public void Every_part_shows_the_level_the_whole_is_at()
|
|
{
|
|
foreach (var preset in GraphicsPreset.All)
|
|
Assert.All(Groups().LevelsOf(At(preset)).Values, level => Assert.Same(preset, level));
|
|
}
|
|
|
|
[Fact]
|
|
public void A_part_moved_by_hand_is_at_no_level_and_the_others_keep_theirs()
|
|
{
|
|
var settings = AtHigh();
|
|
settings.ReflectionsFidelity = 0;
|
|
|
|
var levels = Groups().LevelsOf(settings);
|
|
|
|
Assert.Null(levels[GraphicsGroup.Reflections]);
|
|
Assert.Same(GraphicsPreset.High, levels[GraphicsGroup.Shadows]);
|
|
}
|
|
|
|
[Fact]
|
|
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)
|
|
{
|
|
var settings = Defaults().Copy();
|
|
foreach (var group in GraphicsGroup.All)
|
|
settings = groups.Apply(group, level, settings);
|
|
settings.AntiAliasing = level.AntiAliasing;
|
|
|
|
Assert.Same(level, GraphicsPreset.Matching(settings));
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void Every_part_tells_every_level_from_the_others()
|
|
{
|
|
var groups = Groups();
|
|
foreach (var group in GraphicsGroup.All)
|
|
foreach (var level in GraphicsPreset.All)
|
|
Assert.Same(level, groups.LevelsOf(groups.Apply(group, level, Defaults()))[group]);
|
|
}
|
|
}
|