diff --git a/docs/building.md b/docs/building.md index 44216cc0..3de6466c 100644 --- a/docs/building.md +++ b/docs/building.md @@ -104,7 +104,8 @@ From the repository root, in PowerShell. Every step that depends on the game ver The AMD driver keeps its pipeline cache per exe path and holds a limited amount: preparing another build folder can evict this one's. `totk.exe --warm-shaders` rebuilds it from the shader cache. -7. Run. Keep the window in the foreground; an unfocused window stalls the game. +7. Run. The game pauses while its window is out of focus, as it does on the Switch when Home is pressed; + `assume_focus = 1` in `totk.ini`, or the Game tab, keeps it running in another window. ```powershell build\\totk.exe diff --git a/runtime/cfg.c b/runtime/cfg.c index 25a30f18..24594d63 100644 --- a/runtime/cfg.c +++ b/runtime/cfg.c @@ -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"}, {"ASSUME_FOCUS", "display"}, {"MENU_LANG", "language"}, {"LANG", "language"}, {"OPERATION_MODE", "language"}, {"VOLUME", "audio"}, {"MOTION", "input"}, {"RUMBLE_STRENGTH", "input"}, {"RUMBLE_CURVE", "input"}, {"RUMBLE_TRIGGERS", "input"}, @@ -101,6 +101,7 @@ static const CfgMeta metas[] = { {"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}, + {"ASSUME_FOCUS", "0", "0|1", LIVE}, // read on every focus change (ov_system.c) // Sound, Controls, Menu {"VOLUME", "100", "0..100", LIVE}, {"MOTION", "1", "0|1", LIVE}, {"RUMBLE_STRENGTH", "130", "0..300", LIVE}, {"RUMBLE_CURVE", "0.6", "0.2..1.5", LIVE}, diff --git a/runtime/ov_system.c b/runtime/ov_system.c index c3b5c6f7..663f799a 100644 --- a/runtime/ov_system.c +++ b/runtime/ov_system.c @@ -160,18 +160,15 @@ static void ov_focus_mode(Cpu *c) { // FocusState GetCurrentFocusState(): 1 in focus, 2 out of focus (nn::oe::FocusState). In focus until the window // reports otherwise through oe_set_focus; TOTK_ASSUME_FOCUS=1 (unattended runs) pins it to 1. The caller of // oe_set_focus also pushes OE_MSG_FOCUS_STATE_CHANGED. +// +// The setting is read on every focus change rather than once at start: a focus change is rare, the lookup is a short +// walk of the loaded ini entries, and the Game tab's row then takes effect the next time the window is left, without +// a restart. static volatile LONG focus_state = 1; -static int assume_focus(void) { - static volatile LONG v = -1; - LONG a = v; - if (a < 0) { - const char *e = cfg_get("TOTK_ASSUME_FOCUS"); - a = e && atoi(e) ? 1 : 0; - InterlockedExchange(&v, a); - } - return (int)a; +void oe_set_focus(int in_focus) { + const char *e = cfg_get("TOTK_ASSUME_FOCUS"); + InterlockedExchange(&focus_state, in_focus || (e && atoi(e)) ? 1 : 2); } -void oe_set_focus(int in_focus) { InterlockedExchange(&focus_state, in_focus || assume_focus() ? 1 : 2); } static void ov_focus_state(Cpu *c) { ret_x(c, (uint64_t)focus_state); } static volatile LONG notify_resume, notify_operation, notify_performance; diff --git a/runtime/ui/menu.cpp b/runtime/ui/menu.cpp index 865f6b17..adb23918 100644 --- a/runtime/ui/menu.cpp +++ b/runtime/ui/menu.cpp @@ -553,6 +553,7 @@ static void tab_game(float scale) { row_game_lang(); static const UiTextId mode[] = {UI_MENU_MODE_DOCKED, UI_MENU_MODE_HANDHELD}; opt_choice("TOTK_OPERATION_MODE", UI_MENU_OPERATION_MODE, mode, 2, UI_MENU_OPERATION_MODE_DESC); + opt_toggle("TOTK_ASSUME_FOCUS", UI_MENU_ASSUME_FOCUS, UI_MENU_ASSUME_FOCUS_DESC); opt_end(); } diff --git a/runtime/ui_text.c b/runtime/ui_text.c index 65a1926e..fbb290b9 100644 --- a/runtime/ui_text.c +++ b/runtime/ui_text.c @@ -86,6 +86,10 @@ static const char *const text_en[UI_TEXT_COUNT] = { [UI_MENU_OPERATION_MODE] = "Console mode", [UI_MENU_OPERATION_MODE_DESC] = "Whether the game thinks it runs docked or handheld.", [UI_MENU_MODE_DOCKED] = "Docked", [UI_MENU_MODE_HANDHELD] = "Handheld", + [UI_MENU_ASSUME_FOCUS] = "Keep running out of focus", + [UI_MENU_ASSUME_FOCUS_DESC] = "The game pauses when its window loses focus, as it does on the Switch when Home is " + "pressed. On, it keeps running while you are in another window, and the keyboard " + "stays quiet until the window is in front again.", [UI_MENU_VOLUME] = "Volume", [UI_MENU_VOLUME_DESC] = "Master volume of the game.", @@ -320,6 +324,10 @@ static const char *const text_ru[UI_TEXT_COUNT] = { [UI_MENU_OPERATION_MODE] = "Режим консоли", [UI_MENU_OPERATION_MODE_DESC] = "Игра считает, что консоль в док-станции или в портативном режиме.", [UI_MENU_MODE_DOCKED] = "В док-станции", [UI_MENU_MODE_HANDHELD] = "Портативный", + [UI_MENU_ASSUME_FOCUS] = "Работать без фокуса", + [UI_MENU_ASSUME_FOCUS_DESC] = "Игра встаёт на паузу, когда окно теряет фокус, как на Switch при нажатии Home. " + "Включено: игра идёт, пока вы в другом окне, а клавиатура не действует, пока " + "окно не вернётся на передний план.", [UI_MENU_VOLUME] = "Громкость", [UI_MENU_VOLUME_DESC] = "Общая громкость игры.", diff --git a/runtime/ui_text.h b/runtime/ui_text.h index 13a328b6..e19c4905 100644 --- a/runtime/ui_text.h +++ b/runtime/ui_text.h @@ -47,6 +47,7 @@ typedef enum { UI_MENU_HIGHFPS_FIX, UI_MENU_HIGHFPS_FIX_DESC, UI_MENU_GAME_LANG, UI_MENU_GAME_LANG_DESC, UI_MENU_GAME_LANG_AUTO, UI_MENU_OPERATION_MODE, UI_MENU_OPERATION_MODE_DESC, UI_MENU_MODE_DOCKED, UI_MENU_MODE_HANDHELD, + UI_MENU_ASSUME_FOCUS, UI_MENU_ASSUME_FOCUS_DESC, // Sound UI_MENU_VOLUME, UI_MENU_VOLUME_DESC, diff --git a/totk.ini.example b/totk.ini.example index aba2432d..41356ee8 100644 --- a/totk.ini.example +++ b/totk.ini.example @@ -102,6 +102,9 @@ # here. Changes while the game runs take effect at once. # window_size = 1920x1080 # fullscreen = 0 +# The game pauses when its window loses focus, as it does on the Switch when Home is pressed. 1 keeps it running while +# you are in another window; the keyboard stays quiet until the window is in front again. Read at each focus change. +# assume_focus = 0 # Performance overlay in the top right corner: off, fps, or full (frame rate, mean and longest frame time). F10 # cycles the modes in game. # perf_overlay = off