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:
@@ -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.");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user