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
67
src/AcDream.UI.Abstractions/Settings/QualityPreset.cs
Normal file
67
src/AcDream.UI.Abstractions/Settings/QualityPreset.cs
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
namespace AcDream.UI.Abstractions.Settings;
|
||||
|
||||
/// <summary>
|
||||
/// A.5 T22.5: single user-facing quality knob that drives streaming radii,
|
||||
/// MSAA samples, anisotropic level, alpha-to-coverage, and max completions
|
||||
/// per frame in a single setting. Individual fields can still be overridden
|
||||
/// by env vars (see <see cref="QualitySettings.WithEnvOverrides"/>).
|
||||
/// </summary>
|
||||
public enum QualityPreset { Low, Medium, High, Ultra }
|
||||
|
||||
/// <summary>
|
||||
/// Resolved per-preset quality parameters. Constructed via
|
||||
/// <see cref="From(QualityPreset)"/> then optionally overridden with
|
||||
/// <see cref="WithEnvOverrides(QualitySettings)"/> before applying to the
|
||||
/// renderer and streaming controller.
|
||||
/// </summary>
|
||||
public readonly record struct QualitySettings(
|
||||
int NearRadius,
|
||||
int FarRadius,
|
||||
int MsaaSamples, // 0 = off, 2, 4, 8
|
||||
int AnisotropicLevel, // 1 = off, 4, 8, 16
|
||||
bool AlphaToCoverage,
|
||||
int MaxCompletionsPerFrame)
|
||||
{
|
||||
/// <summary>
|
||||
/// Return the default <see cref="QualitySettings"/> for <paramref name="preset"/>.
|
||||
/// Unknown enum values fall back to <see cref="QualityPreset.High"/>.
|
||||
/// </summary>
|
||||
public static QualitySettings From(QualityPreset preset) => preset switch
|
||||
{
|
||||
QualityPreset.Low => new(NearRadius: 2, FarRadius: 5, MsaaSamples: 0, AnisotropicLevel: 4, AlphaToCoverage: false, MaxCompletionsPerFrame: 2),
|
||||
QualityPreset.Medium => new(NearRadius: 3, FarRadius: 8, MsaaSamples: 2, AnisotropicLevel: 8, AlphaToCoverage: false, MaxCompletionsPerFrame: 3),
|
||||
QualityPreset.High => new(NearRadius: 4, FarRadius: 12, MsaaSamples: 4, AnisotropicLevel: 16, AlphaToCoverage: true, MaxCompletionsPerFrame: 4),
|
||||
QualityPreset.Ultra => new(NearRadius: 5, FarRadius: 15, MsaaSamples: 4, AnisotropicLevel: 16, AlphaToCoverage: true, MaxCompletionsPerFrame: 6),
|
||||
_ => From(QualityPreset.High),
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Apply env-var overrides to a preset's resolved settings. Per-field
|
||||
/// env vars beat the preset (so devs can spot-test a single dimension).
|
||||
/// Unset or empty env vars leave the preset default unchanged.
|
||||
/// </summary>
|
||||
public static QualitySettings WithEnvOverrides(QualitySettings baseSettings)
|
||||
{
|
||||
int nearRadius = TryParseEnvInt("ACDREAM_NEAR_RADIUS", baseSettings.NearRadius);
|
||||
int farRadius = TryParseEnvInt("ACDREAM_FAR_RADIUS", baseSettings.FarRadius);
|
||||
int msaa = TryParseEnvInt("ACDREAM_MSAA_SAMPLES", baseSettings.MsaaSamples);
|
||||
int aniso = TryParseEnvInt("ACDREAM_ANISOTROPIC", baseSettings.AnisotropicLevel);
|
||||
// Bool override: any non-empty value other than "0"/"false" enables A2C.
|
||||
// Empty / unset → keep preset default.
|
||||
var a2cEnv = System.Environment.GetEnvironmentVariable("ACDREAM_A2C");
|
||||
bool a2c = a2cEnv switch
|
||||
{
|
||||
null or "" => baseSettings.AlphaToCoverage,
|
||||
"0" or "false" or "False" or "FALSE" => false,
|
||||
_ => true,
|
||||
};
|
||||
int completions = TryParseEnvInt("ACDREAM_MAX_COMPLETIONS_PER_FRAME", baseSettings.MaxCompletionsPerFrame);
|
||||
return new QualitySettings(nearRadius, farRadius, msaa, aniso, a2c, completions);
|
||||
}
|
||||
|
||||
private static int TryParseEnvInt(string name, int defaultValue)
|
||||
{
|
||||
var s = System.Environment.GetEnvironmentVariable(name);
|
||||
return s is not null && int.TryParse(s, out var v) ? v : defaultValue;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue