diff --git a/recomp/patches-v143.txt b/recomp/patches-v143.txt index 34b5c0ad..e33f165f 100644 --- a/recomp/patches-v143.txt +++ b/recomp/patches-v143.txt @@ -85,6 +85,15 @@ site aspect main b43460 bd406ac0 f81f0fea @page:x10 bd403940 f84107ea # ldr s0 site aspect main 1ff04f4 1e211800 f81f0fea @page:x10 bd403940 f84107ea # fdiv s0, s0, s1 (viewport) site aspect main 253fbb0 1e211800 f81f0fea @page:x10 bd403940 f84107ea # fdiv s0, s0, s1 (viewport) +# Field of view (runtime/resolution.c res_fov_live writes TOTK_FOV / 100 to page +60 and switches the set). The same two +# camera routines as the aspect set load the camera's vertical view angle (radians) a few words before the ratio and +# hand it to sead's perspective projection (+0xa0, then sin / cos / tan of half of it at +0xa4..+0xac). The replacement +# loads the angle as before and multiplies it by the factor on the page; s8 holds the factor because the next +# instruction (fmul s8, s0, s1) overwrites it. Zooms the game makes itself (the bow, the scope) scale with it. +set fov TOTK_FOV_PATCH 0 +site fov main 628c3c bd413e60 f81f0fea @page:x10 bd413e60 bd403d48 1e280800 f84107ea # ldr s0, [x19, #0x13c] (camera update) +site fov main b4342c bd4066c0 f81f0fea @page:x10 bd4066c0 bd403d48 1e280800 f84107ea # ldr s0, [x22, #0x64] (camera setup) + # The game's zstd decoder (BSD zstd, statically linked into main) through the host's libzstd (runtime/ov_zstd.c): # every call of ZSTD_decompressMultiFrame (main+0x3a1f0: dctx, dst, capacity, src, size, dict, dict size, ddict) and of # its wrapper ZSTD_decompress_usingDDict (main+0x3a1e0, which tail-branches to it) goes to a host function on the patch diff --git a/recomp/patches.py b/recomp/patches.py index a54b2a0a..ecc12e7e 100644 --- a/recomp/patches.py +++ b/recomp/patches.py @@ -13,7 +13,8 @@ the generator), each an instruction word (hex) or `@page:x`, wh encoded for the site's address. The patch page is the first 4 KiB page after main's image (layout.py leaves the rest of the 2 MiB-aligned module slot free); the runtime commits it and owns its contents. Words in use, by byte offset: +0..15 the frame-rate step (runtime/frame_rate.c), +16..55 the output, swapchain and scene sizes -(runtime/resolution.c res_init), +56..59 the camera's aspect ratio (runtime/resolution.c res_init, set aspect). A new +(runtime/resolution.c res_init), +56..59 the camera's aspect ratio (runtime/resolution.c res_init, set aspect), +60..63 +the field-of-view factor (runtime/resolution.c res_fov_live, set fov). A new set takes words outside these. The replacement words are lifted at the site's address in place of the original instruction, and the generated C reads diff --git a/runtime/cfg.c b/runtime/cfg.c index 2f989519..cd649348 100644 --- a/runtime/cfg.c +++ b/runtime/cfg.c @@ -37,7 +37,7 @@ static const char *const known[] = { "BIND_SKIP", "BIND_STATS", "BIND_UP", "BIND_X", "BIND_Y", "BIND_ZL", "BIND_ZR", "BLOCK_VIEWS_3D", "CLOTH_REALTIME", "CORE_DIAG", "CRIT", "CRIT_OUT", "DESC_TEMPLATE", "DEVICE_PROFILE", "DUMP", "DUMP_BUF", "DUMP_DIR", "DUMP_LOG", "EXEFS", "FEEDBACK", "FIX_C0", "FIX_ZERO", "FLIGHT", "FLIGHT_AT", "FLIGHT_DIR", "FLIGHT_FRAMES", "FLIGHT_SPIKE_MS", - "FLIGHT_THUMBS", "FPS60", "FPS_LIMIT", "FREEZE_IDLE", "FREE_CORES", "FULLSCREEN", "GPL", "GPL_DRAW_BUILD", "GPU", + "FLIGHT_THUMBS", "FOV", "FOV_PATCH", "FPS60", "FPS_LIMIT", "FREEZE_IDLE", "FREE_CORES", "FULLSCREEN", "GPL", "GPL_DRAW_BUILD", "GPU", "GPU_INDEX", "GPU_NAME", "HIGHFPS_FIX", "INPUT", "INPUT_RECORD", "INPUT_SCRIPT", "LANG", "LIB_PREBUILD", "LIB_PREBUILD_KEEP", "LIB_PREBUILD_THREADS", "LOCALE", "LOD_GUARD", "MEMORY", "MENU_LANG", "MENU_TEST", "MENU_TEST_DIR", "MENU_TEST_SET", "MINIMAL_LAYOUT", "MIRROR_GAP", "MOTION", "MOUSE_SENS", "MOVIE_HOST", "MOVIE_PACE", @@ -59,7 +59,7 @@ static const struct { const char *key, *section; } sections[] = { {"REALTIME", "frame rate"}, {"CLOTH_REALTIME", "frame rate"}, {"HIGHFPS_FIX", "frame rate"}, {"FULLSCREEN", "display"}, {"WINDOW_SIZE", "display"}, {"PERF_OVERLAY", "display"}, {"VK_PRESENT", "display"}, {"GPU_INDEX", "display"}, {"OUTPUT_RES", "display"}, {"RENDER_SCALE", "display"}, {"UPSCALER", "display"}, - {"SHARPNESS", "display"}, {"ASPECT", "display"}, + {"SHARPNESS", "display"}, {"ASPECT", "display"}, {"FOV", "display"}, {"DEVICE_PROFILE", "display"}, {"ASSUME_FOCUS", "display"}, {"MENU_LANG", "language"}, {"LANG", "language"}, {"OPERATION_MODE", "language"}, {"VOLUME", "audio"}, @@ -95,7 +95,7 @@ static const CfgMeta metas[] = { {"PERF_OVERLAY", "off", "off|fps|full", LIVE}, {"OUTPUT_RES", "1920x1080", NULL, RESTART}, {"RENDER_SCALE", "game", "game|50|67|75|100|125|150|200", RESTART}, {"UPSCALER", "fsr", "fsr|bilinear", LIVE}, {"SHARPNESS", "80", "0..100", LIVE}, - {"ASPECT", "fit", "fit|stretch", LIVE}, + {"ASPECT", "fit", "fit|stretch", LIVE}, {"FOV", "100", "70..140", LIVE}, {"DEVICE_PROFILE", "auto", "auto|desktop|deck", RESTART}, // Game {"FPS_LIMIT", "60", "30|40|45|60|90|120|144|display", LIVE}, {"FPS60", "1", "0|1", LIVE}, diff --git a/runtime/gfx_present.c b/runtime/gfx_present.c index e686e08f..fdd60e28 100644 --- a/runtime/gfx_present.c +++ b/runtime/gfx_present.c @@ -214,6 +214,7 @@ static void window_settings_live(void) { unsigned v = cfg_version(); if (started && v == seen) return; seen = v; + res_fov_live(); const char *e = cfg_value("TOTK_VK_PRESENT"); if (!started || strncmp(e, present, sizeof present - 1)) { snprintf(present, sizeof present, "%s", e); diff --git a/runtime/host.h b/runtime/host.h index 452ac8e4..f30cc97b 100644 --- a/runtime/host.h +++ b/runtime/host.h @@ -253,6 +253,7 @@ void res_sizes(unsigned out[2], unsigned scene[2]); // the output and scene 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 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) void rt_patches_init(void); // after ldr_load: switches from the environment, the patch // page committed; logs the sets diff --git a/runtime/resolution.c b/runtime/resolution.c index 6bf0eccd..1d8e2355 100644 --- a/runtime/resolution.c +++ b/runtime/resolution.c @@ -12,7 +12,8 @@ // // Patch page: +16 the scene size {w, h} as floats, +32 the output size and +48 the swapchain size as {w, h} in one // 64-bit word, +40 the renderer (1.2.1) or display configuration (1.4.3) the patched code stores there. -// +56 the camera's aspect ratio as a float when the output is not 16:9 (set aspect). +// +56 the camera's aspect ratio as a float when the output is not 16:9 (set aspect), +60 the field-of-view factor +// (set fov, res_fov_live). // 1.4.3 scales the scene it reads by output width / 1920 (a 2560x1440 output renders its 1600x900 scene at 2128x1200; // MacNativeGames measured the same), so its page holds the wanted size divided by that factor and the game's 5/6 needs // no scene patch. 1.2.1 renders the size it reads (1600x900 on a 2560x1440 output): its page holds the wanted size, and @@ -253,6 +254,29 @@ int res_wants_wide_overlay(const unsigned out[2]) { return !res_is_16x9(out[0], out[1]) && rt_patch_set("aspect") >= 0; } +// Field of view (TOTK_FOV, percent of the game's own, 70..140, live): the camera's vertical view angle times the +// factor on page +60 (recomp/patches-v143.txt, set fov). The horizontal angle follows through the aspect ratio. 100 +// switches the set off, so the camera code is the game's own. Runs on a settings change (gfx_present.c +// window_settings_live), the first time at the first present. +#define FOV_MIN 70 +#define FOV_MAX 140 +void res_fov_live(void) { + static int set = -2, shown = 100; + if (set == -2) set = rt_patch_set("fov"); + int pct = cfg_int("TOTK_FOV"); + pct = pct < FOV_MIN ? FOV_MIN : pct > FOV_MAX ? FOV_MAX : pct; + if (pct == shown) return; + shown = pct; + if (set < 0) { + rt_log("resolution: this game version has no field-of-view patch; TOTK_FOV=%d does nothing", pct); + return; + } + float k = pct / 100.0f; + memcpy((uint8_t *)rt_patch_page() + 60, &k, sizeof k); // before the switch: a site that sees it on reads k + rt_patch_switch(set, pct != 100); + rt_log("resolution: field of view %d%% of the game's", pct); +} + void res_wanted(unsigned out[2]) { decide(); out[0] = R.ow, out[1] = R.oh; diff --git a/runtime/ui/menu.cpp b/runtime/ui/menu.cpp index b6c08720..4098d415 100644 --- a/runtime/ui/menu.cpp +++ b/runtime/ui/menu.cpp @@ -544,6 +544,7 @@ static void tab_screen(float scale) { opt_slider("TOTK_SHARPNESS", UI_MENU_SHARPNESS, 0, 100, UI_MENU_SHARPNESS_DESC, 5, "%.0f %%"); static const UiTextId aspect[] = {UI_MENU_ASPECT_FIT, UI_MENU_ASPECT_STRETCH}; opt_choice("TOTK_ASPECT", UI_MENU_ASPECT, aspect, 2, UI_MENU_ASPECT_DESC); + opt_slider("TOTK_FOV", UI_MENU_FOV, 70, 140, UI_MENU_FOV_DESC, 5, "%.0f %%"); opt_end(); } diff --git a/runtime/ui_text.c b/runtime/ui_text.c index a8ac7155..06939827 100644 --- a/runtime/ui_text.c +++ b/runtime/ui_text.c @@ -67,6 +67,8 @@ static const char *const text_en[UI_TEXT_COUNT] = { [UI_MENU_ASPECT_DESC] = "When the window's shape differs from the game resolution's (a 16:9 picture on a 21:9 " "screen): keep the picture's shape with black bars, or stretch it over the window.", [UI_MENU_ASPECT_FIT] = "Black bars", [UI_MENU_ASPECT_STRETCH] = "Stretch", + [UI_MENU_FOV] = "Field of view", + [UI_MENU_FOV_DESC] = "How much of the world the camera shows, in percent of the game's own. Game version 1.4.3 only.", [UI_MENU_SHARPNESS] = "FSR sharpness", [UI_MENU_SHARPNESS_DESC] = "Sharpening after FSR scaling; 0 turns it off.", @@ -312,6 +314,8 @@ static const char *const text_ru[UI_TEXT_COUNT] = { [UI_MENU_ASPECT_DESC] = "Когда форма окна отличается от разрешения игры (картинка 16:9 на экране 21:9): сохранить " "форму картинки с чёрными полосами или растянуть её на всё окно.", [UI_MENU_ASPECT_FIT] = "Чёрные полосы", [UI_MENU_ASPECT_STRETCH] = "Растянуть", + [UI_MENU_FOV] = "Поле зрения", + [UI_MENU_FOV_DESC] = "Сколько мира показывает камера, в процентах от игрового. Только для версии игры 1.4.3.", [UI_MENU_SHARPNESS] = "Резкость FSR", [UI_MENU_SHARPNESS_DESC] = "Повышение резкости после масштабирования FSR; 0 выключает его.", diff --git a/runtime/ui_text.h b/runtime/ui_text.h index b9e95194..3b25c07a 100644 --- a/runtime/ui_text.h +++ b/runtime/ui_text.h @@ -36,6 +36,7 @@ typedef enum { UI_MENU_RENDER_SCALE, UI_MENU_RENDER_SCALE_DESC, UI_MENU_RENDER_SCALE_GAME, UI_MENU_UPSCALER, UI_MENU_UPSCALER_DESC, UI_MENU_UPSCALER_FSR, UI_MENU_UPSCALER_BILINEAR, UI_MENU_ASPECT, UI_MENU_ASPECT_DESC, UI_MENU_ASPECT_FIT, UI_MENU_ASPECT_STRETCH, + UI_MENU_FOV, UI_MENU_FOV_DESC, UI_MENU_SHARPNESS, UI_MENU_SHARPNESS_DESC, // Game diff --git a/totk.ini.example b/totk.ini.example index 2b8c5d7d..025e658a 100644 --- a/totk.ini.example +++ b/totk.ini.example @@ -140,6 +140,9 @@ # window is no longer stretched as it used to be; stretch fills the window. Changes while the game runs take effect at # once. # aspect = fit +# Field of view, in percent of the game's own: 70 to 140, 100 (the default) leaves the camera as it is. Higher shows +# more of the world around Link. Game version 1.4.3 only. Changes while the game runs take effect at once. +# fov = 100 [language] # Language: a Windows locale such as de-DE, or a Switch code (en-US, ja, zh-Hant, ...). Default: the Windows locale.