mirror of
https://github.com/valentderah/totk-pc-recomp.git
synced 2026-11-19 20:25:57 +00:00
Compile Dear ImGui and draw the menu overlay into the swapchain image, behind the test hook TOTK_MENU_TEST until the pages are agreed
The window follows TOTK_WINDOW_SIZE, TOTK_FULLSCREEN and TOTK_VK_PRESENT while the game runs, and F11 saves the fullscreen state. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c3b3c297cf
commit
c6a7a28ab4
9 files changed
+706
-21
No files matched your search
@@ -6,7 +6,7 @@ Code copied or adapted from another project is listed here with its source, the
|
||||
|---|---|---|---|
|
||||
| MacNativeGames extraction scripts and verification hashes | https://github.com/ly05010419/MacNativeGames @ `b75be8cfa704df3701e86130c8ced268e79d6b11`, Copyright (c) 2026 MacNativeGames contributors | MIT | `tools/vendor/macnativegames/` (unmodified), `tools/data/expected-v*.json` |
|
||||
| LAS Recomp lifter, code generator, FP/SIMD lowering, CPU headers and differential tests | https://github.com/peiikai/LASRecomp @ `da35b83a9611d046a9a681aae668d7085954d37f`, Copyright (c) 2026 Peiikai | MIT | `recomp/lifter.py`, `recomp/simd_c.py`, `recomp/nso.py`, `recomp/gen.py`, `recomp/module.py`, `tests/jumptables_check.py`, `runtime/cpu.h`, `runtime/simd.h`, `runtime/simd_fp.h`, `tests/diff/` |
|
||||
| LAS Recomp host runtime: NSO loader, host-function table, guest-space reservation and re-execution, guest thread start | https://github.com/peiikai/LASRecomp @ `da35b83a9611d046a9a681aae668d7085954d37f`, Copyright (c) 2026 Peiikai | MIT | `runtime/loader.c`, `runtime/hostfn.c`, `runtime/memory.c`; M3 tasks T2 and T6: `runtime/kernel.c`, `runtime/boot.c`; M4 T2: `runtime/vk_device.c`, `runtime/gfx_window.c`, M4 T5a: `runtime/tex_astc.c` (`runtime/nvn/astc.c`; its decode ported to GLSL in `runtime/shaders/astc_decode.comp`, compiled into `runtime/astc_decode_spv.h`, and its tables copied into `runtime/vk_astc.c`), `runtime/vk_formats.c` (format table of `runtime/nvn/vulkan/textures.c`), M4 T5b: `runtime/vk_memory.c` (page write generations of `runtime/nvn/vulkan/exec.c`, deferred destruction of `textures.c`), `runtime/vk_texture.c` (image creation, uploads and samplers of `runtime/nvn/vulkan/textures.c`), M4 T6a: `runtime/vk_sync.c` (timeline submissions and waits of `runtime/nvn/vulkan/exec.c`), M4 T6b: `runtime/vk_pipeline.c` (blend, compare and stencil mappings, vertex format table with its 3-component fallback and pipeline cache file of `runtime/nvn/vulkan/exec.c` and `device.c`), M4 T6c1: `runtime/vk_exec.c` (pass begin and end, scissor clip and attachment clears of `runtime/nvn/vulkan/exec.c`), M4 T6c3: `runtime/vk_exec_xfer.c` (copies of `runtime/nvn/vulkan/exec.c`), M4 T6c2: `runtime/vk_exec_draw.c` (uniform buffer spans, texture and sampler descriptors and dispatch flow of `runtime/nvn/vulkan/exec.c`) |
|
||||
| LAS Recomp host runtime: NSO loader, host-function table, guest-space reservation and re-execution, guest thread start | https://github.com/peiikai/LASRecomp @ `da35b83a9611d046a9a681aae668d7085954d37f`, Copyright (c) 2026 Peiikai | MIT | `runtime/loader.c`, `runtime/hostfn.c`, `runtime/memory.c`; M3 tasks T2 and T6: `runtime/kernel.c`, `runtime/boot.c`; M4 T2: `runtime/vk_device.c`, `runtime/gfx_window.c`, M4 T5a: `runtime/tex_astc.c` (`runtime/nvn/astc.c`; its decode ported to GLSL in `runtime/shaders/astc_decode.comp`, compiled into `runtime/astc_decode_spv.h`, and its tables copied into `runtime/vk_astc.c`), `runtime/vk_formats.c` (format table of `runtime/nvn/vulkan/textures.c`), M4 T5b: `runtime/vk_memory.c` (page write generations of `runtime/nvn/vulkan/exec.c`, deferred destruction of `textures.c`), `runtime/vk_texture.c` (image creation, uploads and samplers of `runtime/nvn/vulkan/textures.c`), M4 T6a: `runtime/vk_sync.c` (timeline submissions and waits of `runtime/nvn/vulkan/exec.c`), M4 T6b: `runtime/vk_pipeline.c` (blend, compare and stencil mappings, vertex format table with its 3-component fallback and pipeline cache file of `runtime/nvn/vulkan/exec.c` and `device.c`), M4 T6c1: `runtime/vk_exec.c` (pass begin and end, scissor clip and attachment clears of `runtime/nvn/vulkan/exec.c`), M4 T6c3: `runtime/vk_exec_xfer.c` (copies of `runtime/nvn/vulkan/exec.c`), M4 T6c2: `runtime/vk_exec_draw.c` (uniform buffer spans, texture and sampler descriptors and dispatch flow of `runtime/nvn/vulkan/exec.c`); in-game menu: `runtime/ui/menu.cpp` (Dear ImGui Vulkan set-up of `runtime/nvn/vulkan/imgui_glue.cpp`) |
|
||||
| MacNativeGames TotK host runtime: dynamic linking, identity check, module permissions, guest memory and SVCs, threads, IPC, audio renderer, system services, RomFS and save storage, boot sequence | https://github.com/ly05010419/MacNativeGames @ `b75be8cfa704df3701e86130c8ced268e79d6b11` (`games/totk/runtime/`, `games/totk/scripts/prepare_runtime.py`), Copyright (c) 2026 MacNativeGames contributors | MIT | `runtime/loader.c`, `runtime/memory.c`; M3 tasks T2-T6: `runtime/kernel.c`, `runtime/svc.c`, `runtime/ipc.c`, `runtime/ipc.h`, `runtime/audren.c`, `runtime/audren.h`, `runtime/audio_mixer.c`, `runtime/audio_effects.c`, `runtime/audio_effects.h`, `runtime/audio_reverb.c`, `runtime/audio_reverb.h` (M5; SDL3 output replaces CoreAudio), `runtime/ov_system.c` (also `shared_font.c`: the BFTTF layout behind nn::pl), `runtime/ov_input.c` (also `hid_feedback.c`: vibration and six-axis handles and calls), `runtime/motion_fusion.c` (six-axis fusion of `motion_fusion.c`), `runtime/ov_media.c` (M5: hardware Opus decoder over libopus), `runtime/swkbd_win.c` (`swkbd_host.c`: ShowKeyboardArg offsets, UTF-8/UTF-16 conversion, disabled-key filter, result codes; Win32 window replaces the macOS text bar), `runtime/ov_gfx.c`, `runtime/romfs.c`, `runtime/romfs_path.h`, `runtime/fs_host.c`, `runtime/fs.h`, `runtime/boot.c`; M4 T2: `runtime/gfx_window.c` |
|
||||
| MacNativeGames TotK frame-rate patches: 60 fps present-interval controller, real-time frame step and its present sampling, hair and cloth clock, trampoline slow-motion check (instruction words and 1.2.1 sites), player position chain; quick-menu capture background RomFS overlay | https://github.com/ly05010419/MacNativeGames @ `ebe621de99bfc48f3c42f2d2aa73e04fbcc6eae2` (`games/totk/runtime/game_patches.c`, `game_version.h`, `world_survey.c`, `games/totk/scripts/make_romfs_patches.py`), Copyright (c) 2026 MacNativeGames contributors | MIT | `runtime/frame_rate.c`, `recomp/patches-v121.txt`, `tools/make_romfs_patches.py` |
|
||||
| MacNativeGames TotK virtual-core preemption: asynchronous preemption of an owner in top-level game code, priority inheritance through guest mutexes, the SDK's preemption-disable protocol (TLR+0x100/+0x102, SVC 0x36), the core-wait diagnostics | https://github.com/ly05010419/MacNativeGames @ `33e8fa83052ea1ae09a3583137008e9797e12950` (`games/totk/runtime/threads.c`, commits 8bf0893 and 19730cd), Copyright (c) 2026 MacNativeGames contributors | MIT | `runtime/kernel.c` (SuspendThread and a register-saving stub replace SIGUSR2), `runtime/hostfn.c`, `runtime/svc.c` (host depth) |
|
||||
@@ -22,7 +22,8 @@ Code copied or adapted from another project is listed here with its source, the
|
||||
| MacNativeGames block-linear deswizzler (address function; copy loop split out as `tex_bl_copy`) | https://github.com/ly05010419/MacNativeGames @ `b75be8cfa704df3701e86130c8ced268e79d6b11` (`games/totk/third_party/d2r_gfx/gfx/tex/nvn_deswizzle.c`), Copyright (c) 2026 jhaizhou | MIT | M4 task T5a: `runtime/tex_deswizzle.c`, `runtime/tex.h` |
|
||||
| SDL 3.4.18, dynamic link, `SDL3.dll` copied next to `totk.exe`. Developer builds use the MSYS2 build (`mingw-w64-ucrt-x86_64-sdl3`, which imports `libiconv-2.dll`, LGPL-2.1, unmodified, copied beside it); the installer release ships the upstream release `SDL3-3.4.18-win32-x64.zip`, which imports no libiconv | https://libsdl.org, Copyright (c) 1997-2026 Sam Lantinga | zlib | `runtime/input_win.c` (gamepad input, rumble, gyro and accelerometer) |
|
||||
| libopus (MSYS2 `mingw-w64-ucrt-x86_64-opus`), dynamic link, `libopus-0.dll` copied next to `totk.exe` | https://opus-codec.org, Copyright (c) 2001-2023 Xiph.Org, Skype Limited, Octasic, Jean-Marc Valin, Timothy B. Terriberry, CSIRO, Gregory Maxwell, Mark Borgerding, Erik de Castro Lopo, Mozilla, Amazon | BSD-3-Clause | `runtime/ov_media.c` (nn::codec hardware Opus decoder) |
|
||||
| Dear ImGui 1.91.9 (core and Vulkan back end, unmodified), as vendored by LAS Recomp | https://github.com/ocornut/imgui, via https://github.com/peiikai/LASRecomp @ `da35b83a9611d046a9a681aae668d7085954d37f` (`third_party/imgui/`), Copyright (c) 2014-2025 Omar Cornut | MIT | `runtime/third_party/imgui/` (for the in-game menu; not compiled yet) |
|
||||
| Dear ImGui 1.91.9 (core and Vulkan back end, unmodified), as vendored by LAS Recomp | https://github.com/ocornut/imgui, via https://github.com/peiikai/LASRecomp @ `da35b83a9611d046a9a681aae668d7085954d37f` (`third_party/imgui/`), Copyright (c) 2014-2025 Omar Cornut | MIT | `runtime/third_party/imgui/` (compiled into `totk.exe` for the in-game menu, `runtime/ui/`) |
|
||||
| Roboto Medium font (Dear ImGui's `misc/fonts/Roboto-Medium.ttf`, unmodified) | https://fonts.google.com/specimen/Roboto, via https://github.com/peiikai/LASRecomp @ `da35b83a9611d046a9a681aae668d7085954d37f` (`third_party/imgui/misc/fonts/`), Copyright 2011 Google Inc. | Apache-2.0 | `runtime/ui/fonts/Roboto-Medium.ttf` (licence text in `runtime/ui/fonts/LICENSE-Roboto.txt`), embedded by `runtime/ui/menu.cpp` |
|
||||
| Vulkan Memory Allocator 3.4.0 (MSYS2 `mingw-w64-ucrt-x86_64-vulkan-memory-allocator`), header-only, compiled into `totk.exe` | https://github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator, Copyright (c) 2017-2026 Advanced Micro Devices, Inc. | MIT | `runtime/vk_vma.cpp` (the allocator behind `runtime/vk_memory.c`) |
|
||||
| MacNativeGames host movie decoder (`movie::Decoder` for VP9 over libvpx: entry list, buffer and event semantics, NV12 output format, PTS pacing) | https://github.com/ly05010419/MacNativeGames @ `b75be8cfa704df3701e86130c8ced268e79d6b11` (`games/totk/runtime/movie_host.c`, `movie_host.h`), Copyright (c) 2026 MacNativeGames contributors | MIT | `runtime/ov_movie.c`, `runtime/movie.h` |
|
||||
| libvpx 1.17.0 (MSYS2 `mingw-w64-ucrt-x86_64-libvpx`), static link (`libvpx.a`), no DLL shipped; the release notices must carry its BSD licence text and the WebM Project's `PATENTS` grant | https://chromium.googlesource.com/webm/libvpx, Copyright (c) 2010, The WebM Project authors | BSD-3-Clause | `runtime/ov_movie.c` (VP9 decoding of the `Event/Movie` WebM files) |
|
||||
|
||||
+1
-1
@@ -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"},
|
||||
{"FULLSCREEN", "display"}, {"WINDOW_SIZE", "display"}, {"FPS_COUNTER", "display"},
|
||||
{"FULLSCREEN", "display"}, {"WINDOW_SIZE", "display"}, {"FPS_COUNTER", "display"}, {"VK_PRESENT", "display"},
|
||||
{"MENU_LANG", "language"},
|
||||
{"VOLUME", "audio"},
|
||||
{"MOTION", "input"}, {"RUMBLE_STRENGTH", "input"}, {"RUMBLE_CURVE", "input"}, {"RUMBLE_TRIGGERS", "input"},
|
||||
|
||||
+188
-18
@@ -8,6 +8,10 @@
|
||||
// bound system events. Presents come from any host thread (the back end's present worker) and take g_pl; every queue
|
||||
// submission takes the recursive queue lock (vk_queue_lock). The swapchain is rebuilt lazily: WM_SIZE only marks it
|
||||
// dirty, the next present (or gfx_window_resize) rebuilds it.
|
||||
//
|
||||
// The in-game menu (ui/menu.h) draws over the game image in the present's command buffer, after the blit; its keyboard
|
||||
// and mouse come from the window procedure (ui/menu_win.cpp). The window's size and fullscreen state are the settings
|
||||
// TOTK_WINDOW_SIZE and TOTK_FULLSCREEN, applied at start and whenever a cfg_set changes them (window_settings_live).
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -17,6 +21,8 @@
|
||||
#include "flight.h"
|
||||
#include "gfx.h"
|
||||
#include "input.h"
|
||||
#include "nvn_api.h"
|
||||
#include "ui/menu.h"
|
||||
#include "vk.h"
|
||||
|
||||
#define FRAMES 2
|
||||
@@ -47,6 +53,7 @@ static VkFormat g_sc_fmt;
|
||||
static VkExtent2D g_sc_ext;
|
||||
static uint32_t g_sc_n;
|
||||
static VkImage g_sc_img[MAX_IMAGES];
|
||||
static VkImageView g_sc_view[MAX_IMAGES]; // colour attachment views for the menu overlay
|
||||
static VkSemaphore g_render_done[MAX_IMAGES];
|
||||
static VkCommandPool g_pool;
|
||||
static VkCommandBuffer g_cb[FRAMES];
|
||||
@@ -171,37 +178,131 @@ HWND gfx_window_handle(void) { return g_hwnd; }
|
||||
|
||||
// ---- window thread
|
||||
#define WND_STYLE WS_OVERLAPPEDWINDOW
|
||||
#define WM_APP_SETTINGS (WM_APP + 1)
|
||||
|
||||
static WINDOWPLACEMENT g_saved_place = {sizeof g_saved_place}; // the window behind fullscreen (window thread)
|
||||
|
||||
static int is_fullscreen(HWND h) { return !(GetWindowLongW(h, GWL_STYLE) & WS_OVERLAPPEDWINDOW); }
|
||||
|
||||
// TOTK_FULLSCREEN=1: borderless window over the monitor. TOTK_WINDOW_SIZE=<w>x<h>: client area of the window, default
|
||||
// 1920x1080 (the swapchain follows the window; the game image is scaled to it).
|
||||
static int cfg_fullscreen(void) {
|
||||
const char *e = cfg_get("TOTK_FULLSCREEN");
|
||||
return e && !strcmp(e, "1");
|
||||
}
|
||||
|
||||
static void cfg_window_size(int *w, int *h) {
|
||||
const char *e = cfg_get("TOTK_WINDOW_SIZE");
|
||||
int x = 0, y = 0;
|
||||
if (!e || sscanf(e, "%dx%d", &x, &y) != 2 || x < 640 || y < 360 || x > 7680 || y > 4320) x = 1920, y = 1080;
|
||||
*w = x;
|
||||
*h = y;
|
||||
}
|
||||
|
||||
// F11: borderless window over the whole monitor, and back to the saved window. The swapchain follows through WM_SIZE.
|
||||
// Not Alt+Enter: Enter is the Plus button (input_win.c).
|
||||
static void toggle_fullscreen(HWND h) {
|
||||
static WINDOWPLACEMENT saved = {sizeof saved};
|
||||
LONG style = GetWindowLongW(h, GWL_STYLE);
|
||||
if (style & WS_OVERLAPPEDWINDOW) {
|
||||
MONITORINFO mi = {sizeof mi};
|
||||
if (!GetWindowPlacement(h, &saved) || !GetMonitorInfoW(MonitorFromWindow(h, MONITOR_DEFAULTTOPRIMARY), &mi))
|
||||
if (!GetWindowPlacement(h, &g_saved_place) || !GetMonitorInfoW(MonitorFromWindow(h, MONITOR_DEFAULTTOPRIMARY), &mi))
|
||||
return;
|
||||
SetWindowLongW(h, GWL_STYLE, (style & ~WS_OVERLAPPEDWINDOW) | WS_POPUP);
|
||||
SetWindowPos(h, HWND_TOP, mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right - mi.rcMonitor.left,
|
||||
mi.rcMonitor.bottom - mi.rcMonitor.top, SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
|
||||
} else {
|
||||
SetWindowLongW(h, GWL_STYLE, (style & ~WS_POPUP) | WND_STYLE);
|
||||
SetWindowPlacement(h, &saved);
|
||||
SetWindowPlacement(h, &g_saved_place);
|
||||
SetWindowPos(h, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
|
||||
}
|
||||
}
|
||||
|
||||
// The window size and fullscreen state last taken from the settings (window thread). apply_settings acts on a change of
|
||||
// either value only, so a window resized by hand keeps its size when another setting changes.
|
||||
static char g_applied_size[32];
|
||||
static int g_applied_fs;
|
||||
|
||||
static void note_applied(void) {
|
||||
const char *e = cfg_get("TOTK_WINDOW_SIZE");
|
||||
snprintf(g_applied_size, sizeof g_applied_size, "%s", e ? e : "");
|
||||
g_applied_fs = cfg_fullscreen();
|
||||
}
|
||||
|
||||
// Window thread: the window takes the size and fullscreen state of the settings when they changed. In fullscreen the
|
||||
// size goes into the placement restored when fullscreen ends.
|
||||
static void apply_settings(HWND h) {
|
||||
const char *e = cfg_get("TOTK_WINDOW_SIZE");
|
||||
int size_changed = strcmp(e ? e : "", g_applied_size) != 0, fs = cfg_fullscreen(), fs_changed = fs != g_applied_fs;
|
||||
note_applied();
|
||||
if (size_changed) {
|
||||
int cw, ch;
|
||||
cfg_window_size(&cw, &ch);
|
||||
RECT r = {0, 0, cw, ch};
|
||||
AdjustWindowRect(&r, WND_STYLE, FALSE);
|
||||
if (is_fullscreen(h)) {
|
||||
RECT *n = &g_saved_place.rcNormalPosition;
|
||||
n->right = n->left + (r.right - r.left);
|
||||
n->bottom = n->top + (r.bottom - r.top);
|
||||
} else {
|
||||
RECT have;
|
||||
if (GetClientRect(h, &have) && (have.right != cw || have.bottom != ch)) {
|
||||
if (IsZoomed(h)) ShowWindow(h, SW_RESTORE);
|
||||
SetWindowPos(h, NULL, 0, 0, r.right - r.left, r.bottom - r.top,
|
||||
SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (fs_changed && fs != is_fullscreen(h)) {
|
||||
input_cursor_suspend(1);
|
||||
toggle_fullscreen(h);
|
||||
input_cursor_suspend(0);
|
||||
}
|
||||
}
|
||||
|
||||
void gfx_window_apply_settings(void) {
|
||||
if (g_hwnd) PostMessageW(g_hwnd, WM_APP_SETTINGS, 0, 0);
|
||||
}
|
||||
|
||||
// Present path (g_pl held): a settings change (cfg_version) reaches the window thread, which applies a changed size or
|
||||
// fullscreen; a changed TOTK_VK_PRESENT rebuilds the swapchain at this present.
|
||||
static void window_settings_live(void) {
|
||||
static unsigned seen;
|
||||
static int started;
|
||||
static char present[16]; // the TOTK_VK_PRESENT the swapchain was made with
|
||||
unsigned v = cfg_version();
|
||||
if (started && v == seen) return;
|
||||
seen = v;
|
||||
const char *e = cfg_get("TOTK_VK_PRESENT");
|
||||
if (!started || strncmp(e ? e : "", present, sizeof present - 1)) {
|
||||
snprintf(present, sizeof present, "%s", e ? e : "");
|
||||
if (started) InterlockedExchange(&g_dirty, 1);
|
||||
}
|
||||
if (started) gfx_window_apply_settings();
|
||||
started = 1;
|
||||
}
|
||||
|
||||
void gfx_window_request_close(void) {
|
||||
if (g_hwnd) PostMessageW(g_hwnd, WM_CLOSE, 0, 0);
|
||||
}
|
||||
|
||||
static LRESULT CALLBACK wnd_proc(HWND h, UINT m, WPARAM w, LPARAM l) {
|
||||
LRESULT input_res;
|
||||
if (input_window_msg(h, m, w, l, &input_res)) return input_res;
|
||||
if (menu_window_msg(h, m, w, l, &input_res)) return input_res;
|
||||
switch (m) {
|
||||
case WM_KEYDOWN:
|
||||
if (w == VK_F11 && !(l & (1 << 30))) { // bit 30: auto-repeat
|
||||
input_cursor_suspend(1);
|
||||
toggle_fullscreen(h);
|
||||
input_cursor_suspend(0);
|
||||
cfg_set("TOTK_FULLSCREEN", is_fullscreen(h) ? "1" : "0"); // the menu shows it; the next start keeps it
|
||||
cfg_save();
|
||||
note_applied(); // what cfg_get reads now (the environment may still override it)
|
||||
}
|
||||
break;
|
||||
case WM_APP_SETTINGS:
|
||||
apply_settings(h);
|
||||
return 0;
|
||||
case WM_SIZE:
|
||||
if (w != SIZE_MINIMIZED) InterlockedExchange(&g_dirty, 1);
|
||||
return 0;
|
||||
@@ -231,10 +332,12 @@ static DWORD WINAPI window_main(void *arg) {
|
||||
WNDCLASSEXW wc = {.cbSize = sizeof wc, .lpfnWndProc = wnd_proc, .hInstance = inst,
|
||||
.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_ARROW), .lpszClassName = L"TotKRecompWindow"};
|
||||
RegisterClassExW(&wc);
|
||||
RECT r = {0, 0, 1920, 1080};
|
||||
int cw, ch;
|
||||
cfg_window_size(&cw, &ch);
|
||||
RECT r = {0, 0, cw, ch};
|
||||
AdjustWindowRect(&r, WND_STYLE, FALSE);
|
||||
// TOTK_BACKGROUND_WINDOW=1 (test runs): the window opens behind the user's windows without taking focus; it keeps its
|
||||
// taskbar button and can be brought up by hand.
|
||||
// taskbar button and can be brought up by hand. It never goes fullscreen at start.
|
||||
int 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,
|
||||
r.right - r.left, r.bottom - r.top, NULL, NULL, inst, NULL);
|
||||
@@ -246,6 +349,8 @@ static DWORD WINAPI window_main(void *arg) {
|
||||
SetWindowPos(g_hwnd, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_SHOWWINDOW);
|
||||
else
|
||||
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();
|
||||
}
|
||||
SetEvent(g_wnd_ready);
|
||||
if (g_wnd_failed) return 1;
|
||||
@@ -329,7 +434,8 @@ static int create_swapchain(void) {
|
||||
VkSwapchainCreateInfoKHR ci = {
|
||||
.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR, .surface = g_surface, .minImageCount = count,
|
||||
.imageFormat = sf.format, .imageColorSpace = sf.colorSpace, .imageExtent = ext, .imageArrayLayers = 1,
|
||||
.imageUsage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
|
||||
.imageUsage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
|
||||
VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, // every surface supports it (the menu overlay draws into it)
|
||||
.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE, .preTransform = caps.currentTransform,
|
||||
.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR, .presentMode = pick_present_mode(c->phys), .clipped = VK_TRUE,
|
||||
.oldSwapchain = old};
|
||||
@@ -340,14 +446,24 @@ static int create_swapchain(void) {
|
||||
vk_queue_unlock();
|
||||
return 0;
|
||||
}
|
||||
for (uint32_t i = 0; i < g_sc_n; i++) vkDestroySemaphore(c->device, g_render_done[i], NULL);
|
||||
for (uint32_t i = 0; i < g_sc_n; i++) {
|
||||
vkDestroySemaphore(c->device, g_render_done[i], NULL);
|
||||
if (g_sc_view[i]) vkDestroyImageView(c->device, g_sc_view[i], NULL);
|
||||
g_sc_view[i] = VK_NULL_HANDLE;
|
||||
}
|
||||
if (old) vkDestroySwapchainKHR(c->device, old, NULL);
|
||||
g_sc_fmt = sf.format;
|
||||
g_sc_ext = ext;
|
||||
g_sc_n = MAX_IMAGES;
|
||||
vkGetSwapchainImagesKHR(c->device, g_sc, &g_sc_n, g_sc_img);
|
||||
VkSemaphoreCreateInfo semi = {.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO};
|
||||
for (uint32_t i = 0; i < g_sc_n; i++) vkCreateSemaphore(c->device, &semi, NULL, &g_render_done[i]);
|
||||
for (uint32_t i = 0; i < g_sc_n; i++) {
|
||||
vkCreateSemaphore(c->device, &semi, NULL, &g_render_done[i]);
|
||||
VkImageViewCreateInfo vi = {.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, .image = g_sc_img[i],
|
||||
.viewType = VK_IMAGE_VIEW_TYPE_2D, .format = sf.format,
|
||||
.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}};
|
||||
if (vkCreateImageView(c->device, &vi, NULL, &g_sc_view[i]) != VK_SUCCESS) g_sc_view[i] = VK_NULL_HANDLE;
|
||||
}
|
||||
free_capture();
|
||||
vk_queue_unlock();
|
||||
InterlockedExchange(&g_dirty, 0);
|
||||
@@ -505,6 +621,23 @@ int vk_present_captured(const uint8_t **px, int *w, int *h, VkFormat *fmt) {
|
||||
return ok;
|
||||
}
|
||||
|
||||
// The captured swapchain image as a PNG (the menu's test hook), RGBA with opaque alpha.
|
||||
static void save_capture(const char *path) {
|
||||
size_t n = (size_t)g_cap_w * (size_t)g_cap_h * 4;
|
||||
uint8_t *px = malloc(n);
|
||||
if (!px) return;
|
||||
int bgra = g_sc_fmt == VK_FORMAT_B8G8R8A8_UNORM || g_sc_fmt == VK_FORMAT_B8G8R8A8_SRGB;
|
||||
for (size_t i = 0; i < n; i += 4) {
|
||||
px[i] = g_cap_ptr[i + (bgra ? 2 : 0)];
|
||||
px[i + 1] = g_cap_ptr[i + 1];
|
||||
px[i + 2] = g_cap_ptr[i + (bgra ? 0 : 2)];
|
||||
px[i + 3] = 255;
|
||||
}
|
||||
rt_write_png(path, px, (uint32_t)g_cap_w, (uint32_t)g_cap_h);
|
||||
free(px);
|
||||
rt_log("gfx: menu test shot %s (%dx%d)", path, g_cap_w, g_cap_h);
|
||||
}
|
||||
|
||||
static void present_image(VkImage src, VkImageLayout layout, int w, int h, const int crop[4], int defer) {
|
||||
int general = layout == VK_IMAGE_LAYOUT_GENERAL;
|
||||
gfx_window_start();
|
||||
@@ -542,7 +675,14 @@ static void present_image(VkImage src, VkImageLayout layout, int w, int h, const
|
||||
if (cy < 0) cy = 0;
|
||||
if (cx + cw > w) cw = w - cx;
|
||||
if (cy + ch > h) ch = h - cy;
|
||||
int cap = g_capture && ensure_capture_buffer();
|
||||
window_settings_live();
|
||||
// The menu overlay: laid out before recording (its first frame starts the ImGui back end and uploads the font)
|
||||
const char *menu_shot = NULL;
|
||||
MenuTarget mt = {c->instance, c->phys, c->device, c->gfx_family, c->gfx_queue, g_sc_fmt, g_sc_ext.width,
|
||||
g_sc_ext.height};
|
||||
int overlay = g_sc_view[idx] &&
|
||||
menu_overlay_frame(__atomic_load_n(&gfx_counters.frames, __ATOMIC_RELAXED), &mt, &menu_shot);
|
||||
int cap = (g_capture || menu_shot) && ensure_capture_buffer();
|
||||
int thumb = g_th_n && ensure_thumbs();
|
||||
|
||||
VkCommandBuffer cb = g_cb[slot];
|
||||
@@ -564,25 +704,46 @@ static void present_image(VkImage src, VkImageLayout layout, int w, int h, const
|
||||
if (general) // later submissions that write the source wait for the blit's read
|
||||
sync_barrier(cb, src, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL, VK_PIPELINE_STAGE_2_TRANSFER_BIT, 0,
|
||||
VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT, 0);
|
||||
// last: the image's layout, and the stage and access of its last write, as each step leaves it
|
||||
VkImageLayout last = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
|
||||
VkPipelineStageFlags2 last_stage = VK_PIPELINE_STAGE_2_TRANSFER_BIT;
|
||||
VkAccessFlags2 last_write = VK_ACCESS_2_TRANSFER_WRITE_BIT;
|
||||
if (overlay) {
|
||||
sync_barrier(cb, dst, last, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, last_stage, last_write,
|
||||
VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT,
|
||||
VK_ACCESS_2_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_2_COLOR_ATTACHMENT_WRITE_BIT);
|
||||
VkRenderingAttachmentInfo ca = {.sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO, .imageView = g_sc_view[idx],
|
||||
.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
|
||||
.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD, .storeOp = VK_ATTACHMENT_STORE_OP_STORE};
|
||||
VkRenderingInfo ri = {.sType = VK_STRUCTURE_TYPE_RENDERING_INFO, .renderArea = {{0, 0}, g_sc_ext}, .layerCount = 1,
|
||||
.colorAttachmentCount = 1, .pColorAttachments = &ca};
|
||||
vkCmdBeginRendering(cb, &ri);
|
||||
menu_overlay_draw(cb);
|
||||
vkCmdEndRendering(cb);
|
||||
last = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
||||
last_stage = VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT;
|
||||
last_write = VK_ACCESS_2_COLOR_ATTACHMENT_WRITE_BIT;
|
||||
}
|
||||
if (cap) {
|
||||
sync_barrier(cb, dst, last, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_PIPELINE_STAGE_2_TRANSFER_BIT,
|
||||
VK_ACCESS_2_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_2_TRANSFER_BIT, VK_ACCESS_2_TRANSFER_READ_BIT);
|
||||
sync_barrier(cb, dst, last, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, last_stage, last_write,
|
||||
VK_PIPELINE_STAGE_2_TRANSFER_BIT, VK_ACCESS_2_TRANSFER_READ_BIT);
|
||||
VkBufferImageCopy bc = {.imageSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1},
|
||||
.imageExtent = {g_sc_ext.width, g_sc_ext.height, 1}};
|
||||
vkCmdCopyImageToBuffer(cb, dst, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, g_cap_buf, 1, &bc);
|
||||
last = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
|
||||
last_stage = VK_PIPELINE_STAGE_2_TRANSFER_BIT;
|
||||
last_write = 0;
|
||||
}
|
||||
if (thumb) {
|
||||
if (last != VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL)
|
||||
sync_barrier(cb, dst, last, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_PIPELINE_STAGE_2_TRANSFER_BIT,
|
||||
VK_ACCESS_2_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_2_TRANSFER_BIT, VK_ACCESS_2_TRANSFER_READ_BIT);
|
||||
sync_barrier(cb, dst, last, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, last_stage, last_write,
|
||||
VK_PIPELINE_STAGE_2_TRANSFER_BIT, VK_ACCESS_2_TRANSFER_READ_BIT);
|
||||
last = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
|
||||
last_stage = VK_PIPELINE_STAGE_2_TRANSFER_BIT;
|
||||
last_write = 0;
|
||||
record_thumb(cb, dst, slot);
|
||||
}
|
||||
sync_barrier(cb, dst, last, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, VK_PIPELINE_STAGE_2_TRANSFER_BIT,
|
||||
last == VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL ? VK_ACCESS_2_TRANSFER_WRITE_BIT : 0,
|
||||
VK_PIPELINE_STAGE_2_NONE, 0);
|
||||
sync_barrier(cb, dst, last, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, last_stage, last_write, VK_PIPELINE_STAGE_2_NONE, 0);
|
||||
vkEndCommandBuffer(cb);
|
||||
|
||||
VkSemaphoreSubmitInfo wait = {.sType = VK_STRUCTURE_TYPE_SEMAPHORE_SUBMIT_INFO, .semaphore = g_acquire[slot],
|
||||
@@ -610,6 +771,7 @@ static void present_image(VkImage src, VkImageLayout layout, int w, int h, const
|
||||
g_cap_w = (int)g_sc_ext.width;
|
||||
g_cap_h = (int)g_sc_ext.height;
|
||||
g_cap_valid = 1;
|
||||
if (menu_shot) save_capture(menu_shot);
|
||||
}
|
||||
out:
|
||||
LeaveCriticalSection(&g_pl);
|
||||
@@ -649,13 +811,18 @@ void gfx_window_release_vk(void) {
|
||||
vkDeviceWaitIdle(c->device);
|
||||
vk_queue_unlock();
|
||||
g_flip_on = 0; // its blit is done (device idle); the swapchain goes away unpresented
|
||||
menu_vk_release();
|
||||
free_capture();
|
||||
free_thumbs();
|
||||
for (int i = 0; i < FRAMES; i++) {
|
||||
vkDestroySemaphore(c->device, g_acquire[i], NULL);
|
||||
vkDestroyFence(c->device, g_fence[i], NULL);
|
||||
}
|
||||
for (uint32_t i = 0; i < g_sc_n; i++) vkDestroySemaphore(c->device, g_render_done[i], NULL);
|
||||
for (uint32_t i = 0; i < g_sc_n; i++) {
|
||||
vkDestroySemaphore(c->device, g_render_done[i], NULL);
|
||||
if (g_sc_view[i]) vkDestroyImageView(c->device, g_sc_view[i], NULL);
|
||||
g_sc_view[i] = VK_NULL_HANDLE;
|
||||
}
|
||||
if (g_pool) vkDestroyCommandPool(c->device, g_pool, NULL);
|
||||
if (g_sc) vkDestroySwapchainKHR(c->device, g_sc, NULL);
|
||||
if (g_surface) vkDestroySurfaceKHR(c->instance, g_surface, NULL);
|
||||
@@ -702,7 +869,10 @@ void gfx_window_start(void) {
|
||||
EnterCriticalSection(&g_pl);
|
||||
create_swapchain();
|
||||
LeaveCriticalSection(&g_pl);
|
||||
rt_log("gfx: window %dx%d, swapchain %ux%u format %d", 1920, 1080, g_sc_ext.width, g_sc_ext.height, (int)g_sc_fmt);
|
||||
RECT rc = {0};
|
||||
GetClientRect(g_hwnd, &rc);
|
||||
rt_log("gfx: window %ldx%ld, swapchain %ux%u format %d", rc.right, rc.bottom, g_sc_ext.width, g_sc_ext.height,
|
||||
(int)g_sc_fmt);
|
||||
}
|
||||
LeaveCriticalSection(&g_start_lock);
|
||||
vsync_ensure();
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
|
||||
|
||||
1. You must give any other recipients of the Work or Derivative Works a copy of this License; and
|
||||
|
||||
2. You must cause any modified files to carry prominent notices stating that You changed the files; and
|
||||
|
||||
3. You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
|
||||
|
||||
4. If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
APPENDIX: How to apply the Apache License to your work
|
||||
|
||||
To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
|
||||
|
||||
------------
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
||||
Binary file not shown.
@@ -0,0 +1,300 @@
|
||||
// The in-game menu core: Dear ImGui state, the event queue the window adapter fills, gamepad navigation, the Vulkan back
|
||||
// end on our device and the menu's pages. Free of any window system (menu.h). ImGui runs on the present path only,
|
||||
// under gfx_window.c's present lock; the event functions only queue.
|
||||
//
|
||||
// The Vulkan set-up follows LAS Recomp's runtime/nvn/vulkan/imgui_glue.cpp (https://github.com/peiikai/LASRecomp @
|
||||
// da35b83a9611d046a9a681aae668d7085954d37f, MIT, Copyright (c) 2026 Peiikai): dynamic rendering into the swapchain
|
||||
// image, an internal descriptor pool, vertex buffers rotated over more frames than are in flight.
|
||||
#include <atomic>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "imgui.h"
|
||||
#include "backends/imgui_impl_vulkan.h"
|
||||
|
||||
extern "C" {
|
||||
#include "cfg.h"
|
||||
#include "input.h"
|
||||
#include "input_map.h"
|
||||
#include "platform/platform.h"
|
||||
#include "ui/menu.h"
|
||||
// host.h and vk.h pull in cpu.h, which is C only: the three functions the menu needs from them, as declared there.
|
||||
void rt_log(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
|
||||
void vk_queue_lock(void);
|
||||
void vk_queue_unlock(void);
|
||||
}
|
||||
|
||||
// Roboto Medium (Apache-2.0, ui/fonts/LICENSE-Roboto.txt) with Latin and Cyrillic glyphs.
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wc23-extensions" // #embed in C++
|
||||
static const unsigned char roboto_ttf[] = {
|
||||
#embed "fonts/Roboto-Medium.ttf"
|
||||
};
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
// ---- open state, any thread
|
||||
static std::atomic<int> g_open; // the menu is open
|
||||
static std::atomic<int> g_reset; // opened or closed since the last laid-out frame: drop stale input
|
||||
static std::atomic<int> g_combo; // Minus and Plus were held at the last menu_pad_combo
|
||||
|
||||
static void set_open(int open) {
|
||||
if (g_open.exchange(open) == open) return;
|
||||
g_reset.store(1);
|
||||
input_menu(open);
|
||||
rt_log("menu: %s", open ? "open" : "closed");
|
||||
}
|
||||
|
||||
// TOTK_MENU_TEST=<frame>: the presented frame the test window opens at; 0 when unset (the menu cannot open, no pages yet)
|
||||
static uint64_t test_frame(void) {
|
||||
static std::atomic<long long> f{-1};
|
||||
long long v = f.load(std::memory_order_relaxed);
|
||||
if (v < 0) {
|
||||
const char *e = cfg_get("TOTK_MENU_TEST");
|
||||
v = e ? atoll(e) : 0;
|
||||
if (v < 0) v = 0;
|
||||
f.store(v);
|
||||
}
|
||||
return (uint64_t)v;
|
||||
}
|
||||
|
||||
extern "C" int menu_available(void) { return test_frame() != 0; }
|
||||
extern "C" int menu_is_open(void) { return g_open.load(std::memory_order_relaxed); }
|
||||
extern "C" void menu_toggle(void) {
|
||||
if (menu_available()) set_open(!g_open.load());
|
||||
}
|
||||
|
||||
extern "C" void menu_pad_combo(int held) {
|
||||
if (g_combo.exchange(held) != held && held) menu_toggle();
|
||||
}
|
||||
|
||||
// ---- events from the window adapter, queued while the menu is open; the present path hands them to ImGui
|
||||
enum { EV_KEY, EV_POS, EV_BUTTON, EV_WHEEL, EV_FOCUS, EV_MAX = 256 };
|
||||
struct Ev { int type, a, b; float x, y; };
|
||||
static PlatMutex ev_lock = PLAT_MUTEX_INIT;
|
||||
static Ev ev_q[EV_MAX];
|
||||
static int ev_n;
|
||||
|
||||
static void push(Ev e) {
|
||||
if (!menu_is_open()) return;
|
||||
plat_mutex_lock(&ev_lock);
|
||||
if (e.type == EV_POS && ev_n && ev_q[ev_n - 1].type == EV_POS) ev_q[ev_n - 1] = e; // only the newest position
|
||||
else if (ev_n < EV_MAX) ev_q[ev_n++] = e;
|
||||
plat_mutex_unlock(&ev_lock);
|
||||
}
|
||||
|
||||
extern "C" void menu_event_key(int key, int down) { push({EV_KEY, key, down, 0, 0}); }
|
||||
extern "C" void menu_event_mouse_pos(float x, float y) { push({EV_POS, 0, 0, x, y}); }
|
||||
extern "C" void menu_event_mouse_button(int button, int down) { push({EV_BUTTON, button, down, 0, 0}); }
|
||||
extern "C" void menu_event_wheel(float dx, float dy) { push({EV_WHEEL, 0, 0, dx, dy}); }
|
||||
extern "C" void menu_event_focus(int focused) { push({EV_FOCUS, focused, 0, 0, 0}); }
|
||||
|
||||
static void drain_events(ImGuiIO &io) {
|
||||
Ev q[EV_MAX];
|
||||
plat_mutex_lock(&ev_lock);
|
||||
int n = ev_n;
|
||||
for (int i = 0; i < n; i++) q[i] = ev_q[i];
|
||||
ev_n = 0;
|
||||
plat_mutex_unlock(&ev_lock);
|
||||
for (int i = 0; i < n; i++) {
|
||||
const Ev &e = q[i];
|
||||
switch (e.type) {
|
||||
case EV_KEY: io.AddKeyEvent((ImGuiKey)e.a, e.b != 0); break;
|
||||
case EV_POS: io.AddMousePosEvent(e.x, e.y); break;
|
||||
case EV_BUTTON: io.AddMouseButtonEvent(e.a, e.b != 0); break;
|
||||
case EV_WHEEL: io.AddMouseWheelEvent(e.x, e.y); break;
|
||||
case EV_FOCUS: io.AddFocusEvent(e.a != 0); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---- gamepad navigation: the Switch buttons of our SDL3 gamepad to ImGui's gamepad keys. Nintendo layout: A (east)
|
||||
// activates, B (south) cancels.
|
||||
static const struct { int bit; ImGuiKey key; } pad_keys[] = {
|
||||
{B_A, ImGuiKey_GamepadFaceDown}, {B_B, ImGuiKey_GamepadFaceRight}, {B_X, ImGuiKey_GamepadFaceUp},
|
||||
{B_Y, ImGuiKey_GamepadFaceLeft}, {B_L, ImGuiKey_GamepadL1}, {B_R, ImGuiKey_GamepadR1},
|
||||
{B_ZL, ImGuiKey_GamepadL2}, {B_ZR, ImGuiKey_GamepadR2}, {B_LEFT, ImGuiKey_GamepadDpadLeft},
|
||||
{B_UP, ImGuiKey_GamepadDpadUp}, {B_RIGHT, ImGuiKey_GamepadDpadRight}, {B_DOWN, ImGuiKey_GamepadDpadDown},
|
||||
};
|
||||
static uint64_t pad_prev; // buttons at the last frame; a button held when the menu opened counts once released
|
||||
static float stick_prev[4]; // left stick left, right, up, down as ImGui analog values
|
||||
|
||||
static void pad_events(ImGuiIO &io, int reset) {
|
||||
uint64_t b;
|
||||
int32_t lx, ly;
|
||||
int have = input_pad_read(&b, &lx, &ly);
|
||||
if (have) io.BackendFlags |= ImGuiBackendFlags_HasGamepad;
|
||||
else io.BackendFlags &= ~ImGuiBackendFlags_HasGamepad;
|
||||
if (reset) {
|
||||
pad_prev = b;
|
||||
for (float &s : stick_prev) s = 0;
|
||||
return;
|
||||
}
|
||||
for (const auto &k : pad_keys) {
|
||||
uint64_t m = 1ull << k.bit;
|
||||
if ((b ^ pad_prev) & m) io.AddKeyEvent(k.key, (b & m) != 0);
|
||||
}
|
||||
pad_prev = b;
|
||||
const float dead = 0.3f;
|
||||
float v[4] = {-lx / 32767.0f, lx / 32767.0f, ly / 32767.0f, -ly / 32767.0f};
|
||||
static const ImGuiKey sk[4] = {ImGuiKey_GamepadLStickLeft, ImGuiKey_GamepadLStickRight, ImGuiKey_GamepadLStickUp,
|
||||
ImGuiKey_GamepadLStickDown};
|
||||
for (int i = 0; i < 4; i++) {
|
||||
float a = v[i] > dead ? (v[i] - dead) / (1 - dead) : 0;
|
||||
if (a != stick_prev[i]) io.AddKeyAnalogEvent(sk[i], a > 0.1f, a);
|
||||
stick_prev[i] = a;
|
||||
}
|
||||
}
|
||||
|
||||
// ---- ImGui and its Vulkan back end (present path)
|
||||
static int g_ctx_ok, g_failed; // context made; set-up failed for good (the menu stays closed)
|
||||
static int g_vk_ok; // back end initialised for g_vk_fmt
|
||||
static VkFormat g_vk_fmt;
|
||||
static uint64_t g_last_ns;
|
||||
static uint64_t g_cost_ns, g_cost_frames; // CPU time of layout and recording while open, logged per 600 frames
|
||||
|
||||
static void make_context(uint32_t h) {
|
||||
ImGui::CreateContext();
|
||||
ImGuiIO &io = ImGui::GetIO();
|
||||
io.IniFilename = nullptr;
|
||||
io.LogFilename = nullptr;
|
||||
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard | ImGuiConfigFlags_NavEnableGamepad;
|
||||
io.BackendPlatformName = "totk_menu";
|
||||
float scale = h >= 720 ? h / 1080.0f : 720 / 1080.0f;
|
||||
ImFontConfig fc;
|
||||
fc.FontDataOwnedByAtlas = false;
|
||||
io.Fonts->AddFontFromMemoryTTF((void *)roboto_ttf, (int)sizeof roboto_ttf, 26.0f * scale, &fc,
|
||||
io.Fonts->GetGlyphRangesCyrillic());
|
||||
ImGui::StyleColorsDark();
|
||||
ImGuiStyle &st = ImGui::GetStyle();
|
||||
st.WindowRounding = 6;
|
||||
st.FrameRounding = 4;
|
||||
st.WindowPadding = ImVec2(18, 14);
|
||||
st.ItemSpacing = ImVec2(12, 10);
|
||||
st.ScaleAllSizes(scale);
|
||||
g_ctx_ok = 1;
|
||||
}
|
||||
|
||||
static void vk_down(void) {
|
||||
if (!g_vk_ok) return;
|
||||
ImGui_ImplVulkan_Shutdown();
|
||||
g_vk_ok = 0;
|
||||
}
|
||||
|
||||
static int vk_up(const MenuTarget *t) {
|
||||
if (g_vk_ok && g_vk_fmt == t->format) return 1;
|
||||
if (g_vk_ok) { // the swapchain changed format: pipelines for the new one
|
||||
vk_queue_lock();
|
||||
vkQueueWaitIdle(t->queue);
|
||||
vk_queue_unlock();
|
||||
vk_down();
|
||||
}
|
||||
ImGui_ImplVulkan_InitInfo ii = {};
|
||||
ii.ApiVersion = VK_API_VERSION_1_3;
|
||||
ii.Instance = t->instance;
|
||||
ii.PhysicalDevice = t->phys;
|
||||
ii.Device = t->device;
|
||||
ii.QueueFamily = t->queue_family;
|
||||
ii.Queue = t->queue;
|
||||
ii.DescriptorPoolSize = 16;
|
||||
ii.MinImageCount = 2;
|
||||
ii.ImageCount = 4; // vertex buffers rotate per recorded frame: more than gfx_window.c's 2 frames in flight
|
||||
ii.MSAASamples = VK_SAMPLE_COUNT_1_BIT;
|
||||
ii.UseDynamicRendering = true;
|
||||
g_vk_fmt = t->format;
|
||||
ii.PipelineRenderingCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO;
|
||||
ii.PipelineRenderingCreateInfo.colorAttachmentCount = 1;
|
||||
ii.PipelineRenderingCreateInfo.pColorAttachmentFormats = &g_vk_fmt;
|
||||
if (!ImGui_ImplVulkan_Init(&ii)) return 0;
|
||||
g_vk_ok = 1;
|
||||
vk_queue_lock(); // the font upload submits on the queue and waits for it
|
||||
int ok = ImGui_ImplVulkan_CreateFontsTexture();
|
||||
vk_queue_unlock();
|
||||
if (!ok) vk_down();
|
||||
return ok;
|
||||
}
|
||||
|
||||
extern "C" void menu_vk_release(void) {
|
||||
if (g_ctx_ok) vk_down();
|
||||
}
|
||||
|
||||
// ---- the test window (TOTK_MENU_TEST): no words, so no catalog entry; the pages and the translation catalog replace it.
|
||||
// A dimmed frame, a centred window with a progress bar (font glyphs: the percentage) and a colour swatch.
|
||||
static void layout_test(uint32_t w, uint32_t h, float progress) {
|
||||
ImGui::GetBackgroundDrawList()->AddRectFilled(ImVec2(0, 0), ImVec2((float)w, (float)h), IM_COL32(0, 0, 0, 120));
|
||||
ImGui::SetNextWindowPos(ImVec2(w * 0.5f, h * 0.5f), ImGuiCond_Always, ImVec2(0.5f, 0.5f));
|
||||
ImGui::SetNextWindowSize(ImVec2(w * 0.32f, 0), ImGuiCond_Always);
|
||||
ImGui::Begin("##menu_test", nullptr,
|
||||
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize |
|
||||
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings);
|
||||
ImGui::ProgressBar(progress, ImVec2(-1, 0));
|
||||
ImGui::Spacing();
|
||||
ImGui::ColorButton("##swatch", ImVec4(0.2f, 0.6f, 0.9f, 1), ImGuiColorEditFlags_NoTooltip,
|
||||
ImVec2(ImGui::GetContentRegionAvail().x, 40));
|
||||
// Esc on the keyboard, B on the gamepad: close
|
||||
if (ImGui::IsKeyPressed(ImGuiKey_Escape, false) || ImGui::IsKeyPressed(ImGuiKey_GamepadFaceRight, false)) set_open(0);
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
enum { TEST_SHOT_AFTER = 30 }; // frames between the test window opening and its shot
|
||||
|
||||
extern "C" int menu_overlay_frame(uint64_t frame, const MenuTarget *t, const char **shot) {
|
||||
static uint64_t opened_at; // frame of the test hook's open; ~0 once its shot is taken
|
||||
*shot = NULL;
|
||||
if (!g_open.load(std::memory_order_relaxed)) {
|
||||
uint64_t at = test_frame();
|
||||
if (!at || opened_at || frame < at) return 0;
|
||||
opened_at = frame;
|
||||
set_open(1);
|
||||
}
|
||||
if (g_failed) {
|
||||
set_open(0);
|
||||
return 0;
|
||||
}
|
||||
uint64_t t0 = plat_now_ns();
|
||||
if (!g_ctx_ok) make_context(t->height);
|
||||
if (!vk_up(t)) {
|
||||
rt_log("menu: Dear ImGui Vulkan back end set-up failed; the menu stays closed");
|
||||
g_failed = 1;
|
||||
set_open(0);
|
||||
return 0;
|
||||
}
|
||||
ImGuiIO &io = ImGui::GetIO();
|
||||
int reset = g_reset.exchange(0);
|
||||
if (reset) {
|
||||
io.ClearInputKeys();
|
||||
io.ClearInputMouse();
|
||||
g_last_ns = 0;
|
||||
}
|
||||
io.DisplaySize = ImVec2((float)t->width, (float)t->height);
|
||||
double dt = g_last_ns ? (t0 - g_last_ns) / 1e9 : 1 / 60.0;
|
||||
io.DeltaTime = (float)(dt < 1e-4 ? 1e-4 : dt > 0.1 ? 0.1 : dt);
|
||||
g_last_ns = t0;
|
||||
drain_events(io);
|
||||
pad_events(io, reset);
|
||||
ImGui_ImplVulkan_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
uint64_t since = opened_at != ~0ull && frame > opened_at ? frame - opened_at : 0;
|
||||
layout_test(t->width, t->height, since >= TEST_SHOT_AFTER ? 1.0f : (float)since / TEST_SHOT_AFTER);
|
||||
ImGui::Render();
|
||||
g_cost_ns += plat_now_ns() - t0;
|
||||
if (opened_at != ~0ull && since >= TEST_SHOT_AFTER) { // this frame's image goes to a file, then the window closes
|
||||
static char path[512];
|
||||
const char *dir = cfg_get("TOTK_MENU_TEST_DIR");
|
||||
snprintf(path, sizeof path, "%s/menu-test-%llu.png", dir ? dir : ".", (unsigned long long)frame);
|
||||
*shot = path;
|
||||
opened_at = ~0ull;
|
||||
set_open(0); // the next frame lays out nothing
|
||||
}
|
||||
return ImGui::GetDrawData()->TotalVtxCount > 0;
|
||||
}
|
||||
|
||||
extern "C" void menu_overlay_draw(VkCommandBuffer cb) {
|
||||
uint64_t t0 = plat_now_ns();
|
||||
ImGui_ImplVulkan_RenderDrawData(ImGui::GetDrawData(), cb);
|
||||
g_cost_ns += plat_now_ns() - t0;
|
||||
if (++g_cost_frames == 600) {
|
||||
rt_log("menu: %.3f ms CPU per open frame (layout and recording, mean of 600)", g_cost_ns / 600 / 1e6);
|
||||
g_cost_ns = g_cost_frames = 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
// The in-game menu (ui/menu.cpp, Dear ImGui) and its seams to the platform side: the window and its input (ui/menu_win.cpp
|
||||
// on Windows; an SDL3 window gets its own adapter later), the gamepad (input_pad_read, input.h) and the present path
|
||||
// (gfx_window.c). The menu core calls no window system: events come in through menu_event_*, the drawing happens in the
|
||||
// present path's command buffer.
|
||||
//
|
||||
// No pages yet (the tabs and options are still being agreed): the menu opens only for the test hook
|
||||
// TOTK_MENU_TEST=<frame>, which opens a text-free test window at that presented frame, saves one swapchain shot 30
|
||||
// frames later into TOTK_MENU_TEST_DIR (default: the working directory) and closes it. While the test hook is set, F1 or
|
||||
// Esc on the keyboard and Minus and Plus held together on the gamepad also open and close it. While it is open the game
|
||||
// gets no input (input_menu, input.h) and keeps running; the cursor is released from the mouse camera.
|
||||
//
|
||||
// Threads: the event functions are called by the window thread, menu_pad_combo by whichever thread polls the gamepad, the
|
||||
// overlay functions by the present path under its lock. ImGui itself runs on the present path only.
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// ---- state, any thread
|
||||
int menu_available(void); // the menu can open (for now only with the test hook TOTK_MENU_TEST)
|
||||
int menu_is_open(void);
|
||||
void menu_toggle(void); // F1 / Esc on the keyboard
|
||||
void menu_pad_combo(int held); // Minus and Plus held together on the gamepad (toggles once per hold)
|
||||
|
||||
// ---- events from the window adapter, used only while the menu is open. key: an ImGuiKey; coordinates in pixels of the
|
||||
// window's client area, which is the swapchain image.
|
||||
void menu_event_key(int key, int down);
|
||||
void menu_event_mouse_pos(float x, float y);
|
||||
void menu_event_mouse_button(int button, int down); // 0 left, 1 right, 2 middle
|
||||
void menu_event_wheel(float dx, float dy);
|
||||
void menu_event_focus(int focused);
|
||||
|
||||
// ---- the overlay, drawn into the swapchain image after the game image (gfx_window.c, present lock held)
|
||||
typedef struct {
|
||||
VkInstance instance;
|
||||
VkPhysicalDevice phys;
|
||||
VkDevice device;
|
||||
uint32_t queue_family;
|
||||
VkQueue queue; // submissions take vk_queue_lock
|
||||
VkFormat format; // of the swapchain image, a colour attachment
|
||||
uint32_t width, height;
|
||||
} MenuTarget;
|
||||
// Lays out this frame's overlay; 1 when there is something to draw. frame: the presented frame (0 unknown). *shot: a
|
||||
// path when the test hook wants this frame's swapchain image saved, else NULL. The first open starts ImGui's Vulkan
|
||||
// back end and uploads the font. With the menu closed it costs two loads and a compare.
|
||||
int menu_overlay_frame(uint64_t frame, const MenuTarget *t, const char **shot);
|
||||
// Records the frame menu_overlay_frame laid out into cb, which is inside dynamic rendering on the image.
|
||||
void menu_overlay_draw(VkCommandBuffer cb);
|
||||
void menu_vk_release(void); // before the device goes away (gfx_window_release_vk)
|
||||
|
||||
// ---- what the menu asks of the platform side (gfx_window.c)
|
||||
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
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,80 @@
|
||||
// Win32 adapter of the in-game menu: window messages to menu events (menu.h). The only Win32 code of the menu; an SDL3
|
||||
// window gets its own adapter later. Window thread.
|
||||
//
|
||||
// F1 opens and closes the menu, Esc opens it (with the menu open, Esc goes to the menu, which closes); both only while
|
||||
// menu_available. Esc also releases the cursor (input_window_msg runs first). While the menu is open, its keys, the
|
||||
// mouse and focus changes go to it; the game polls the keyboard on its own (input_win.c) and gets nothing while the menu
|
||||
// is open (input_menu).
|
||||
#include <windows.h>
|
||||
#include <windowsx.h>
|
||||
|
||||
#include "imgui.h"
|
||||
|
||||
extern "C" {
|
||||
#include "input.h"
|
||||
#include "ui/menu.h"
|
||||
}
|
||||
|
||||
static ImGuiKey key_of(WPARAM vk) {
|
||||
switch (vk) {
|
||||
case VK_UP: return ImGuiKey_UpArrow;
|
||||
case VK_DOWN: return ImGuiKey_DownArrow;
|
||||
case VK_LEFT: return ImGuiKey_LeftArrow;
|
||||
case VK_RIGHT: return ImGuiKey_RightArrow;
|
||||
case VK_RETURN: return ImGuiKey_Enter;
|
||||
case VK_SPACE: return ImGuiKey_Space;
|
||||
case VK_ESCAPE: return ImGuiKey_Escape;
|
||||
case VK_TAB: return ImGuiKey_Tab;
|
||||
case VK_BACK: return ImGuiKey_Backspace;
|
||||
case VK_HOME: return ImGuiKey_Home;
|
||||
case VK_END: return ImGuiKey_End;
|
||||
case VK_PRIOR: return ImGuiKey_PageUp;
|
||||
case VK_NEXT: return ImGuiKey_PageDown;
|
||||
case VK_SHIFT: return ImGuiKey_LeftShift;
|
||||
case VK_CONTROL: return ImGuiKey_LeftCtrl;
|
||||
case 'Q': return ImGuiKey_Q; // previous page (later)
|
||||
case 'E': return ImGuiKey_E; // next page (later)
|
||||
default: return ImGuiKey_None;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" int menu_window_msg(HWND h, UINT m, WPARAM w, LPARAM l, LRESULT *res) {
|
||||
(void)h;
|
||||
switch (m) {
|
||||
case WM_KEYDOWN:
|
||||
case WM_SYSKEYDOWN:
|
||||
// bit 30: auto-repeat
|
||||
if (!(l & (1 << 30)) && menu_available() && (w == VK_F1 || (w == VK_ESCAPE && !menu_is_open()))) {
|
||||
menu_toggle();
|
||||
*res = 0;
|
||||
return 1;
|
||||
}
|
||||
[[fallthrough]];
|
||||
case WM_KEYUP:
|
||||
case WM_SYSKEYUP:
|
||||
if (!menu_is_open()) return 0;
|
||||
if (ImGuiKey k = key_of(w)) menu_event_key(k, m == WM_KEYDOWN || m == WM_SYSKEYDOWN);
|
||||
return 0; // F11 and the system keys keep working
|
||||
case WM_MOUSEMOVE:
|
||||
if (menu_is_open()) menu_event_mouse_pos((float)GET_X_LPARAM(l), (float)GET_Y_LPARAM(l));
|
||||
return 0;
|
||||
case WM_LBUTTONDOWN: case WM_LBUTTONUP:
|
||||
case WM_RBUTTONDOWN: case WM_RBUTTONUP:
|
||||
case WM_MBUTTONDOWN: case WM_MBUTTONUP: {
|
||||
if (!menu_is_open()) return 0;
|
||||
int b = m == WM_LBUTTONDOWN || m == WM_LBUTTONUP ? 0 : m == WM_RBUTTONDOWN || m == WM_RBUTTONUP ? 1 : 2;
|
||||
int down = m == WM_LBUTTONDOWN || m == WM_RBUTTONDOWN || m == WM_MBUTTONDOWN;
|
||||
menu_event_mouse_pos((float)GET_X_LPARAM(l), (float)GET_Y_LPARAM(l));
|
||||
menu_event_mouse_button(b, down);
|
||||
return 0;
|
||||
}
|
||||
case WM_MOUSEWHEEL:
|
||||
if (menu_is_open()) menu_event_wheel(0, (float)GET_WHEEL_DELTA_WPARAM(w) / WHEEL_DELTA);
|
||||
return 0;
|
||||
case WM_SETFOCUS:
|
||||
case WM_KILLFOCUS:
|
||||
menu_event_focus(m == WM_SETFOCUS);
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -17,9 +17,14 @@
|
||||
# async_preempt = 1
|
||||
# Replay NVN submissions on their own thread, at most one frame behind the game (1 = on).
|
||||
# replay_async = 0
|
||||
|
||||
[display]
|
||||
# Presentation mode: mailbox (default when the driver offers it, vsync otherwise), fifo (vsync) or immediate.
|
||||
# vk_present = mailbox
|
||||
# Window client area in pixels (640x360 to 7680x4320), and borderless fullscreen. F11 switches fullscreen and saves it
|
||||
# here. Changes while the game runs take effect at once.
|
||||
# window_size = 1920x1080
|
||||
# fullscreen = 0
|
||||
# Which GPU to use: its index in the log, or part of its name. Default: the first discrete GPU with Vulkan 1.3.
|
||||
# gpu_index = 0
|
||||
# gpu_name = NVIDIA
|
||||
|
||||
Reference in new issue
Block a user