mirror of
https://git.triforceproject.com/triforce/source
synced 2026-11-23 17:49:57 -04:00
Triforce v0.7.1
Crash fixes (a load crash from the virtual cores' escape, the upscaler-before-the-bloom crash, out of memory at a file's open), slow motion after a movie fixed, three save files with per-save achievements (ZakyPew), ten more achievements and their own menu group, N64 Classic, native ultrawide output (Kaefergeneral), the community AMD frame-time fixes, the helper threads' calm-scene tuner and benchmark test, update and Linux launcher fixes.
This commit is contained in:
@@ -18,7 +18,12 @@ public sealed partial class Backend
|
||||
void RegisterBench()
|
||||
{
|
||||
On("bench", _ => BenchAsk());
|
||||
OnAsync("bench.go", m => (string?)m["id"] == "go" ? RunBench(compare: false) : Task.CompletedTask);
|
||||
OnAsync("bench.go", m => (string?)m["id"] switch
|
||||
{
|
||||
"go" => RunBench(compare: false),
|
||||
"helpers" => RunBench(compare: false, helperTest: true), // ((Triforce) 11-22: with the helper-thread test)
|
||||
_ => Task.CompletedTask,
|
||||
});
|
||||
OnAsync("bench.compare", _ => RunBench(compare: true));
|
||||
On("benchstop", _ => { try { benchCts?.Cancel(); } catch { } });
|
||||
On("benchapply", _ => ApplyBench());
|
||||
@@ -49,11 +54,13 @@ public sealed partial class Backend
|
||||
"<p>The game opens full screen, loads your newest save by itself and flies through four places: Hyrule Field, " +
|
||||
"Castle Town Market, Kokiri Forest and Lake Hylia. Its own panel shows where it is and the frame rate.</p>" +
|
||||
"<p><b>About 2 minutes.</b> Leave the controls alone meanwhile. Esc in the game stops it.</p>" +
|
||||
"<p>Your saves are not touched, and your settings are put back as they were. Then this window shows what it found.</p>",
|
||||
"bench.go", new[] { ("no", "Not now", false), ("go", "Start", true) });
|
||||
"<p>Your saves are not touched, and your settings are put back as they were. Then this window shows what it found.</p>" +
|
||||
"<p><b>With the helper-thread test</b> it measures each place twice, with the replay helper threads off and on, and " +
|
||||
"says which your PC runs faster (about 1 minute more).</p>",
|
||||
"bench.go", new[] { ("no", "Not now", false), ("helpers", "With the helper-thread test", false), ("go", "Start", true) });
|
||||
}
|
||||
|
||||
async Task RunBench(bool compare)
|
||||
async Task RunBench(bool compare, bool helperTest = false)
|
||||
{
|
||||
var g = GameDir;
|
||||
if (g == null || benchCts != null) return;
|
||||
@@ -70,8 +77,9 @@ public sealed partial class Backend
|
||||
var t0 = DateTime.UtcNow;
|
||||
void Running(string line) => Send(new JsonObject
|
||||
{
|
||||
["t"] = "bench", ["phase"] = "run", ["pass"] = compare ? "Comparing with " + second!.Value.Item2 : "Finding your best settings",
|
||||
["frac"] = Math.Min(0.97, (DateTime.UtcNow - t0).TotalSeconds / 150), ["fps"] = null,
|
||||
["t"] = "bench", ["phase"] = "run",
|
||||
["pass"] = compare ? "Comparing with " + second!.Value.Item2 : helperTest ? "Finding your best settings · with the helper-thread test" : "Finding your best settings",
|
||||
["frac"] = Math.Min(0.97, (DateTime.UtcNow - t0).TotalSeconds / (helperTest ? 220 : 150)), ["fps"] = null,
|
||||
["place"] = new JsonObject { ["name"] = "Running in the game window", ["img"] = pic },
|
||||
["line"] = line + " · " + BuildClock.Span(DateTime.UtcNow - t0),
|
||||
});
|
||||
@@ -85,7 +93,7 @@ public sealed partial class Backend
|
||||
});
|
||||
try
|
||||
{
|
||||
var run = await bm.RunOnceAsync(g, second, progress, cts.Token);
|
||||
var run = await bm.RunOnceAsync(g, second, progress, cts.Token, helperTest);
|
||||
if (compare) { benchRun2 = run; benchSecond = second; }
|
||||
else { benchRun = run; benchRun2 = null; benchSecond = bm.SecondPass(g, BenchIni.Read(Path.Combine(g, GameOptionsSchema.FileName))); }
|
||||
benchLast = "Last run " + DateTime.Now.ToString("d MMM, HH:mm");
|
||||
@@ -113,8 +121,14 @@ public sealed partial class Backend
|
||||
if (g == null || benchRun == null) return;
|
||||
var now = BenchIni.Read(Path.Combine(g, GameOptionsSchema.FileName));
|
||||
var r1 = benchRun; var r2 = benchRun2;
|
||||
benchRecs = Benchmark.Recommend(now, r1.Scenes, r2?.Scenes, r2 != null ? benchSecond : null, Benchmark.DisplayHz());
|
||||
// ((Triforce) 11-22) after the helper-thread test the other rows are judged by the frame rates of the way it recommends
|
||||
var helpers = Benchmark.RecommendHelpers(now, r1.Scenes);
|
||||
var p1 = helpers == null ? r1.Scenes : Benchmark.AsRecommended(r1.Scenes, helpers.To);
|
||||
var recs0 = Benchmark.Recommend(now, p1, r2?.Scenes, r2 != null ? benchSecond : null, Benchmark.DisplayHz());
|
||||
if (helpers != null) recs0.Add(helpers);
|
||||
benchRecs = recs0;
|
||||
var use2 = r2 != null && benchRecs.Any(c => c.Key == Benchmark.KUpscaler && c.Changes);
|
||||
var tested = r2 == null && r1.Scenes.Any(s => s.Helpers != null); // (the helper-thread test's halves side by side)
|
||||
var places = new JsonArray();
|
||||
for (var i = 0; i < r1.Scenes.Count; i++)
|
||||
{
|
||||
@@ -126,6 +140,11 @@ public sealed partial class Backend
|
||||
["graph"] = Graph(a.FrameTimes),
|
||||
};
|
||||
if (b != null) { o["fps2"] = Math.Round(b.AverageFps); o["low2"] = Math.Round(b.OnePercentLow); o["graph2"] = Graph(b.FrameTimes); }
|
||||
else if (tested && a.Helpers is { } h)
|
||||
{
|
||||
o["fps"] = Math.Round(h.OffFps); o["low"] = Math.Round(h.OffLow); o["graph"] = Graph(h.OffTimes);
|
||||
o["fps2"] = Math.Round(h.OnFps); o["low2"] = Math.Round(h.OnLow); o["graph2"] = Graph(h.OnTimes);
|
||||
}
|
||||
places.Add(o);
|
||||
}
|
||||
var recs = new JsonArray();
|
||||
@@ -135,10 +154,12 @@ public sealed partial class Backend
|
||||
Send(new JsonObject
|
||||
{
|
||||
["t"] = "bench", ["phase"] = "done", ["places"] = places, ["recs"] = recs,
|
||||
["verdict"] = Benchmark.Summary(r1.Scenes, r2?.Scenes, r2 != null ? benchSecond?.name : null) + Benchmark.SkippedNote(r1.Skipped),
|
||||
["verdict"] = Benchmark.Summary(r1.Scenes, r2?.Scenes, r2 != null ? benchSecond?.name : null) + Benchmark.SkippedNote(r1.Skipped) +
|
||||
Benchmark.HelperNote(r1),
|
||||
["eb"] = "Benchmark finished · " + BuildClock.Span(r1.Took + (r2?.Took ?? TimeSpan.Zero)) + (gpu != null ? " · " + gpu : ""),
|
||||
["compare"] = r2 == null && benchSecond != null ? "Compare with " + benchSecond.Value.name : null,
|
||||
["second"] = r2 != null ? benchSecond?.name : null,
|
||||
["second"] = r2 != null ? benchSecond?.name : tested ? "Helpers on" : null,
|
||||
["first"] = tested ? "Helpers off" : r1.Scenes.Any(s => s.Helpers != null) ? "Your settings, helpers off" : null,
|
||||
["apply"] = benchRecs.Any(c => c.Changes),
|
||||
});
|
||||
}
|
||||
@@ -176,6 +197,8 @@ public sealed partial class Backend
|
||||
/// <summary>The menu's own words for the values the benchmark touches (Triforce.Logic.GameOptionsSchema).</summary>
|
||||
static string BenchLabel(string key, int v, IReadOnlyList<SettingChange> all, bool after = false)
|
||||
{
|
||||
if (key == Benchmark.KHelpers) // ((Triforce) 11-22: the Debug tab's row, not one of the schema's; gpu/vk/vk_menu.cpp tx_replay_threads)
|
||||
return v == Benchmark.HelpersOff ? "Off" : v is >= 1 and <= 7 ? $"Auto, {v + 1} threads" : "Automatic";
|
||||
if (GameOptionsSchema.ByKey(key) is not { } row) return GameOptionsSchema.Part(key)?.Label(v) ?? v.ToString(); // ((Triforce, options_version 8) a merged row's part: Steady frame rate, Frame generation)
|
||||
if (key == Benchmark.KResolution)
|
||||
{
|
||||
|
||||
@@ -113,10 +113,11 @@ public sealed partial class Backend
|
||||
|
||||
static string Capital(string s) => s.Length > 0 ? char.ToUpperInvariant(s[0]) + s.Substring(1) : s;
|
||||
|
||||
/// <summary>((Triforce) 11-20) The folder the game writes triforce_log.txt in: its program's (Game.FindExe: the game folder on
|
||||
/// Windows, bin/ under it on Linux with the launcher script). Null without a built game.</summary>
|
||||
/// <summary>((Triforce) 11-20) The folder the game writes triforce_log.txt in: the game folder itself. ((Triforce, 11-23) Not
|
||||
/// the folder of Game.FindExe's program: on Linux that is bin/, and the game writes its log beside image.bin, a folder up
|
||||
/// (host/hos_paths.h hos_game_path_a), so the row opened a bin/ with no log in it.) Null without a built game.</summary>
|
||||
string? GameLogFolder(string? game) =>
|
||||
game != null && new Game(ctx).FindExe(game) is { } exe ? Path.GetDirectoryName(exe) : null;
|
||||
game != null && new Game(ctx).FindExe(game) != null ? game : null;
|
||||
|
||||
string VersionsLine(string? game) =>
|
||||
"launcher " + BuildInfo.Version + " · tools " + (new Tools(ctx).InstalledVersion ?? "none") + " · game " + (game != null ? Game.BuiltVersion(game) ?? "unknown" : "not built");
|
||||
|
||||
@@ -30,6 +30,18 @@ public sealed record PlaceResult(string Place, double AverageFps, double OnePerc
|
||||
{
|
||||
public double Low01 { get; init; }
|
||||
public IReadOnlyList<double> FrameTimes { get; init; } = Array.Empty<double>();
|
||||
/// <summary>((Triforce) 11-22) the helper-thread test's two halves of this place (null: not tested)</summary>
|
||||
public HelperHalves? Helpers { get; init; }
|
||||
}
|
||||
|
||||
/// <summary>((Triforce) 11-22) A place measured twice in a row by the helper-thread test (host/hos_bench.c HOS_BENCH_HELPERS):
|
||||
/// the replay helper threads off and on, the tuner out of the way; OnFirst: the order (it turns from place to place).</summary>
|
||||
public sealed record HelperHalves(double OffFps, double OffLow, double OnFps, double OnLow, bool OnFirst)
|
||||
{
|
||||
public IReadOnlyList<double> OffTimes { get; init; } = Array.Empty<double>();
|
||||
public IReadOnlyList<double> OnTimes { get; init; } = Array.Empty<double>();
|
||||
/// <summary>"on" faster by more than the margin: +1; slower by more: -1; else 0 (too close to tell)</summary>
|
||||
public int Verdict => OnFps >= OffFps * Benchmark.HelperMargin ? 1 : OffFps >= OnFps * Benchmark.HelperMargin ? -1 : 0;
|
||||
}
|
||||
|
||||
/// <summary>One benchmark run as the game wrote it.</summary>
|
||||
@@ -37,6 +49,9 @@ public sealed record BenchRun(IReadOnlyList<PlaceResult> Scenes, string? Gpu, bo
|
||||
{
|
||||
/// <summary>((Triforce, 11-19) the places the game would not take Link to, left out (host/hos_bench.c skip_scene)</summary>
|
||||
public IReadOnlyList<string> Skipped { get; init; } = Array.Empty<string>();
|
||||
/// <summary>((Triforce) 11-22) the helper-thread test: null not asked for; 0 asked, but the game had no helper threads to
|
||||
/// test (a PC Automatic gives none); else the threads it tested</summary>
|
||||
public int? HelperThreads { get; init; }
|
||||
}
|
||||
|
||||
/// <summary>A setting the benchmark would change: its triforce_options.ini key, the menu's row name, the value now and the
|
||||
@@ -79,6 +94,13 @@ public sealed class Benchmark : IBenchmarkRunner
|
||||
static readonly (int value, int fps)[] Caps = { (0, 60), (2, 120), (3, 144), (5, 240) };
|
||||
public const int UpGame = 0, UpDlss = 1, UpFsr3 = 3, ResQuality = 3, ResBalanced = 5, CapUncapped = 5;
|
||||
public const int SteadyRefreshSteps = 2; // (fps_cap.h: 0 Off, 1 Any rate, 2 Refresh steps)
|
||||
// ((Triforce) 11-22) the Debug tab's Replay helper threads row (gpu/vk/replay_threads.h): 0 Off, 1 to 7 a fixed count
|
||||
// (n + 1 threads), 8 Automatic, also when the file has no such line
|
||||
public const string KHelpers = "replay_helper_threads";
|
||||
public const int HelpersOff = 0, HelpersAutomatic = 8;
|
||||
/// <summary>A place counts as faster one way only by more than this (the run-to-run spread of a place's average on a lab PC,
|
||||
/// about 3 %)</summary>
|
||||
public const double HelperMargin = 1.03;
|
||||
|
||||
public string WorkFolder => Path.Combine(ctx.WorkFolder, "benchmark");
|
||||
string Marker => Path.Combine(WorkFolder, "restore.txt");
|
||||
@@ -150,7 +172,8 @@ public sealed class Benchmark : IBenchmarkRunner
|
||||
/// <summary>One benchmark run: the game in its benchmark mode (it loads the newest save by itself, visits the scenes with
|
||||
/// its own panel on screen, writes its results and quits). Settings for the run: the player's, uncapped and without VSync,
|
||||
/// plus <paramref name="upscaler"/> at Quality when given. Stop: the token (the game is closed and writes "stopped").</summary>
|
||||
public async Task<BenchRun> RunOnceAsync(string game, (int upscaler, string name)? upscaler, IProgress<BenchmarkProgress>? progress, CancellationToken token)
|
||||
public async Task<BenchRun> RunOnceAsync(string game, (int upscaler, string name)? upscaler, IProgress<BenchmarkProgress>? progress, CancellationToken token,
|
||||
bool helperTest = false)
|
||||
{
|
||||
var g = new Game(ctx);
|
||||
var exe = g.FindExe(game) ?? throw new BenchmarkException("There is no built game in " + game + ".");
|
||||
@@ -175,6 +198,9 @@ public sealed class Benchmark : IBenchmarkRunner
|
||||
{
|
||||
var keys = new Dictionary<string, int> { [KCap] = CapUncapped, [KVsync] = 0, [KSteady] = 0, [KFrameGen] = 0 };
|
||||
if (upscaler is { } u) { keys[KUpscaler] = u.upscaler; keys[KResolution] = ResQuality; }
|
||||
// ((Triforce) 11-22) the helper-thread test needs the helper threads there: the row's fixed count as the player has it,
|
||||
// else Automatic's (its Off has none); the game holds them off and on itself, the tuner out of the way
|
||||
if (helperTest && !(BenchIni.Read(ini).TryGetValue(KHelpers, out var hr) && hr is >= 1 and <= 7)) keys[KHelpers] = HelpersAutomatic;
|
||||
BenchIni.Set(ini, keys);
|
||||
var si = new ProcessStartInfo(exe) { UseShellExecute = false, WorkingDirectory = game, RedirectStandardError = true, RedirectStandardOutput = true };
|
||||
foreach (var a in new[] { Path.Combine(game, "image.bin"), "--romfs", Path.Combine(game, "romfs"), "--user", userCopy }) si.ArgumentList.Add(a);
|
||||
@@ -183,6 +209,7 @@ public sealed class Benchmark : IBenchmarkRunner
|
||||
si.Environment["HOS_OOT_PROTECT_HEARTS"] = "1";
|
||||
si.Environment["HOS_INPUT_SCRIPT_BACKGROUND"] = "1";
|
||||
si.Environment["HOOKSHOT_NO_UPDATE_CHECK"] = "1";
|
||||
if (helperTest) si.Environment["HOS_BENCH_HELPERS"] = "1";
|
||||
if (ctx.Env("TRIFORCE_BENCH_GAME_ENV") is { Length: > 0 } extra) // (tests: e.g. the stand-in game's speed)
|
||||
foreach (var kv in extra.Split(';')) if (kv.IndexOf('=') is var i and > 0) si.Environment[kv[..i]] = kv[(i + 1)..];
|
||||
var logPath = Path.Combine(WorkFolder, upscaler == null ? "run.log" : "run-upscaler.log");
|
||||
@@ -202,7 +229,8 @@ public sealed class Benchmark : IBenchmarkRunner
|
||||
p.ErrorDataReceived += (_, e) => Got(e.Data);
|
||||
p.OutputDataReceived += (_, e) => Got(e.Data);
|
||||
p.BeginErrorReadLine(); p.BeginOutputReadLine();
|
||||
ctx.Log.Write("benchmark: started the game in benchmark mode (pid " + p.Id + ")" + (upscaler is { } up2 ? " with " + up2.name : ""));
|
||||
ctx.Log.Write("benchmark: started the game in benchmark mode (pid " + p.Id + ")" + (upscaler is { } up2 ? " with " + up2.name : "") +
|
||||
(helperTest ? ", with the helper-thread test" : ""));
|
||||
using (token.Register(() => { try { if (!p.HasExited && !(p.CloseMainWindow() && p.WaitForExit(15000))) p.Kill(true); } catch { } }))
|
||||
{
|
||||
while (!p.HasExited)
|
||||
@@ -243,14 +271,30 @@ public sealed class Benchmark : IBenchmarkRunner
|
||||
double D(string k) => s.TryGetProperty(k, out var v) && v.TryGetDouble(out var d) ? d : 0;
|
||||
var ft = new List<double>();
|
||||
if (s.TryGetProperty("frametimes_ms", out var f)) foreach (var x in f.EnumerateArray()) if (x.TryGetDouble(out var d)) ft.Add(d);
|
||||
scenes.Add(new PlaceResult(s.TryGetProperty("name", out var n) ? n.GetString() ?? "" : "", D("avg"), D("low1"), false) { Low01 = D("low01"), FrameTimes = ft });
|
||||
HelperHalves? halves = null;
|
||||
if (s.TryGetProperty("helpers", out var h) && h.ValueKind == System.Text.Json.JsonValueKind.Object &&
|
||||
h.TryGetProperty("off", out var off) && h.TryGetProperty("on", out var on))
|
||||
{
|
||||
static double H(System.Text.Json.JsonElement e, string k) => e.TryGetProperty(k, out var v) && v.TryGetDouble(out var d) ? d : 0;
|
||||
static List<double> T(System.Text.Json.JsonElement e)
|
||||
{
|
||||
var l = new List<double>();
|
||||
if (e.TryGetProperty("frametimes_ms", out var a)) foreach (var x in a.EnumerateArray()) if (x.TryGetDouble(out var d)) l.Add(d);
|
||||
return l;
|
||||
}
|
||||
halves = new HelperHalves(H(off, "avg"), H(off, "low1"), H(on, "avg"), H(on, "low1"),
|
||||
h.TryGetProperty("first", out var fi) && fi.GetString() == "on") { OffTimes = T(off), OnTimes = T(on) };
|
||||
}
|
||||
scenes.Add(new PlaceResult(s.TryGetProperty("name", out var n) ? n.GetString() ?? "" : "", D("avg"), D("low1"), false)
|
||||
{ Low01 = D("low01"), FrameTimes = ft, Helpers = halves });
|
||||
}
|
||||
var skipped = new List<string>();
|
||||
if (r.TryGetProperty("skipped", out var sk) && sk.ValueKind == System.Text.Json.JsonValueKind.Array)
|
||||
foreach (var x in sk.EnumerateArray()) if (x.GetString() is { Length: > 0 } name) skipped.Add(name);
|
||||
int? helperThreads = r.TryGetProperty("helper_test", out var ht) && ht.TryGetProperty("threads", out var htn) && htn.TryGetInt32(out var hn) ? hn : null;
|
||||
return new BenchRun(scenes, r.TryGetProperty("gpu", out var gpu) ? gpu.GetString() : null,
|
||||
r.TryGetProperty("stopped", out var st) && st.ValueKind == System.Text.Json.JsonValueKind.True,
|
||||
r.TryGetProperty("error", out var er) ? er.GetString() : null, took) { Skipped = skipped };
|
||||
r.TryGetProperty("error", out var er) ? er.GetString() : null, took) { Skipped = skipped, HelperThreads = helperThreads };
|
||||
}
|
||||
|
||||
/// <summary>The old interface: one run, then the rules (the App runs the upscaler pass on its own, when asked).</summary>
|
||||
@@ -302,6 +346,44 @@ public sealed class Benchmark : IBenchmarkRunner
|
||||
return recs;
|
||||
}
|
||||
|
||||
/// <summary>((Triforce) 11-22) The helper-thread test's suggestion for the Replay helper threads row, or null (not tested,
|
||||
/// or no place measured both ways): no place faster with them, Off; every place faster, the row as it is when it has
|
||||
/// them (Automatic or a fixed count), else Automatic; some faster and some not, Automatic, where the tuner decides as the
|
||||
/// game runs.</summary>
|
||||
public static SettingChange? RecommendHelpers(IReadOnlyDictionary<string, int> now, IReadOnlyList<PlaceResult> places)
|
||||
{
|
||||
var tested = places.Where(p => p.Helpers != null).Select(p => p.Helpers!.Verdict).ToList();
|
||||
if (tested.Count == 0) return null;
|
||||
var from = now.TryGetValue(KHelpers, out var v) && v is >= 0 and <= 8 ? v : HelpersAutomatic;
|
||||
var to = !tested.Contains(1) ? HelpersOff : tested.All(x => x == 1) ? (from == HelpersOff ? HelpersAutomatic : from) : HelpersAutomatic;
|
||||
return new SettingChange(KHelpers, "Replay helper threads", from, to);
|
||||
}
|
||||
|
||||
/// <summary>((Triforce) 11-22) The places as they run with the row set to <paramref name="row"/>: the "off" half's figures for
|
||||
/// Off, the faster half's otherwise (Automatic's tuner keeps the faster way; a fixed count does too)</summary>
|
||||
public static IReadOnlyList<PlaceResult> AsRecommended(IReadOnlyList<PlaceResult> places, int row) => places.Select(p =>
|
||||
p.Helpers is not { } h ? p
|
||||
: row == HelpersOff || h.OffFps >= h.OnFps ? p with { AverageFps = h.OffFps, OnePercentLow = h.OffLow, FrameTimes = h.OffTimes }
|
||||
: p with { AverageFps = h.OnFps, OnePercentLow = h.OnLow, FrameTimes = h.OnTimes }).ToList();
|
||||
|
||||
/// <summary>((Triforce) 11-22) the verdict's sentence for the helper-thread test ("" when it did not run)</summary>
|
||||
public static string HelperNote(BenchRun run)
|
||||
{
|
||||
if (run.HelperThreads is not { } threads) return "";
|
||||
if (threads < 2) return " The helper-thread test could not run: the game has no replay helper threads on this PC.";
|
||||
var tested = run.Scenes.Where(p => p.Helpers != null).ToList();
|
||||
if (tested.Count == 0) return "";
|
||||
static string Pct(HelperHalves h) => (h.OnFps / h.OffFps - 1).ToString("+0%;-0%;0%", CultureInfo.InvariantCulture);
|
||||
var faster = tested.Where(p => p.Helpers!.Verdict == 1).Select(p => p.Place + " " + Pct(p.Helpers!)).ToList();
|
||||
var slower = tested.Where(p => p.Helpers!.Verdict == -1).Select(p => p.Place + " " + Pct(p.Helpers!)).ToList();
|
||||
var s = $" With the {threads} replay helper threads on: ";
|
||||
if (faster.Count == tested.Count) return s + $"faster everywhere ({string.Join(", ", faster)}).";
|
||||
if (faster.Count == 0)
|
||||
return s + (slower.Count > 0 ? $"faster nowhere, slower in {string.Join(", ", slower)}" : "no place more than 3 % apart") +
|
||||
", so they are better off.";
|
||||
return s + $"faster in {string.Join(", ", faster)}, not elsewhere, so Automatic decides as you play.";
|
||||
}
|
||||
|
||||
/// <summary>((Triforce, 11-19) the verdict's note for places left out ("" when none)</summary>
|
||||
public static string SkippedNote(IReadOnlyList<string> skipped) => skipped.Count == 0 ? ""
|
||||
: " " + string.Join(" and ", skipped) + (skipped.Count == 1 ? " was" : " were") + " left out: the game would not take Link there from your save.";
|
||||
|
||||
@@ -17,14 +17,20 @@ public enum GameOptionKind { Choice, Slider }
|
||||
public sealed record GameOptionChoice(int Value, string Label);
|
||||
|
||||
/// <summary>The values of the other rows, for the labels that depend on them (the Render resolution's sizes follow the
|
||||
/// Upscaler and the Output resolution; the Anti-aliasing row shows the upscaler's own while one draws; the Microphone shows
|
||||
/// the saved device's name). GameOptionsFile is one.</summary>
|
||||
/// Upscaler and the Output resolution; the Anti-aliasing row shows the upscaler's own while one
|
||||
/// draws; the Microphone shows the saved device's name; the Output resolution's Screen and Custom show their sizes, and the
|
||||
/// Ultrawide row the shape of an Output resolution that has its own). GameOptionsFile is one.</summary>
|
||||
public interface IGameOptionValues
|
||||
{
|
||||
/// <summary>A row's value as the game reads it (its default when the file has no line).</summary>
|
||||
int Get(string key);
|
||||
/// <summary>A line's value as the file has it, null when it has no such line.</summary>
|
||||
string? Raw(string key);
|
||||
/// <summary>The main monitor's size in pixels, for the Output resolution's Screen; null where it is not known.</summary>
|
||||
(int W, int H)? Screen => null;
|
||||
/// <summary>The Custom size the game's menu keeps aside (output_custom_size), which choosing Custom takes back; null
|
||||
/// where there is none.</summary>
|
||||
(int W, int H)? EnteredCustomSize => null;
|
||||
}
|
||||
|
||||
/// <summary>((Triforce, options_version 8) A saved value that a merged row stands for (vk_menu.cpp's TAB_HIDDEN rows): its key
|
||||
|
||||
@@ -21,6 +21,7 @@ public sealed class GameOptionsFile : IGameOptionValues
|
||||
Dictionary<string, string> raw = new(StringComparer.Ordinal); // (each key's last value, trimmed as ini_merge.h does)
|
||||
Dictionary<string, int> read = new(StringComparer.Ordinal); // (each row's value as the game reads this file)
|
||||
readonly Dictionary<string, int> set = new(StringComparer.Ordinal); // (the rows the launcher changed: their new values)
|
||||
bool customSizeUsed; // (the launcher gave Custom another size, or took the entered one back: Save empties output_custom_size)
|
||||
|
||||
GameOptionsFile(string path, (int W, int H)? mainScreen)
|
||||
{
|
||||
@@ -31,12 +32,16 @@ public sealed class GameOptionsFile : IGameOptionValues
|
||||
|
||||
/// <summary>The game folder's options. mainScreen: the main monitor's size in pixels, for a file from before
|
||||
/// options_version 6 whose Ultrawide is 1 (then "Monitor's shape": the game reads it as the shape nearest the main
|
||||
/// monitor's); without it such a 1 is read as 16:9, as the game does where it cannot ask. A missing file is all defaults.</summary>
|
||||
/// monitor's). Without it (the launcher has none off Windows) that row is the game's to read: the game knows its
|
||||
/// screen on every system, and a guess here would be written as the player's choice. The row then stays 1 and the
|
||||
/// file stays at its version (WaitsForGame). A missing file is all defaults.</summary>
|
||||
public static GameOptionsFile Load(string gameFolder, (int W, int H)? mainScreen = null) =>
|
||||
new(System.IO.Path.Combine(gameFolder, GameOptionsSchema.FileName), mainScreen);
|
||||
|
||||
/// <summary>The file was there when it was last read.</summary>
|
||||
public bool Exists { get; private set; }
|
||||
/// <summary>The main monitor's size it was loaded with (the Output resolution's Screen shows it).</summary>
|
||||
public (int W, int H)? Screen => mainScreen;
|
||||
/// <summary>Its options_version (0: none, a file from before the line, or no file).</summary>
|
||||
public int Version { get; private set; }
|
||||
|
||||
@@ -47,6 +52,7 @@ public sealed class GameOptionsFile : IGameOptionValues
|
||||
var text = Exists ? File.ReadAllText(Path, Encoding.Latin1) : "";
|
||||
Parse(text);
|
||||
set.Clear();
|
||||
customSizeUsed = false;
|
||||
}
|
||||
|
||||
void Parse(string text)
|
||||
@@ -93,6 +99,10 @@ public sealed class GameOptionsFile : IGameOptionValues
|
||||
foreach (var p in GameOptionsSchema.Parts.Values)
|
||||
v[p.Key] = exists && lines.TryGetValue(p.Key, out var s) ? p.AsRead(Atoi(s)) : p.Default;
|
||||
if (!exists) return v;
|
||||
// (Custom's size: the file's own two numbers, not each kept to its row's ends, as the game reads them)
|
||||
(v[GameOptionsSchema.OutputWidthKey], v[GameOptionsSchema.OutputHeightKey]) = GameOptionsSchema.CustomRowsRead(
|
||||
lines.TryGetValue(GameOptionsSchema.OutputWidthKey, out var cw) ? Atoi(cw) : 0,
|
||||
lines.TryGetValue(GameOptionsSchema.OutputHeightKey, out var ch) ? Atoi(ch) : 0);
|
||||
foreach (var (key, value) in Migrated(lines)) if (v.ContainsKey(key)) v[key] = value;
|
||||
if (!lines.ContainsKey(GameOptionsSchema.ResolutionKey) && lines.TryGetValue("dynamic_resolution", out var dyn))
|
||||
v[GameOptionsSchema.ResolutionKey] = Atoi(dyn) != 0 ? 0 : 1;
|
||||
@@ -100,8 +110,19 @@ public sealed class GameOptionsFile : IGameOptionValues
|
||||
return v;
|
||||
}
|
||||
|
||||
/// <summary>A file from before options_version 6 with Ultrawide 1, "Monitor's shape", and no main monitor known here to
|
||||
/// read it by: the launcher cannot say which shape that is (on a 3440x1440 display the game reads 21:9). It leaves the
|
||||
/// row for the game: not shown as another value, and Save neither writes the older file's rules' values nor raises its
|
||||
/// options_version, because a file at the current version with ultrawide=1 means 16:10. Until the game has saved the
|
||||
/// file, the game reads the launcher's other changes by that older version's rules. A row the launcher's user sets
|
||||
/// here is a choice among the current shapes, and ends the wait.</summary>
|
||||
bool WaitsForGame(Dictionary<string, string> lines) =>
|
||||
mainScreen == null && (lines.TryGetValue(GameOptionsSchema.VersionKey, out var v) ? Atoi(v) : 0) < 6 &&
|
||||
lines.TryGetValue(GameOptionsSchema.UltrawideKey, out var row) && Atoi(row) == 1;
|
||||
|
||||
/// <summary>menu_init's rules for a file of an older options_version, as key and the value the game takes in its place
|
||||
/// (only the keys whose value it changes). The Debug tab's keys too: the game's readers before the menu take the same rules.</summary>
|
||||
/// (only the keys whose value it changes). The Debug tab's keys too: the game's readers before the menu take the same
|
||||
/// rules. Not the Ultrawide row's old 1, nor the Output resolution that depends on it, while that waits for the game.</summary>
|
||||
List<(string Key, int Value)> Migrated(Dictionary<string, string> lines)
|
||||
{
|
||||
var list = new List<(string, int)>();
|
||||
@@ -111,10 +132,11 @@ public sealed class GameOptionsFile : IGameOptionValues
|
||||
{
|
||||
if (!lines.TryGetValue(key, out var s) || Atoi(s) != value) list.Add((key, value));
|
||||
}
|
||||
var nativeOld = version < 8 || (version == 8 && (lines.ContainsKey(GameOptionsSchema.OutputWidthKey) || lines.ContainsKey(GameOptionsSchema.OutputHeightKey) || lines.ContainsKey(GameOptionsSchema.CustomSizeKey)));
|
||||
// ((Triforce, options_version 8) merged_rows.h migrate: the handheld profile is the Output resolution's 1536x864, the
|
||||
// shared stick dead zone each stick's own where it had none of its own. The other rows that went move nothing; their
|
||||
// lines stay until the game's next save drops them. A 436f9ac-based build's 7 has none of these lines: nothing moves)
|
||||
if (version < 8)
|
||||
if (nativeOld)
|
||||
{
|
||||
if (lines.TryGetValue("handheld_profile", out var hh) && Atoi(hh) != 0) Force(GameOptionsSchema.OutputResKey, GameOptionsSchema.HandheldOutput);
|
||||
var old = lines.TryGetValue("stick_dead_zone", out var sz) ? Atoi(sz) : 0;
|
||||
@@ -135,9 +157,24 @@ public sealed class GameOptionsFile : IGameOptionValues
|
||||
if (version < 6)
|
||||
{
|
||||
Force("tail_early", 1);
|
||||
if (lines.TryGetValue("ultrawide", out var uw) && Atoi(uw) == 1) Force("ultrawide", NearestShape(mainScreen));
|
||||
if (!WaitsForGame(lines) && lines.TryGetValue("ultrawide", out var uw) && Atoi(uw) == 1) Force("ultrawide", NearestShape(mainScreen));
|
||||
}
|
||||
if (version < 7) Force("frame_pacing", 1);
|
||||
// (before 8 the Output resolution's 5120x1440 and 5120x2160 were the game's frame, and the Ultrawide row gave the
|
||||
// picture's shape there too: output_sizes.h output_res_read, with the row as the game reads it)
|
||||
if (version < 9 && !WaitsForGame(lines) && lines.TryGetValue(GameOptionsSchema.OutputResKey, out var res))
|
||||
{
|
||||
var row = lines.TryGetValue(GameOptionsSchema.UltrawideKey, out var shape) ? Math.Clamp(Atoi(shape), 0, 3) : 0;
|
||||
if (version < 6 && row == 1) row = NearestShape(mainScreen);
|
||||
var legacy = nativeOld;
|
||||
var now = GameOptionsSchema.OutputResRead(Atoi(res), legacy ? version : 7, row);
|
||||
if (legacy && now is 7 or 8) now++;
|
||||
if ((version < 8 || legacy) && lines.TryGetValue("handheld_profile", out var handheld) && Atoi(handheld) != 0) now = 7;
|
||||
if (now != Atoi(res)) Force(GameOptionsSchema.OutputResKey, now);
|
||||
}
|
||||
// Native 0.6 still wrote the old profile row in version 9. Stock version 8 ignores it.
|
||||
if (version == 9 && lines.TryGetValue("handheld_profile", out var profile) && Atoi(profile) != 0)
|
||||
Force(GameOptionsSchema.OutputResKey, 7);
|
||||
return list;
|
||||
}
|
||||
|
||||
@@ -180,7 +217,8 @@ public sealed class GameOptionsFile : IGameOptionValues
|
||||
public string? Raw(string key) => raw.GetValueOrDefault(key);
|
||||
|
||||
/// <summary>A row's value's label as the game's menu shows it, the other rows as they are here (the Render resolution's
|
||||
/// sizes, the Anti-aliasing while an upscaler draws, the Microphone's device).</summary>
|
||||
/// sizes, the Anti-aliasing while an upscaler draws, the Microphone's device, Screen's and Custom's sizes, the shape of
|
||||
/// an Output resolution that has its own).</summary>
|
||||
public string Label(string key) => GameOptionsSchema.Get(key).Label(Get(key), this);
|
||||
|
||||
/// <summary>The values a row offers with the other rows as they are here: the Upscaler's engines (the one chosen by its
|
||||
@@ -197,6 +235,8 @@ public sealed class GameOptionsFile : IGameOptionValues
|
||||
GameOptionsSchema.ResolutionKey => GameOptionsSchema.ResolutionSteps(Value(GameOptionsSchema.UpscalerKey)).ToList(),
|
||||
GameOptionsSchema.UpscalerKey => GameOptionsSchema.UpscalerOrder.Select(e => e == GameOptionsSchema.Engine(now) ? now : e).ToList(),
|
||||
GameOptionsSchema.MicKey => Raw(GameOptionsSchema.MicDeviceKey) is { Length: > 0 } ? new List<int> { 0, 1, 2 } : new List<int> { 0, 1 },
|
||||
// (an Output resolution of its own shape: the row has nothing to choose, as in the menu)
|
||||
GameOptionsSchema.UltrawideKey when GameOptionsSchema.OutputShaped(this) => new List<int> { Get(key) },
|
||||
_ => row.Choices.Select(c => c.Value).ToList(),
|
||||
};
|
||||
if (!values.Contains(now)) values.Add(now);
|
||||
@@ -210,6 +250,23 @@ public sealed class GameOptionsFile : IGameOptionValues
|
||||
return values.Select(v => new GameOptionChoice(v, row.Label(v, this))).ToList();
|
||||
}
|
||||
|
||||
/// <summary>The Custom size the game's menu keeps beside a screen's (output_custom_size, read as the menu reads it,
|
||||
/// read_remembered_custom: under any Output resolution, a size the two rows can hold), null when there is none or the
|
||||
/// launcher has used it up.</summary>
|
||||
public (int W, int H)? EnteredCustomSize
|
||||
{
|
||||
get
|
||||
{
|
||||
if (customSizeUsed) return null;
|
||||
if (Raw(GameOptionsSchema.CustomSizeKey) is not { } text) return null;
|
||||
var x = text.IndexOfAny(new[] { 'x', 'X' });
|
||||
if (x <= 0 || !text.All(c => c is >= '0' and <= '9' or 'x' or 'X') || text.Count(c => c is 'x' or 'X') != 1) return null;
|
||||
int w = Atoi(text[..x]), h = Atoi(text[(x + 1)..]);
|
||||
var (width, height) = (GameOptionsSchema.Get(GameOptionsSchema.OutputWidthKey), GameOptionsSchema.Get(GameOptionsSchema.OutputHeightKey));
|
||||
return w >= width.Lo && w <= width.Hi && h >= height.Lo && h <= height.Hi ? (w, h) : null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The saved values the launcher changed since the file was read, by their keys in the file (a merged row's are
|
||||
/// its parts'), with their new values (Save writes these).</summary>
|
||||
public IReadOnlyDictionary<string, int> Changes => set;
|
||||
@@ -274,7 +331,17 @@ public sealed class GameOptionsFile : IGameOptionValues
|
||||
Put(Res, row.Clamp(value));
|
||||
return Get(key);
|
||||
}
|
||||
Put(key, row.Clamp(value));
|
||||
var next = row.Clamp(value);
|
||||
var changed = Get(key) != next;
|
||||
// Custom edits replace the remembered pair; choosing another output restores it, as the game's menu does.
|
||||
if (changed && key is GameOptionsSchema.OutputWidthKey or GameOptionsSchema.OutputHeightKey) customSizeUsed = true;
|
||||
if (changed && key == GameOptionsSchema.OutputResKey && EnteredCustomSize is { } entered)
|
||||
{
|
||||
Put(GameOptionsSchema.OutputWidthKey, entered.W);
|
||||
Put(GameOptionsSchema.OutputHeightKey, entered.H);
|
||||
customSizeUsed = true;
|
||||
}
|
||||
Put(key, next);
|
||||
return Get(key);
|
||||
}
|
||||
|
||||
@@ -307,13 +374,14 @@ public sealed class GameOptionsFile : IGameOptionValues
|
||||
/// get its value, every other line stays exactly as the file has it (so a line changed outside since Load is kept, as
|
||||
/// the game's merge keeps it), a changed row the file has no line for is added before options_version. A file of an
|
||||
/// older options_version is brought up to the current one as the game would read it (the values its rules give are
|
||||
/// written, options_version=8), so the game does not read the launcher's values by the old rules. The whole file is
|
||||
/// written, options_version=9), so the game does not read the launcher's values by the old rules; not while an old
|
||||
/// Monitor's shape waits for the game (WaitsForGame). The whole file is
|
||||
/// written beside it as .new and then put in its place: a reader never meets half a file, and a failure leaves the old
|
||||
/// one (IOException). Nothing to write: nothing written. The caller refuses while the game runs (Game.IsRunning).
|
||||
/// Afterwards this object holds the file as written.</summary>
|
||||
public void Save()
|
||||
{
|
||||
if (set.Count == 0) return;
|
||||
if (set.Count == 0) { customSizeUsed = false; return; }
|
||||
var exists = File.Exists(Path);
|
||||
var text = exists ? File.ReadAllText(Path, Encoding.Latin1) : "";
|
||||
var disk = SplitLines(text);
|
||||
@@ -324,18 +392,36 @@ public sealed class GameOptionsFile : IGameOptionValues
|
||||
|
||||
var write = new Dictionary<string, string>(StringComparer.Ordinal);
|
||||
var hasVersion = diskRaw.TryGetValue(GameOptionsSchema.VersionKey, out var vs);
|
||||
if (exists && (!hasVersion || Atoi(vs!) < GameOptionsSchema.CurrentVersion))
|
||||
// (an old Monitor's shape the launcher cannot read: the file keeps its version and its rules, for the game; unless
|
||||
// the row is set here, which is a choice among the current shapes)
|
||||
var waits = WaitsForGame(diskRaw) && !set.ContainsKey(GameOptionsSchema.UltrawideKey);
|
||||
if (exists && !waits)
|
||||
{
|
||||
foreach (var (k, v) in Migrated(diskRaw)) write[k] = v.ToString(CultureInfo.InvariantCulture);
|
||||
if (!diskRaw.ContainsKey(GameOptionsSchema.ResolutionKey) && diskRaw.TryGetValue("dynamic_resolution", out var dyn))
|
||||
write[GameOptionsSchema.ResolutionKey] = (Atoi(dyn) != 0 ? 0 : 1).ToString(CultureInfo.InvariantCulture);
|
||||
}
|
||||
foreach (var (k, v) in set) write[k] = v.ToString(CultureInfo.InvariantCulture);
|
||||
// An older native launcher left this line behind. Keep it consistent when the current output row changes.
|
||||
if (!waits && diskRaw.ContainsKey("handheld_profile"))
|
||||
{
|
||||
var output = write.TryGetValue(GameOptionsSchema.OutputResKey, out var written) ? Atoi(written) : Get(GameOptionsSchema.OutputResKey);
|
||||
write["handheld_profile"] = output == GameOptionsSchema.HandheldOutput ? "1" : "0";
|
||||
}
|
||||
// ((Triforce) 11-20) the GPU device row's card by its name too: the game finds it by the name first, so the number
|
||||
// counted in Windows' order (no triforce_gpus.txt before the game's first run) no longer picks another card. Auto: empty
|
||||
if (set.TryGetValue(GameOptionsSchema.GpuKey, out var gpu))
|
||||
write[GameOptionsSchema.GpuNameKey] = (GameOptionsSchema.GpuNameOf(gpu) ?? "").Replace('\r', ' ').Replace('\n', ' ');
|
||||
var bump = !exists || !hasVersion || Atoi(vs!) < GameOptionsSchema.CurrentVersion;
|
||||
// (Custom's size is its two sides together: the launcher shows the pair as the game takes it (Effective: 7680x4320 in
|
||||
// the file is 5120x2880), so a change of one side is a change of that pair. Written with only the changed side,
|
||||
// 3840 beside the file's 4320 would be another size than the one shown. Both sides whenever either is written)
|
||||
foreach (var (side, other) in new[] { (GameOptionsSchema.OutputWidthKey, GameOptionsSchema.OutputHeightKey),
|
||||
(GameOptionsSchema.OutputHeightKey, GameOptionsSchema.OutputWidthKey) })
|
||||
if (write.ContainsKey(side) && !write.ContainsKey(other)) write[other] = Get(other).ToString(CultureInfo.InvariantCulture);
|
||||
// (emptied, as the menu writes it with none kept; only where the file has the line)
|
||||
if (customSizeUsed && diskRaw.TryGetValue(GameOptionsSchema.CustomSizeKey, out var kept) && kept.Length > 0)
|
||||
write[GameOptionsSchema.CustomSizeKey] = "";
|
||||
var bump = !waits && (!exists || !hasVersion || Atoi(vs!) < GameOptionsSchema.CurrentVersion);
|
||||
if (bump) write[GameOptionsSchema.VersionKey] = GameOptionsSchema.CurrentVersion.ToString(CultureInfo.InvariantCulture);
|
||||
|
||||
var outLines = new List<string>(disk.Count + write.Count);
|
||||
@@ -360,6 +446,7 @@ public sealed class GameOptionsFile : IGameOptionValues
|
||||
Exists = true;
|
||||
Parse(sb.ToString());
|
||||
set.Clear();
|
||||
customSizeUsed = false;
|
||||
}
|
||||
|
||||
static int IndexOf(GameOptionRow r)
|
||||
|
||||
@@ -17,11 +17,17 @@ public static class GameOptionsSchema
|
||||
{
|
||||
/// <summary>The file the game reads at its start and writes at every change in its menu, in the game folder.</summary>
|
||||
public const string FileName = "triforce_options.ini";
|
||||
/// <summary>The options_version the game writes (vk_menu.cpp save, merged_rows.h kVersion): the file's format, which
|
||||
/// menu_init's rules read.</summary>
|
||||
public const int CurrentVersion = 8;
|
||||
/// <summary>The options_version the game writes (vk_menu.cpp save): the file's format, which menu_init's rules read.</summary>
|
||||
public const int CurrentVersion = 9;
|
||||
|
||||
public const string OutputResKey = "output_res";
|
||||
public const string OutputWidthKey = "output_width";
|
||||
public const string OutputHeightKey = "output_height";
|
||||
public const string UltrawideKey = "ultrawide";
|
||||
/// <summary>The Custom size the player entered, <w>x<h>, kept by the game's menu while a screen's size is in
|
||||
/// output_width and output_height (vk_menu.cpp remembered_custom); empty or absent when there is none. The menu reads
|
||||
/// it under any Output resolution, and so does GameOptionsFile. No row.</summary>
|
||||
public const string CustomSizeKey = "output_custom_size";
|
||||
public const string ResolutionKey = "resolution";
|
||||
public const string UpscalerKey = "dlss";
|
||||
public const string RumbleKey = "rumble_strength";
|
||||
@@ -155,7 +161,23 @@ public static class GameOptionsSchema
|
||||
static string TxRdxGrade(int v, IGameOptionValues? o) => v.ToString(CultureInfo.InvariantCulture);
|
||||
static string TxSpeed(int v, IGameOptionValues? o) => v != 0 ? "Real time" : "Per frame";
|
||||
static string TxTextSpeed(int v, IGameOptionValues? o) => OrFirst(new[] { "Normal", "2x", "4x", "Instant" }, v);
|
||||
static string TxUltrawide(int v, IGameOptionValues? o) => Pick(new[] { "16:9", "16:10", "21:9", "32:9" }, v);
|
||||
static readonly string[] Shapes = { "16:9", "16:10", "21:9", "32:9" };
|
||||
/// <summary>tx_shape: the row's choice, or the shape of an Output resolution that has its own (the row then has nothing
|
||||
/// to choose) with its size. (The game shows HOS_ASPECT's there while it is set.)</summary>
|
||||
static string TxUltrawide(int v, IGameOptionValues? o)
|
||||
{
|
||||
if (!OutputShaped(o)) return Pick(Shapes, v);
|
||||
var (w, h) = OutputSizeOf(V(o, OutputResKey, 0), o);
|
||||
return ShapeName((double)w / h) + " (" + w + "x" + h + ")";
|
||||
}
|
||||
/// <summary>shape_name: one of the Ultrawide row's where it is that one, else its width for a height of 1 (2.40:1).</summary>
|
||||
static string ShapeName(double ratio)
|
||||
{
|
||||
for (var row = 1; row <= 3; row++)
|
||||
if (Math.Abs(ratio / UltrawideRatio(row) - 1.0) < 0.001) return Shapes[row];
|
||||
return ratio.ToString("0.00", CultureInfo.InvariantCulture) + ":1";
|
||||
}
|
||||
static string TxPixels(int v, IGameOptionValues? o) => v.ToString(CultureInfo.InvariantCulture);
|
||||
static string TxWideHud(int v, IGameOptionValues? o) => v != 0 ? "Screen edges" : "Middle";
|
||||
static string TxWideMenus(int v, IGameOptionValues? o) => Pick(new[] { "Full width", "Centred, blurred sides", "Centred, black bars" }, v);
|
||||
static string TxPrompts(int v, IGameOptionValues? o) =>
|
||||
@@ -213,22 +235,148 @@ public static class GameOptionsSchema
|
||||
/// <summary>The microphone_device line's name as text: the file's bytes are UTF-8 (read here as Latin-1, byte for byte).</summary>
|
||||
internal static string MicName(string raw) => System.Text.Encoding.UTF8.GetString(System.Text.Encoding.Latin1.GetBytes(raw)).Trim();
|
||||
|
||||
// ---- the Output resolution and the Render resolution ----
|
||||
// ---- the Output resolution, the picture it gives, and the Render resolution ----
|
||||
|
||||
/// <summary>The Output resolution's sizes by their saved value (kOutputs); 6 and 7 came after the others so that saved
|
||||
/// values keep their sizes. (options_version 8) 7 is 1536x864, the game's handheld profile, once a row of its own.</summary>
|
||||
/// <summary>The Output resolution's fixed sizes by their saved value (kOutputs); 6 came after the others so that saved
|
||||
/// values keep their sizes. 9 is Custom, any size (gpu/vk/output_sizes.h): the size is the picture's, the game's frame
|
||||
/// 16:9 at its height, and a size that is not 16:9 is a wider or narrower picture by itself. The game's menu lists the
|
||||
/// size of every connected screen by its name and saves the one chosen as Custom's size, so here such a choice is
|
||||
/// Custom with that size. 8 is Screen, the size of the screen the game's window opens on: what an older file has, and
|
||||
/// still read; the game's menu saves it as that size.</summary>
|
||||
public static readonly IReadOnlyList<(int W, int H)> Outputs = new[] { (2048, 1152), (2560, 1440), (3840, 2160), (1920, 1080), (5120, 1440), (5120, 2880), (5120, 2160), (1536, 864) };
|
||||
/// <summary>The Output resolution's handheld profile (merged_rows.h kHandheldOutput).</summary>
|
||||
public const int HandheldOutput = 7;
|
||||
/// <summary>The order the menu shows them in, smallest to largest (kOutputOrder).</summary>
|
||||
public static readonly IReadOnlyList<int> OutputOrder = new[] { 7, 3, 0, 1, 2, 4, 6, 5 };
|
||||
static int OutputChoice(int v) => v >= 0 && v < Outputs.Count ? v : 0;
|
||||
public const int OutputScreen = 8, OutputCustom = 9;
|
||||
/// <summary>The order the launcher lists them in: the fixed sizes smallest to largest, then Screen and Custom. (The menu
|
||||
/// puts the screens' sizes and Custom among the fixed ones by their sizes, output_entries.)</summary>
|
||||
public static readonly IReadOnlyList<int> OutputOrder = new[] { 7, 3, 0, 1, 2, 4, 6, 5, OutputScreen, OutputCustom };
|
||||
static int OutputChoice(int v) => v >= 0 && v <= OutputCustom ? v : 0;
|
||||
|
||||
// (gpu/vk/output_sizes.h, as plain code)
|
||||
const int OutputMinW = 640, OutputMinH = 360, OutputMaxW = 7680, OutputMaxH = 2880;
|
||||
const double OutputMaxPixels = 5120.0 * 2880.0, OutputRowPixels = 3840.0 * 2160.0, ShapeMin = 5.0 / 4.0, ShapeMax = 32.0 / 9.0;
|
||||
static int OutputFrameWidth(int height) => (height * 16 + 36) / 72 * 8;
|
||||
static bool ShapeIsGame(double shape) => !(shape > 16.0 / 9.0 * 1.01 || shape < 16.0 / 9.0 * 0.99);
|
||||
static bool SizeShaped((int W, int H) s) => s.W > 0 && s.H > 0 && !ShapeIsGame((double)s.W / s.H);
|
||||
/// <summary>ultrawide_row_ratio: the Ultrawide row's shape, 0 for the game's own 16:9.</summary>
|
||||
static double UltrawideRatio(int row) => row <= 0 ? 0 : row == 1 ? 1.6f : row == 2 ? (float)(64.0 / 27.0) : (float)(32.0 / 9.0);
|
||||
/// <summary>output_width_range: the widths, whole multiples of 8, a picture of height h can have on one side of 16:9:
|
||||
/// within 5:4 to 32:9 and outside the 1% beside 16:9, within the width's ends and the pixels. Lo above Hi: none.</summary>
|
||||
static (int Lo, int Hi) OutputWidthRange(int h, bool wide)
|
||||
{
|
||||
const double game = 16.0 / 9.0;
|
||||
var edge = h * game * (wide ? 1.01 : 0.99);
|
||||
var least = wide ? Math.Floor(edge / 8.0) * 8.0 + 8.0 : Math.Ceiling(h * ShapeMin / 8.0) * 8.0;
|
||||
var most = wide ? Math.Floor(h * ShapeMax / 8.0) * 8.0 : Math.Ceiling(edge / 8.0) * 8.0 - 8.0;
|
||||
var pixels = Math.Floor(OutputMaxPixels / h / 8.0) * 8.0;
|
||||
least = Math.Max(least, OutputMinW);
|
||||
most = Math.Min(Math.Min(most, OutputMaxW), pixels);
|
||||
return ((int)least, most < 0 ? 0 : (int)most);
|
||||
}
|
||||
/// <summary>output_size_used: a size from outside (the screen's, Custom's) as the game takes it, null for none. Its
|
||||
/// shape first (5:4 to 32:9), then into the limits in that shape: 7680x4320 is 5120x2880. The width is the multiple of
|
||||
/// 8 nearest the shape's among those OutputWidthRange allows, so what comes out is taken as itself when given again.</summary>
|
||||
internal static (int W, int H)? OutputSizeUsed(long w, long h)
|
||||
{
|
||||
if (w <= 0 || h <= 0) return null;
|
||||
var shape = Math.Clamp((double)w / h, ShapeMin, ShapeMax);
|
||||
if (ShapeIsGame(shape))
|
||||
{
|
||||
var gh = (int)Math.Clamp(h, OutputMinH, OutputMaxH);
|
||||
return (OutputFrameWidth(gh), gh);
|
||||
}
|
||||
var wide = shape > 16.0 / 9.0;
|
||||
double fh = h, scale = 1.0;
|
||||
var fw = fh * shape;
|
||||
if (fh * scale > OutputMaxH) scale = OutputMaxH / fh;
|
||||
if (fw * scale > OutputMaxW) scale = OutputMaxW / fw;
|
||||
if (fw * fh * scale * scale > OutputMaxPixels) scale = Math.Sqrt(OutputMaxPixels / (fw * fh));
|
||||
int uh;
|
||||
if (scale < 1.0) uh = (int)(fh * scale / 8.0) * 8;
|
||||
else
|
||||
{
|
||||
if (fh < OutputMinH) fh = OutputMinH;
|
||||
if (fh * shape < OutputMinW) fh = OutputMinW / shape;
|
||||
uh = (int)Math.Ceiling(fh);
|
||||
}
|
||||
var (lo, hi) = OutputWidthRange(uh, wide);
|
||||
if (lo > hi)
|
||||
{
|
||||
uh = (uh - 1) / 8 * 8;
|
||||
(lo, hi) = OutputWidthRange(uh, wide);
|
||||
}
|
||||
return (Math.Clamp((int)(uh * shape / 8.0 + 0.5) * 8, lo, hi), uh);
|
||||
}
|
||||
/// <summary>custom_rows_read: the Output width and Output height rows' values for the file's two numbers (0: no line): a
|
||||
/// side that is not a size is its default; as written where the rows can hold them, else the size the game takes.</summary>
|
||||
internal static (int W, int H) CustomRowsRead(long w, long h)
|
||||
{
|
||||
if (w <= 0) w = 2560;
|
||||
if (h <= 0) h = 1440;
|
||||
var held = w >= OutputMinW && w <= OutputMaxW && h >= OutputMinH && h <= OutputMaxH;
|
||||
return held ? ((int)w, (int)h) : OutputSizeUsed(w, h)!.Value;
|
||||
}
|
||||
/// <summary>output_picture: the picture for the frame's height and a shape, null for the game's own 16:9 picture.</summary>
|
||||
internal static (int W, int H)? OutputPicture(int frameH, double want, bool sized)
|
||||
{
|
||||
if (!(want > 1.0) || ShapeIsGame(want)) return null;
|
||||
var r = Math.Clamp(want, ShapeMin, ShapeMax);
|
||||
var most = sized ? OutputMaxPixels : OutputRowPixels;
|
||||
int oh = frameH, ow = (int)(oh * r / 8 + 0.5) * 8;
|
||||
if ((double)ow * oh > most)
|
||||
{
|
||||
oh = (int)(Math.Sqrt(most / r) / 8) * 8;
|
||||
ow = (int)(oh * r / 8) * 8;
|
||||
}
|
||||
return (ow, oh);
|
||||
}
|
||||
/// <summary>output_res_read: output_res as a file of an older options_version holds it, with its Ultrawide row. Before 8,
|
||||
/// 5120x1440 (4) and 5120x2160 (6) were the game's frame: with the row on another shape than theirs, the 16:9 size of
|
||||
/// their height, which gives the same picture.</summary>
|
||||
internal static int OutputResRead(int v, int version, int ultrawide)
|
||||
{
|
||||
if (version >= 8) return v;
|
||||
if (v == 4 && ultrawide != 0 && ultrawide != 3) return 1;
|
||||
if (v == 6 && ultrawide != 0 && ultrawide != 2) return 2;
|
||||
return v;
|
||||
}
|
||||
/// <summary>row_size: the size a choice shows, null for a Screen that is not known.</summary>
|
||||
static (int W, int H)? RowSize(int v, IGameOptionValues? o)
|
||||
{
|
||||
v = OutputChoice(v);
|
||||
if (v < OutputScreen) return Outputs[v];
|
||||
if (v == OutputScreen) return o?.Screen is { } s ? OutputSizeUsed(s.W, s.H) : null;
|
||||
// (under another choice with a size kept aside, Custom is that size: choosing it takes it back, as in the menu, where
|
||||
// only the kept pair is offered then, output_entries)
|
||||
if (V(o, OutputResKey, 0) != OutputCustom && o?.EnteredCustomSize is { } entered) return OutputSizeUsed(entered.W, entered.H);
|
||||
return OutputSizeUsed(V(o, OutputWidthKey, 2560), V(o, OutputHeightKey, 1440));
|
||||
}
|
||||
/// <summary>output_size_of: the size a choice runs at (2560x1440 for a Screen that is not known, as the game).</summary>
|
||||
static (int W, int H) OutputSizeOf(int v, IGameOptionValues? o) => RowSize(v, o) ?? Outputs[1];
|
||||
/// <summary>output_shaped: the Output resolution chosen has a shape of its own (docked), so the Ultrawide row does not apply.</summary>
|
||||
internal static bool OutputShaped(IGameOptionValues? o) =>
|
||||
o != null && V(o, OutputResKey, 0) != HandheldOutput && SizeShaped(OutputSizeOf(V(o, OutputResKey, 0), o));
|
||||
/// <summary>output_picture_of: the picture the options give, the size's own or its height in the Ultrawide row's shape.</summary>
|
||||
static (int W, int H) PictureOf(IGameOptionValues? o)
|
||||
{
|
||||
var v = OutputChoice(V(o, OutputResKey, 0));
|
||||
var size = OutputSizeOf(v, o);
|
||||
var frameH = v == 0 ? Outputs[1].H : size.H;
|
||||
var sized = SizeShaped(size);
|
||||
var want = sized ? (double)size.W / size.H : UltrawideRatio(Math.Clamp(V(o, UltrawideKey, 0), 0, 3));
|
||||
if (OutputPicture(frameH, want, sized) is not { } p) return v == 0 ? Outputs[0] : size;
|
||||
return v == 0 ? (p.W * 4 / 5, p.H * 4 / 5) : p;
|
||||
}
|
||||
/// <summary>tx_output_res: a fixed size, "Screen (WxH)" with the main monitor's size where the launcher knows it (the
|
||||
/// game shows the monitor's it opens on), "Custom (WxH)" with the Output width and Output height rows' size as the game
|
||||
/// takes it.</summary>
|
||||
static string TxOutputRes(int v, IGameOptionValues? o)
|
||||
{
|
||||
v = OutputChoice(v);
|
||||
if (v == HandheldOutput) return "1536x864 (handheld)";
|
||||
var (w, h) = Outputs[v];
|
||||
return w + "x" + h;
|
||||
var size = RowSize(v, o);
|
||||
if (v == 7) return "1536x864 (handheld)";
|
||||
if (v < OutputScreen) return size!.Value.W + "x" + size.Value.H;
|
||||
var name = v == OutputScreen ? "Screen" : "Custom";
|
||||
return size is { } s ? name + " (" + s.W + "x" + s.H + ")" : name;
|
||||
}
|
||||
|
||||
// (upscaler_rows.h)
|
||||
@@ -272,7 +420,8 @@ public static class GameOptionsSchema
|
||||
}
|
||||
static string ModeName(int v) => Percent(v) switch { 67 => "Quality", 58 => "Balanced", 50 => "Performance", 33 => "Ultra Performance", _ => "" };
|
||||
/// <summary>tx_resolution: by the Upscaler chosen, and the size the game draws the 3D at for a fixed share of the
|
||||
/// Output resolution (the handheld profile's 1536x864 among them), a twelfth of it as the game takes it.</summary>
|
||||
/// picture (the Output resolution's own, or its height in the Ultrawide row's shape; the handheld profile's 1536x864),
|
||||
/// a twelfth of it as the game takes it.</summary>
|
||||
static string TxResolution(int v, IGameOptionValues? o)
|
||||
{
|
||||
var up = V(o, UpscalerKey, 0);
|
||||
@@ -280,7 +429,7 @@ public static class GameOptionsSchema
|
||||
var p = Percent(v);
|
||||
if (p == 0) return "Auto (dynamic)";
|
||||
if (ScalesByMode(up) && ModeName(v).Length > 0) return ModeName(v) + " (" + p + "%)";
|
||||
var (ow, oh) = Outputs[OutputChoice(V(o, OutputResKey, 0))];
|
||||
var (ow, oh) = (V(o, OutputResKey, 0) == HandheldOutput) ? (1536, 864) : PictureOf(o);
|
||||
var k = Math.Min(Math.Max((int)(p / 100.0f * 12.0f + 0.5f), 1), 12);
|
||||
return p + "% (" + (ow * k + 11) / 12 + "x" + oh * k / 12 + ")";
|
||||
}
|
||||
@@ -382,16 +531,20 @@ public static class GameOptionsSchema
|
||||
{
|
||||
Row(GameOptionTab.Display, "Screen", "Fullscreen", 0, 1, 1, 0, GameOptionKind.Choice, TxOnoff, false, true,
|
||||
"The game fills the whole screen, without the window's border. F10 and Alt+Enter do the same."),
|
||||
Row(GameOptionTab.Display, "Screen", "Output resolution", 0, 7, 1, 0, GameOptionKind.Choice, TxOutputRes, true, false,
|
||||
"The size of the game's whole frame, HUD included, before it is scaled to the window. Applies after a restart."),
|
||||
Row(GameOptionTab.Display, "Screen", "Output resolution", 0, 9, 1, 0, GameOptionKind.Choice, TxOutputRes, true, false,
|
||||
"The picture's size, before it is scaled to the window: the fixed sizes, and the size of each connected screen by its name. A size that is not 16:9 is a wider or narrower picture: the HUD, menus and story movies keep their 16:9 shape at its height. Docked only. Applies after a restart."),
|
||||
Row(GameOptionTab.Display, "Screen", "Output width", 640, 7680, 8, 2560, GameOptionKind.Slider, TxPixels, true, false,
|
||||
"The output resolution's width in pixels, where it is a screen's size or Custom; hold Left or Right to move faster. Output resolution shows the size the game takes: 5:4 to 32:9 in shape, at most the pixels of 5120x2880. Applies after a restart."),
|
||||
Row(GameOptionTab.Display, "Screen", "Output height", 360, 2880, 8, 1440, GameOptionKind.Slider, TxPixels, true, false,
|
||||
"The output resolution's height in pixels, where it is a screen's size or Custom; hold Left or Right to move faster. Output resolution shows the size the game takes: 5:4 to 32:9 in shape, at most the pixels of 5120x2880. Applies after a restart."),
|
||||
Row(GameOptionTab.Display, "Screen", "GPU device", 0, 8, 1, 0, GameOptionKind.Choice, TxGpu, true, true,
|
||||
"Which graphics card the game runs on. Applies after a restart."),
|
||||
Row(GameOptionTab.Display, "Ultrawide", "Aspect ratio", 0, 3, 1, 0, GameOptionKind.Choice, TxUltrawide, true, false,
|
||||
"The shape of the picture: the game's own 16:9, or 16:10, 21:9 or 32:9 for a screen of that shape. A screen of another shape shows it between black bars. Applies after a restart."),
|
||||
"The picture's shape for a 16:9 Output resolution: the game's own 16:9, or a fixed 16:10, 21:9 or 32:9 at the same height, for a screen or a window of that shape. A screen of another shape shows the picture between black bars. An Output resolution that is not 16:9 has its own shape, shown here. Applies after a restart."),
|
||||
Row(GameOptionTab.Display, "Ultrawide", "HUD position", 0, 1, 1, 0, GameOptionKind.Choice, TxWideHud, true, true,
|
||||
"Where the hearts, the item buttons and the map sit. Middle: in the middle 16:9, as on a normal screen. Screen edges: in the screen's corners. Applies after a restart."),
|
||||
"With a picture wider than 16:9: where corner HUD elements, tips and notices sit. Middle: in the middle 16:9, as on a normal screen. Screen edges: out in the screen's corners. Applies after a restart."),
|
||||
Row(GameOptionTab.Display, "Ultrawide", "Menu sides", 0, 2, 1, 1, GameOptionKind.Choice, TxWideMenus, false, false,
|
||||
"What is beside the pause, item and map menus, loading screens and movies, which are 16:9. Changes at once."),
|
||||
"With a picture wider than 16:9: the pause, item and map menus, and what shows beside them. Loading screens and story movies, which draw no world either, get the same sides (the title's movie fills the picture up to 12:5); a fade always covers the whole screen. Changes at once."),
|
||||
Merged(GameOptionTab.Display, "HDR", "HDR", 0, 3, 1, MergeHdr, TxHdrMode, true, true,
|
||||
"HDR10 on an HDR display (Windows: Use HDR on in the display settings). Native + RenoDX applies after a restart."),
|
||||
Row(GameOptionTab.Display, "HDR", "Paper white", 80, 400, 10, 200, GameOptionKind.Slider, TxNits, false, true,
|
||||
@@ -560,6 +713,7 @@ public static class GameOptionsSchema
|
||||
[VersionKey] = "the file's format: the rules the game reads an older file by (GameOptionsFile.Save writes 8 when it brings an older file up to date)",
|
||||
[MicDeviceKey] = "the Microphone row's device, by its name: the game's to choose from the devices it lists",
|
||||
[GpuNameKey] = "the GPU device row's card by its name (11-20): Save writes it with the row; the game finds the card by it first",
|
||||
[CustomSizeKey] = "the Custom size entered before a screen's size was chosen in the game's Output resolution row: the game's to keep; GameOptionsFile empties it when it writes another Custom size, and takes it back into the rows when the Output resolution is changed",
|
||||
["layout_preset"] = "the Controls page's Layout preset: choosing one in the game rebinds the pad_ lines, which a changed value alone would not do",
|
||||
["debug_tools"] = "the Debug tab (not ported)",
|
||||
["descriptor_reuse"] = "the Debug tab's Developer rows (not ported)",
|
||||
|
||||
@@ -190,7 +190,10 @@ public static class Startup
|
||||
|
||||
var result = new StartupResult { Args = a, Screen = StartScreen.Check, Lock = held, GameFolder = a.UpdateFolder ?? a.LaunchFolder, SignalUpWhenShown = a.Relaunched };
|
||||
if (!ctx.IsWindows)
|
||||
{
|
||||
if (a.LaunchFolder != null && a.UpdateFolder == null) UseLaunchFolder(ctx, a.LaunchFolder);
|
||||
return a.LaunchFolder != null && a.UpdateFolder == null ? Same(result, StartScreen.Launch) : result;
|
||||
}
|
||||
|
||||
// (TRIFORCE_DEV=1: run in place, without installing, for testing)
|
||||
if (ctx.RunningInstalled || ctx.Env("TRIFORCE_DEV") == "1") return result;
|
||||
@@ -215,6 +218,24 @@ public static class Startup
|
||||
return Same(result, StartScreen.Install);
|
||||
}
|
||||
|
||||
/// <summary>((Triforce, 11-23, ticket "[Linux] Non-default dir for triforce not generating log files") Linux --launch <dir>:
|
||||
/// that folder becomes the launcher's game folder (Settings.GameFolder), as a build there makes it. The folder's own
|
||||
/// "triforce" script (its menu entry, desktop shortcut and Steam shortcut) starts the launcher so, and the launcher read
|
||||
/// the folder and never used it: Home, Play, the saves and Game logs were the last built folder's. A game in a folder
|
||||
/// of its own was played from that other folder, whose triforce_log.txt it wrote, and nothing was written beside it.
|
||||
/// Only a folder that holds a game. TRIFORCE_LAUNCH_SAVED_FOLDER=1: the saved folder stays, as before.</summary>
|
||||
static void UseLaunchFolder(TriforceContext ctx, string folder)
|
||||
{
|
||||
if (ctx.Env("TRIFORCE_LAUNCH_SAVED_FOLDER") == "1") return;
|
||||
string full;
|
||||
try { full = Path.GetFullPath(folder); } catch (Exception) { return; }
|
||||
if (new Game(ctx).FindExe(full) == null) { ctx.Log.Write("start: --launch " + full + " holds no game: the saved game folder stays"); return; }
|
||||
var was = ctx.Settings.GameFolder;
|
||||
if (was != null && TriforceContext.SamePath(was, full)) return;
|
||||
ctx.Settings.GameFolder = full;
|
||||
ctx.Log.Write("start: --launch " + full + ": the game folder now (it was " + (was ?? "none") + ")");
|
||||
}
|
||||
|
||||
static StartupResult Same(StartupResult r, StartScreen screen) => new()
|
||||
{
|
||||
Args = r.Args, Screen = screen, Lock = r.Lock, GameFolder = r.GameFolder, SignalUpWhenShown = r.SignalUpWhenShown,
|
||||
|
||||
@@ -298,6 +298,9 @@ public sealed class Tools
|
||||
}
|
||||
foreach (var f in b.Files) // (the base whole in the new folder, whichever way it came)
|
||||
{
|
||||
// ((Triforce, 11-22, the v0.7.0 update stop "The tools' base lacks python/Lib/.../__pycache__/...pyc") the bytecode
|
||||
// caches as HasBase takes them: rewritten by Python as it runs, so kept bases have them at other sizes or not at all)
|
||||
if (Regenerated(f.Path)) continue;
|
||||
var fi = new FileInfo(Path.Combine(part, f.Path));
|
||||
if (!fi.Exists || fi.Length != f.Size) throw new InvalidDataException("The tools' base lacks " + f.Path + " (or it has another size): they were not changed.");
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ static partial class Tests
|
||||
yield return Sync("linux: the user folder follows the saves (triforce/user, then hookshot, then the game's)", LinuxUserFolder);
|
||||
yield return Sync("benchmark: an uneven run gets Steady frame rate Refresh steps, an even one keeps the player's", BenchSteady);
|
||||
yield return Sync("benchmark: a place left out is read and said", BenchSkipped);
|
||||
yield return Sync("benchmark: the helper-thread test's halves are read, and the row is suggested from them", BenchHelpers);
|
||||
yield return Sync("settings: color scheme, the page's 'color' read", ColorParse);
|
||||
yield return Sync("settings: color scheme kept and read back (registry.txt, builder.ini, old files)", ColorKept);
|
||||
yield return Sync("settings: color scheme, the launcher's color (--snapshot, commands out of order)", ColorChoice);
|
||||
@@ -103,6 +104,46 @@ static partial class Tests
|
||||
Equal(0, Benchmark.ReadResults(f, TimeSpan.Zero).Skipped.Count, "an older game's results: none");
|
||||
}
|
||||
|
||||
static void BenchHelpers()
|
||||
{
|
||||
var root = NewRoot("benchhelpers");
|
||||
var f = Path.Combine(root, "results.json");
|
||||
// (as host/hos_bench.c writes it with HOS_BENCH_HELPERS=1: the scene's own figures are the "off" half's)
|
||||
File.WriteAllText(f, "{\"version\":1,\"stopped\":false,\"scenes\":[" +
|
||||
"{\"name\":\"Hyrule Field\",\"avg\":80.2,\"low1\":55,\"frametimes_ms\":[12.5],\"helpers\":{\"first\":\"off\"," +
|
||||
"\"off\":{\"avg\":80.2,\"low1\":55,\"frametimes_ms\":[12.5]},\"on\":{\"avg\":75.3,\"low1\":52,\"frametimes_ms\":[13.3,13.4]}}}," +
|
||||
"{\"name\":\"Castle Town Market\",\"avg\":71.4,\"low1\":40,\"frametimes_ms\":[14],\"helpers\":{\"first\":\"on\"," +
|
||||
"\"off\":{\"avg\":71.4,\"low1\":40,\"frametimes_ms\":[14]},\"on\":{\"avg\":64.4,\"low1\":36,\"frametimes_ms\":[15.5]}}}]," +
|
||||
"\"skipped\":[],\"helper_test\":{\"threads\":3},\"settings\":{}}");
|
||||
var run = Benchmark.ReadResults(f, TimeSpan.FromSeconds(1));
|
||||
Equal(3, run.HelperThreads, "the threads tested");
|
||||
var field = run.Scenes[0].Helpers;
|
||||
Check(field != null && field.OffFps == 80.2 && field.OnFps == 75.3 && !field.OnFirst && field.OnTimes.Count == 2, "the Field's halves");
|
||||
Check(run.Scenes[1].Helpers is { OnFirst: true }, "the order, turned in the second place");
|
||||
Equal(-1, field!.Verdict, "6 % slower with them: slower");
|
||||
// the suggestion: slower everywhere, Off; from Automatic (the file without the line is Automatic too)
|
||||
var none = new Dictionary<string, int>();
|
||||
var off = Benchmark.RecommendHelpers(none, run.Scenes)!;
|
||||
Check(off.Key == Benchmark.KHelpers && off.From == Benchmark.HelpersAutomatic && off.To == Benchmark.HelpersOff, "slower everywhere: Off");
|
||||
Check(Benchmark.HelperNote(run).Contains("faster nowhere"), "the verdict says so");
|
||||
static PlaceResult P(string n, double offFps, double onFps) => new(n, offFps, offFps * 0.8) { Helpers = new HelperHalves(offFps, offFps * 0.8, onFps, onFps * 0.8, false) };
|
||||
var faster = new[] { P("Hyrule Field", 70, 80), P("Kokiri Forest", 60, 66) };
|
||||
Equal(Benchmark.HelpersAutomatic, Benchmark.RecommendHelpers(none, faster)!.To, "faster everywhere: Automatic stays");
|
||||
Equal(Benchmark.HelpersAutomatic, Benchmark.RecommendHelpers(new Dictionary<string, int> { [Benchmark.KHelpers] = 0 }, faster)!.To, "from Off: Automatic");
|
||||
Equal(2, Benchmark.RecommendHelpers(new Dictionary<string, int> { [Benchmark.KHelpers] = 2 }, faster)!.To, "a fixed count stays");
|
||||
var mixed = new[] { P("Hyrule Field", 70, 80), P("Kokiri Forest", 66, 60) };
|
||||
Equal(Benchmark.HelpersAutomatic, Benchmark.RecommendHelpers(new Dictionary<string, int> { [Benchmark.KHelpers] = 0 }, mixed)!.To, "mixed: Automatic decides");
|
||||
Check(Benchmark.HelperNote(new BenchRun(mixed, null, false, null, TimeSpan.Zero) { HelperThreads = 3 }).Contains("Automatic decides"), "mixed: said");
|
||||
var close = new[] { P("Hyrule Field", 70, 71), P("Kokiri Forest", 66, 65) };
|
||||
Equal(Benchmark.HelpersOff, Benchmark.RecommendHelpers(none, close)!.To, "nowhere more than 3 % apart: Off, nothing gained");
|
||||
Equal(null, Benchmark.RecommendHelpers(none, new[] { new PlaceResult("Hyrule Field", 60, 50) }), "not tested: no suggestion");
|
||||
Check(Benchmark.HelperNote(new BenchRun(Array.Empty<PlaceResult>(), null, false, null, TimeSpan.Zero) { HelperThreads = 0 }).Contains("could not run"), "no helper threads: said");
|
||||
Equal("", Benchmark.HelperNote(new BenchRun(faster, null, false, null, TimeSpan.Zero)), "not asked: nothing said");
|
||||
// the other rows are judged by the way suggested
|
||||
var asOff = Benchmark.AsRecommended(faster, Benchmark.HelpersOff);
|
||||
Check(asOff[0].AverageFps == 70 && Benchmark.AsRecommended(faster, Benchmark.HelpersAutomatic)[0].AverageFps == 80, "the way's own figures");
|
||||
}
|
||||
|
||||
static void BenchSteady()
|
||||
{
|
||||
var now = new Dictionary<string, int> { [Benchmark.KSteady] = 0 };
|
||||
|
||||
@@ -13,6 +13,7 @@ static partial class Tests
|
||||
public static IEnumerable<(string Name, Func<Task> Run)> GameOptionsTests()
|
||||
{
|
||||
(string, Func<Task>) Sync(string n, Action a) => (n, () => { a(); return Task.CompletedTask; });
|
||||
yield return Sync("game options: output migration", OutputMigration);
|
||||
yield return Sync("game options: schema matches vk_menu.cpp's table", GameOptionsMatchMenu);
|
||||
yield return Sync("game options: keys, labels, choices, no Hookshot", GameOptionsLabels);
|
||||
yield return Sync("game options: the real triforce_options.ini (read only)", GameOptionsRealFile);
|
||||
@@ -121,7 +122,7 @@ static partial class Tests
|
||||
Check(table.Count > 100, "the table read: " + table.Count + " entries");
|
||||
var symbols = new Dictionary<string, int>
|
||||
{
|
||||
["kLastOutput"] = 7, ["ur::kValues - 1"] = 6, ["ur::kUpscalers - 1"] = 6, ["ur::kModels - 1"] = 3, ["aa_rows::kValues - 1"] = 3,
|
||||
["kLastOutput"] = 9, ["OUTPUT_MIN_W"] = 640, ["OUTPUT_MAX_W"] = 7680, ["OUTPUT_MIN_H"] = 360, ["OUTPUT_MAX_H"] = 2880, ["ur::kValues - 1"] = 6, ["ur::kUpscalers - 1"] = 6, ["ur::kModels - 1"] = 3, ["aa_rows::kValues - 1"] = 3,
|
||||
["2 + kMaxMics"] = 18, ["HOS_PROMPT_N"] = 6, ["mr7::FG_DLSS_LAST"] = 12, ["framegen_rows::kRowMax"] = 9,
|
||||
};
|
||||
int Num(string s, string what) => int.TryParse(s, out var v) ? v : symbols.TryGetValue(s, out v) ? v : throw new TestFailed(what + ": a symbol the test does not know, " + s);
|
||||
@@ -182,7 +183,9 @@ static partial class Tests
|
||||
Equal(string.Join("|", names), string.Join("|", GameOptionsSchema.All.Select(r => r.Name)), "the rows, in the menu's order");
|
||||
// (the lines the game's save drops, merged_rows.h kDropped: kept keys, read once to move them)
|
||||
var mr = File.ReadAllText(Path.Combine(dir!, "merged_rows.h"));
|
||||
Check(mr.Contains("kVersion = " + GameOptionsSchema.CurrentVersion + ";"), "merged_rows.h's kVersion is CurrentVersion");
|
||||
Check(mr.Contains("kVersion = 8;"), "merged rows retain stock version 8");
|
||||
var sizes = File.ReadAllText(Path.Combine(dir!, "output_sizes.h"));
|
||||
Check(sizes.Contains("#define OUTPUT_OPTIONS_VERSION " + GameOptionsSchema.CurrentVersion), "output_sizes.h owns CurrentVersion");
|
||||
var dropped = Regex.Match(mr, @"kDropped\[\]\s*=\s*\{([^}]*)\}").Groups[1].Value;
|
||||
foreach (Match d in Regex.Matches(dropped, "\"([^\"]+)\""))
|
||||
Check(GameOptionsSchema.KeptKeys.ContainsKey(d.Groups[1].Value) && GameOptionsSchema.ByKey(d.Groups[1].Value) == null, d.Groups[1].Value + ": dropped by the game, a kept key here");
|
||||
@@ -241,7 +244,8 @@ static partial class Tests
|
||||
string L(string key, int v) => GameOptionsSchema.Get(key).Label(v);
|
||||
string Cs(string key) => string.Join("|", GameOptionsSchema.Get(key).Choices.Select(c => c.Value + "=" + c.Label));
|
||||
Equal("-3=30|-2=40|-1=45|0=60 (the console's)|1=90|2=120|3=144|4=165|5=240|6=Monitor's rate", Cs("frame_rate_cap"), "fps cap");
|
||||
Equal("7=1536x864 (handheld)|3=1920x1080|0=2048x1152|1=2560x1440|2=3840x2160|4=5120x1440|6=5120x2160|5=5120x2880", Cs("output_res"), "output sizes, smallest first");
|
||||
Equal("7=1536x864 (handheld)|3=1920x1080|0=2048x1152|1=2560x1440|2=3840x2160|4=5120x1440|6=5120x2160|5=5120x2880|8=Screen|9=Custom (2560x1440)", Cs("output_res"),
|
||||
"output sizes, smallest first, then Screen and Custom");
|
||||
Equal("0=Game|1=NVIDIA DLSS|3=AMD FSR 3.1|4=AMD FSR 4", Cs("dlss"), "upscalers: the engines, in the menu's order");
|
||||
Equal("0=Auto (dynamic)|1=100% (2048x1152)|2=75% (1536x864)|3=67% (1366x768)|4=50% (1024x576)", Cs("resolution"), "render resolution, the game's own");
|
||||
Equal("0=Off|1=Default", Cs("microphone"), "microphone without devices");
|
||||
@@ -281,6 +285,123 @@ static partial class Tests
|
||||
Equal("NVIDIA DLSS", L("dlss", 2), "DLAA reads as its engine");
|
||||
Equal("AMD FSR 3.1", L("dlss", 6), "FSR 3.1's native AA too");
|
||||
Equal("Native (100%)", L("resolution", GameOptionsSchema.NativeStep), "the Render resolution's Native");
|
||||
Equal("3440", L("output_width", 3440), "Custom's width, in pixels");
|
||||
|
||||
// (the Output resolution is the picture's size, output_sizes.h: Screen and Custom show theirs as the game takes it, a size
|
||||
// that is not 16:9 has its own shape, which the Ultrawide row then shows with nothing to choose, and the Render
|
||||
// resolution's sizes are the picture's)
|
||||
var wide = GameOptionsFile.Load(NewGameFolder("game-options-wide", "output_res=8\nultrawide=2\nresolution=2\noptions_version=9\n"), (3840, 1600));
|
||||
Equal("Screen (3840x1600)", wide.Label("output_res"), "Screen: the main monitor's size");
|
||||
Equal("2.40:1 (3840x1600)", wide.Label("ultrawide"), "its own shape, not the row's 21:9");
|
||||
Equal("2=2.40:1 (3840x1600)", string.Join("|", wide.ChoicesOf("ultrawide").Select(c => c.Value + "=" + c.Label)), "nothing to choose there");
|
||||
Equal("75% (2880x1200)", wide.Label("resolution"), "the 3D's size is the picture's share");
|
||||
Check(wide.ChoicesOf("output_res").Any(c => c.Label == "Custom (2560x1440)"), "Custom before its rows are set");
|
||||
wide.Set("output_res", 9);
|
||||
wide.Set("output_width", 3437);
|
||||
Equal(3440, wide.Get("output_width"), "the width on its steps of 8");
|
||||
wide.Set("output_height", 1440);
|
||||
Equal("Custom (3440x1440)", wide.Label("output_res"), "Custom: its rows' size");
|
||||
Equal("2.39:1 (3440x1440)", wide.Label("ultrawide"), "3440x1440 is not 64:27");
|
||||
wide.Set("output_width", 7680);
|
||||
wide.Set("output_height", 2880);
|
||||
Equal("Custom (6248x2344)", wide.Label("output_res"), "more pixels than 5120x2880's: smaller, in its shape");
|
||||
wide.Set("output_res", 4);
|
||||
Equal("32:9 (5120x1440)", wide.Label("ultrawide"), "5120x1440 is a 32:9 picture by itself");
|
||||
wide.Set("output_res", 6);
|
||||
Equal("21:9 (5120x2160)", wide.Label("ultrawide"), "5120x2160 a 21:9 one");
|
||||
Equal("75% (3840x1620)", wide.Label("resolution"), "of the whole 5120x2160");
|
||||
wide.Set("output_res", 2);
|
||||
Equal("21:9", wide.Label("ultrawide"), "a 16:9 size: the row's shape");
|
||||
Equal(4, wide.ChoicesOf("ultrawide").Count, "and its four choices");
|
||||
Equal("75% (3312x1398)", wide.Label("resolution"), "the row's 21:9 at the 4K output: kept to 3840x2160's pixels");
|
||||
wide.Set("ultrawide", 0);
|
||||
Equal("75% (2880x1620)", wide.Label("resolution"), "the game's own picture");
|
||||
wide.Set("output_res", 8);
|
||||
wide.Set("output_res", 7);
|
||||
Equal("16:9", wide.Label("ultrawide"), "the handheld profile runs the game's own output: the row's shape");
|
||||
// (output_custom_size: the Custom size the game's menu keeps while a screen's size is in the two rows. A kept key; a
|
||||
// Custom size written here is the entered one from now on and empties it, so the menu does not offer both; another
|
||||
// Output resolution chosen takes it back into the rows, as walking the menu's row does; any other change leaves it)
|
||||
Check(GameOptionsSchema.IsKept("output_custom_size"), "output_custom_size is a kept key");
|
||||
const string screenChosen = "output_res=9\noutput_width=3840\noutput_height=1600\noutput_custom_size=3437x1440\noptions_version=9\n";
|
||||
var kept = NewGameFolder("game-options-kept", screenChosen);
|
||||
var kf = GameOptionsFile.Load(kept);
|
||||
Equal("", string.Join(",", kf.UnknownKeys), "no key nobody knows");
|
||||
Equal((3437, 1440), kf.EnteredCustomSize!.Value, "the entered size, as the menu reads it");
|
||||
kf.Set("sharpness", 30);
|
||||
kf.Save();
|
||||
Check(File.ReadAllText(Path.Combine(kept, GameOptionsSchema.FileName)).Contains("output_custom_size=3437x1440\n"), "another row: the line as it was");
|
||||
kf.Set("output_width", 3440);
|
||||
kf.Set("output_height", 1440);
|
||||
Equal(null, kf.EnteredCustomSize, "used up by a size written here");
|
||||
kf.Save();
|
||||
Equal("output_res=9\noutput_width=3440\noutput_height=1440\noutput_custom_size=\nsharpness=30\noptions_version=9\n",
|
||||
File.ReadAllText(Path.Combine(kept, GameOptionsSchema.FileName)), "a Custom size written by the launcher: the kept one emptied");
|
||||
var left = NewGameFolder("game-options-left", screenChosen);
|
||||
var lf = GameOptionsFile.Load(left);
|
||||
lf.Set("output_res", 1);
|
||||
Equal(3437, lf.Get("output_width"), "leaving Custom: the entered size back in the rows");
|
||||
lf.Save();
|
||||
Equal("output_res=1\noutput_width=3437\noutput_height=1440\noutput_custom_size=\noptions_version=9\n",
|
||||
File.ReadAllText(Path.Combine(left, GameOptionsSchema.FileName)), "and the line emptied");
|
||||
// (read under any Output resolution, as the menu does: under a fixed size with a screen's size in the rows, Custom
|
||||
// is the size kept aside, and choosing it, or another fixed size, takes it back into the rows)
|
||||
const string fixedChosen = "output_res=1\noutput_width=3840\noutput_height=1600\noutput_custom_size=3437x1440\noptions_version=9\n";
|
||||
var ff = GameOptionsFile.Load(NewGameFolder("game-options-kept-fixed", fixedChosen));
|
||||
Equal((3437, 1440), ff.EnteredCustomSize!.Value, "read under a fixed size too");
|
||||
Check(ff.ChoicesOf("output_res").Any(c => c.Value == 9 && c.Label == "Custom (3440x1440)"), "Custom offered as the size it takes back, not the screen's in the rows");
|
||||
ff.Set("output_res", 9);
|
||||
Equal("Custom (3440x1440)", ff.Label("output_res"), "chosen: that size");
|
||||
Equal(3437, ff.Get("output_width"), "as entered, in the rows");
|
||||
ff.Save();
|
||||
Equal("output_res=9\noutput_width=3437\noutput_height=1440\noutput_custom_size=\noptions_version=9\n", File.ReadAllText(ff.Path), "written, the line emptied");
|
||||
var f2 = GameOptionsFile.Load(NewGameFolder("game-options-kept-fixed2", fixedChosen));
|
||||
f2.Set("output_res", 3);
|
||||
f2.Save();
|
||||
Equal("output_res=3\noutput_width=3437\noutput_height=1440\noutput_custom_size=\noptions_version=9\n", File.ReadAllText(f2.Path), "another fixed size: taken back as well");
|
||||
var f3 = GameOptionsFile.Load(NewGameFolder("game-options-kept-fixed3", fixedChosen));
|
||||
f3.Set("sharpness", 30);
|
||||
f3.Save();
|
||||
Check(File.ReadAllText(f3.Path).Contains("output_width=3840\noutput_height=1600\noutput_custom_size=3437x1440\n"), "any other row: all three as they were");
|
||||
Equal(null, GameOptionsFile.Load(NewGameFolder("game-options-kept-bad", "output_res=9\noutput_custom_size=100x100\noptions_version=9\n")).EnteredCustomSize,
|
||||
"nor a size the rows cannot hold");
|
||||
var none = NewGameFolder("game-options-kept-none", "output_res=9\noutput_width=3840\noutput_height=1600\noptions_version=9\n");
|
||||
var nf8 = GameOptionsFile.Load(none);
|
||||
nf8.Set("output_width", 3440);
|
||||
nf8.Save();
|
||||
Check(!File.ReadAllText(Path.Combine(none, GameOptionsSchema.FileName)).Contains("output_custom_size"), "no line where the file has none");
|
||||
|
||||
// (a size keeps its shape: one past the rows' ends is made smaller in it, as the game reads the file's two numbers)
|
||||
var tall = GameOptionsFile.Load(NewGameFolder("game-options-tall", "output_res=9\noutput_width=10000\noutput_height=5000\noptions_version=9\n"));
|
||||
Equal("Custom (5424x2712)", tall.Label("output_res"), "10000x5000 is 2:1 at 5120x2880's pixels");
|
||||
Equal(5424, tall.Get("output_width"), "and the rows hold that size");
|
||||
Equal("2.00:1 (5424x2712)", tall.Label("ultrawide"), "its shape kept");
|
||||
// (the pair is shown as the game takes it, so one side changed is written with the other as shown: 3840 beside the
|
||||
// file's 4320 would be 16:18 by the file, 5:4 for the game, where the launcher showed 3840x2880)
|
||||
var pair = NewGameFolder("game-options-pair", "output_res=9\noutput_width=7680\noutput_height=4320\noptions_version=9\n");
|
||||
var pf = GameOptionsFile.Load(pair);
|
||||
Equal("Custom (5120x2880)", pf.Label("output_res"), "7680x4320 in the file: 5120x2880");
|
||||
Equal(2880, pf.Get("output_height"), "the rows hold the size taken");
|
||||
pf.Set("output_width", 3840);
|
||||
Equal("Custom (3840x2880)", pf.Label("output_res"), "the width changed, beside the height shown");
|
||||
pf.Save();
|
||||
Equal("output_res=9\noutput_width=3840\noutput_height=2880\noptions_version=9\n", File.ReadAllText(Path.Combine(pair, GameOptionsSchema.FileName)),
|
||||
"both sides written: the size shown");
|
||||
Equal("Custom (3840x2880)", GameOptionsFile.Load(pair).Label("output_res"), "and read back as shown");
|
||||
var one = NewGameFolder("game-options-one-side", "output_res=9\noutput_height=1600\noptions_version=9\n");
|
||||
var of1 = GameOptionsFile.Load(one);
|
||||
of1.Set("output_height", 1440);
|
||||
of1.Save();
|
||||
Equal("output_res=9\noutput_height=1440\noutput_width=2560\noptions_version=9\n", File.ReadAllText(Path.Combine(one, GameOptionsSchema.FileName)),
|
||||
"a side the file has no line for: written too");
|
||||
Equal("Screen (5120x2880)", GameOptionsFile.Load(NewGameFolder("game-options-8k", "output_res=8\noptions_version=9\n"), (7680, 4320)).Label("output_res"),
|
||||
"a 7680x4320 screen: 16:9 still");
|
||||
Equal("Custom (2560x1440)", GameOptionsFile.Load(NewGameFolder("game-options-nosize", "output_res=9\noutput_width=0\noutput_height=-3\noptions_version=9\n")).Label("output_res"),
|
||||
"a side that is not a size: its default");
|
||||
Equal("Screen", GameOptionsFile.Load(NewGameFolder("game-options-noscreen", "output_res=8\noptions_version=9\n")).Label("output_res"),
|
||||
"Screen where the launcher does not know the monitor");
|
||||
Equal("Screen (1368x768)", GameOptionsFile.Load(NewGameFolder("game-options-1366", "output_res=8\noptions_version=9\n"), (1366, 768)).Label("output_res"),
|
||||
"a 16:9 screen: the game's frame at its height");
|
||||
|
||||
// (the GPU device row: the names the launcher gives it)
|
||||
var before = GameOptionsSchema.GpuNames;
|
||||
@@ -397,7 +518,7 @@ static partial class Tests
|
||||
"fps_counter=1\r\nhdr=0\r\nhdr_paper_white=400\r\nhdr_peak_brightness=4000\r\nrenodx_midgray=2\r\nrenodx_color_space=2\r\nquality_preset=0\r\n" +
|
||||
"resolution=1\r\ntexture_detail=1\r\ndlss=0\r\ndlss_model=1\r\nanti-aliasing=1\r\nsharpness=50\r\nupscaling=2\r\nframe_pacing=1\r\nnvidia_reflex=0\r\n" +
|
||||
"robust_buffers=1\r\nmicrophone=1\r\nmouse_sensitivity=125\r\ncontroller_in_background=1\r\nlayout_preset=1\r\nbutton_prompts=2\r\ndebug_tools=0\r\n" +
|
||||
"replay_helper_threads=0\r\ntail_early=1\r\noptions_version=7\r\nmenu_size=1\r\npad_a=0\r\nkey_a=69,0\r\nkey_cam_right=39,76\r\n";
|
||||
"replay_helper_threads=0\r\ntail_early=1\r\noptions_version=9\r\nmenu_size=1\r\npad_a=0\r\nkey_a=69,0\r\nkey_cam_right=39,76\r\n";
|
||||
|
||||
static string NewGameFolder(string name, string content)
|
||||
{
|
||||
@@ -510,23 +631,23 @@ static partial class Tests
|
||||
Check(merged.Contains("\r\nhdr=2\r\nzz_tool_line=5\r\n"), "the outside change and its new line kept in place");
|
||||
Check(merged.StartsWith("fullscreen=1\r\n"), "the launcher's change in its line");
|
||||
Check(merged.Contains("\r\nsharpness=70\r\n"), "a row changed on both sides: the launcher's (the later writer)");
|
||||
Equal(outside.Replace("fullscreen=0", "fullscreen=1").Replace("sharpness=20", "sharpness=70").Replace("options_version=7", "options_version=8"), merged,
|
||||
Equal(outside.Replace("fullscreen=0", "fullscreen=1").Replace("sharpness=20", "sharpness=70").Replace("options_version=7", "options_version=9"), merged,
|
||||
"every other line as the file had it (the version 7 file brought up to 8: nothing of it moves)");
|
||||
Equal("zz_tool_line", a.UnknownKeys.Single(), "an unknown key, kept");
|
||||
Equal(2, a.Get("hdr"), "this object holds the file as written");
|
||||
|
||||
// (a row with no line goes in before options_version; duplicates all take the value)
|
||||
var d = NewGameFolder("game-options-dup", "sharpness=10\nsharpness=20\n#note\noptions_version=7\nmenu_size=1\n");
|
||||
var d = NewGameFolder("game-options-dup", "sharpness=10\nsharpness=20\n#note\noptions_version=9\nmenu_size=1\n");
|
||||
var df = GameOptionsFile.Load(d);
|
||||
Equal(20, df.Get("sharpness"), "the last line wins, as the game reads it");
|
||||
df.Set("sharpness", 30);
|
||||
df.Set("vsync", 0);
|
||||
df.Save();
|
||||
Equal("sharpness=30\nsharpness=30\n#note\nvsync=0\noptions_version=8\nmenu_size=1\n", File.ReadAllText(Path.Combine(d, GameOptionsSchema.FileName)), "LF kept, line added, comment kept, brought up to 8");
|
||||
Equal("sharpness=30\nsharpness=30\n#note\nvsync=0\noptions_version=9\nmenu_size=1\n", File.ReadAllText(Path.Combine(d, GameOptionsSchema.FileName)), "LF kept, line added, comment kept");
|
||||
|
||||
// (a device's name in UTF-8: its bytes as they were, its label as text)
|
||||
var mic = "microphone_device=Mikrofon (Ä USB)";
|
||||
var micBytes = Encoding.UTF8.GetBytes("microphone=2\r\n" + mic + "\r\noptions_version=7\r\n");
|
||||
var micBytes = Encoding.UTF8.GetBytes("microphone=2\r\n" + mic + "\r\noptions_version=9\r\n");
|
||||
var mg = Path.Combine(NewRoot("game-options-mic"), "game");
|
||||
Directory.CreateDirectory(mg);
|
||||
File.WriteAllBytes(Path.Combine(mg, GameOptionsSchema.FileName), micBytes);
|
||||
@@ -559,7 +680,7 @@ static partial class Tests
|
||||
Equal(10000, f.Set("hdr_peak_brightness", 12345), "past the end: the end");
|
||||
Equal(130, f.Set("mouse_sensitivity", 125), "onto the steps: the nearest, the larger on a tie");
|
||||
Equal(50, f.Set("rumble_strength", 60), "rumble on 25s");
|
||||
Equal(0, f.Set("output_res", 9), "an output past the list: the first");
|
||||
Equal(0, f.Set("output_res", 10), "an output past the list: the first");
|
||||
Equal(7, f.Set("output_res", 7), "the handheld profile's output");
|
||||
Equal(-1, f.Set("left_stick_dead_zone", -7), "a range below 0");
|
||||
Equal(-3, f.Set("frame_rate_cap", -3), "the cap's 30");
|
||||
@@ -648,14 +769,38 @@ static partial class Tests
|
||||
Equal(1, f.Get("frame_pacing"), "pacing on, as the game reads a file before 7");
|
||||
Equal(2, f.Get("ultrawide"), "the monitor's shape at 2560x1080: 21:9");
|
||||
Equal(0, f.Get("nvidia_reflex"), "Reflex as saved from 5 on");
|
||||
Equal(0, GameOptionsFile.Load(g).Get("ultrawide"), "without the screen: 16:9, as the game where it cannot ask");
|
||||
// (without the screen, as the launcher is off Windows: the row is the game's to read, which knows its screen and reads
|
||||
// 21:9 on this one. Not shown as a guess; and a save keeps the file at its version with its old lines, where it
|
||||
// wrote ultrawide=0 and the current version, which the game then took as the player's 16:9)
|
||||
var blind = NewGameFolder("game-options-v5-blind", "frame_pacing=0\r\nultrawide=1\r\noutput_res=4\r\nsharpness=20\r\noptions_version=5\r\n");
|
||||
var bf = GameOptionsFile.Load(blind);
|
||||
Equal(1, bf.Get("ultrawide"), "without the screen: the row as the file has it, for the game");
|
||||
Equal(4, bf.Get("output_res"), "and the 5120x1440 that depends on it");
|
||||
Equal(1, bf.Get("frame_pacing"), "the file's other old rules still read");
|
||||
bf.Set("sharpness", 30);
|
||||
bf.Save();
|
||||
Equal("frame_pacing=0\r\nultrawide=1\r\noutput_res=4\r\nsharpness=30\r\noptions_version=5\r\n",
|
||||
File.ReadAllText(Path.Combine(blind, GameOptionsSchema.FileName)), "saved at its version: nothing guessed, nothing migrated");
|
||||
Equal(5, GameOptionsFile.Load(blind).Version, "still 5");
|
||||
// (the row set here is a choice among the current shapes: the file is brought up to date with it)
|
||||
bf.Set("ultrawide", 2);
|
||||
bf.Save();
|
||||
Equal("frame_pacing=1\r\nultrawide=2\r\noutput_res=4\r\nsharpness=30\r\noptions_version=9\r\n",
|
||||
File.ReadAllText(Path.Combine(blind, GameOptionsSchema.FileName)).Replace("tail_early=1\r\n", ""),
|
||||
"the row chosen here: up to date, beside the 5120x1440 the launcher showed");
|
||||
// (with the screen known nothing waits, as before; nor from version 6 on, where 1 is 16:10)
|
||||
Equal(1, GameOptionsFile.Load(NewGameFolder("game-options-v6-blind", "ultrawide=1\noptions_version=6\n")).Get("ultrawide"), "from 6 on: 16:10");
|
||||
var v6 = GameOptionsFile.Load(NewGameFolder("game-options-v6-save", "ultrawide=1\nsharpness=20\noptions_version=6\n"));
|
||||
v6.Set("sharpness", 30);
|
||||
v6.Save();
|
||||
Check(File.ReadAllText(v6.Path).Contains("options_version=9"), "a version 6 file is brought up to date without a screen");
|
||||
f.Set("sharpness", 30);
|
||||
f.Save();
|
||||
Equal("frame_pacing=1\r\nultrawide=2\r\nnvidia_reflex=0\r\nsharpness=30\r\noptions_version=8\r\npad_a=0\r\n",
|
||||
Equal("frame_pacing=1\r\nultrawide=2\r\nnvidia_reflex=0\r\nsharpness=30\r\noptions_version=9\r\npad_a=0\r\n",
|
||||
File.ReadAllText(Path.Combine(g, GameOptionsSchema.FileName)).Replace("tail_early=1\r\n", ""), "brought up to 8 as the game would read it");
|
||||
Check(File.ReadAllText(Path.Combine(g, GameOptionsSchema.FileName)).Contains("tail_early=1\r\noptions_version=8"), "the Debug tab's tail_early too, before the version");
|
||||
Check(File.ReadAllText(Path.Combine(g, GameOptionsSchema.FileName)).Contains("tail_early=1\r\noptions_version=9"), "the Debug tab's tail_early too, before the version");
|
||||
var again = GameOptionsFile.Load(g);
|
||||
Equal(8, again.Version, "now 8");
|
||||
Equal(9, again.Version, "now 8");
|
||||
again.Set(GameOptionsSchema.PacingKey, 0);
|
||||
again.Save();
|
||||
Equal(0, GameOptionsFile.Load(g).Get("frame_pacing"), "and from 7 on the choice is read as it is");
|
||||
@@ -671,7 +816,7 @@ static partial class Tests
|
||||
Equal("", string.Join(",", hf.UnknownKeys), "the old rows' lines: known");
|
||||
hf.Set("vsync", 0);
|
||||
hf.Save();
|
||||
Equal("output_res=7\nhandheld_profile=1\nstick_dead_zone=3\nright_stick_dead_zone=12\nquality_preset=4\nupscaling=2\nvsync=0\nleft_stick_dead_zone=15\noptions_version=8\n",
|
||||
Equal("output_res=7\nhandheld_profile=1\nstick_dead_zone=3\nright_stick_dead_zone=12\nquality_preset=4\nupscaling=2\nvsync=0\nleft_stick_dead_zone=15\noptions_version=9\n",
|
||||
File.ReadAllText(Path.Combine(h, GameOptionsSchema.FileName)), "brought up to 8: the moved values written, the old lines left for the game to drop");
|
||||
var h8 = GameOptionsFile.Load(h);
|
||||
h8.Set("output_res", 1);
|
||||
@@ -681,6 +826,23 @@ static partial class Tests
|
||||
var n7 = GameOptionsFile.Load(NewGameFolder("game-options-n7", "output_res=3\nleft_stick_dead_zone=-1\noptions_version=7\n"));
|
||||
Equal(3, n7.Get("output_res"), "no handheld line: the output as it is");
|
||||
Equal(-1, n7.Get("left_stick_dead_zone"), "no shared line: the default");
|
||||
// (options_version 7: 5120x1440 and 5120x2160 were the game's frame, and the Ultrawide row gave the picture's shape there
|
||||
// too. With the row on another shape than theirs: the 16:9 size of their height, the same picture; else as they are)
|
||||
var w7 = NewGameFolder("game-options-v7", "output_res=4\r\nultrawide=2\r\nsharpness=20\r\noptions_version=7\r\n");
|
||||
var wf7 = GameOptionsFile.Load(w7);
|
||||
Equal(1, wf7.Get("output_res"), "5120x1440 with the row on 21:9: 2560x1440, whose 21:9 picture it was");
|
||||
Equal("21:9", wf7.Label("ultrawide"), "and the row's shape still");
|
||||
wf7.Set("sharpness", 30);
|
||||
wf7.Save();
|
||||
Equal("output_res=1\r\nultrawide=2\r\nsharpness=30\r\noptions_version=9\r\n", File.ReadAllText(Path.Combine(w7, GameOptionsSchema.FileName)),
|
||||
"written as the game reads it, at 8");
|
||||
Equal(4, GameOptionsFile.Load(NewGameFolder("game-options-v7b", "output_res=4\nultrawide=3\noptions_version=7\n")).Get("output_res"), "its own shape: as it is");
|
||||
Equal(4, GameOptionsFile.Load(NewGameFolder("game-options-v7c", "output_res=4\nultrawide=0\noptions_version=7\n")).Get("output_res"), "16:9 there: as it is, now its picture");
|
||||
Equal(2, GameOptionsFile.Load(NewGameFolder("game-options-v7d", "output_res=6\nultrawide=3\noptions_version=7\n")).Get("output_res"), "5120x2160 with 32:9: 3840x2160");
|
||||
Equal(6, GameOptionsFile.Load(NewGameFolder("game-options-v7e", "output_res=6\nultrawide=2\noptions_version=7\n")).Get("output_res"), "5120x2160 with its 21:9");
|
||||
Equal(4, GameOptionsFile.Load(NewGameFolder("game-options-v8", "output_res=4\nultrawide=2\noptions_version=9\n")).Get("output_res"), "from 8 on as chosen: the row is not read there");
|
||||
Equal(4, GameOptionsFile.Load(NewGameFolder("game-options-v5b", "output_res=4\nultrawide=1\noptions_version=5\n"), (5120, 1440)).Get("output_res"),
|
||||
"before 6 the row's 1 was the monitor's shape: 32:9 on a 5120x1440 one, 5120x1440's own");
|
||||
|
||||
// (no options_version line: Game speed real time; no resolution line but the old dynamic_resolution)
|
||||
var o = NewGameFolder("game-options-v0", "game_speed=0\ndynamic_resolution=0\n");
|
||||
@@ -704,7 +866,7 @@ static partial class Tests
|
||||
nf.Set(GameOptionsSchema.PacingKey, 3);
|
||||
nf.Save();
|
||||
var nl = OperatingSystem.IsWindows() ? "\r\n" : "\n";
|
||||
Equal("vsync=0" + nl + "steady_frame_rate=2" + nl + "master_volume=85" + nl + "options_version=8" + nl, File.ReadAllText(nf.Path),
|
||||
Equal("vsync=0" + nl + "steady_frame_rate=2" + nl + "master_volume=85" + nl + "options_version=9" + nl, File.ReadAllText(nf.Path),
|
||||
"a new file: the values in the menu's order (a merged row's parts at its place; frame_pacing at its default not written), then the version");
|
||||
Check(nf.Exists, "now there");
|
||||
}
|
||||
|
||||
42
launcher/LogicTests/Tests.OutputMigration.cs
Normal file
42
launcher/LogicTests/Tests.OutputMigration.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using Triforce.Logic;
|
||||
using static Triforce.LogicTests.T;
|
||||
|
||||
namespace Triforce.LogicTests;
|
||||
|
||||
static partial class Tests
|
||||
{
|
||||
static void OutputMigration()
|
||||
{
|
||||
foreach (var (name, text, output) in new[]
|
||||
{
|
||||
("launcher-profile", "handheld_profile=1\noptions_version=9\n", 7),
|
||||
("stock-stale-profile", "output_res=1\nhandheld_profile=1\noptions_version=8\n", 1),
|
||||
("stock-handheld", "output_res=7\noptions_version=8\n", 7),
|
||||
("stock-wide", "output_res=4\nultrawide=2\noptions_version=8\n", 1),
|
||||
("native-screen", "output_res=7\noutput_width=2560\noutput_height=1440\noptions_version=8\n", 8),
|
||||
("native-wide", "output_res=4\nultrawide=2\noutput_width=2560\noutput_height=1440\noptions_version=8\n", 4),
|
||||
("player", "output_res=8\noutput_width=3840\noutput_height=1600\noutput_custom_size=2560x1440\nultrawide=2\noptions_version=8\n", 9),
|
||||
})
|
||||
{
|
||||
var folder = NewGameFolder("migration-" + name, text);
|
||||
var file = GameOptionsFile.Load(folder, (3840, 1600));
|
||||
Equal(output, file.Get("output_res"), name + " read");
|
||||
file.Set("sharpness", 25);
|
||||
file.Save();
|
||||
var again = GameOptionsFile.Load(folder, (3840, 1600));
|
||||
Equal(9, again.Version, name + " version");
|
||||
Equal(output, again.Get("output_res"), name + " round trip");
|
||||
if (name == "player")
|
||||
{
|
||||
Equal(3840, again.Get("output_width"), "player active width");
|
||||
Equal(1600, again.Get("output_height"), "player active height");
|
||||
Check(File.ReadAllText(again.Path).Contains("output_custom_size=2560x1440"), "remembered pair retained");
|
||||
}
|
||||
}
|
||||
var handheld = GameOptionsFile.Load(NewGameFolder("migration-handheld", "output_res=7\nhandheld_profile=1\noptions_version=9\n"));
|
||||
handheld.Set("output_res", 0);
|
||||
handheld.Save();
|
||||
Equal(0, GameOptionsFile.Load(Path.GetDirectoryName(handheld.Path)!).Get("output_res"), "leaving native handheld round trip");
|
||||
Check(File.ReadAllText(handheld.Path).Contains("handheld_profile=0"), "old native profile follows the output row");
|
||||
}
|
||||
}
|
||||
@@ -294,6 +294,24 @@ static partial class Tests
|
||||
File.Delete(Path.Combine(t2.Folder, Tools.BaseHave));
|
||||
Check(!Tools.HasBase(b2, t2.Folder, null), "a real base file changed still is not");
|
||||
Check(Tools.Regenerated(@"python\Lib\x\__pycache__\a.pyc") && !Tools.Regenerated("python/Lib/os.py"), "what counts as rewritten");
|
||||
|
||||
// (11-22, v0.7.0's update stop "The tools' base lacks python/Lib/.../__pycache__/...pyc (or it has another size)": HasBase
|
||||
// kept a base whose caches Python had rewritten, and UnpackParts' last look then wanted them at their packed sizes)
|
||||
var root3 = NewRoot("parts-pyc-unpack");
|
||||
var t3 = new Tools(Ctx(root3));
|
||||
var list3 = BaseList(("python/python.exe", "py"), ("python/Lib/__pycache__/os.cpython-314.pyc", "packed bytes"),
|
||||
("python/Lib/__pycache__/gone.cpython-314.pyc", "packed"));
|
||||
var b3 = Tools.ParseBaseList(list3)!;
|
||||
Directory.CreateDirectory(Path.Combine(t3.Folder, "python", "Lib", "__pycache__"));
|
||||
File.WriteAllText(Path.Combine(t3.Folder, "python", "python.exe"), "py");
|
||||
File.WriteAllText(Path.Combine(t3.Folder, "python", "Lib", "__pycache__", "os.cpython-314.pyc"), "rewritten by python, longer");
|
||||
File.WriteAllText(Path.Combine(t3.Folder, "version.txt"), "v0.6.0");
|
||||
Check(Tools.HasBase(b3, t3.Folder, null), "the kept base with rewritten and missing caches");
|
||||
var code3 = Path.Combine(root3, "code.zip");
|
||||
File.WriteAllBytes(code3, Zip(("tools/nx2/make_game.py", "new"), ("tools/base.list", list3)));
|
||||
t3.UnpackParts(code3, null, b3, "v0.7.0", null);
|
||||
Equal("v0.7.0", t3.InstalledVersion, "a code part over a base whose caches Python rewrote");
|
||||
Equal("rewritten by python, longer", File.ReadAllText(Path.Combine(t3.Folder, "python", "Lib", "__pycache__", "os.cpython-314.pyc")), "its caches kept as they were");
|
||||
}
|
||||
|
||||
static async Task ToolsUpdate()
|
||||
|
||||
@@ -754,7 +754,7 @@ function onBench(b) {
|
||||
$('#benchEb').textContent = b.eb || '';
|
||||
$('#places').innerHTML = (b.places || []).map(p => `<div class="place noimg${p.fps2 != null ? ' two' : ''}"><div class="pg">${sparkline(p.graph)}${p.graph2 ? sparkline(p.graph2, 'b') : ''}</div>` +
|
||||
(p.fps2 != null
|
||||
? `<div class="two"><b>${esc(p.name)}</b><span><i>Your settings</i><strong>${p.fps}</strong> fps · low ${p.low}</span><span class="vs"><i>${esc(b.second || '')}</i><strong>${p.fps2}</strong> fps · low ${p.low2}</span></div></div>`
|
||||
? `<div class="two"><b>${esc(p.name)}</b><span><i>${esc(b.first || 'Your settings')}</i><strong>${p.fps}</strong> fps · low ${p.low}</span><span class="vs"><i>${esc(b.second || '')}</i><strong>${p.fps2}</strong> fps · low ${p.low2}</span></div></div>`
|
||||
: `<div><b>${esc(p.name)}</b><span><strong>${p.fps}</strong> fps · low ${p.low}</span></div></div>`)).join('');
|
||||
$('#verdict').innerHTML = b.verdict || '';
|
||||
$('#recs').innerHTML = (b.recs || []).map(r => `<div class="rec${r.same ? ' same' : ''}"><b>${esc(r.name)}</b><s>${esc(r.from)}</s><em>→</em><strong>${esc(r.to)}</strong></div>`).join('');
|
||||
|
||||
Reference in New Issue
Block a user