From b1cbbb93a6e46d43de13b043d776709be8a32861 Mon Sep 17 00:00:00 2001 From: Valiantsin Dzerakh Date: Mon, 26 Oct 2026 20:39:13 +0300 Subject: [PATCH] Make the frame limit a setting: 30, 60, 120, 144 or the monitor's refresh rate TOTK_FPS_LIMIT (fps_limit in totk.ini, live, menu row on the Game tab) replaces the 30/60 choice of TOTK_FPS60. The pacer holds frames to the limit in nanoseconds instead of 60 Hz ticks; the real-time step has no lower bound, so game speed stays 1.000 above 60. `display` follows the exact refresh rate of the window's monitor (QueryDisplayConfig), measured again when the window moves or the display mode changes. A limit of 30 switches the patch set fps60 off as before; unset, the older fps60 = 0 still means 30. Above 60 needs the real-time step and is marked experimental. The vsync event stays at 60 Hz: on 1.4.3 the title runs at 144 fps with it, so the game does not wait for it each frame. Field on machine A: 69-88 fps, CPU-bound (GPU 3.4 ms per frame). Co-Authored-By: Claude Opus 5.5 --- README.md | 4 +-- runtime/cfg.c | 7 +++-- runtime/frame_rate.c | 67 ++++++++++++++++++++++++++++++++----------- runtime/gfx.h | 1 + runtime/gfx_window.c | 54 ++++++++++++++++++++++++++++++++++ runtime/host.h | 4 +-- runtime/nvn_api_obj.c | 9 +++--- runtime/ui/menu.cpp | 21 ++++++++++++-- runtime/ui/menu.h | 1 + runtime/ui_text.c | 15 +++++++--- runtime/ui_text.h | 3 +- totk.ini.example | 7 +++-- 12 files changed, 155 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index 40768b0e..d1b2951f 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ To report a problem, open an issue and follow [CONTRIBUTING.md](CONTRIBUTING.md) ## Features - Native code, not emulation: the 1.2.1 `main`, `sdk` and `subsdk0` modules are compiled into `totk.exe`. -- 60 fps with the game running at real-time speed, using MacNativeGames' frame-rate patches (`TOTK_FPS60=0` and `TOTK_REALTIME=0` switch them off). +- 60 fps with the game running at real-time speed, using MacNativeGames' frame-rate patches; `TOTK_FPS_LIMIT` sets the limit (30, 60, 120, 144 or `display`; above 60 is experimental) and `TOTK_REALTIME=0` switches the real-time step off. - Keyboard, mouse and the first gamepad, merged into one controller, with the mouse on the camera and every button remappable: [docs/controls.md](docs/controls.md). - Rumble with adjustable strength, and motion controls on gamepads that have a gyro. - Sound through the game's own audio renderer, including voice. @@ -113,7 +113,7 @@ From the repository root, in PowerShell: `build\v121\totk.exe --selftest` checks the build without game files. -Settings live in `totk.ini` next to `totk.exe`; copy [totk.ini.example](totk.ini.example), which lists them, and edit it. A `TOTK_*` environment variable of the same name overrides the file (`TOTK_FPS60=0` beats `fps60 = 1`). Saves go to `build\profile`, created on first use. Everything the build writes stays under `build\` and `generated\`, which git ignores. +Settings live in `totk.ini` next to `totk.exe`; copy [totk.ini.example](totk.ini.example), which lists them, and edit it. A `TOTK_*` environment variable of the same name overrides the file (`TOTK_FPS_LIMIT=30` beats `fps_limit = 60`). Saves go to `build\profile`, created on first use. Everything the build writes stays under `build\` and `generated\`, which git ignores. ## Contributing diff --git a/runtime/cfg.c b/runtime/cfg.c index bc1e8d8e..328a8443 100644 --- a/runtime/cfg.c +++ b/runtime/cfg.c @@ -35,7 +35,7 @@ static const char *const known[] = { "BIND_PLUS", "BIND_R", "BIND_RCLICK", "BIND_RIGHT", "BIND_SKIP", "BIND_STATS", "BIND_UP", "BIND_X", "BIND_Y", "BIND_ZL", "BIND_ZR", "CLOTH_REALTIME", "CORE_DIAG", "DESC_TEMPLATE", "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", "FREEZE_IDLE", "FREE_CORES", "FULLSCREEN", "GPL", "GPL_DRAW_BUILD", "GPU", + "FLIGHT_THUMBS", "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", @@ -52,7 +52,7 @@ static const char *const known[] = { // The totk.ini section a key cfg_set may write goes to when the file lacks it (totk.ini.example's sections). static const struct { const char *key, *section; } sections[] = { - {"FPS60", "frame rate"}, + {"FPS_LIMIT", "frame rate"}, {"FPS60", "frame rate"}, {"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"}, @@ -82,7 +82,8 @@ static const CfgMeta metas[] = { {"VK_PRESENT", "mailbox", "mailbox|fifo|immediate", LIVE}, {"GPU_INDEX", "", NULL, RESTART}, {"PERF_OVERLAY", "off", "off|fps|full", LIVE}, // Game - {"FPS60", "1", "0|1", LIVE}, {"REALTIME", "1", "0|1", RESTART}, {"CLOTH_REALTIME", "1", "0|1", RESTART}, + {"FPS_LIMIT", "60", "30|60|120|144|display", LIVE}, {"FPS60", "1", "0|1", LIVE}, + {"REALTIME", "1", "0|1", RESTART}, {"CLOTH_REALTIME", "1", "0|1", RESTART}, {"HIGHFPS_FIX", "1", "0|1", RESTART}, {"LANG", "", "ja|en-US|fr|de|it|es|zh-CN|ko|nl|pt|ru|zh-TW|en-GB|fr-CA|es-419|zh-Hans|zh-Hant|pt-BR", RESTART}, {"OPERATION_MODE", "docked", "docked|handheld", RESTART}, diff --git a/runtime/frame_rate.c b/runtime/frame_rate.c index 02c52c11..b5d57c88 100644 --- a/runtime/frame_rate.c +++ b/runtime/frame_rate.c @@ -1,7 +1,7 @@ // Adapted from MacNativeGames games/totk/runtime/game_patches.c @ ebe621d (MIT, Copyright (c) 2026 MacNativeGames // contributors): runtime_frame_step_update (2338bb0: no 1/120 s floor) and the speed survey's player chain // (world_survey.c player_actor). -// Frame rate: 60 fps and the real-time frame step, the host half of the patch sets fps60, realtime and cloth +// Frame rate: the frame limit and the real-time frame step, the host half of the patch sets fps60, realtime and cloth // (build tables patches-v121.txt, patches-v143.txt; docs/research/macnativegames.md section 6.2). // // TotK's adaptive present-interval controller (main+0x8f26c8) turns the main thread's measured work into a number of @@ -12,11 +12,13 @@ // instead: +0 ratio = seconds * 30, +4 seconds (1.4.3: +8 interval = seconds * 60, the producer's nominal interval // before its half-step coefficient), the moving average of the last 5 display intervals, at most 1/15 s // (slower frames slow the game down, as on the console), no lower bound, so a higher frame-rate cap only changes the -// pacer (nvn_api_obj.c VSYNC_HZ). The set cloth gives hair and cloth the same clock and needs realtime. +// pacer (frame_step_cap_ns, TOTK_FPS_LIMIT). The set cloth gives hair and cloth the same clock and needs realtime. // // The sample is the display time the pacer gives each present (nvnQueuePresentTexture), so the step follows the // frames as shown, pacing waits included. With the step on, the pacer ignores the game's interval and holds a frame -// only to the frame-rate cap (nvn_api_obj.c present_period): the controller's 2 or 3 vsyncs would only add latency. +// only to the frame limit (nvn_api_obj.c present_period): the controller's 2 or 3 vsyncs would only add latency. The +// vsync event stays at 60 Hz whatever the limit: the game does not wait for it each frame (1.4.3 shows its title at 144 +// fps with the event at 60 Hz). // One 64-bit and one 32-bit store per present; the guest reads the floats on its own threads, and each stays finite // and in range whichever store it sees. // @@ -31,6 +33,7 @@ #include #include "cfg.h" +#include "gfx.h" #include "host.h" #include "layout.h" #include "platform/platform.h" @@ -56,6 +59,8 @@ static void step_store(float seconds) { atomic_store_explicit(step_interval, iv, memory_order_release); } +static void frame_limit_live(void); + void frame_step_init(void) { int fps60 = rt_patch_set("fps60"), realtime = rt_patch_set("realtime"), cloth = rt_patch_set("cloth"); if (realtime < 0) { @@ -71,32 +76,60 @@ void frame_step_init(void) { step_interval = (_Atomic uint32_t *)((uint8_t *)rt_patch_page() + 8); step_store((float)STEP_FIRST_S); } - rt_log("frame rate: present interval %s, %s", rt_patch_enabled(fps60) ? "1..3 (60 fps)" : "2..3 (shipping 30 fps)", + frame_limit_live(); // TOTK_FPS_LIMIT decides the set fps60 from the start + rt_log("frame rate: present interval %s, %s", rt_patch_enabled(fps60) ? "1..3 (above 30 fps)" : "2..3 (shipping 30 fps)", step_word ? "real-time step (5-frame average of display intervals, at most 1/15 s)" : "whole-vsync steps"); } int frame_step_realtime(void) { return step_word != NULL; } -// The frame limit (menu: 30 or 60): TOTK_FPS60 switches the set fps60 while the game runs; the controller reads its -// minimum interval from the patched sites each frame. With the real-time step the pacer holds frames to the cap. +// The frame limit (menu, TOTK_FPS_LIMIT, live): 30, 60, 120, 144, any whole rate from 30 to 360, or display (the +// refresh rate of the window's monitor). Unset, the older TOTK_FPS60=0 still means 30. A limit of 30 switches the set +// fps60 off (the shipping minimum interval 2), every other limit switches it on; the controller reads its minimum +// interval from the patched sites each frame. With the real-time step the pacer holds frames to the limit; above 60 +// only the pacer changes, as the step has no lower bound. Without it the game steps whole 60 Hz vsyncs and the pacer +// follows the game's interval, so the limit stops at 60. +#define LIMIT_MIN_HZ 30 +#define LIMIT_MAX_HZ 360 static int fps60_set = -2; -static unsigned fps60_seen; +static unsigned limit_seen; +static int limit_read; +static int limit_hz = -1; // 0: display; -1 before the first read + +static int limit_parse(void) { + const char *e = cfg_get("TOTK_FPS_LIMIT"), *old = cfg_get("TOTK_FPS60"); + if (!e || !*e) return old && !strcmp(old, "0") ? 30 : 60; + if (!strcmp(e, "display")) return 0; + char *end; + long n = strtol(e, &end, 10); + if (!*end && n >= LIMIT_MIN_HZ && n <= LIMIT_MAX_HZ) return (int)n; + rt_log("frame rate: TOTK_FPS_LIMIT=%s is not 30..360 or display; 60", e); + return 60; +} static void frame_limit_live(void) { unsigned v = cfg_version(); - if (v == fps60_seen) return; - fps60_seen = v; + if (limit_read && v == limit_seen) return; + limit_read = 1; + limit_seen = v; + int hz = limit_parse(); + if (hz == limit_hz) return; + limit_hz = hz; if (fps60_set == -2) fps60_set = rt_patch_set("fps60"); - if (fps60_set < 0) return; - int on = cfg_bool("TOTK_FPS60"); - if (on == rt_patch_enabled(fps60_set)) return; - rt_patch_switch(fps60_set, on); - rt_log("frame rate: limit %d fps (TOTK_FPS60=%d)", on ? 60 : 30, on); + if (fps60_set >= 0) rt_patch_switch(fps60_set, hz != 30); + if ((hz > 60 || hz == 0) && !step_word) + rt_log("frame rate: limits above 60 need the real-time step (TOTK_REALTIME=1); 60 fps"); + else if (hz) rt_log("frame rate: limit %d fps", hz); + else if (gfx_window_refresh_hz() > 0) rt_log("frame rate: limit at the monitor's refresh rate (%.3f Hz now)", gfx_window_refresh_hz()); + else rt_log("frame rate: limit at the monitor's refresh rate (60 until the window measures it)"); } -int frame_step_cap_ticks(void) { - if (fps60_set == -2) fps60_set = rt_patch_set("fps60"); - return fps60_set < 0 || rt_patch_enabled(fps60_set) ? 1 : 2; +uint64_t frame_step_cap_ns(void) { + frame_limit_live(); + double hz = limit_hz ? limit_hz : gfx_window_refresh_hz(); + if (hz < LIMIT_MIN_HZ) hz = 60; // display rate unknown (no window yet) + if (hz > LIMIT_MAX_HZ) hz = LIMIT_MAX_HZ; + return (uint64_t)(1e9 / hz + 0.5); } // ---- TOTK_TRACE=perf speed lines diff --git a/runtime/gfx.h b/runtime/gfx.h index 9d54c916..2ef5c446 100644 --- a/runtime/gfx.h +++ b/runtime/gfx.h @@ -22,6 +22,7 @@ void gfx_window_start(void); // window thread, Vul void gfx_vsync_bind(uint64_t system_event); // nn::vi vsync event; signalled at 60 Hz uint64_t gfx_vsync_ticks(void); // ticks since start uint64_t gfx_vsync_time_ns(uint64_t tick); // kern_now_ns() time of a tick (pacing) +double gfx_window_refresh_hz(void); // refresh rate of the window's monitor; 0 unknown int gfx_window_focused(void); // ---- shader service client (gfx_shader.c: T4) diff --git a/runtime/gfx_window.c b/runtime/gfx_window.c index 9dfe8cab..3ba52f1e 100644 --- a/runtime/gfx_window.c +++ b/runtime/gfx_window.c @@ -288,6 +288,52 @@ void gfx_window_request_close(void) { if (g_hwnd) PostMessageW(g_hwnd, WM_CLOSE, 0, 0); } +// ---- refresh rate of the window's monitor (TOTK_FPS_LIMIT=display). The window thread measures it when the window +// opens, lands on another monitor or the display mode changes; readers take the stored value. QueryDisplayConfig gives +// the exact rational rate (59.94, 143.998); EnumDisplaySettings' whole hertz is the fallback. +static HMONITOR g_rate_mon; +static volatile LONG g_rate_mhz; // millihertz, 0 unknown + +static double monitor_rate_hz(HMONITOR mon) { + MONITORINFOEXW mi = {.cbSize = sizeof mi}; + if (!GetMonitorInfoW(mon, (MONITORINFO *)&mi)) return 0; + double hz = 0; + UINT32 np = 0, nm = 0; + if (GetDisplayConfigBufferSizes(QDC_ONLY_ACTIVE_PATHS, &np, &nm) == ERROR_SUCCESS && np && nm) { + DISPLAYCONFIG_PATH_INFO *paths = calloc(np, sizeof *paths); + DISPLAYCONFIG_MODE_INFO *modes = calloc(nm, sizeof *modes); + if (paths && modes && QueryDisplayConfig(QDC_ONLY_ACTIVE_PATHS, &np, paths, &nm, modes, NULL) == ERROR_SUCCESS) + for (UINT32 i = 0; i < np && !hz; i++) { + DISPLAYCONFIG_SOURCE_DEVICE_NAME src = {.header = {.type = DISPLAYCONFIG_DEVICE_INFO_GET_SOURCE_NAME, + .size = sizeof src, + .adapterId = paths[i].sourceInfo.adapterId, + .id = paths[i].sourceInfo.id}}; + DISPLAYCONFIG_RATIONAL r = paths[i].targetInfo.refreshRate; + if (DisplayConfigGetDeviceInfo(&src.header) == ERROR_SUCCESS && !wcscmp(src.viewGdiDeviceName, mi.szDevice) && + r.Denominator) + hz = (double)r.Numerator / r.Denominator; + } + free(paths); + free(modes); + } + DEVMODEW dm = {.dmSize = sizeof dm}; + if (!hz && EnumDisplaySettingsW(mi.szDevice, ENUM_CURRENT_SETTINGS, &dm) && dm.dmDisplayFrequency > 1) + hz = dm.dmDisplayFrequency; // 0 and 1 mean the hardware default + return hz; +} + +// Window thread. force: the display mode changed, measure even on the same monitor. +static void refresh_rate_update(HWND h, int force) { + HMONITOR mon = MonitorFromWindow(h, MONITOR_DEFAULTTOPRIMARY); + if (!force && mon == g_rate_mon) return; + g_rate_mon = mon; + double hz = monitor_rate_hz(mon); + LONG mhz = (LONG)(hz * 1000 + 0.5); + if (InterlockedExchange(&g_rate_mhz, mhz) != mhz) rt_log("gfx: monitor refresh rate %.3f Hz", hz); +} + +double gfx_window_refresh_hz(void) { return InterlockedCompareExchange(&g_rate_mhz, 0, 0) / 1000.0; } + int gfx_window_monitor_size(int *w, int *h) { MONITORINFO mi = {sizeof mi}; if (!g_hwnd || !GetMonitorInfoW(MonitorFromWindow(g_hwnd, MONITOR_DEFAULTTOPRIMARY), &mi)) return 0; @@ -316,7 +362,14 @@ static LRESULT CALLBACK wnd_proc(HWND h, UINT m, WPARAM w, LPARAM l) { return 0; case WM_SIZE: if (w != SIZE_MINIMIZED) InterlockedExchange(&g_dirty, 1); + refresh_rate_update(h, 0); return 0; + case WM_EXITSIZEMOVE: // dragged onto another monitor + refresh_rate_update(h, 0); + break; + case WM_DISPLAYCHANGE: + refresh_rate_update(h, 1); + break; case WM_ACTIVATEAPP: { int in = w != 0; InterlockedExchange(&g_focused, in); @@ -367,6 +420,7 @@ static DWORD WINAPI window_main(void *arg) { ShowWindow(g_hwnd, cfg_get("TOTK_ASSUME_FOCUS") ? SW_SHOWNOACTIVATE : SW_SHOW); // scripted runs leave focus alone if (!background && cfg_fullscreen()) toggle_fullscreen(g_hwnd); note_applied(); + refresh_rate_update(g_hwnd, 1); } SetEvent(g_wnd_ready); if (g_wnd_failed) return 1; diff --git a/runtime/host.h b/runtime/host.h index dd75a3d7..ff2e9cb3 100644 --- a/runtime/host.h +++ b/runtime/host.h @@ -229,8 +229,8 @@ void rt_patch_switch(int set, int on); // at run time (live void *rt_patch_page(void); // the page the patched code reads (NULL without the table) void frame_step_init(void); // after rt_patches_init: the real-time step's first value int frame_step_realtime(void); // the real-time step is on: presents ignore the interval -int frame_step_cap_ticks(void); // with the real-time step: 60 Hz ticks per frame at most - // (1 = 60 fps, 2 = 30 fps; TOTK_FPS60, live) +uint64_t frame_step_cap_ns(void); // with the real-time step: the shortest frame in ns + // (TOTK_FPS_LIMIT, live) void frame_step_present(uint64_t display_ns, int interval); // nvnQueuePresentTexture: the frame's display time and // present interval (60 Hz ticks) // ---- boot (boot.c T6, main.c T1) diff --git a/runtime/nvn_api_obj.c b/runtime/nvn_api_obj.c index 17a06e4e..a21fe3b7 100644 --- a/runtime/nvn_api_obj.c +++ b/runtime/nvn_api_obj.c @@ -633,13 +633,12 @@ NVN_API(nvnWindowSetCrop) { // ---------- Present pacing // The vsync thread ticks at a fixed 60 Hz whatever the monitor does, so one game frame lasts `interval` ticks. With // the real-time frame step (frame_rate.c) game speed does not depend on the interval, so a frame is shown when it is -// ready, at most at the frame limit (60 or 30 per second): holding it to the 2nd or 3rd tick would only add latency -// and 50 ms frames. +// ready, at most at the frame limit (TOTK_FPS_LIMIT: 30 to 360 per second or the monitor's rate): holding it to the +// 2nd or 3rd tick would only add latency and 50 ms frames. #define VSYNC_HZ 60ull static uint64_t present_period(const win_t *o) { - uint64_t ticks = frame_step_realtime() ? (uint64_t)frame_step_cap_ticks() - : o->interval > 0 ? (uint64_t)o->interval : 1ull; - return ticks * 1000000000ull / VSYNC_HZ; + if (frame_step_realtime()) return frame_step_cap_ns(); + return (o->interval > 0 ? (uint64_t)o->interval : 1ull) * 1000000000ull / VSYNC_HZ; } // MacNativeGames nvn_pace.h: the present slot is the previous slot plus one period. Early: wait for the slot. Late by diff --git a/runtime/ui/menu.cpp b/runtime/ui/menu.cpp index 4ca251d5..cc896b76 100644 --- a/runtime/ui/menu.cpp +++ b/runtime/ui/menu.cpp @@ -435,6 +435,24 @@ static void row_game_lang(void) { opt_choice_list("TOTK_LANG", UI_MENU_GAME_LANG, vals, names, N, UI_MENU_GAME_LANG_DESC, cur); } +// The frame limit (frame_rate.c): unset, the older fps60 = 0 still means 30. The monitor choice shows the rate it gives. +static void row_fps_limit() { + static const char *const vals[] = {"30", "60", "120", "144", "display"}; + static const UiTextId ids[] = {UI_MENU_FPS_30, UI_MENU_FPS_60, UI_MENU_FPS_120, UI_MENU_FPS_144, UI_MENU_FPS_DISPLAY}; + enum { N = sizeof vals / sizeof *vals }; + const char *names[N]; + for (int i = 0; i < N; i++) names[i] = menu_text(ids[i]); + static char display[64]; + double hz = gfx_window_refresh_hz(); + if (hz > 0) { + snprintf(display, sizeof display, menu_text(UI_MENU_FPS_DISPLAY_HZ), hz); + names[N - 1] = display; + } + const char *set = cfg_get("TOTK_FPS_LIMIT"), *old = cfg_get("TOTK_FPS60"); + int cur = (!set || !*set) && old && !strcmp(old, "0") ? 0 : -1; + opt_choice_list("TOTK_FPS_LIMIT", UI_MENU_FPS_LIMIT, vals, names, N, UI_MENU_FPS_LIMIT_DESC, cur); +} + // ---- the tabs static void tab_screen(float scale) { opt_begin("##screen", scale); @@ -450,8 +468,7 @@ static void tab_screen(float scale) { static void tab_game(float scale) { opt_begin("##game", scale); - static const UiTextId fps[] = {UI_MENU_FPS_30, UI_MENU_FPS_60}; // values 0|1 - opt_choice("TOTK_FPS60", UI_MENU_FPS60, fps, 2, UI_MENU_FPS60_DESC); + row_fps_limit(); opt_toggle("TOTK_REALTIME", UI_MENU_REALTIME, UI_MENU_REALTIME_DESC); opt_toggle("TOTK_CLOTH_REALTIME", UI_MENU_CLOTH_REALTIME, UI_MENU_CLOTH_REALTIME_DESC); opt_toggle("TOTK_HIGHFPS_FIX", UI_MENU_HIGHFPS_FIX, UI_MENU_HIGHFPS_FIX_DESC); diff --git a/runtime/ui/menu.h b/runtime/ui/menu.h index 05ce9bf5..a4343d50 100644 --- a/runtime/ui/menu.h +++ b/runtime/ui/menu.h @@ -56,6 +56,7 @@ void menu_vk_release(void); // before the device goes away (gfx_wi void gfx_window_apply_settings(void); // TOTK_FULLSCREEN or TOTK_WINDOW_SIZE changed: the window follows void gfx_window_request_close(void); // as the window's close button: the process ends int gfx_window_monitor_size(int *w, int *h); // pixels of the monitor the window is on; 0 when unknown +double gfx_window_refresh_hz(void); // its refresh rate (TOTK_FPS_LIMIT=display); 0 when unknown #ifdef __cplusplus } diff --git a/runtime/ui_text.c b/runtime/ui_text.c index 051ad2a8..2ac4ef66 100644 --- a/runtime/ui_text.c +++ b/runtime/ui_text.c @@ -48,8 +48,12 @@ static const char *const text_en[UI_TEXT_COUNT] = { // printf formats of the overlay line: frame rate; frame rate, mean and longest frame time in ms [UI_PERF_LINE_FPS] = "%.0f fps", [UI_PERF_LINE_FULL] = "%.0f fps %.1f ms max %.1f ms", - [UI_MENU_FPS60] = "Frame rate", [UI_MENU_FPS60_DESC] = "Runs the game at 60 frames per second instead of 30.", - [UI_MENU_FPS_60] = "60 FPS", [UI_MENU_FPS_30] = "30 FPS", + [UI_MENU_FPS_LIMIT] = "Frame rate limit", + [UI_MENU_FPS_LIMIT_DESC] = "The most frames per second the game draws. Above 60 is experimental and needs Game speed " + "follows the clock.", + [UI_MENU_FPS_30] = "30 FPS", [UI_MENU_FPS_60] = "60 FPS", [UI_MENU_FPS_120] = "120 FPS", [UI_MENU_FPS_144] = "144 FPS", + // the monitor's refresh rate; printf format with the rate in Hz when it is known + [UI_MENU_FPS_DISPLAY] = "Monitor rate", [UI_MENU_FPS_DISPLAY_HZ] = "Monitor rate (%.0f Hz)", [UI_MENU_REALTIME] = "Game speed follows the clock", [UI_MENU_REALTIME_DESC] = "Steps the game by real time, so a slow frame does not slow the game down.", [UI_MENU_CLOTH_REALTIME] = "Cloth on the clock", @@ -184,8 +188,11 @@ static const char *const text_ru[UI_TEXT_COUNT] = { [UI_MENU_PERF_OFF] = "Выкл.", [UI_MENU_PERF_FPS] = "FPS", [UI_MENU_PERF_FULL] = "Полный", [UI_PERF_LINE_FPS] = "%.0f к/с", [UI_PERF_LINE_FULL] = "%.0f к/с %.1f мс макс. %.1f мс", - [UI_MENU_FPS60] = "Частота кадров", [UI_MENU_FPS60_DESC] = "Игра идёт в 60 кадров в секунду вместо 30.", - [UI_MENU_FPS_60] = "60 FPS", [UI_MENU_FPS_30] = "30 FPS", + [UI_MENU_FPS_LIMIT] = "Ограничение частоты кадров", + [UI_MENU_FPS_LIMIT_DESC] = "Наибольшее число кадров в секунду. Выше 60 — экспериментальный режим, нужна «Скорость " + "игры по часам».", + [UI_MENU_FPS_30] = "30 FPS", [UI_MENU_FPS_60] = "60 FPS", [UI_MENU_FPS_120] = "120 FPS", [UI_MENU_FPS_144] = "144 FPS", + [UI_MENU_FPS_DISPLAY] = "Как у монитора", [UI_MENU_FPS_DISPLAY_HZ] = "Как у монитора (%.0f Гц)", [UI_MENU_REALTIME] = "Скорость игры по часам", [UI_MENU_REALTIME_DESC] = "Игра идёт по реальному времени, медленный кадр её не замедляет.", [UI_MENU_CLOTH_REALTIME] = "Ткань по часам", diff --git a/runtime/ui_text.h b/runtime/ui_text.h index e8426cd0..519ee901 100644 --- a/runtime/ui_text.h +++ b/runtime/ui_text.h @@ -31,7 +31,8 @@ typedef enum { UI_PERF_LINE_FPS, UI_PERF_LINE_FULL, // Game - UI_MENU_FPS60, UI_MENU_FPS60_DESC, UI_MENU_FPS_60, UI_MENU_FPS_30, + UI_MENU_FPS_LIMIT, UI_MENU_FPS_LIMIT_DESC, UI_MENU_FPS_30, UI_MENU_FPS_60, UI_MENU_FPS_120, UI_MENU_FPS_144, + UI_MENU_FPS_DISPLAY, UI_MENU_FPS_DISPLAY_HZ, UI_MENU_REALTIME, UI_MENU_REALTIME_DESC, UI_MENU_CLOTH_REALTIME, UI_MENU_CLOTH_REALTIME_DESC, UI_MENU_HIGHFPS_FIX, UI_MENU_HIGHFPS_FIX_DESC, diff --git a/totk.ini.example b/totk.ini.example index 5112c539..6c1b2e22 100644 --- a/totk.ini.example +++ b/totk.ini.example @@ -1,9 +1,12 @@ # totk.ini: settings for totk.exe. Copy this file to totk.ini next to totk.exe and remove the '#' of a line to change it. -# Each line shows the default. A TOTK_* environment variable of the same name (TOTK_FPS60 for fps60) overrides the +# Each line shows the default. A TOTK_* environment variable of the same name (TOTK_FPS_LIMIT for fps_limit) overrides the # file. Keys are case-insensitive; '#' and ';' start a comment; [sections] only group lines. [frame rate] -# 60 fps patch (0 = the game's own 30 fps). +# Frame rate limit: 30, 60, 120, 144, any whole rate from 30 to 360, or display (the refresh rate of the window's +# monitor). Above 60 is experimental and needs realtime = 1. Changes while the game runs take effect at once. +# fps_limit = 60 +# Older key, read only while fps_limit is unset: fps60 = 0 means a limit of 30. # fps60 = 1 # Real-time frame step: game speed follows the clock instead of the frame count. # realtime = 1