mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-19 10:49:58 -04:00
Default to the Switch's own button positions on every gamepad, and fix menu edge cases.
pad_layout defaults to nintendo: Switch A on the right face button, B bottom, X top, Y left, on an Xbox pad too, where auto had picked the Xbox layout. The settings probe checks every button's position. Menu: the "default" mark follows the Steam Deck profile's values (cfg_default); Left on a value the list does not hold goes to the last entry; the HDR row says "in use: off" when the swapchain is not HDR10; the open state is read again after taking the reset, so a menu opened by F1 while the overlay alone was drawn starts with its focus row; the font atlas is rebuilt only for a scale more than 12% off or one that held for half a second, so dragging the window's edge no longer rebuilds it every frame. A shader that fails to translate keeps its request and code in the shader cache. NX2NAVI_GPA_TWIN=0 turns the guest copy of device address table stores off (diagnosis). The memcpy override no longer prints its first 500 calls. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -58,6 +58,8 @@ void res_sizes(unsigned out[2], unsigned scene[2]);
|
||||
int res_adjustable(void);
|
||||
int wide_available(void);
|
||||
const char *const *vk_color_preset(const char *name);
|
||||
int vk_hdr_wanted(void);
|
||||
int vk_hdr_active(void);
|
||||
double frame_step_limit_hz(void);
|
||||
int frame_limit_adjustable(void);
|
||||
int frame_free_running(void);
|
||||
@@ -447,6 +449,21 @@ static int fonts_up(float scale) {
|
||||
return ok;
|
||||
}
|
||||
|
||||
// The font atlas follows the window's scale: rebuilt at once when it is more than 12% off (text would blur or shrink
|
||||
// visibly), else once the scale has held for half a second, so dragging a window's edge does not rebuild it, and read the
|
||||
// system's fonts again, every frame. Until then io.FontGlobalScale stretches the atlas there is. False: fonts_up failed.
|
||||
static bool fonts_follow(float scale) {
|
||||
static float last;
|
||||
static uint64_t since;
|
||||
uint64_t now = plat_now_ns();
|
||||
if (scale != last) last = scale, since = now;
|
||||
ImGuiIO &io = ImGui::GetIO();
|
||||
if (g_font_scale != scale && (!g_font_scale || fabsf(g_font_scale / scale - 1) > 0.12f || now - since > 500000000ull))
|
||||
if (!fonts_up(scale)) return false;
|
||||
io.FontGlobalScale = scale / g_font_scale;
|
||||
return true;
|
||||
}
|
||||
|
||||
extern "C" void menu_vk_release(void) {
|
||||
if (g_ctx_ok) vk_down();
|
||||
}
|
||||
@@ -761,12 +778,22 @@ static void row_upscaling(void) {
|
||||
if (nv >= 2) opt_apply("NX2NAVI_TAA", nv >= 7 ? "fsr3" : "dlss");
|
||||
}
|
||||
|
||||
// "in use: off" under the HDR value when the game started with HDR on but the swapchain is not HDR10 (the display or
|
||||
// Windows' HDR switch is off, vk_hdr_surface_format); else the restart note.
|
||||
static const char *hdr_note(void) {
|
||||
const char *restart = menu_text(UI_MENU_HDR_NOTE);
|
||||
if (!vk_hdr_wanted() || vk_hdr_active() || !*gfx_window_present_mode() || !cfg_bool("NX2NAVI_HDR")) return restart;
|
||||
static char note[96];
|
||||
snprintf(note, sizeof note, menu_text(UI_MENU_PRESENT_IN_USE), menu_text(UI_MENU_FRAMEGEN_OFF));
|
||||
return note;
|
||||
}
|
||||
|
||||
// HDR (vk_hdr.c), after a restart: off, the runtime's own (the game's tonemap kept above SDR white) or the game's native
|
||||
// HDR. The brightness rows follow while it is on.
|
||||
static void row_hdr(void) {
|
||||
static const char *const values[] = {"0", "1", "native"};
|
||||
const char *names[] = {menu_text(UI_MENU_FRAMEGEN_OFF), menu_text(UI_MENU_HDR_ENHANCED), menu_text(UI_MENU_HDR_NATIVE)};
|
||||
opt_choice_list("NX2NAVI_HDR", UI_MENU_HDR, values, names, 3, UI_MENU_HDR_DESC, -1, menu_text(UI_MENU_HDR_NOTE));
|
||||
opt_choice_list("NX2NAVI_HDR", UI_MENU_HDR, values, names, 3, UI_MENU_HDR_DESC, -1, hdr_note());
|
||||
if (!cfg_bool("NX2NAVI_HDR")) return;
|
||||
opt_slider("NX2NAVI_HDR_PEAK_NITS", UI_MENU_HDR_PEAK, 400, 10000, UI_MENU_HDR_PEAK_DESC, 50, "%.0f nits");
|
||||
opt_slider("NX2NAVI_HDR_GAME_NITS", UI_MENU_HDR_GAME, 80, 500, UI_MENU_HDR_GAME_DESC, 5, "%.0f nits");
|
||||
@@ -1438,7 +1465,7 @@ extern "C" int menu_overlay_frame(uint64_t frame, const MenuTarget *t, const cha
|
||||
uint64_t t0 = plat_now_ns();
|
||||
if (!g_ctx_ok) make_context();
|
||||
float scale = menu_scale(t->height);
|
||||
if (!vk_up(t) || (g_font_scale != scale && !fonts_up(scale))) {
|
||||
if (!vk_up(t) || !fonts_follow(scale)) {
|
||||
rt_log("menu: Dear ImGui Vulkan back end set-up failed; the menu stays closed");
|
||||
g_failed.store(1);
|
||||
set_open(0);
|
||||
@@ -1452,6 +1479,10 @@ extern "C" int menu_overlay_frame(uint64_t frame, const MenuTarget *t, const cha
|
||||
list_gpus(t->instance);
|
||||
ImGuiIO &io = ImGui::GetIO();
|
||||
int reset = g_reset.exchange(0);
|
||||
// Read again after taking the reset: the menu may have opened since the read above (F1 on the window thread while
|
||||
// the overlay alone was drawn), and that frame's reset would be spent on an overlay frame, so the first open frame
|
||||
// ran without its focus row and with the opening key still down.
|
||||
open = g_open.load(std::memory_order_acquire);
|
||||
if (reset) {
|
||||
io.ClearInputKeys();
|
||||
io.ClearInputMouse();
|
||||
@@ -1514,7 +1545,7 @@ extern "C" int menu_boot_frame(const MenuTarget *t) {
|
||||
if (g_failed_flag() || g_boot_phase.load(std::memory_order_acquire) < 0) return 0; // -1: done, a black frame
|
||||
if (!g_ctx_ok) make_context();
|
||||
float scale = menu_scale(t->height);
|
||||
if (!vk_up(t) || (g_font_scale != scale && !fonts_up(scale))) {
|
||||
if (!vk_up(t) || !fonts_follow(scale)) {
|
||||
rt_log("menu: Dear ImGui Vulkan back end set-up failed; no boot screen, and the menu stays closed");
|
||||
g_failed.store(1);
|
||||
return 0;
|
||||
@@ -1548,7 +1579,7 @@ extern "C" int menu_boot_frame(const MenuTarget *t) {
|
||||
ImFont *body = ImGui::GetFont();
|
||||
float body_px = ImGui::GetFontSize();
|
||||
ImFont *head = g_title_font ? g_title_font : body;
|
||||
float head_px = g_title_font ? g_title_font->FontSize : body_px * 1.2f;
|
||||
float head_px = g_title_font ? g_title_font->FontSize * ImGui::GetIO().FontGlobalScale : body_px * 1.2f;
|
||||
ImVec2 ts = head->CalcTextSizeA(head_px, FLT_MAX, 0, title), ss = body->CalcTextSizeA(body_px, FLT_MAX, 0, step),
|
||||
hs = body->CalcTextSizeA(body_px * 0.8f, FLT_MAX, 0, hint);
|
||||
float bar_h = 10 * scale;
|
||||
|
||||
@@ -274,8 +274,8 @@ int opt_save_tick(int force) {
|
||||
// ---- rows
|
||||
|
||||
bool opt_toggle(const char *key, UiTextId label, UiTextId desc, bool inverted) {
|
||||
const CfgMeta *m = cfg_meta(key);
|
||||
bool set = cfg_bool(key) != 0, def = m && strcmp(m->def, "0") != 0;
|
||||
const char *d = cfg_default(key);
|
||||
bool set = cfg_bool(key) != 0, def = d && *d && strcmp(d, "0") != 0;
|
||||
bool on = set != inverted; // what the row shows
|
||||
RowView v = {menu_text(on ? UI_MENU_ON : UI_MENU_OFF), set == def, false, NULL};
|
||||
if (!row(key, label, desc, v)) return false; // any step flips it
|
||||
@@ -322,19 +322,19 @@ void opt_text(UiTextId text, bool warn) {
|
||||
|
||||
bool opt_choice_list(const char *key, UiTextId label, const char *const *values, const char *const *names, int n,
|
||||
UiTextId desc, int cur, const char *note) {
|
||||
const CfgMeta *m = cfg_meta(key);
|
||||
const char *d = cfg_default(key);
|
||||
const char *now = cfg_value(key);
|
||||
if (cur < 0)
|
||||
for (int i = 0; i < n; i++)
|
||||
if (!strcmp(values[i], now)) cur = i;
|
||||
int def = -1;
|
||||
for (int i = 0; m && i < n; i++)
|
||||
if (!strcmp(values[i], m->def)) def = i;
|
||||
for (int i = 0; d && i < n; i++)
|
||||
if (!strcmp(values[i], d)) def = i;
|
||||
RowView v = {cur >= 0 ? names[cur] : now, cur == def, true, note};
|
||||
int step = row(key, label, desc, v);
|
||||
if (!step || n <= 0) return false;
|
||||
int nv;
|
||||
if (cur < 0) nv = 0;
|
||||
if (cur < 0) nv = step < 0 ? n - 1 : 0; // a value not in the list: left from the end, right / A from the start
|
||||
else if (step == 2) nv = (cur + 1) % n; // A / click: the next value, round to the first
|
||||
else nv = cur + step < 0 ? 0 : cur + step >= n ? n - 1 : cur + step; // left / right stop at the ends
|
||||
if (nv == cur) return false;
|
||||
@@ -347,7 +347,7 @@ int opt_choice_index(const char *key, UiTextId label, const char *const *names,
|
||||
RowView v = {cur >= 0 && cur < n ? names[cur] : "", cur == def, true, note};
|
||||
int step = row(key, label, desc, v);
|
||||
if (!step || n <= 0) return -1;
|
||||
int nv = cur < 0 ? 0 : step == 2 ? (cur + 1) % n : cur + step < 0 ? 0 : cur + step >= n ? n - 1 : cur + step;
|
||||
int nv = cur < 0 ? (step < 0 ? n - 1 : 0) : step == 2 ? (cur + 1) % n : cur + step < 0 ? 0 : cur + step >= n ? n - 1 : cur + step;
|
||||
if (nv == cur) return -1;
|
||||
menu_sound_play(MENU_SOUND_CURSOR);
|
||||
return nv;
|
||||
@@ -386,11 +386,11 @@ bool opt_slider(const char *key, UiTextId label, float lo, float hi, UiTextId de
|
||||
const char *note, const char *fallback) {
|
||||
const char *set = cfg_get(key);
|
||||
const char *src = fallback && !(set && *set) ? fallback : key; // unset: show the value in effect, the fallback's
|
||||
const CfgMeta *m = cfg_meta(src);
|
||||
// A key without a table default of its own (the per-stick dead zones) defaults to its fallback: the "default" mark
|
||||
const char *d = cfg_default(src);
|
||||
// A key without a default of its own (the per-stick dead zones) defaults to its fallback: the "default" mark
|
||||
// follows the fallback's default, not 0, even once the key is set.
|
||||
if (fallback && m && !m->def[0]) m = cfg_meta(fallback);
|
||||
double v = cfg_double(src), def = m && m->def[0] ? strtod(m->def, NULL) : lo;
|
||||
if (fallback && !(d && *d)) d = cfg_default(fallback);
|
||||
double v = cfg_double(src), def = d && *d ? strtod(d, NULL) : lo;
|
||||
char shown[48];
|
||||
snprintf(shown, sizeof shown, fmt, v);
|
||||
RowView rv = {shown, fabs(v - def) < step * 0.01, true, note};
|
||||
|
||||
Reference in New Issue
Block a user