From beb93276ebdc4962faa3a7614970b6bb2a523b99 Mon Sep 17 00:00:00 2001 From: Valiantsin Dzerakh Date: Tue, 3 Nov 2026 20:09:22 +0300 Subject: [PATCH 1/3] Offer every game language the build ships in the F1 menu (#580) The game language row listed eleven languages. 1.4.3 also ships Brazilian Portuguese (Mals USpt), and every build ships British English, Canadian French and Latin American Spanish (EUen, USfr, USes), which ov_language already accepted. ui_text_game_langs lists them per game build: pt-BR from 1.4.3 on, since 1.2.1 has no USpt. A row selects only its own code, so en-GB and es-419 no longer show as English and Spanish. Co-Authored-By: Claude Opus 5.5 --- runtime/ov_probe.c | 18 +++++++++++++++++- runtime/ui/menu.cpp | 24 +++++++++++------------- runtime/ui_text.c | 19 ++++++++++++++++++- runtime/ui_text.h | 9 ++++++++- 4 files changed, 54 insertions(+), 16 deletions(-) diff --git a/runtime/ov_probe.c b/runtime/ov_probe.c index c7ff374d..89fbecb1 100644 --- a/runtime/ov_probe.c +++ b/runtime/ov_probe.c @@ -889,10 +889,26 @@ static void probe_menu_text(void) { CHECK(!strcmp(ui_text_in("ru", UI_SWKBD_OK), "ОК") && !strcmp(ui_text_in("de", UI_SWKBD_CANCEL), "Abbrechen") && !strcmp(ui_text_in("en", UI_SWKBD_OK), "OK"), "keyboard texts changed"); // language names: the same string in every row - for (int id = UI_MENU_LANGNAME_EN; id <= UI_MENU_LANGNAME_PT_BR; id++) + for (int id = UI_MENU_LANGNAME_EN; id <= UI_MENU_LANGNAME_ES_419; id++) for (size_t i = 1; i < sizeof langs / sizeof *langs; i++) CHECK(!strcmp(ui_text_in(langs[i], (UiTextId)id), ui_text_in("en", (UiTextId)id)), "language name %d differs in %s", id, langs[i]); CHECK(!strcmp(ui_text_in("en", UI_MENU_LANGNAME_RU), "Русский"), "Russian is not shown as Russian"); + // game language list: pt-BR only where the build ships USpt; the Switch variants are entries of their own + { + UiGameLang gl[16]; + int n121 = ui_text_game_langs(121, gl, 16), has[16] = {0}; + for (int i = 0; i < n121; i++) CHECK(strcmp(gl[i].code, "pt-BR"), "1.2.1 game language list offers pt-BR"); + int n143 = ui_text_game_langs(143, gl, 16), pt = 0; + for (int i = 0; i < n143; i++) { + pt |= !strcmp(gl[i].code, "pt-BR"); + for (int j = 0; j < i; j++) CHECK(strcmp(gl[i].code, gl[j].code), "duplicate game language %s", gl[i].code); + } + CHECK(pt && n143 == n121 + 1, "1.4.3 game language list lacks pt-BR"); + static const char *const want[] = {"en-GB", "fr-CA", "es-419"}; + for (int w = 0; w < 3; w++) + for (int i = 0; i < n143; i++) has[w] |= !strcmp(gl[i].code, want[w]); + CHECK(has[0] && has[1] && has[2], "game language list lacks en-GB, fr-CA or es-419"); + } // the overlay formats keep their conversions CHECK(strstr(ui_text_in("ru", UI_MENU_OV_GAME_PCT), "%.0f%%") && strstr(ui_text_in("ru", UI_MENU_OV_MAX_MS), "%.1f"), "overlay format lost its conversion"); diff --git a/runtime/ui/menu.cpp b/runtime/ui/menu.cpp index b1777f22..8f4a15f0 100644 --- a/runtime/ui/menu.cpp +++ b/runtime/ui/menu.cpp @@ -559,27 +559,25 @@ static void row_gpu(void) { opt_choice_list("TOTK_GPU_INDEX", UI_MENU_GPU, vals, names, g_gpu_n + 1, UI_MENU_GPU_DESC); } -// The game language: one entry per language TotK ships (a Switch code that names it), each under its own name. The -// Switch's Portuguese is not among them. +// The game language: one entry per Mals language file the running game build ships (ui_text_game_langs), each under +// its own name. A code that names no entry exactly (older "en", "fr-CA" on a build without it) selects the first entry +// of the same catalog language. static void row_game_lang(void) { - static const struct { const char *code; UiTextId name; } langs[] = { - {"en-US", UI_MENU_LANGNAME_EN}, {"ja", UI_MENU_LANGNAME_JA}, {"fr", UI_MENU_LANGNAME_FR}, - {"de", UI_MENU_LANGNAME_DE}, {"it", UI_MENU_LANGNAME_IT}, {"es", UI_MENU_LANGNAME_ES}, - {"nl", UI_MENU_LANGNAME_NL}, {"ru", UI_MENU_LANGNAME_RU}, - {"zh-Hans", UI_MENU_LANGNAME_ZH_HANS}, {"zh-Hant", UI_MENU_LANGNAME_ZH_HANT}, {"ko", UI_MENU_LANGNAME_KO}, - }; - enum { N = sizeof langs / sizeof *langs + 1 }; - const char *vals[N], *names[N]; + UiGameLang langs[16]; + int n = ui_text_game_langs(rt_game_version, langs, 16); + const char *vals[17], *names[17]; vals[0] = ""; names[0] = menu_text(UI_MENU_GAME_LANG_AUTO); const char *now = cfg_value("TOTK_LANG"); int cur = *now ? -1 : 0; - for (int i = 1; i < N; i++) { + for (int i = 1; i <= n; i++) { vals[i] = langs[i - 1].code; names[i] = menu_text(langs[i - 1].name); - if (*now && !strcmp(ui_text_lang(now), ui_text_lang(vals[i]))) cur = i; // en-GB is English too + if (*now && !strcmp(now, vals[i])) cur = i; } - opt_choice_list("TOTK_LANG", UI_MENU_GAME_LANG, vals, names, N, UI_MENU_GAME_LANG_DESC, cur); + for (int i = 1; i <= n && *now && cur < 0; i++) + if (!strcmp(ui_text_lang(now), ui_text_lang(vals[i]))) cur = i; + opt_choice_list("TOTK_LANG", UI_MENU_GAME_LANG, vals, names, n + 1, 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. diff --git a/runtime/ui_text.c b/runtime/ui_text.c index d023b66a..293d3c38 100644 --- a/runtime/ui_text.c +++ b/runtime/ui_text.c @@ -18,7 +18,8 @@ typedef struct { const char *lang; const char *const *text; } Row; [UI_MENU_LANGNAME_DE] = "Deutsch", [UI_MENU_LANGNAME_IT] = "Italiano", [UI_MENU_LANGNAME_ES] = "Español", \ [UI_MENU_LANGNAME_NL] = "Nederlands", [UI_MENU_LANGNAME_RU] = "Русский", \ [UI_MENU_LANGNAME_ZH_HANS] = "简体中文", [UI_MENU_LANGNAME_ZH_HANT] = "繁體中文", [UI_MENU_LANGNAME_KO] = "한국어", \ - [UI_MENU_LANGNAME_PT_BR] = "Português (Brasil)" + [UI_MENU_LANGNAME_PT_BR] = "Português (Brasil)", [UI_MENU_LANGNAME_EN_GB] = "English (UK)", \ + [UI_MENU_LANGNAME_FR_CA] = "Français (Canada)", [UI_MENU_LANGNAME_ES_419] = "Español (Latinoamérica)" // SWKBD: TITLE, PROMPT, DEFAULT_NAME (at most 9 UTF-16 units, no '@' '%' '\'), OK, CANCEL, PAD_HINT. #define SWKBD(title, prompt, name, ok, cancel, hint) \ @@ -1932,6 +1933,22 @@ const char *ui_text_lang(const char *code) { return code; } +// Every game language: the Mals files EUen/USen, USfr/EUfr, USes/EUes ship in both builds; USpt only from 1.4.3. +int ui_text_game_langs(int game_version, UiGameLang *out, int max) { + static const struct { const char *code; UiTextId name; int since; } all[] = { + {"en-US", UI_MENU_LANGNAME_EN, 0}, {"en-GB", UI_MENU_LANGNAME_EN_GB, 0}, {"ja", UI_MENU_LANGNAME_JA, 0}, + {"fr", UI_MENU_LANGNAME_FR, 0}, {"fr-CA", UI_MENU_LANGNAME_FR_CA, 0}, {"de", UI_MENU_LANGNAME_DE, 0}, + {"it", UI_MENU_LANGNAME_IT, 0}, {"es", UI_MENU_LANGNAME_ES, 0}, {"es-419", UI_MENU_LANGNAME_ES_419, 0}, + {"pt-BR", UI_MENU_LANGNAME_PT_BR, 143}, {"nl", UI_MENU_LANGNAME_NL, 0}, {"ru", UI_MENU_LANGNAME_RU, 0}, + {"zh-Hans", UI_MENU_LANGNAME_ZH_HANS, 0}, {"zh-Hant", UI_MENU_LANGNAME_ZH_HANT, 0}, + {"ko", UI_MENU_LANGNAME_KO, 0}, + }; + int n = 0; + for (size_t i = 0; i < sizeof all / sizeof *all && n < max; i++) + if (game_version >= all[i].since) out[n++] = (UiGameLang){all[i].code, all[i].name}; + return n; +} + static const Row *find_row(const char *lang) { for (size_t i = 0; i < sizeof rows / sizeof *rows; i++) if (!strcmp(rows[i].lang, lang)) return &rows[i]; diff --git a/runtime/ui_text.h b/runtime/ui_text.h index 1845d052..116128c1 100644 --- a/runtime/ui_text.h +++ b/runtime/ui_text.h @@ -154,7 +154,8 @@ typedef enum { // Language names, each in its own language and the same in every row (game language and menu language lists) UI_MENU_LANGNAME_EN, UI_MENU_LANGNAME_JA, UI_MENU_LANGNAME_FR, UI_MENU_LANGNAME_DE, UI_MENU_LANGNAME_IT, UI_MENU_LANGNAME_ES, UI_MENU_LANGNAME_NL, UI_MENU_LANGNAME_RU, UI_MENU_LANGNAME_ZH_HANS, - UI_MENU_LANGNAME_ZH_HANT, UI_MENU_LANGNAME_KO, UI_MENU_LANGNAME_PT_BR, + UI_MENU_LANGNAME_ZH_HANT, UI_MENU_LANGNAME_KO, UI_MENU_LANGNAME_PT_BR, UI_MENU_LANGNAME_EN_GB, + UI_MENU_LANGNAME_FR_CA, UI_MENU_LANGNAME_ES_419, // Advanced UI_MENU_ADV_WARNING, @@ -246,6 +247,12 @@ int ui_text_defined(const char *lang, UiTextId id); // The catalog language for a Switch language code ("en-GB" -> "en", "zh-CN" -> "zh-Hans", ...). const char *ui_text_lang(const char *switch_code); +// The game languages the F1 menu offers for a game build (rt_game_version): one entry per Mals language file the build +// ships, each with the Switch code TOTK_LANG takes and the id of its name. 1.4.3 adds Brazilian Portuguese (USpt). +// Fills out (room for max entries) and returns the count. +typedef struct { const char *code; UiTextId name; } UiGameLang; +int ui_text_game_langs(int game_version, UiGameLang *out, int max); + // Menu text: ui_text_in(menu language, id). The menu language is TOTK_MENU_LANG ("en", "ru", "pt-BR", "zh-Hans"); // unset, the system UI language when the catalog has menu text for it (English, Russian, Brazilian Portuguese, // Simplified Chinese), else English. Follows a live change of the setting. From 3422952e857e25c3dbf8e6ebf8643ba309d936e9 Mon Sep 17 00:00:00 2001 From: Valiantsin Dzerakh Date: Tue, 3 Nov 2026 20:09:22 +0300 Subject: [PATCH 2/3] Show the versions, 1% low and 0.1% low in the full performance overlay (#587, #588) The panel opens with the port version and the game update, so a screenshot in a bug report carries both. Under RAM, after a gap, two rows on the same grid: FPS with the 1% and 0.1% lows, and the frame times. perfmon.c keeps a histogram of frame times in 0.25 ms bins, one slice per second over the last ten seconds, and reads the lows from it twice a second. Co-Authored-By: Claude Opus 5.5 --- runtime/ov_probe.c | 6 ++++-- runtime/perfmon.c | 36 ++++++++++++++++++++++++++++++++++++ runtime/perfmon.h | 2 ++ runtime/ui/menu.cpp | 43 ++++++++++++++++++++++++++++++------------- runtime/ui_text.c | 8 ++++++++ runtime/ui_text.h | 2 ++ 6 files changed, 82 insertions(+), 15 deletions(-) diff --git a/runtime/ov_probe.c b/runtime/ov_probe.c index 89fbecb1..3d1a4327 100644 --- a/runtime/ov_probe.c +++ b/runtime/ov_probe.c @@ -910,10 +910,12 @@ static void probe_menu_text(void) { CHECK(has[0] && has[1] && has[2], "game language list lacks en-GB, fr-CA or es-419"); } // the overlay formats keep their conversions - CHECK(strstr(ui_text_in("ru", UI_MENU_OV_GAME_PCT), "%.0f%%") && strstr(ui_text_in("ru", UI_MENU_OV_MAX_MS), "%.1f"), + CHECK(strstr(ui_text_in("ru", UI_MENU_OV_GAME_PCT), "%.0f%%") && strstr(ui_text_in("ru", UI_MENU_OV_MAX_MS), "%.1f") && + strstr(ui_text_in("ru", UI_MENU_OV_LOW1), "%.0f") && strstr(ui_text_in("ru", UI_MENU_OV_LOW01), "%.0f"), "overlay format lost its conversion"); CHECK(strstr(ui_text_in("pt-BR", UI_MENU_OV_GAME_PCT), "%.0f%%") && - strstr(ui_text_in("pt-BR", UI_MENU_OV_MAX_MS), "%.1f"), "pt-BR overlay format lost its conversion"); + strstr(ui_text_in("pt-BR", UI_MENU_OV_MAX_MS), "%.1f") && + strstr(ui_text_in("pt-BR", UI_MENU_OV_LOW1), "%.0f") && strstr(ui_text_in("zh-Hans", UI_MENU_OV_LOW01), "%.0f"), "pt-BR overlay format lost its conversion"); // a Brazilian game language gets the Brazilian keyboard row, Portugal's Portuguese keeps its own CHECK(!strcmp(ui_text_lang("pt-BR"), "pt-BR") && !strcmp(ui_text_lang("pt"), "pt") && strcmp(ui_text_in("pt-BR", UI_SWKBD_PROMPT), ui_text_in("pt", UI_SWKBD_PROMPT)), "pt-BR keyboard row not used"); diff --git a/runtime/perfmon.c b/runtime/perfmon.c index 3a5e2f28..f2f01beb 100644 --- a/runtime/perfmon.c +++ b/runtime/perfmon.c @@ -32,6 +32,14 @@ static float g_ring[PERF_HISTORY]; static uint64_t g_ring_at[PERF_HISTORY]; // when each frame ended static int g_ring_n, g_ring_pos; +// The lows: a histogram of the frame times (perf.c's 0.25 ms bins) over the last LOW_SLICES seconds, kept as one slice +// per second so the oldest second drops out whole. Per frame: one increment. The percentiles are read twice a second. +#define LOW_BINS 1024 +#define LOW_SLICES 10 +static uint16_t g_low_hist[LOW_SLICES][LOW_BINS]; +static int g_low_cur; +static uint64_t g_low_t0; + // The per-frame counters, summed since t0 (the overlay's lines are averages over half a second). static struct { uint64_t t0, frames, gpu0; @@ -47,6 +55,14 @@ void perfmon_frame(uint64_t now, uint64_t interval_ns, const uint64_t *wait_ns, g_ring_at[g_ring_pos] = now; g_ring_pos = (g_ring_pos + 1) % PERF_HISTORY; if (g_ring_n < PERF_HISTORY) g_ring_n++; + if (now - g_low_t0 >= 1000000000ull) { // the next second: its slice starts empty + g_low_cur = (g_low_cur + 1) % LOW_SLICES; + memset(g_low_hist[g_low_cur], 0, sizeof g_low_hist[0]); + g_low_t0 = now; + } + uint64_t bin = interval_ns / 250000ull; + uint16_t *h = &g_low_hist[g_low_cur][bin < LOW_BINS ? bin : LOW_BINS - 1]; + if (*h < 65535) (*h)++; } g_win.frames++; g_win.replay += replay_ns / 1e6; @@ -76,9 +92,27 @@ static void frames_summary(PerfStats *s, uint64_t now) { // (lock held) } } +// The fps of the slowest 1% and 0.1% of the frames in the window (the bin's upper edge, as perf.c's summary does); -1 +// when the window holds too few frames. (lock held) +static void lows_summary(PerfStats *s) { + uint32_t total = 0; + for (int k = 0; k < LOW_SLICES; k++) + for (int b = 0; b < LOW_BINS; b++) total += g_low_hist[k][b]; + s->low1_fps = s->low01_fps = -1; + if (total < 100) return; + uint32_t cut1 = (total + 99) / 100, cut01 = (total + 999) / 1000, acc = 0; + for (int b = LOW_BINS - 1; b >= 0 && s->low1_fps < 0; b--) { + for (int k = 0; k < LOW_SLICES; k++) acc += g_low_hist[k][b]; + float fps = 1000.0f / ((b + 1) * 0.25f); + if (s->low01_fps < 0 && acc >= cut01) s->low01_fps = fps; + if (acc >= cut1) s->low1_fps = fps; + } +} + // Every half second: the window's sums as per-frame averages into g_stats, and a new window. (lock held) static void counters_summary(uint64_t now) { if (now - g_win.t0 < 500000000ull) return; + lows_summary(&g_stats); uint64_t gpu = perf_gpu_busy_total(); if (g_win.t0 && g_win.frames) { double n = (double)g_win.frames; @@ -342,6 +376,8 @@ void perfmon_mode(int mode) { } if (!mode) { // the next start begins a new graph and a new counter window g_ring_n = g_ring_pos = 0; + memset(g_low_hist, 0, sizeof g_low_hist); + g_low_t0 = 0; memset(&g_win, 0, sizeof g_win); } plat_mutex_unlock(&g_lock); diff --git a/runtime/perfmon.h b/runtime/perfmon.h index c5ea1d3a..7c2b99bb 100644 --- a/runtime/perfmon.h +++ b/runtime/perfmon.h @@ -17,6 +17,8 @@ extern "C" { typedef struct { // the game's frames (presents), over the last second float fps, frame_ms_avg, frame_ms_max; + // fps of the slowest 1% and 0.1% of the frames over the last ten seconds (-1: too few frames yet) + float low1_fps, low01_fps; float frame_ms[PERF_HISTORY]; // oldest first // CPU: the whole machine and this process, percent of all logical processors char cpu_name[64]; diff --git a/runtime/ui/menu.cpp b/runtime/ui/menu.cpp index 8f4a15f0..848eada2 100644 --- a/runtime/ui/menu.cpp +++ b/runtime/ui/menu.cpp @@ -1381,17 +1381,30 @@ static void perf_full_draw(const MenuTarget *t, float scale) { ImGui::SetWindowFontScale(0.72f); const ImVec4 gpu_c(0.55f, 0.83f, 0.31f, 1), cpu_c(0.18f, 0.59f, 0.80f, 1), ram_c(0.80f, 0.45f, 0.70f, 1), fps_c(0.95f, 0.95f, 0.95f, 1), wait_c(0.93f, 0.76f, 0.33f, 1), pic_c(0.62f, 0.70f, 0.95f, 1); + // the port version and the game update first, so a screenshot in a bug report carries both; formatted once per + // menu language + static char ver[96]; + static const char *ver_fmt; + if (ver_fmt != menu_text(UI_MENU_VERSION)) { + ver_fmt = menu_text(UI_MENU_VERSION); + char game[16]; + snprintf(game, sizeof game, "%d.%d.%d", rt_game_version / 100, rt_game_version / 10 % 10, rt_game_version % 10); + snprintf(ver, sizeof ver, ver_fmt, rt_port_version, game); + } + ImGui::TextDisabled("%s", ver); if (ImGui::BeginTable("##perft", 4, ImGuiTableFlags_SizingFixedFit)) { - static const UiTextId labels[] = {UI_MENU_OV_GPU, UI_MENU_OV_VRAM, UI_MENU_OV_CPU, UI_MENU_OV_RAM}; - static const PerfCol c0[] = {{UI_MENU_OV_FPS, 888}}; - static const PerfCol c1[] = {{UI_MENU_OV_FMT_PCT, 100}, {UI_MENU_OV_FMT_GB, 888.8f}, {UI_MENU_OV_FRAME_MS, 888.8f}}; - static const PerfCol c2[] = {{UI_MENU_OV_FMT_TEMP, 188}, {UI_MENU_OV_FMT_GB_OF, 888.8f}, {UI_MENU_OV_MAX_MS, 8888.8f}}; + static const UiTextId labels[] = {UI_MENU_OV_GPU, UI_MENU_OV_VRAM, UI_MENU_OV_CPU, UI_MENU_OV_RAM, + UI_MENU_OV_FPS_LABEL, UI_MENU_OV_FRAME_LABEL}; + static const PerfCol c1[] = {{UI_MENU_OV_FMT_PCT, 100}, {UI_MENU_OV_FMT_GB, 888.8f}, {UI_MENU_OV_FMT_FPS, 888}, + {UI_MENU_OV_FRAME_MS, 888.8f}}; + static const PerfCol c2[] = {{UI_MENU_OV_FMT_TEMP, 188}, {UI_MENU_OV_FMT_GB_OF, 888.8f}, {UI_MENU_OV_LOW1, 888}, + {UI_MENU_OV_MAX_MS, 8888.8f}}; static const PerfCol c3[] = {{UI_MENU_OV_FMT_POWER, 888}, {UI_MENU_OV_FMT_MHZ, 8888}, {UI_MENU_OV_GAME_PCT, 100}, - {UI_MENU_OV_GAME_GB, 888.8f}}; - perf_column("##c0", c0, 1, labels, 4); - perf_column("##c1", c1, 3); - perf_column("##c2", c2, 3); - perf_column("##c3", c3, 4); + {UI_MENU_OV_GAME_GB, 888.8f}, {UI_MENU_OV_LOW01, 888}}; + perf_column("##c0", nullptr, 0, labels, 6); + perf_column("##c1", c1, 4); + perf_column("##c2", c2, 4); + perf_column("##c3", c3, 5); perf_label(UI_MENU_OV_GPU, gpu_c); perf_cell(UI_MENU_OV_FMT_PCT, s.gpu_pct); perf_cell(UI_MENU_OV_FMT_TEMP, s.gpu_temp_c); @@ -1408,12 +1421,16 @@ static void perf_full_draw(const MenuTarget *t, float scale) { perf_cell(UI_MENU_OV_FMT_GB, perf_gb(s.ram_used_mb)); perf_cell(UI_MENU_OV_FMT_GB_OF, perf_gb(s.ram_total_mb)); perf_cell(UI_MENU_OV_GAME_GB, perf_gb(s.ram_game_mb)); - ImGui::TableNextColumn(); // the frame row: no label, the rate in its place - char b[64]; - snprintf(b, sizeof b, menu_text(UI_MENU_OV_FPS), s.fps); - ImGui::TextColored(fps_c, "%s", b); + ImGui::TableNextRow(ImGuiTableRowFlags_None, 6 * scale); // a gap between the machine and the frames + // the frames: the rate over the last second with the lows over the last ten seconds, then the frame times + perf_label(UI_MENU_OV_FPS_LABEL, fps_c); + perf_cell(UI_MENU_OV_FMT_FPS, s.fps); + perf_cell(UI_MENU_OV_LOW1, s.low1_fps); + perf_cell(UI_MENU_OV_LOW01, s.low01_fps); + perf_label(UI_MENU_OV_FRAME_LABEL, fps_c); perf_cell(UI_MENU_OV_FRAME_MS, s.frame_ms_avg); perf_cell(UI_MENU_OV_MAX_MS, s.frame_ms_max); + ImGui::TableNextColumn(); ImGui::EndTable(); } float top = s.frame_ms_max > 50 ? s.frame_ms_max : 50; diff --git a/runtime/ui_text.c b/runtime/ui_text.c index 293d3c38..053dea1c 100644 --- a/runtime/ui_text.c +++ b/runtime/ui_text.c @@ -408,6 +408,8 @@ static const char *const text_en[UI_TEXT_COUNT] = { [UI_MENU_OV_FPS] = "%.0f FPS", [UI_MENU_OV_FRAME_MS] = "%.1f ms", [UI_MENU_OV_GAME_PCT] = "game %.0f%%", [UI_MENU_OV_MAX_MS] = "max %.1f ms", + [UI_MENU_OV_FPS_LABEL] = "FPS", [UI_MENU_OV_FRAME_LABEL] = "Frame", [UI_MENU_OV_FMT_FPS] = "%.0f", + [UI_MENU_OV_LOW1] = "1%% low %.0f", [UI_MENU_OV_LOW01] = "0.1%% low %.0f", [UI_MENU_OV_GPU] = "GPU", [UI_MENU_OV_CPU] = "CPU", [UI_MENU_OV_RAM] = "RAM", [UI_MENU_OV_VRAM] = "VRAM", [UI_MENU_OV_TEMP] = "Temperature", [UI_MENU_OV_POWER] = "Power", [UI_MENU_OV_CLOCK] = "Clock", [UI_MENU_OV_NONE] = "-", @@ -843,6 +845,8 @@ static const char *const text_ru[UI_TEXT_COUNT] = { [UI_MENU_OV_FPS] = "%.0f FPS", [UI_MENU_OV_FRAME_MS] = "%.1f мс", [UI_MENU_OV_GAME_PCT] = "игра %.0f%%", [UI_MENU_OV_MAX_MS] = "макс. %.1f мс", + [UI_MENU_OV_FPS_LABEL] = "FPS", [UI_MENU_OV_FRAME_LABEL] = "Кадр", [UI_MENU_OV_FMT_FPS] = "%.0f", + [UI_MENU_OV_LOW1] = "1%% худших %.0f", [UI_MENU_OV_LOW01] = "0.1%% худших %.0f", [UI_MENU_OV_GPU] = "GPU", [UI_MENU_OV_CPU] = "ЦП", [UI_MENU_OV_RAM] = "ОЗУ", [UI_MENU_OV_VRAM] = "Видеопамять", [UI_MENU_OV_TEMP] = "Температура", [UI_MENU_OV_POWER] = "Мощность", [UI_MENU_OV_CLOCK] = "Частота", [UI_MENU_OV_NONE] = "-", @@ -1193,6 +1197,8 @@ static const char *const text_pt_br[UI_TEXT_COUNT] = { [UI_MENU_OV_FPS] = "%.0f FPS", [UI_MENU_OV_FRAME_MS] = "%.1f ms", [UI_MENU_OV_GAME_PCT] = "jogo %.0f%%", [UI_MENU_OV_MAX_MS] = "máx. %.1f ms", + [UI_MENU_OV_FPS_LABEL] = "FPS", [UI_MENU_OV_FRAME_LABEL] = "Quadro", [UI_MENU_OV_FMT_FPS] = "%.0f", + [UI_MENU_OV_LOW1] = "1%% piores %.0f", [UI_MENU_OV_LOW01] = "0.1%% piores %.0f", [UI_MENU_OV_GPU] = "GPU", [UI_MENU_OV_CPU] = "CPU", [UI_MENU_OV_RAM] = "RAM", [UI_MENU_OV_VRAM] = "VRAM", [UI_MENU_OV_TEMP] = "Temperatura", [UI_MENU_OV_POWER] = "Consumo", [UI_MENU_OV_CLOCK] = "Frequência", [UI_MENU_OV_NONE] = "-", @@ -1785,6 +1791,8 @@ static const char *const text_zh_hans[UI_TEXT_COUNT] = { [UI_MENU_OV_FRAME_MS] = "%.1f ms", [UI_MENU_OV_GAME_PCT] = "游戏 %.0f%%", [UI_MENU_OV_MAX_MS] = "最长 %.1f ms", + [UI_MENU_OV_FPS_LABEL] = "FPS", [UI_MENU_OV_FRAME_LABEL] = "帧时间", [UI_MENU_OV_FMT_FPS] = "%.0f", + [UI_MENU_OV_LOW1] = "1%% 低 %.0f", [UI_MENU_OV_LOW01] = "0.1%% 低 %.0f", [UI_MENU_OV_GPU] = "GPU", [UI_MENU_OV_CPU] = "CPU", [UI_MENU_OV_RAM] = "内存", diff --git a/runtime/ui_text.h b/runtime/ui_text.h index 116128c1..9082b55d 100644 --- a/runtime/ui_text.h +++ b/runtime/ui_text.h @@ -204,6 +204,8 @@ typedef enum { // Performance overlay UI_MENU_OV_FPS, UI_MENU_OV_FRAME_MS, UI_MENU_OV_GAME_PCT, UI_MENU_OV_MAX_MS, + UI_MENU_OV_FPS_LABEL, UI_MENU_OV_FRAME_LABEL, UI_MENU_OV_FMT_FPS, // the frame rows: their labels, the rate + UI_MENU_OV_LOW1, UI_MENU_OV_LOW01, // printf: the fps of the slowest 1% / 0.1% of the frames, no unit (the overlay column stays narrow) UI_MENU_OV_GPU, UI_MENU_OV_CPU, UI_MENU_OV_RAM, UI_MENU_OV_VRAM, UI_MENU_OV_TEMP, UI_MENU_OV_POWER, UI_MENU_OV_CLOCK, UI_MENU_OV_NONE, UI_MENU_OV_REPLAY, UI_MENU_OV_GPU_TIME, UI_MENU_OV_PIPE_WAIT, UI_MENU_OV_SHADER_WAIT, UI_MENU_OV_TEX_UPLOADS, From d2fbe0a2b1b16c5cf74e7c042813c10efd5d40ed Mon Sep 17 00:00:00 2001 From: Valiantsin Dzerakh Date: Tue, 3 Nov 2026 20:09:23 +0300 Subject: [PATCH 3/3] Close the game's own console and bring its window to the front (#208, #521) A game started from a frontend (Playnite, RetroBat, ES-DE) or a shortcut got a console beside it, and its window opened behind other windows, out of reach without a mouse. Once the log file is open, the console is freed when no other process shares it; a terminal launch keeps its output, and show_console = 1 keeps the console. The window is raised at start, with AttachThreadInput when Windows refuses the foreground. rt_fatal writes only to the log, and a console owned by the game closed with it anyway, so no error text is lost. Co-Authored-By: Claude Opus 5.5 --- runtime/cfg.c | 6 +++--- runtime/gfx_window_win.c | 27 +++++++++++++++++++++++---- runtime/main.c | 4 ++++ runtime/platform/linux.c | 2 ++ runtime/platform/platform.h | 5 +++++ runtime/platform/win32.c | 11 +++++++++++ totk.ini.example | 4 ++++ 7 files changed, 52 insertions(+), 7 deletions(-) diff --git a/runtime/cfg.c b/runtime/cfg.c index 7fd33b50..d915c6d3 100644 --- a/runtime/cfg.c +++ b/runtime/cfg.c @@ -51,7 +51,7 @@ static const char *const known[] = { "REPLAY_CHECK", "RESOLVE_CHECK", "RESTART_WAIT", "ROMFS", "ROMFS_INDEX", "ROMFS_MMAP", "ROMFS_MODS", "ROMFS_PATCHES", "ROMFS_PROOF_DIR", "ROMFS_VERIFY", "RSTICK_DEADZONE", "RUMBLE", "RUMBLE_CURVE", "RUMBLE_STRENGTH", "RUMBLE_TRIGGERS", "SHADER_CACHE", "SHADER_MEMO", "SHADOW_RANGE", "SHADOW_RES", "SHADOW_SCALE", "SHARED_FONTS", "SHARPNESS", "SHOTS", "SHOTS_DIR", - "SHOTS_FULL", "SPEED_PROBE", "SPIN", "SPIN_HANDOFF_US", "SPLIT_DRAWS", "SPLIT_US", "STICK_DEADZONE", "STICK_SENS", + "SHOTS_FULL", "SHOW_CONSOLE", "SPEED_PROBE", "SPIN", "SPIN_HANDOFF_US", "SPLIT_DRAWS", "SPLIT_US", "STICK_DEADZONE", "STICK_SENS", "SWKBD_ANSWER", "SWKBD_TEST", "TEST_PAD", "TEST_PREPARE_SHADERS", "TEX_ALIAS", "TEX_MEMO", "TEX_VRAM_PRESSURE", "TIMER_1MS", "TRACE", "TXD_TRANSPOSE", "UBO_SNAPSHOT", "UPSCALER", "VK_DYN_A2C", "VK_DYN_VERTEX", "VK_NO_FLOAT64", "VK_PRESENT", "VK_RECORDER", "VK_SSBO_ALIGN", "VK_SUBGROUP", "VK_SUBGROUP_PIN", "VK_VALIDATION", "VOLUME", "VRAM_HEADROOM", "VS_OUTS", @@ -96,7 +96,7 @@ static const struct { const char *key, *section; } sections[] = { {"PUSH_SKIP", "performance"}, {"SPLIT_DRAWS", "performance"}, {"SPLIT_US", "performance"}, {"VK_VALIDATION", "performance"}, {"VK_DYN_VERTEX", "performance"}, {"VK_DYN_A2C", "performance"}, {"VK_SUBGROUP_PIN", "performance"}, {"TRACE", "diagnostics"}, {"FLIGHT", "diagnostics"}, {"PASS_CRUMBS", "diagnostics"}, {"FLIGHT_SPIKE_MS", "diagnostics"}, - {"WB_FENCE_LIMIT", "diagnostics"}, {"WB_EXACT", "diagnostics"}, + {"WB_FENCE_LIMIT", "diagnostics"}, {"WB_EXACT", "diagnostics"}, {"SHOW_CONSOLE", "diagnostics"}, }; // The settings the menu shows: the value in effect when the key is unset, and what the key accepts. The only place a @@ -166,7 +166,7 @@ static const CfgMeta metas[] = { {"VK_DYN_A2C", "", "0|1", RESTART}, {"VK_SUBGROUP_PIN", "1", "0|1", RESTART}, // diagnostics {"TRACE", "", NULL, RESTART}, {"FLIGHT", "0", "0|1", RESTART}, {"FLIGHT_SPIKE_MS", "100", "0..60000", RESTART}, - {"WB_FENCE_LIMIT", "65536", "0..1073741824", RESTART}, {"WB_EXACT", "1", "0|1", RESTART}, + {"SHOW_CONSOLE", "0", "0|1", RESTART}, {"WB_FENCE_LIMIT", "65536", "0..1073741824", RESTART}, {"WB_EXACT", "1", "0|1", RESTART}, {"PASS_CRUMBS", "", "0|1", RESTART}, // vk_crumbs.c pass marks; unset: VK_AMD_buffer_marker only {"INPUT_RECORD", "", NULL, RESTART}, }; diff --git a/runtime/gfx_window_win.c b/runtime/gfx_window_win.c index 6c026127..51dafe04 100644 --- a/runtime/gfx_window_win.c +++ b/runtime/gfx_window_win.c @@ -279,6 +279,24 @@ static LRESULT CALLBACK wnd_proc(HWND h, UINT m, WPARAM w, LPARAM l) { return DefWindowProcW(h, m, w, l); } +// Brings the game window to the front. Windows refuses SetForegroundWindow to a process that was not the last to get +// input, which is the case for a game started by a frontend; attaching this thread's input queue to the foreground +// window's thread for the call is the documented way around it. The window is not left topmost. +static void raise_window(HWND h) { + HWND fg = GetForegroundWindow(); + DWORD me = GetCurrentThreadId(), other = fg ? GetWindowThreadProcessId(fg, NULL) : 0; + int attached = other && other != me && AttachThreadInput(me, other, TRUE); + ShowWindow(h, IsIconic(h) ? SW_RESTORE : SW_SHOW); + BringWindowToTop(h); + SetForegroundWindow(h); + SetActiveWindow(h); + if (attached) AttachThreadInput(me, other, FALSE); + if (GetForegroundWindow() != h) { // still refused: a topmost toggle puts it above the others without keeping it there + SetWindowPos(h, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); + SetWindowPos(h, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); + } +} + static void window_main(void *arg) { (void)arg; HINSTANCE inst = GetModuleHandleW(NULL); @@ -293,10 +311,10 @@ static void window_main(void *arg) { int cw, ch, ow, oh; cfg_window_size(&cw, &ch); outer_size(NULL, cw, ch, &ow, &oh); - // The window opens behind the user's windows without taking focus: it shows the game's blank loading frames for a - // while, and must not cover what the player works on meanwhile. The game still counts itself in focus until the - // first WM_ACTIVATEAPP, so loading goes on, and keyboard input waits for the foreground (input_win.c). Its taskbar - // button flashes until it is brought up, and TOTK_FULLSCREEN waits for that first activation. + // The window opens behind the user's windows first and is then raised (raise_window): a game started by a frontend + // has no other way to reach it. The game counts itself in focus until the first WM_ACTIVATEAPP, so loading goes on, + // and keyboard input waits for the foreground (input_win.c). If Windows still refuses the foreground, the taskbar + // button flashes, and TOTK_FULLSCREEN waits for the first activation. // TOTK_BACKGROUND_WINDOW=1 (test runs): no flashing, never fullscreen at start, and F11 keeps the window's place. int background = g_background = cfg_get("TOTK_BACKGROUND_WINDOW") && atoi(cfg_get("TOTK_BACKGROUND_WINDOW")); g_hwnd = CreateWindowExW(0, wc.lpszClassName, L"TotK Recomp", WND_STYLE, CW_USEDEFAULT, CW_USEDEFAULT, ow, oh, NULL, @@ -315,6 +333,7 @@ static void window_main(void *arg) { outer_size(g_hwnd, cw, ch, &ow, &oh); SetWindowPos(g_hwnd, HWND_BOTTOM, 0, 0, ow, oh, SWP_NOMOVE | SWP_NOACTIVATE | SWP_SHOWWINDOW); if (!background) { + raise_window(g_hwnd); // a frontend's player may have no way to reach a window left behind FLASHWINFO fw = {.cbSize = sizeof fw, .hwnd = g_hwnd, .dwFlags = FLASHW_TRAY | FLASHW_TIMERNOFG}; FlashWindowEx(&fw); g_fs_pending = cfg_fullscreen(); diff --git a/runtime/main.c b/runtime/main.c index e0a82263..31c10608 100644 --- a/runtime/main.c +++ b/runtime/main.c @@ -546,6 +546,10 @@ int main(int argc, char **argv) { if (cfg.seconds && mode) return usage(argv[0]); log_open(!mode); if (!mode) { + // A game launched by a frontend or a shortcut gets a console of its own that only gets in the way. The log is in + // a file by now; with no log file, or with show_console = 1, the console stays. + if (rt_log_path() && !cfg_bool("TOTK_SHOW_CONSOLE") && plat_console_release_if_owned()) + rt_log("console: owned by the game alone, released (show_console = 1 keeps it)"); cfg.boot = cfg.seconds > 0; // --seconds starts the game like --boot, with its checkpoints rt_boot(); return 0; diff --git a/runtime/platform/linux.c b/runtime/platform/linux.c index 194bc9d8..33ff86b6 100644 --- a/runtime/platform/linux.c +++ b/runtime/platform/linux.c @@ -1262,6 +1262,8 @@ int plat_os_version(char *out, size_t cap) { int plat_is_wine(void) { return 0; } +int plat_console_release_if_owned(void) { return 0; } + int plat_stderr_path(char *out, size_t cap) { struct stat st; if (fstat(2, &st) || !S_ISREG(st.st_mode)) return 0; diff --git a/runtime/platform/platform.h b/runtime/platform/platform.h index ec7050aa..5291ad51 100644 --- a/runtime/platform/platform.h +++ b/runtime/platform/platform.h @@ -378,6 +378,11 @@ int plat_is_wine(void); // 1 when the Windows // The file the process's stderr (the log) goes to, as a UTF-8 path; 0 when stderr is not a file (a console, a pipe). int plat_stderr_path(char *out, size_t cap); +// Detaches the process from its console when no other process shares it (a frontend or a shortcut started us and +// Windows made the console for us); a terminal the user started us from keeps its output. Returns 1 when detached. +// Linux: 0. +int plat_console_release_if_owned(void); + // ---- desktop: the in-game menu's "Copy system info" and "Open log folder" int plat_clipboard_set(const char *utf8); // replaces the clipboard's text; 1 on success int plat_open_folder(const char *path); // shows the folder in the file manager; 1 on success diff --git a/runtime/platform/win32.c b/runtime/platform/win32.c index 1dc456b1..e510135e 100644 --- a/runtime/platform/win32.c +++ b/runtime/platform/win32.c @@ -1303,6 +1303,17 @@ int plat_stderr_path(char *out, size_t cap) { return WideCharToMultiByte(CP_UTF8, 0, p, -1, out, (int)cap, NULL, NULL) != 0; } +// GetConsoleProcessList counts this process alone only when the console was created for it. The window is hidden first +// and then the console freed: under Windows Terminal as the default terminal, freeing is what closes the terminal +// window that opened beside the game. +int plat_console_release_if_owned(void) { + DWORD pids[2]; + if (!GetConsoleWindow() || GetConsoleProcessList(pids, 2) != 1) return 0; + ShowWindow(GetConsoleWindow(), SW_HIDE); + FreeConsole(); + return 1; +} + // ---- desktop int plat_clipboard_set(const char *utf8) { diff --git a/totk.ini.example b/totk.ini.example index 9067ebb1..a9ecbc11 100644 --- a/totk.ini.example +++ b/totk.ini.example @@ -325,6 +325,10 @@ # cheat_0123abcd = 1 [diagnostics] +# Keep the console window of a game started from a frontend (Playnite, RetroBat, ES-DE) or a shortcut. Default 0: the +# console that Windows opened for the game alone is closed once the log is open. A game started from a terminal keeps +# printing there either way; the log is logs\totk.log. +# show_console = 0 # Extra lines in the log, comma separated: svc, host, ipc, fs, gfx, perf, sched, audio, present or all. The menu's # Performance log sets perf (frame timings). Default: none. # trace = perf