Merge #809 and #814: draw a 16:9 picture with bars when the HUD layout for a wider or narrower game resolution is missing, and fix the installer DPI test at 125% scaling

#809: on 1.4.3 at 2560x1080 without romfs-patches-2560x1080 the game drew 1920x1080 with the 16:9 HUD, aspect patch
off, 0 validation errors; the four probes pass. #814 changes the test only; DpiTest passes at 96 DPI, the 125% case
was checked by hand against Tk's rounding.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Valiantsin DzerakhandClaude Opus 5.5 committed 2026-11-06 20:27:18 +03:00
commit 03c703a712
7 files changed
+64 -13

No files matched your search

+7
View File
@@ -118,6 +118,13 @@ of them.
button prompts"), which `build_game.py` copies next to `totk.exe` like `romfs-patches`. `--prompts pc` writes
`romfs-patches-pc`, the keyboard and mouse prompts ([controls.md](controls.md), "PC button prompts").
A build from source has no layouts for other shapes than 16:9. At an `output_res` such as 5120x1440 the game then
draws the largest 16:9 size inside it (2560x1440) and the present adds bars, instead of a wide camera over a
stretched HUD (`runtime/resolution.c`, `shape_fallback`). For the full shape make `romfs-patches-<w>x<h>` once per
size: `make_romfs_patches.py --version <ver> --aspect <w>x<h> --out build\<ver>\romfs-patches-<w>x<h>` (the sizes
the installer makes are `ASPECT_SIZES` in `installer/steps.py`); `build_game.py` copies every `romfs-patches*`
folder next to `totk.exe`.
6. Prepare the shaders (once per build folder and translator). It needs `refs\MacNativeGames` (`tools\fetch_refs.sh`)
for the shared shader list:
+2
View File
@@ -276,6 +276,8 @@ void res_sizes(unsigned out[2], unsigned scene[2]); // the output and scene
// until res_init switched the sets on)
int res_is_16x9(unsigned w, unsigned h); // within 1% of 16:9 (the test res_init and romfs.c share)
int res_wants_wide_overlay(const unsigned out[2]); // not 16:9 on a game version with the camera aspect patch
int romfs_shaped_ready(unsigned w, unsigned h); // romfs-patches-<w>x<h> has a manifest (romfs.c; works
// before fs_init)
void res_wanted(unsigned out[2]); // the output size TOTK_OUTPUT_RES asks for
void res_fov_live(void); // TOTK_FOV to the camera (set fov); on a settings change
// ---- code patches (patches.c) and the frame step (frame_rate.c)
+20
View File
@@ -122,6 +122,25 @@ static double dlss_share(const char *m) {
return 0;
}
// A game resolution that is not 16:9 needs the HUD's layout for its shape (romfs-patches-<w>x<h>, romfs.c
// overlay_init), which the installer makes but a developer build only has after tools/make_romfs_patches.py --aspect.
// Without it the camera would widen while the 16:9 HUD stretched across the picture, so the game draws the largest
// 16:9 size that fits inside the asked one and the camera aspect patch stays off (res_init); gfx_present.c shows the
// picture with bars (present setting aspect). Not when TOTK_ROMFS_PATCHES names the overlay itself or the game version
// has no camera aspect patch. TOTK_OUTPUT_RES is restart-only (cfg.c, RESTART), so this one decision holds all run.
static void shape_fallback(void) {
const char *own = cfg_get("TOTK_ROMFS_PATCHES");
unsigned out[2] = {R.ow, R.oh};
if (own || !res_wants_wide_overlay(out) || romfs_shaped_ready(R.ow, R.oh)) return;
unsigned h = R.oh, w = R.ow;
if ((uint64_t)w * 9 <= (uint64_t)h * 16) h = (unsigned)((uint64_t)w * 9 / 16) & ~1u;
w = (unsigned)((uint64_t)h * 16 / 9) & ~1u;
rt_log("resolution: no romfs-patches-%ux%u for the HUD at this shape; the game draws %ux%u (16:9) and the present "
"adds bars. Make the layout with: tools/make_romfs_patches.py --version <v121|v143> --aspect %ux%u --out "
"build/<version>/romfs-patches-%ux%u", R.ow, R.oh, w, h, R.ow, R.oh, R.ow, R.oh);
R.ow = w, R.oh = h;
}
static void decide(void) {
if (R.decided) return;
R.decided = 1;
@@ -133,6 +152,7 @@ static void decide(void) {
if (sscanf(o, "%ux%u%c", &w, &h, &tail) == 2 && w >= 1280 && h >= 720 && w <= 7680 && h <= 4320) {
R.ow = w & ~1u;
R.oh = h & ~1u;
shape_fallback();
} else {
rt_log("resolution: TOTK_OUTPUT_RES=%s is not <width>x<height> in 1280x720..7680x4320; 1920x1080", o);
}
+13
View File
@@ -1052,6 +1052,19 @@ static void index_path(char *out, size_t cap) {
strcpy(out + k, "romfs-index.bin");
}
// 1 when the game resolution w x h has the UI layout of its shape: romfs-patches-<w>x<h> next to romfs-index.bin with a
// manifest, the folder overlay_init looks for. Works before fs_init: index_dir is not set that early (res_init and
// resolution.c decide run first), so the index path is worked out again here.
int romfs_shaped_ready(unsigned w, unsigned h) {
char dir[2100], path[2200];
index_path(dir, sizeof dir);
char *sep = plat_last_sep(dir);
if (sep) *sep = 0;
else strcpy(dir, ".");
return snprintf(path, sizeof path, "%s/romfs-patches-%ux%u/manifest.tsv", dir, w, h) < (int)sizeof path &&
plat_file_exists(path);
}
static void load_index(void) {
char path[2100];
index_path(path, sizeof path);
+9 -3
View File
@@ -377,13 +377,19 @@ class DpiTest(unittest.TestCase):
code = ('import tkinter\n'
'from installer import dpi, gui\n'
'root = tkinter.Tk()\n'
'print(dpi.awareness(), dpi.scale(), root.tk.call("tk", "scaling"), gui.PAD, gui.WRAP)\n'
'print(dpi.awareness(), dpi.scale(), root.tk.call("tk", "scaling"), gui.PAD, gui.WRAP, '
'root.winfo_screenwidth())\n'
'root.destroy()\n')
r = subprocess.run([sys.executable, '-c', code], cwd=ROOT, capture_output=True, text=True, timeout=120)
self.assertEqual(r.returncode, 0, r.stderr[-2000:])
awareness, scale, scaling, pad, wrap = r.stdout.split()
awareness, scale, scaling, pad, wrap, width = r.stdout.split()
self.assertGreaterEqual(int(awareness), 1) # 1 system aware, 2 per-monitor aware
self.assertAlmostEqual(float(scaling), float(scale) * 96 / 72, places=6)
# Tk's win/tkWinX.c TkWinDisplayChanged rounds the nominal screen width to whole millimetres.
# Its generic/tkCmds.c ScalingCmd converts that width back to pixels per point, so a 120 DPI display
# can report 120.118 DPI. Keep the exact comparison, accounting for that round trip.
width_mm = int(25.4 * int(width) / (float(scale) * 96) + 0.5)
expected_scaling = 25.4 * int(width) / (72 * width_mm)
self.assertAlmostEqual(float(scaling), expected_scaling, places=6)
self.assertEqual((int(pad), int(wrap)), (round(14 * float(scale)), round(620 * float(scale))))
+7 -4
View File
@@ -271,10 +271,13 @@ def write_if_changed(path, text):
def copy_romfs_patches(version, out):
"""totk.exe loads romfs-patches beside romfs-index.bin (runtime/romfs.c overlay_init). tools/make_romfs_patches.py
writes them into build/<version> only, so a build in another directory ran without the 60 fps overlay (the quick
menus' captured background turned black). Copies them when their manifest differs; romfs-patches-xbox,
romfs-patches-xbox-label and romfs-patches-pc (the same with Xbox or keyboard and mouse button prompts,
make_romfs_patches.py --prompts) the same way when they were made."""
for name in ('romfs-patches', 'romfs-patches-xbox', 'romfs-patches-xbox-label', 'romfs-patches-pc'):
menus' captured background turned black). Copies every romfs-patches* folder of build/<version> that has a
manifest, the same way when it differs: romfs-patches, romfs-patches-xbox, romfs-patches-xbox-label and
romfs-patches-pc (the same with Xbox or keyboard and mouse button prompts, make_romfs_patches.py --prompts) and
the ones of another shape, romfs-patches-<w>x<h> and romfs-patches-pc-<w>x<h> (make_romfs_patches.py --aspect),
which runtime/romfs.c overlay_init needs for a game resolution that is not 16:9."""
names = sorted(p.name for p in (ROOT / 'build' / version).glob('romfs-patches*') if p.is_dir())
for name in names:
src = ROOT / 'build' / version / name
dst = out / name
if src.resolve() == dst.resolve() or not (src / 'manifest.tsv').is_file():
+6 -6
View File
@@ -145,12 +145,12 @@
# the Steam Deck's 1280x800 (16:10), gives the camera's view that shape and lays the HUD out for it. The installer
# prepares the UI layout for fifteen sizes: 2560x1080, 3440x1440, 3840x1600, 5120x2160 (21:9), 3840x1080, 5120x1440
# (32:9), 1280x800, 1680x1050, 1920x1200, 2560x1600 (16:10), 1920x1280, 2160x1440, 2256x1504, 2880x1920 and 3000x2000
# (3:2). Any other size
# gets the camera's view but a 16:9 HUD, stretched over the picture, unless you build its layout with
# tools/make_romfs_patches.py --aspect WxH. Read at start. Default: 1920x1080, or on a primary display of one of those
# shapes the smallest of its sizes at least 1080 high that fits the display (1920x1280 on a 3:2 laptop, 2560x1080 on
# a 21:9 monitor), so the picture fills the screen without black bars; with prompts = xbox or pc it stays 1920x1080,
# the only shape the setup builds those prompts for.
# (3:2). For any other size, or a source build that has not made the layout, the game draws the largest 16:9 size that
# fits inside it (3440x1080 gives 1920x1080) and the present adds bars; build the layout with
# tools/make_romfs_patches.py --aspect WxH to use the full shape. Read at start. Default: 1920x1080, or on a primary
# display of one of those shapes the smallest of its sizes at least 1080 high that fits the display (1920x1280 on a 3:2
# laptop, 2560x1080 on a 21:9 monitor), so the picture fills the screen without black bars; with prompts = xbox or pc it
# stays 1920x1080, the only shape the setup builds those prompts for.
# output_res = 1920x1080
# 3D render scale: the scene's size relative to the game resolution, game (5/6, the game's own 1600x900 at 1080p) or
# a percentage (25 to 400, at most 4096 pixels a side); above 100 supersamples the scene (anti-aliasing). Read at start.