feat(A.5 T22.5): QualityPreset schema + tests (commit 1/2)
Add QualityPreset enum + QualitySettings readonly record struct with From(preset) table and WithEnvOverrides() env-var override layer. Four presets (Low/Medium/High/Ultra) drive NearRadius, FarRadius, MsaaSamples, AnisotropicLevel, AlphaToCoverage, MaxCompletionsPerFrame. Env vars (ACDREAM_NEAR_RADIUS, ACDREAM_FAR_RADIUS, ACDREAM_MSAA_SAMPLES, ACDREAM_ANISOTROPIC, ACDREAM_A2C, ACDREAM_MAX_COMPLETIONS_PER_FRAME) override individual preset fields for dev spot-testing. DisplaySettings gains a Quality: QualityPreset field (default High); SettingsStore persists/loads it under display."quality" as an enum name string with Enum.TryParse fallback. 12 new QualityPresetTests cover the preset table (radii, msaa, aniso, a2c, completions) and all six env-var override paths. 415 UI.Abstractions tests passing. Wiring into GameWindow / WbDrawDispatcher / TerrainAtlas follows in commit 2 of this task. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
c473feedb3
commit
afa4200107
5 changed files with 272 additions and 9 deletions
|
|
@ -0,0 +1,181 @@
|
|||
using AcDream.UI.Abstractions.Settings;
|
||||
using Xunit;
|
||||
|
||||
namespace AcDream.UI.Abstractions.Tests.Panels.Settings;
|
||||
|
||||
/// <summary>
|
||||
/// A.5 T22.5: <see cref="QualitySettings"/> preset table + env-var override
|
||||
/// coverage. Env-var tests clear their variables in <c>finally</c> blocks so
|
||||
/// parallel runners cannot bleed state between tests.
|
||||
/// </summary>
|
||||
public class QualityPresetTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData(QualityPreset.Low, 2, 5, 0)]
|
||||
[InlineData(QualityPreset.Medium, 3, 8, 2)]
|
||||
[InlineData(QualityPreset.High, 4, 12, 4)]
|
||||
[InlineData(QualityPreset.Ultra, 5, 15, 4)]
|
||||
public void From_Preset_ProducesExpectedRadiiAndMsaa(
|
||||
QualityPreset preset, int n1, int n2, int msaa)
|
||||
{
|
||||
var s = QualitySettings.From(preset);
|
||||
Assert.Equal(n1, s.NearRadius);
|
||||
Assert.Equal(n2, s.FarRadius);
|
||||
Assert.Equal(msaa, s.MsaaSamples);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(QualityPreset.Low, 4, false)]
|
||||
[InlineData(QualityPreset.Medium, 8, false)]
|
||||
[InlineData(QualityPreset.High, 16, true)]
|
||||
[InlineData(QualityPreset.Ultra, 16, true)]
|
||||
public void From_Preset_ProducesExpectedAnisoAndA2C(
|
||||
QualityPreset preset, int aniso, bool a2c)
|
||||
{
|
||||
var s = QualitySettings.From(preset);
|
||||
Assert.Equal(aniso, s.AnisotropicLevel);
|
||||
Assert.Equal(a2c, s.AlphaToCoverage);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(QualityPreset.Low, 2)]
|
||||
[InlineData(QualityPreset.Medium, 3)]
|
||||
[InlineData(QualityPreset.High, 4)]
|
||||
[InlineData(QualityPreset.Ultra, 6)]
|
||||
public void From_Preset_ProducesExpectedMaxCompletions(
|
||||
QualityPreset preset, int expected)
|
||||
{
|
||||
var s = QualitySettings.From(preset);
|
||||
Assert.Equal(expected, s.MaxCompletionsPerFrame);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EnvVar_NearRadius_OverridesPreset()
|
||||
{
|
||||
System.Environment.SetEnvironmentVariable("ACDREAM_NEAR_RADIUS", "2");
|
||||
try
|
||||
{
|
||||
var s = QualitySettings.From(QualityPreset.High); // High = NearRadius=4 normally
|
||||
var resolved = QualitySettings.WithEnvOverrides(s);
|
||||
Assert.Equal(2, resolved.NearRadius);
|
||||
Assert.Equal(12, resolved.FarRadius); // FarRadius unaffected
|
||||
}
|
||||
finally { System.Environment.SetEnvironmentVariable("ACDREAM_NEAR_RADIUS", null); }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EnvVar_FarRadius_OverridesPreset()
|
||||
{
|
||||
System.Environment.SetEnvironmentVariable("ACDREAM_FAR_RADIUS", "20");
|
||||
try
|
||||
{
|
||||
var s = QualitySettings.From(QualityPreset.High);
|
||||
var resolved = QualitySettings.WithEnvOverrides(s);
|
||||
Assert.Equal(4, resolved.NearRadius); // NearRadius unaffected
|
||||
Assert.Equal(20, resolved.FarRadius);
|
||||
}
|
||||
finally { System.Environment.SetEnvironmentVariable("ACDREAM_FAR_RADIUS", null); }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EnvVar_AlphaToCoverage_BooleanParsing()
|
||||
{
|
||||
// Ensure "0" and "false" disable; other values enable.
|
||||
System.Environment.SetEnvironmentVariable("ACDREAM_A2C", "0");
|
||||
try
|
||||
{
|
||||
var s = QualitySettings.From(QualityPreset.High); // High has A2C=true
|
||||
var resolved = QualitySettings.WithEnvOverrides(s);
|
||||
Assert.False(resolved.AlphaToCoverage);
|
||||
}
|
||||
finally { System.Environment.SetEnvironmentVariable("ACDREAM_A2C", null); }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EnvVar_AlphaToCoverage_FalseString_Disables()
|
||||
{
|
||||
System.Environment.SetEnvironmentVariable("ACDREAM_A2C", "false");
|
||||
try
|
||||
{
|
||||
var s = QualitySettings.From(QualityPreset.High);
|
||||
var resolved = QualitySettings.WithEnvOverrides(s);
|
||||
Assert.False(resolved.AlphaToCoverage);
|
||||
}
|
||||
finally { System.Environment.SetEnvironmentVariable("ACDREAM_A2C", null); }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EnvVar_AlphaToCoverage_NonZeroEnables()
|
||||
{
|
||||
System.Environment.SetEnvironmentVariable("ACDREAM_A2C", "1");
|
||||
try
|
||||
{
|
||||
var s = QualitySettings.From(QualityPreset.Low); // Low has A2C=false
|
||||
var resolved = QualitySettings.WithEnvOverrides(s);
|
||||
Assert.True(resolved.AlphaToCoverage);
|
||||
}
|
||||
finally { System.Environment.SetEnvironmentVariable("ACDREAM_A2C", null); }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EnvVar_Unset_LeavesPresetDefault()
|
||||
{
|
||||
// Ensure no env vars are set for this test's fields.
|
||||
System.Environment.SetEnvironmentVariable("ACDREAM_NEAR_RADIUS", null);
|
||||
System.Environment.SetEnvironmentVariable("ACDREAM_FAR_RADIUS", null);
|
||||
System.Environment.SetEnvironmentVariable("ACDREAM_A2C", null);
|
||||
|
||||
var s = QualitySettings.From(QualityPreset.High);
|
||||
var resolved = QualitySettings.WithEnvOverrides(s);
|
||||
Assert.Equal(s, resolved);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void From_UndefinedPreset_FallsBackToHigh()
|
||||
{
|
||||
var s = QualitySettings.From((QualityPreset)99);
|
||||
Assert.Equal(4, s.NearRadius); // High default
|
||||
Assert.Equal(12, s.FarRadius);
|
||||
Assert.Equal(4, s.MsaaSamples);
|
||||
Assert.True(s.AlphaToCoverage);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EnvVar_MaxCompletionsPerFrame_OverridesPreset()
|
||||
{
|
||||
System.Environment.SetEnvironmentVariable("ACDREAM_MAX_COMPLETIONS_PER_FRAME", "8");
|
||||
try
|
||||
{
|
||||
var s = QualitySettings.From(QualityPreset.High); // High = 4
|
||||
var resolved = QualitySettings.WithEnvOverrides(s);
|
||||
Assert.Equal(8, resolved.MaxCompletionsPerFrame);
|
||||
}
|
||||
finally { System.Environment.SetEnvironmentVariable("ACDREAM_MAX_COMPLETIONS_PER_FRAME", null); }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EnvVar_MsaaSamples_OverridesPreset()
|
||||
{
|
||||
System.Environment.SetEnvironmentVariable("ACDREAM_MSAA_SAMPLES", "8");
|
||||
try
|
||||
{
|
||||
var s = QualitySettings.From(QualityPreset.High); // High = 4
|
||||
var resolved = QualitySettings.WithEnvOverrides(s);
|
||||
Assert.Equal(8, resolved.MsaaSamples);
|
||||
}
|
||||
finally { System.Environment.SetEnvironmentVariable("ACDREAM_MSAA_SAMPLES", null); }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EnvVar_Anisotropic_OverridesPreset()
|
||||
{
|
||||
System.Environment.SetEnvironmentVariable("ACDREAM_ANISOTROPIC", "4");
|
||||
try
|
||||
{
|
||||
var s = QualitySettings.From(QualityPreset.High); // High = 16
|
||||
var resolved = QualitySettings.WithEnvOverrides(s);
|
||||
Assert.Equal(4, resolved.AnisotropicLevel);
|
||||
}
|
||||
finally { System.Environment.SetEnvironmentVariable("ACDREAM_ANISOTROPIC", null); }
|
||||
}
|
||||
}
|
||||
|
|
@ -44,7 +44,8 @@ public sealed class SettingsStoreTests : System.IDisposable
|
|||
VSync: false,
|
||||
FieldOfView: 100f,
|
||||
Gamma: 1.4f,
|
||||
ShowFps: true);
|
||||
ShowFps: true,
|
||||
Quality: AcDream.UI.Abstractions.Settings.QualityPreset.Ultra);
|
||||
|
||||
store.SaveDisplay(original);
|
||||
var loaded = store.LoadDisplay();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue