diff --git a/docs/building.md b/docs/building.md index 5be975bc..fd972520 100644 --- a/docs/building.md +++ b/docs/building.md @@ -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-x` once per + size: `make_romfs_patches.py --version --aspect x --out build\\romfs-patches-x` (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: diff --git a/runtime/host.h b/runtime/host.h index 7bcc152a..4d29dd79 100644 --- a/runtime/host.h +++ b/runtime/host.h @@ -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-x 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) diff --git a/runtime/resolution.c b/runtime/resolution.c index 20b73d06..e2af918e 100644 --- a/runtime/resolution.c +++ b/runtime/resolution.c @@ -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-x, 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 --aspect %ux%u --out " + "build//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 x in 1280x720..7680x4320; 1920x1080", o); } diff --git a/runtime/romfs.c b/runtime/romfs.c index 484c6c0d..3a82ad36 100644 --- a/runtime/romfs.c +++ b/runtime/romfs.c @@ -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-x 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); diff --git a/tests/installer_gui_test.py b/tests/installer_gui_test.py index b8ba833b..1b31b13e 100644 --- a/tests/installer_gui_test.py +++ b/tests/installer_gui_test.py @@ -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)))) diff --git a/tools/build_game.py b/tools/build_game.py index 2d3f22a2..7eb8f705 100644 --- a/tools/build_game.py +++ b/tools/build_game.py @@ -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/ 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/ 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-x and romfs-patches-pc-x (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(): diff --git a/totk.ini.example b/totk.ini.example index 4a09a50c..b1530609 100644 --- a/totk.ini.example +++ b/totk.ini.example @@ -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.