Triforce v0.5.2

The new launcher (Windows and Linux: the game's own look, music and settings, saves and mods pages, smaller updates in parts), benchmark mode (Find my best settings: the game tours four places by itself and writes its results), Quit and Restart in the pause menu under Mods, Squadala! in the Mods menu, battle music above 60 fps, menu text, the controller in the menus with the game in the background, the whole GameBanana list, RX 580 and RX 5000/6000 shader fixes, the pipeline cache kept through an update, async present black flashes, and faster builds.
This commit is contained in:
ruckus7382sfgsgdf
2026-11-19 10:52:50 -06:00
parent a750a21025
commit fb26495475
167 changed files with 21552 additions and 293 deletions

View File

@@ -437,6 +437,13 @@ static void theme_caption(HWND w) {
set(w, 34, &border, sizeof border);
}
/* ((Triforce, 11-19) benchmark mode's end, host/hos_bench.c: the window closed as by the player, on its own thread, so the game
quits the way its window's close does; with no window (HOS_HEADLESS) that same exit at once) */
void hos_window_close(void) {
if (hwnd) PostMessageA(hwnd, WM_CLOSE, 0, 0);
else hos_window_closed_exit();
}
static void display_start_failed(const char *operation) {
const DWORD error = GetLastError();
hos_log("display: %s failed (error %lu)", operation, (unsigned long)error);

651
host/hos_bench.c Normal file
View File

@@ -0,0 +1,651 @@
/* (Triforce, 11-19) Benchmark mode, for the launcher's benchmark: HOS_BENCHMARK=<results.json>. Nothing changes without it.
The owner's words on the first, launcher-driven try: "It needs to be faster, there is a ton of just standing around. It
needs to skip the main menu. All I saw was the game open, how am I supposed to know what it's doing". So the game drives
itself here, reacting to what it shows, with no timed waits, and says what it does in a panel the renderer draws
(gpu/vk/vk_menu.cpp draw_bench, through MkwVkHost.bench):
1. Boot: as each of the start's three screens gets a focused button (host/oot_menu.c: the title 0x84c106e8, the file select
0x84c0eba0, the file's box 0x84c0f840), A is pressed at once. The file select opens on the newest save's file (the
game's own choice: the file it saved last); the file loaded and the newest by its caption's date are both logged.
Another screen with a focused button (a first-start dialog) is logged and pressed too; after a few, the run fails with
a clear error in the results.
2. The tour, once Link is in play: per scene (HOS_BENCH_SCENES="1001:Hyrule Field,..." = the teleport actions of
host/hos_main.c and their names; HOS_BENCH_SECONDS each, default 15) a teleport, its arrival (the map loaded and no event
playing), 1.5 s settling (not counted), then every present's interval is measured while the camera turns steadily
(the right stick at 35%, Link standing). The next teleport follows the moment a scene ends.
3. The results (version 1): average fps, 1% and 0.1% lows (nearest rank, as gpu/vk/perf_stats.h), frames, seconds and the
frame times in ~120 points per scene, the GPU and the options that shape the frame rate, written atomically (.new, then
renamed); then the game quits as its window's close does (host/hos_relaunch.c: a save being committed finished, the
renderer told), so the caches are written. Esc (the window in front) or the window closed by the launcher: written
with "stopped": true.
4. No save is written while it runs (host/nn_fs.c Commit), the hearts are protected (host/hos_main.c), and the player's
devices do not count (host/nn_hid.c): the benchmark's presses count with the window behind other windows. */
#include "hos.h"
#include "hos_paths.h"
#include "hos_bench.h"
#include "../gpu/vk/vk_api.h"
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
#ifndef _WIN32
#include <dirent.h>
#include <sys/stat.h>
#endif
void hos_hid_tap(const char *press); /* host/nn_hid.c */
void hos_hid_stick(int lx, int ly, int rx, int ry, int hold_ms);
const char *rx_describe(void); /* host/rx_backend.c */
int rx_option(int id, int otherwise);
void hos_window_close(void); /* host/display.c, host/posix/display_sdl.c */
extern const char *hos_user_dir; /* host/nn_fs.c */
#define TITLE_VT 0x84c106e8ULL /* the title's list (Continue, ...) */
#define FILES_VT 0x84c0eba0ULL /* the file select: six files */
#define FILE_BOX_VT 0x84c0f840ULL /* the chosen file's box: Load first */
#define MAX_SCENES 12
#define GRAPH_POINTS 120
#define SETTLE_NS 1500000000LL
#define PAN 11469 /* (the right stick at 35%) */
#define HIST_BINS 2000 /* (the scene's frame times so far, 0.1 ms each up to 200 ms: the panel's 1% low) */
typedef struct { int action; char name[48]; } Scene;
typedef struct {
int frames;
double seconds, avg, low1, low01, max_ms;
float points[GRAPH_POINTS];
int npoints;
} Result;
typedef struct { uint64_t screen, vt; int stage, presses, focus_asks; int64_t press_ns, ask_ns; } Screen;
static struct {
SRWLOCK lock;
int on;
char path[1024];
double seconds;
Scene scenes[MAX_SCENES];
int nscenes;
int phase, scene; /* MKWVK_BENCH_*; the scene gone to or measured, 0-based */
int64_t t_start, t_play, t_phase;
/* boot */
Screen screens[16];
int nscreens, unknown, stage_max, slot, newest, slot_looked; /* (slot: the file the game loaded; newest: by date) */
/* travel */
int want, tries, resends, saw_load;
int64_t sent_ns, retry_ns, last_link_ns;
/* measure */
int64_t last_present, measure_t0;
int64_t *iv; /* (the scene's present intervals, ns) */
int n, cap;
unsigned hist[HIST_BINS + 1];
/* the panel's graph and live rate: the newest intervals of any phase */
float ring[MKWVK_BENCH_GRAPH];
uint32_t ring_n;
Result results[MAX_SCENES];
int nresults;
char error[160];
int written, closing;
int64_t end_ns;
} B = {SRWLOCK_INIT};
int hos_bench_on(void) { return B.on; }
int hos_bench_input_only(void) { return B.on; }
int hos_bench_blocks_save(void) {
if (B.on) hos_log("benchmark: the game's save commit left out (benchmark mode writes no save)");
return B.on;
}
static void parse_scenes(const char *s) {
B.nscenes = 0;
while (s && *s && B.nscenes < MAX_SCENES) {
while (*s == ' ' || *s == ',') s++;
char *end;
const long action = strtol(s, &end, 10);
if (end == s) break;
s = end;
Scene *sc = &B.scenes[B.nscenes];
sc->action = (int)action;
snprintf(sc->name, sizeof sc->name, "Place %ld", action - 1000);
if (*s == ':') {
s++;
size_t n = strcspn(s, ",");
while (n && s[n - 1] == ' ') n--;
if (n >= sizeof sc->name) n = sizeof sc->name - 1;
memcpy(sc->name, s, n);
sc->name[n] = 0;
s += strcspn(s, ",");
}
if (action >= 1000 && action < 1100) B.nscenes++;
}
}
void hos_bench_init(void) {
const char *p = getenv("HOS_BENCHMARK");
if (!p || !*p) return;
snprintf(B.path, sizeof B.path, "%s", p);
const char *sec = getenv("HOS_BENCH_SECONDS");
B.seconds = sec && atof(sec) >= 1 ? atof(sec) : 15;
const char *scenes = getenv("HOS_BENCH_SCENES");
parse_scenes(scenes && *scenes ? scenes : "1001:Hyrule Field,1003:Castle Town Market,1000:Kokiri Forest,1007:Lake Hylia");
if (!B.nscenes) parse_scenes("1001:Hyrule Field");
B.slot = B.newest = -1;
B.t_start = hos_now_ns();
B.phase = MKWVK_BENCH_BOOT;
B.on = 1;
}
/* ---- the newest save: <user>/save/<user id>/slot_0N/caption.sav. Its Int values (the save files' format: a 0x01020304 magic,
(hash, value) pairs from 0x20 to the data area, a pair of hash 0 opening the next type's section, Int = type 2) hold the
date it was saved: year 0x9811a3f7, month 0xdfd840d3, day 0xbd46f485, hour 0x23f3d75e, minute 0x27853bf7, second
0x5ee50bed (read from the lab's saves, 11-19: a file saved at 08:28:27 on 11-19 says 2026, 11, 19, 8, 28, 27 there). The
file's own time is no help: every commit writes all six files. For the log and the results only: the game's file select
is a carousel whose entries are places, not files (entry 2 focused loaded file 6 in a lab run), so the newest file is not
focused by its entry; the game itself opens on the newest file (its last saved), which the benchmark then loads (checked
by the file it opens: hos_bench_file_opened) */
static int64_t caption_stamp(const char *path) {
FILE *f = fopen(path, "rb");
if (!f) return -1;
unsigned char *b = (unsigned char *)malloc(65536);
const size_t n = b ? fread(b, 1, 65536, f) : 0;
fclose(f);
int64_t stamp = 0;
uint32_t magic = 0, data = 0;
if (n >= 0x20) memcpy(&magic, b, 4), memcpy(&data, b + 8, 4);
if (magic == 0x01020304u && data <= n) {
static const uint32_t keys[6] = {0x9811a3f7u, 0xdfd840d3u, 0xbd46f485u, 0x23f3d75eu, 0x27853bf7u, 0x5ee50bedu};
int v[6] = {-1, -1, -1, -1, -1, -1};
uint32_t type = 0;
for (size_t o = 0x20; o + 8 <= data; o += 8) {
uint32_t h, x;
memcpy(&h, b + o, 4), memcpy(&x, b + o + 4, 4);
if (!h) { type = x; continue; }
if (type != 2) continue;
for (int k = 0; k < 6; k++)
if (h == keys[k]) v[k] = (int)x;
}
if (v[0] > 2000 && v[1] >= 1 && v[1] <= 12 && v[2] >= 1 && v[2] <= 31 && v[3] >= 0 && v[4] >= 0 && v[5] >= 0)
stamp = ((((((int64_t)v[0] * 13 + v[1]) * 32 + v[2]) * 24 + v[3]) * 60 + v[4]) * 60 + v[5]);
}
free(b);
return stamp;
}
static int64_t file_time(const char *path) {
#ifdef _WIN32
WIN32_FILE_ATTRIBUTE_DATA a;
if (!GetFileAttributesExA(path, GetFileExInfoStandard, &a)) return -1;
return (int64_t)a.ftLastWriteTime.dwHighDateTime << 32 | a.ftLastWriteTime.dwLowDateTime;
#else
struct stat st;
return stat(path, &st) ? -1 : (int64_t)st.st_mtime;
#endif
}
#ifdef _WIN32
#define SEP "\\"
#else
#define SEP "/"
#endif
/* the newest file in one user's folder: *stamp its caption's date (0 none), *time its file's time */
static int newest_in(const char *dir, int64_t *stamp, int64_t *time) {
int best = -1;
*stamp = -1, *time = -1;
for (int i = 0; i < 6; i++) {
char p[1200];
snprintf(p, sizeof p, "%s" SEP "slot_%02d" SEP "caption.sav", dir, i);
const int64_t t = file_time(p);
if (t < 0) continue;
const int64_t s = caption_stamp(p);
if (best < 0 || s > *stamp || (s == *stamp && t > *time)) best = i, *stamp = s, *time = t;
}
return best;
}
static int newest_slot(void) {
if (!hos_user_dir) return -1;
char root[1100];
snprintf(root, sizeof root, "%s" SEP "save", hos_user_dir);
int best = -1;
int64_t best_stamp = -1, best_time = -1;
#ifdef _WIN32
char pat[1200];
snprintf(pat, sizeof pat, "%s\\*", root);
WIN32_FIND_DATAA fd;
HANDLE h = FindFirstFileA(pat, &fd);
if (h == INVALID_HANDLE_VALUE) return -1;
do {
if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) || fd.cFileName[0] == '.') continue;
const char *name = fd.cFileName;
#else
DIR *d = opendir(root);
if (!d) return -1;
for (struct dirent *e; (e = readdir(d));) {
if (e->d_name[0] == '.') continue;
const char *name = e->d_name;
#endif
char dir[1200];
snprintf(dir, sizeof dir, "%s" SEP "%s", root, name);
int64_t s, t;
const int i = newest_in(dir, &s, &t);
if (i >= 0 && (best < 0 || s > best_stamp || (s == best_stamp && t > best_time))) best = i, best_stamp = s, best_time = t;
#ifdef _WIN32
} while (FindNextFileA(h, &fd));
FindClose(h);
#else
}
closedir(d);
#endif
hos_log("benchmark: the newest save is file %d (%s)", best + 1, best_stamp > 0 ? "by the date in its caption.sav" : "by its file's time");
return best;
}
/* ---- the results ---- */
static int cmp_i64(const void *a, const void *b) {
const int64_t x = *(const int64_t *)a, y = *(const int64_t *)b;
return x < y ? -1 : x > y;
}
/* of n values sorted upwards, the one at q by the nearest rank (gpu/vk/perf_stats.h percentile) */
static int64_t rank_of(const int64_t *v, int n, double q) {
if (n <= 0) return 0;
int r = (int)(q * n);
if ((double)r < q * n) r++;
if (r < 1) r = 1;
if (r > n) r = n;
return v[r - 1];
}
static void scene_done(void) { /* (under the lock) */
if (B.nresults >= MAX_SCENES) return;
Result *r = &B.results[B.nresults++];
memset(r, 0, sizeof *r);
r->frames = B.n;
int64_t sum = 0;
for (int i = 0; i < B.n; i++) sum += B.iv[i];
r->seconds = sum / 1e9;
r->avg = sum ? B.n * 1e9 / (double)sum : 0;
/* (the graph's points: GRAPH_POINTS runs of frames in order, each its mean) */
r->npoints = B.n < GRAPH_POINTS ? B.n : GRAPH_POINTS;
for (int p = 0; p < r->npoints; p++) {
const int a = (int)((int64_t)p * B.n / r->npoints), z = (int)((int64_t)(p + 1) * B.n / r->npoints);
int64_t s = 0;
for (int i = a; i < z; i++) s += B.iv[i];
r->points[p] = z > a ? (float)(s / 1e6 / (z - a)) : 0;
}
if (B.n) {
qsort(B.iv, (size_t)B.n, sizeof *B.iv, cmp_i64);
r->max_ms = B.iv[B.n - 1] / 1e6;
if (B.n >= 100) { /* (as the performance overlay: no lows under 100 frames) */
const int64_t p99 = rank_of(B.iv, B.n, 0.99), p999 = rank_of(B.iv, B.n, 0.999);
r->low1 = p99 ? 1e9 / (double)p99 : 0;
r->low01 = p999 ? 1e9 / (double)p999 : 0;
} else {
r->low1 = r->low01 = -1;
}
}
hos_log("benchmark: scene %d of %d, %s: %.1f fps average, 1%% low %.1f, 0.1%% low %.1f, %d frames in %.2f s", B.nresults,
B.nscenes, B.scenes[B.nresults - 1].name, r->avg, r->low1, r->low01, r->frames, r->seconds);
}
static void json_text(FILE *f, const char *s) {
fputc('"', f);
for (; s && *s; s++) {
const unsigned char ch = (unsigned char)*s;
if (ch == '"' || ch == '\\') fprintf(f, "\\%c", ch);
else if (ch < 32) fprintf(f, "\\u%04x", ch);
else fputc(ch, f);
}
fputc('"', f);
}
static double bench_finite(double v) { return v == v && v < 1e12 && v > -1e12 ? v : 0; }
/* the options that shape the frame rate, as the options file has them (beside the game: triforce_options.ini) */
static void json_settings(FILE *out) {
static const char *const keys[] = {"frame_rate_cap", "vsync", "fullscreen", "output_res", "resolution", "quality_preset",
"upscaling", "dlss", "dlss_model", "frame_generation", "dlss_frame_generation",
"frame_pacing", "steady_frame_rate", "nvidia_reflex", "amd_anti-lag_2", "texture_detail",
"texture_filtering", "anti-aliasing", "sharpness", "hdr", "replay_helper_threads"};
char path[MAX_PATH];
const DWORD len = hos_game_path_a(path, MAX_PATH);
char *slash = len ? (strrchr(path, 92) ? strrchr(path, 92) : strrchr(path, 47)) : NULL;
FILE *f = NULL;
if (slash) {
snprintf(slash + 1, (size_t)(path + MAX_PATH - slash - 1), "triforce_options.ini");
f = fopen(path, "r");
}
fprintf(out, "{");
int first = 1;
char line[256];
while (f && fgets(line, sizeof line, f)) {
char *eq = strchr(line, '=');
if (!eq) continue;
*eq = 0;
char *v = eq + 1;
v[strcspn(v, "\r\n")] = 0;
for (unsigned k = 0; k < sizeof keys / sizeof *keys; k++) {
if (strcmp(line, keys[k])) continue;
char *end;
strtol(v, &end, 10);
fprintf(out, "%s", first ? "" : ",");
first = 0;
json_text(out, line);
if (*v && !*end) fprintf(out, ":%s", v);
else fputc(':', out), json_text(out, v);
}
}
if (f) fclose(f);
fprintf(out, "}");
}
static void write_results(int stopped) { /* (under the lock; once) */
if (B.written || !B.path[0]) return;
B.written = 1;
char tmp[1100];
snprintf(tmp, sizeof tmp, "%s.new", B.path);
FILE *f = fopen(tmp, "w");
if (!f) {
hos_log("benchmark: the results could not be written to %s", tmp);
return;
}
char gpu[160];
snprintf(gpu, sizeof gpu, "%s", rx_describe() ? rx_describe() : "");
char *paren = strstr(gpu, " (Vulkan");
if (paren) *paren = 0;
const int64_t now = hos_now_ns();
fprintf(f, "{\"version\":1,\"stopped\":%s,", stopped ? "true" : "false");
if (B.error[0]) fprintf(f, "\"error\":"), json_text(f, B.error), fputc(',', f);
fprintf(f, "\"gpu\":"), json_text(f, gpu);
fprintf(f, ",\"seconds_per_scene\":%.1f,\"boot_seconds\":%.1f,\"total_seconds\":%.1f,\"file\":%d,\"scenes\":[", B.seconds,
B.t_play ? (B.t_play - B.t_start) / 1e9 : -1.0, (now - B.t_start) / 1e9, B.slot + 1);
for (int i = 0; i < B.nresults; i++) {
const Result *r = &B.results[i];
fprintf(f, "%s{\"name\":", i ? "," : "");
json_text(f, B.scenes[i].name);
fprintf(f, ",\"avg\":%.2f,\"low1\":%.2f,\"low01\":%.2f,\"frames\":%d,\"seconds\":%.3f,\"max_ms\":%.2f,\"frametimes_ms\":[",
bench_finite(r->avg), bench_finite(r->low1), bench_finite(r->low01), r->frames, bench_finite(r->seconds), bench_finite(r->max_ms));
for (int p = 0; p < r->npoints; p++) fprintf(f, "%s%.2f", p ? "," : "", bench_finite(r->points[p]));
fprintf(f, "]}");
}
fprintf(f, "],\"settings\":");
json_settings(f);
fprintf(f, "}\n");
const int ok = fflush(f) == 0;
fclose(f);
if (ok && MoveFileExA(tmp, B.path, MOVEFILE_REPLACE_EXISTING))
hos_log("benchmark: results written to %s (%s, %d of %d scenes, %.1f s since the start)", B.path,
stopped ? "stopped" : "finished", B.nresults, B.nscenes, (now - B.t_start) / 1e9);
else
hos_log("benchmark: the results could not be moved to %s", B.path);
hos_log_flush();
}
static void fail(int64_t now, const char *why) { /* (under the lock) */
if (B.phase >= MKWVK_BENCH_DONE) return;
snprintf(B.error, sizeof B.error, "%s", why);
hos_log("benchmark: FAILED: %s", why);
B.phase = MKWVK_BENCH_FAILED, B.end_ns = now;
write_results(1);
}
static void stop(int64_t now, const char *why) { /* (under the lock) */
if (B.phase >= MKWVK_BENCH_DONE) return;
hos_log("benchmark: stopped (%s)", why);
B.phase = MKWVK_BENCH_STOPPED, B.end_ns = now;
write_results(1);
}
/* host/nn_fs.c, each file the game opens: a save file's progress.sav is the file it loads ("save:/slot_0N/progress.sav") */
void hos_bench_file_opened(const char *guest) {
if (!B.on || !guest || B.phase != MKWVK_BENCH_BOOT) return;
const char *p = strstr(guest, "slot_");
if (!p || p[5] < '0' || p[5] > '9' || p[6] < '0' || p[6] > '9' || strcmp(p + 7, "/progress.sav")) return;
const int slot = (p[5] - '0') * 10 + (p[6] - '0');
if (slot == B.slot) return;
B.slot = slot;
hos_log("benchmark: the game loads file %d%s", slot + 1,
B.newest < 0 ? "" : slot == B.newest ? " (the newest by its date)" : " (NOT the newest by its date)");
}
/* ---- the boot: the start's screens ---- */
static const char *stage_name(int stage) {
return stage == 0 ? "the title" : stage == 1 ? "the file select" : stage == 2 ? "the file's box" : "a screen it does not know";
}
int hos_bench_menu(uint64_t screen, uint64_t vt, int focus, int focused_entry, int entries, int *entry) {
if (!B.on || !focus || B.phase != MKWVK_BENCH_BOOT) return HOS_BENCH_MENU_NONE;
const int64_t now = hos_now_ns();
int act = HOS_BENCH_MENU_NONE;
AcquireSRWLockExclusive(&B.lock);
Screen *s = NULL;
for (int i = 0; i < B.nscreens; i++)
if (B.screens[i].screen == screen && B.screens[i].vt == vt) s = &B.screens[i];
if (!s && B.nscreens < (int)(sizeof B.screens / sizeof *B.screens)) {
s = &B.screens[B.nscreens++];
memset(s, 0, sizeof *s);
s->screen = screen, s->vt = vt;
s->stage = vt == TITLE_VT ? 0 : vt == FILES_VT ? 1 : vt == FILE_BOX_VT ? 2 : 3;
hos_log("benchmark: %s has a focused button (screen %#llx, vtable %#llx, %d entries, entry %d focused) at %.1f s",
stage_name(s->stage), (unsigned long long)screen, (unsigned long long)vt, entries, focused_entry, (now - B.t_start) / 1e9);
if (s->stage == 3 && ++B.unknown > 3) {
char why[160];
snprintf(why, sizeof why, "The game showed screens the benchmark does not know at its start (the last: vtable %#llx)",
(unsigned long long)vt);
fail(now, why);
ReleaseSRWLockExclusive(&B.lock);
return HOS_BENCH_MENU_NONE;
}
}
/* (a screen of an earlier step still fading out while the next is up: never pressed again, the press would be the next's) */
if (s && s->stage < 3 && s->stage < B.stage_max) s = NULL;
if (s && s->stage < 3 && s->stage > B.stage_max) B.stage_max = s->stage;
if (s && s->stage == 1 && !B.slot_looked) B.slot_looked = 1, B.newest = newest_slot();
(void)entry;
if (s) {
/* (A at once; again if the screen is still there with its focus after a while: a press the screen was not taking yet.
The box is given longer: Load takes a moment before the box goes) */
const int64_t again = s->stage == 2 ? 5000000000LL : 700000000LL; /* (the title drops the first, lab 11-19) */
if (!s->presses || now - s->press_ns > again) {
if (s->presses >= 4) {
char why[160];
snprintf(why, sizeof why, "The game did not take the benchmark's presses on %s", stage_name(s->stage));
fail(now, why);
} else {
s->presses++, s->press_ns = now;
act = HOS_BENCH_MENU_PRESS_A;
hos_log("benchmark: A pressed on %s%s", stage_name(s->stage), s->presses > 1 ? " again" : "");
}
}
}
ReleaseSRWLockExclusive(&B.lock);
return act;
}
/* ---- the tour: Link's update ---- */
int hos_bench_link_wants_state(void) {
const int p = B.on ? B.phase : MKWVK_BENCH_OFF;
return p == MKWVK_BENCH_BOOT || p == MKWVK_BENCH_TRAVEL;
}
static void go_scene(int64_t now) { /* (under the lock) the next scene's teleport */
B.phase = MKWVK_BENCH_TRAVEL, B.t_phase = now;
B.want = 1, B.tries = 0, B.resends = 0, B.saw_load = 0, B.retry_ns = 0, B.sent_ns = 0;
hos_log("benchmark: going to %s (scene %d of %d)", B.scenes[B.scene].name, B.scene + 1, B.nscenes);
}
int hos_bench_link(int64_t now, uint64_t actor, const char *map, int loading, int event) {
(void)actor;
if (!B.on) return -1;
int want = -1;
AcquireSRWLockExclusive(&B.lock);
const int64_t gap = B.last_link_ns ? now - B.last_link_ns : 0;
B.last_link_ns = now;
if (B.phase == MKWVK_BENCH_BOOT && !loading && !event && map && map[0]) {
B.t_play = now;
hos_log("benchmark: Link is in play on \"%s\" after %.1f s", map, (now - B.t_start) / 1e9);
B.scene = 0;
go_scene(now);
}
if (B.phase == MKWVK_BENCH_TRAVEL) {
if (B.want) {
if (now >= B.retry_ns && !loading) want = B.scenes[B.scene].action - 1000;
} else {
if (loading || gap > 250000000LL) B.saw_load = 1;
if (B.saw_load && !loading && !event && map && map[0]) {
hos_log("benchmark: arrived at %s (\"%s\") %.1f s after the teleport", B.scenes[B.scene].name, map, (now - B.sent_ns) / 1e9);
B.phase = MKWVK_BENCH_SETTLE, B.t_phase = now;
} else if (!B.saw_load && now - B.sent_ns > 12000000000LL) {
if (++B.resends > 3) {
char why[160];
snprintf(why, sizeof why, "The benchmark could not reach %s", B.scenes[B.scene].name);
fail(now, why);
} else {
hos_log("benchmark: no map change 12 s after the teleport to %s: asked again", B.scenes[B.scene].name);
B.want = 1, B.retry_ns = 0;
}
}
}
}
ReleaseSRWLockExclusive(&B.lock);
return want;
}
void hos_bench_teleport_sent(int index, int ok) {
(void)index;
const int64_t now = hos_now_ns();
AcquireSRWLockExclusive(&B.lock);
if (B.phase == MKWVK_BENCH_TRAVEL && B.want) {
if (ok) {
B.want = 0, B.sent_ns = now, B.saw_load = 0;
} else if (++B.tries > 60) { /* (an event playing refuses it: asked again every half second, 30 s at most) */
char why[160];
snprintf(why, sizeof why, "The game kept refusing the teleport to %s", B.scenes[B.scene].name);
fail(now, why);
} else {
B.retry_ns = now + 500000000LL;
}
}
ReleaseSRWLockExclusive(&B.lock);
}
/* ---- each present: the measurement, the camera, the clock's steps, Esc ---- */
static void ring_put(float ms) { B.ring[B.ring_n++ % MKWVK_BENCH_GRAPH] = ms; }
void hos_bench_present(int64_t now) {
if (!B.on) return;
int close = 0;
AcquireSRWLockExclusive(&B.lock);
static int64_t last;
const int64_t d = last ? now - last : 0;
last = now;
if (d > 0 && B.phase != MKWVK_BENCH_BOOT) ring_put((float)(d / 1e6));
static int told;
if (!told) {
told = 1;
hos_log("benchmark: on: %d scenes of %.1f s, results to %s", B.nscenes, B.seconds, B.path);
}
switch (B.phase) {
case MKWVK_BENCH_BOOT: {
const char *e = getenv("HOS_BENCH_BOOT_S");
const double limit = e && atof(e) > 0 ? atof(e) : 900;
if (now - B.t_start > (int64_t)(limit * 1e9)) fail(now, "The game did not reach play from its start in time");
break;
}
case MKWVK_BENCH_TRAVEL:
if (now - B.t_phase > 120000000000LL) {
char why[160];
snprintf(why, sizeof why, "The game did not finish loading %s", B.scenes[B.scene].name);
fail(now, why);
}
break;
case MKWVK_BENCH_SETTLE:
hos_hid_stick(0, 0, PAN, 0, 250);
if (now - B.t_phase >= SETTLE_NS) {
B.phase = MKWVK_BENCH_MEASURE, B.measure_t0 = now, B.n = 0;
memset(B.hist, 0, sizeof B.hist);
}
break;
case MKWVK_BENCH_MEASURE:
hos_hid_stick(0, 0, PAN, 0, 250);
if (B.measure_t0 != now && d > 0) {
if (B.n == B.cap) {
const int cap = B.cap ? B.cap * 2 : 16384;
int64_t *p = (int64_t *)realloc(B.iv, (size_t)cap * sizeof *p);
if (p) B.iv = p, B.cap = cap;
}
if (B.n < B.cap) B.iv[B.n++] = d;
const int64_t bin = d / 100000;
B.hist[bin < HIST_BINS ? bin : HIST_BINS]++;
}
if (now - B.measure_t0 >= (int64_t)(B.seconds * 1e9)) {
scene_done();
if (++B.scene >= B.nscenes) {
B.phase = MKWVK_BENCH_DONE, B.end_ns = now;
write_results(0);
} else {
go_scene(now);
}
}
break;
default: /* (done, stopped, failed: the panel's last words for a moment, then the game quits as at its window's close) */
if (!B.closing && now - B.end_ns > (B.phase == MKWVK_BENCH_FAILED ? 4000000000LL : 1200000000LL)) B.closing = 1, close = 1;
break;
}
/* (Esc, the game's window in front and the options closed: the run stops) */
if (B.phase < MKWVK_BENCH_DONE && (GetAsyncKeyState(VK_ESCAPE) & 0x8000) && !rx_option(1, 0)) {
DWORD pid = 0;
HWND w = GetForegroundWindow();
if (w) GetWindowThreadProcessId(w, &pid);
if (pid == GetCurrentProcessId()) stop(now, "Esc pressed");
}
ReleaseSRWLockExclusive(&B.lock);
if (close) {
hos_log("benchmark: the game quits");
hos_window_close();
}
}
void hos_bench_closing(void) {
if (!B.on) return;
AcquireSRWLockExclusive(&B.lock);
if (B.phase < MKWVK_BENCH_DONE) stop(hos_now_ns(), "the window was closed");
ReleaseSRWLockExclusive(&B.lock);
}
/* ---- the panel ---- */
int hos_bench_state(MkwVkBench *out) {
if (!B.on || !out) return 0;
AcquireSRWLockExclusive(&B.lock);
memset(out, 0, sizeof *out);
out->phase = B.phase;
out->scenes = B.nscenes;
const int sc = B.scene < B.nscenes ? B.scene : B.nscenes - 1;
out->scene = B.phase == MKWVK_BENCH_BOOT ? 0 : sc + 1;
snprintf(out->name, sizeof out->name, "%s", B.phase == MKWVK_BENCH_BOOT ? "" : B.scenes[sc].name);
const int64_t now = hos_now_ns();
double frac = 0;
if (B.phase == MKWVK_BENCH_MEASURE) frac = (now - B.measure_t0) / (B.seconds * 1e9);
if (frac > 1) frac = 1;
out->progress = B.phase >= MKWVK_BENCH_DONE && B.phase != MKWVK_BENCH_DONE ? (float)B.nresults / B.nscenes
: B.phase == MKWVK_BENCH_DONE ? 1.0f : B.phase == MKWVK_BENCH_BOOT ? 0.0f : (float)((sc + frac) / B.nscenes);
if (B.phase == MKWVK_BENCH_FAILED) snprintf(out->line, sizeof out->line, "%s", B.error);
/* (the newest frame times, oldest first; the rate of the last second of them) */
const int have = B.ring_n < MKWVK_BENCH_GRAPH ? (int)B.ring_n : MKWVK_BENCH_GRAPH;
for (int i = 0; i < have; i++) out->graph_ms[i] = B.ring[(B.ring_n - (uint32_t)have + (uint32_t)i) % MKWVK_BENCH_GRAPH];
out->graph_n = have;
double sum = 0;
int n = 0;
for (int i = have - 1; i >= 0 && sum < 1000; i--) sum += out->graph_ms[i], n++;
out->fps = sum > 0 ? (float)(n * 1000.0 / sum) : 0;
/* (the scene's 1% low so far, from its histogram: the bin the slowest 1% reach) */
out->low1 = -1;
if (B.phase == MKWVK_BENCH_DONE && B.nresults) { /* (finished: the whole run's average and its lowest 1% low) */
int64_t frames = 0;
double secs = 0, low = 1e9;
for (int i = 0; i < B.nresults; i++) {
frames += B.results[i].frames, secs += B.results[i].seconds;
if (B.results[i].low1 > 0 && B.results[i].low1 < low) low = B.results[i].low1;
}
out->fps = secs > 0 ? (float)(frames / secs) : 0;
out->low1 = low < 1e9 ? (float)low : -1;
}
if (B.phase == MKWVK_BENCH_MEASURE && B.n >= 100) {
const int want = B.n - (int)ceil(0.99 * B.n) + 1; /* (how many are at or above the 99th percentile's rank) */
int above = 0;
for (int b = HIST_BINS; b >= 0; b--) {
above += (int)B.hist[b];
if (above >= want) {
out->low1 = (float)(1e4 / (b + 0.5));
break;
}
}
}
ReleaseSRWLockExclusive(&B.lock);
return 1;
}

42
host/hos_bench.h Normal file
View File

@@ -0,0 +1,42 @@
/* (Triforce, 11-19) Benchmark mode (host/hos_bench.c): HOS_BENCHMARK=<results.json> starts the game straight into play on
the newest save, tours a few places with the camera turning, measures every frame and writes the results for the launcher.
Nothing changes without the variable. The game's sides call in here: */
#pragma once
#include <stdint.h>
/* at the start (hos_main.c, before anything else reads it): the variables read once */
void hos_bench_init(void);
/* 1 while benchmark mode is on (HOS_BENCHMARK set), from the start to the exit */
int hos_bench_on(void);
/* host/nn_hid.c: 1 while the benchmark drives the game: the player's devices do not count, the benchmark's presses count with
the window behind other windows */
int hos_bench_input_only(void);
/* host/oot_menu.c, a menu screen's update with what it shows now: its vtable, whether it has a focused button, the focused
entry's place in its list (-1 none) and how many entries it has. Returns what to do: */
enum { HOS_BENCH_MENU_NONE, HOS_BENCH_MENU_PRESS_A };
/* (*entry: kept for an entry to focus first; none is asked for now: the file select opens on the newest file itself) */
int hos_bench_menu(uint64_t screen, uint64_t vt, int focus, int focused_entry, int entries, int *entry);
/* host/hos_main.c, Link's update: the map now (Sequence_CurrentBanc), whether a map loads, whether an event plays. Returns the
destination index to teleport to now (oot_destinations), -1 none; then hos_bench_teleport_sent with what oot_teleport said */
int hos_bench_link(int64_t now, uint64_t actor, const char *map, int loading, int event);
void hos_bench_teleport_sent(int index, int ok);
/* 1 while hos_bench_link wants the map's state (it is read only then: nothing is asked of the game while a scene is measured) */
int hos_bench_link_wants_state(void);
/* host/nn_vi.c, each of the game's presents (now: hos_now_ns at that present) */
void hos_bench_present(int64_t now);
/* host/nn_fs.c, each file opened (its guest path): the save file the game loads, for the log and the results */
void hos_bench_file_opened(const char *guest);
/* host/nn_fs.c: 1 when a save commit is to be left out (benchmark mode writes no save) */
int hos_bench_blocks_save(void);
/* host/hos_relaunch.c: the window is closing (the player, the launcher or the benchmark itself): a run not finished writes
that it was stopped */
void hos_bench_closing(void);
/* host/rx_backend.c: MkwVkHost.bench, the overlay's state for the renderer (gpu/vk/vk_api.h MkwVkBench) */
struct MkwVkBench;
int hos_bench_state(struct MkwVkBench *out);

View File

@@ -11,6 +11,7 @@
#include "hos.h"
#include "hos_paths.h"
#include "hos_instance.h" /* ((Triforce) one game at a time for a game folder) */
#include "hos_bench.h" /* ((Triforce, 11-19) benchmark mode: HOS_BENCHMARK */
#include "../gpu/vk/vk_api.h"
#include "../gpu/vk/oot_cheat_items.h"
#include "../gpu/vk/oot_debug_link.h" /* ((Triforce) the Game flags and Cutscenes pages' lines) */
@@ -455,6 +456,7 @@ volatile int hos_oot_live_action; /* (test runs) the live input file's "!cheat
int hos_oot_hearts_enabled(void) {
int rx_option(int id, int otherwise);
if (hos_bench_on()) return 1; /* ((Triforce) benchmark mode: the hearts protected, whatever the Debug tab says) */
const int menu = rx_option(HOS_OPT_CHEAT_HEARTS, -1);
return menu < 0 ? hos_oot_protect_hearts : menu;
}
@@ -710,6 +712,7 @@ static struct {
int64_t requested_at, check_at;
unsigned destination;
} teleport;
static uint64_t teleport_result; /* ((Triforce) the last request's own result, oot_teleport: benchmark mode's retry */
/* (Triforce, lab) The pipeline crawl's commands, from the live input file (host/nn_hid.c). "!banc <map> <entry> <event>
[child|adult]" asks for a map change to any map by its names, as the game's own entrance actors do (the names are in the
@@ -839,6 +842,7 @@ static int oot_teleport(Ctx *c, uint64_t actor, unsigned index) {
release_link(c);
}
*c = saved;
teleport_result = ok ? result : 0; /* ((Triforce) benchmark mode: 0 = the event manager did not take it) */
const int refused = crawl_banc && (!ok || !result); /* (the crawl: asked again soon, not after the 8 s of a request under way) */
teleport.requested_at = refused ? 0 : now;
teleport.check_at = refused ? 0 : now + 1500000000LL;
@@ -1232,6 +1236,24 @@ static float oot_load_float(Ctx *c, uint64_t addr) {
return value;
}
/* ((Triforce, 11-19) benchmark mode, host/hos_bench.c) its tour at Link's update: the map's state while it waits for play or for
an arrival (nothing is read of the game while a scene is measured), and the teleports it asks for, sent at once: its own
pace, not the 8 s a teleport from the menu keeps between two */
static void oot_bench_tick(Ctx *c, uint64_t actor, int64_t now) {
if (!hos_bench_on() || !hos_bench_link_wants_state()) return;
char current[80];
int loading = 0;
oot_gamedata_string(c, 0x1d6189dau, current, sizeof current); /* Sequence_CurrentBanc */
oot_gamedata_bool(c, 0xef2b60c2u, &loading); /* Sequence_IsLoadingBanc */
const uint64_t events = oot_singleton(c, OOT_EVENTMGR_SLOT);
const int event = events && recomp_load64(c, events + 104) ? 1 : 0;
const int want = hos_bench_link(now, actor, current, loading, event);
if (want < 0) return;
teleport.requested_at = 0;
teleport_result = 0;
const int sent = oot_teleport(c, actor, (unsigned)want);
hos_bench_teleport_sent(want, sent && teleport_result != 0); /* (a request the event manager refused: asked again soon) */
}
static _Thread_local uint64_t flight_transform_controller;
static _Thread_local uint64_t flight_pose_actor;
static _Thread_local float flight_transform_yaw;
@@ -1251,6 +1273,7 @@ static void oot_update_player_cheats(Ctx *c, uint64_t actor, uint64_t components
int action = rx_option(HOS_OPT_CHEAT_ACTION, 0);
if (!action) action = __atomic_exchange_n(&hos_oot_live_action, 0, __ATOMIC_RELAXED);
oot_teleport_followup(c);
oot_bench_tick(c, actor, now); /* ((Triforce, 11-19) benchmark mode: its tour, host/hos_bench.c */
oot_inventory_refresh(c, now);
oot_link_tick(c, actor, now); /* ((Triforce) the Game flags and Cutscenes pages) */
if (action >= OOT_CHEAT_ITEM_ACTION && action < OOT_CHEAT_ITEM_ACTION + 256 * (int)OOT_ITEM_COUNT) {
@@ -1774,6 +1797,8 @@ static int game_main(int argc, char **argv) {
const char *protect_hearts = getenv("HOS_OOT_PROTECT_HEARTS");
hos_oot_protect_hearts = protect_hearts && !strcmp(protect_hearts, "1");
}
hos_bench_init(); /* ((Triforce, 11-19) benchmark mode, HOS_BENCHMARK: host/hos_bench.c */
if (hos_bench_on()) hos_oot_protect_hearts = 1;
#ifdef _WIN32
{ // (the whole process, not only the window's thread: the renderer asks the window's size from its own, and on a 4K screen at 150%
// Windows answered such a thread 2560 x 1440: the picture was that size, in the corner of the window. Hookshot issues 15, 18, 20)

View File

@@ -92,6 +92,7 @@ static void relaunch(void) {
first when the menu asked for it */
void hos_window_closed_exit(void) {
const int again = relaunch_asked != 0;
{ void hos_bench_closing(void); hos_bench_closing(); } /* ((Triforce) benchmark mode: a run not finished writes that it stopped) */
hos_log(again ? "display: window closed for a restart (the Insert menu's Restart now)" : "display: window closed, exiting");
hos_log_flush();
{ void hos_fs_save_finish(void); hos_fs_save_finish(); } /* (host/nn_fs.c: a save still being committed is finished first) */

View File

@@ -526,6 +526,9 @@ HLE(_ZN2nn2fs6CommitEPKc) {
AcquireSRWLockExclusive(&tx_lock);
int i;
for (i = 0; i < ntx && strcmp(tx_mounts[i].name, name); i++) {}
/* ((Triforce, 11-19) benchmark mode writes no save: the commit is left out (the working copy alone has the game's writes) */
int hos_bench_blocks_save(void);
if (i < ntx && hos_bench_blocks_save()) i = ntx;
if (i < ntx) {
const int away = hos_vcore_away();
const ULONGLONG t0 = GetTickCount64();
@@ -562,6 +565,7 @@ HLE(_ZN2nn2fs8OpenFileEPNS0_10FileHandleEPKci) {
if (!host_path(g, path, sizeof path, &writable)) { hos_log("fs: OpenFile(%s): unknown mount", g); RET(R_PATH_NOT_FOUND); return; }
int want_write = (ARG(2) & 6) != 0;
if (want_write && !writable) { RET(R_PATH_NOT_FOUND); return; }
{ void hos_bench_file_opened(const char *guest); hos_bench_file_opened(g); } /* ((Triforce) benchmark mode: which save file loads */
/* (mkw-recomp) HOS_NO_MOVIES=1: MKW's WebM movies (cup openings, billboards, emblems) are not found, and the
game goes on without them (decoded by nn_video.c otherwise) */
if (!want_write && getenv("HOS_NO_MOVIES")) {

View File

@@ -953,6 +953,11 @@ static void read_input(uint64_t *buttons, int32_t stick[4]) {
memset(stick, 0, 4 * sizeof *stick);
void hos_mouse_native_stick(int held);
scripted_input(buttons, stick);
/* ((Triforce, 11-19) benchmark mode (host/hos_bench.c) drives the game itself: its presses and stick alone, with the window
in front or behind other windows; the player's devices do not count while it runs (a mouse or a pad would move the camera
it measures) */
int hos_bench_input_only(void);
if (hos_bench_input_only()) return;
/* A scripted run (a test) takes no input from the player's devices until 5 s after its last press (a variable
left set in a shell no longer leaves the game without controls), and otherwise the pads count only
while the game's window is in front, like the keyboard: XInput is global, so a test run in the background
@@ -975,7 +980,17 @@ static void read_input(uint64_t *buttons, int32_t stick[4]) {
static const char *env;
static int looked;
if (!looked) looked = 1, env = getenv("HOS_INPUT_BACKGROUND");
if (pads_in_background(env, rx_option(4, 0))) pads_read(buttons, stick);
/* ((Triforce, 11-18) while the Insert menu is open the pads are its own here too (it reads them in the background
now: gpu/vk/vk_menu.cpp pads_ok), as in front below; read all the same, so the menu's bits stay current) */
if (pads_in_background(env, rx_option(4, 0))) {
uint64_t pb = 0;
int32_t ps[4] = {0};
pads_read(&pb, ps);
if (!rx_option(1, 0)) {
*buttons |= pb;
stick_max(stick, ps);
}
}
return;
}
{ /* (Triforce) The options' tabs inside the game's own Options screen (host/oot_menu.c, gpu/vk/vk_menu.cpp): one of

View File

@@ -760,6 +760,11 @@ static void present_trace(int64_t frame, int64_t now) {
flushed = now;
}
}
/* (qsort: longest interval first) */
static int cmp_i64_desc(const void *a, const void *b) {
const int64_t x = *(const int64_t *)a, y = *(const int64_t *)b;
return x < y ? 1 : x > y ? -1 : 0;
}
void hos_vi_native_presented(void) {
static long long scan_n;
scan_dt(++scan_n);
@@ -771,6 +776,7 @@ void hos_vi_native_presented(void) {
/* (a cap under 60 paces by itself, whatever interval the game asked for while Monitor's rate was not known yet) */
const int interval = fps_max() < 60 ? 1 : present_interval;
const int64_t now = hos_now_ns();
{ void hos_bench_present(int64_t now); hos_bench_present(now); } /* ((Triforce) benchmark mode: every present's interval) */
/* ((Triforce) the Steady frame rate row: a period this PC holds in the scene, never shorter than the cap's) */
const int64_t period = steady_period(1000000000LL / fps_max() * interval, now);
pace_period_ns = period; /* (Triforce: what another limiter is given to hold in this file's place, pace_handed) */
@@ -802,8 +808,13 @@ void hos_vi_native_presented(void) {
distance from it, the frame-time spread a change of the pacing shows in) */
static int rel[6];
static int64_t off_sum;
/* ((Triforce) the window's present-to-present intervals themselves, for its 1% low: the launcher's benchmark reads that
line. 4096 at most: 5 s at over 800 fps fills it, and the slowest one in a hundred of what it holds is still the low) */
static int64_t lows[4096];
static int lows_n;
if (last_present) {
const int64_t d = now - last_present, off = d > period ? d - period : period - d;
if (lows_n < (int)(sizeof lows / sizeof lows[0])) lows[lows_n++] = d;
hist[d < 15500000 ? 0 : d < 17800000 ? 1 : d < 22000000 ? 2 : d < 30000000 ? 3 : d < 40000000 ? 4 : 5]++;
rel[d * 4 < period * 3 ? 0 : d * 20 < period * 19 ? 1 : d * 20 <= period * 21 ? 2 : d * 4 <= period * 5 ? 3 : d <= period * 2 ? 4 : 5]++;
off_sum += off;
@@ -818,6 +829,12 @@ void hos_vi_native_presented(void) {
hos_log("vi: frame intervals against the paced period of %.3f ms: under 0.75 of it %d, 0.75-0.95 %d, 0.95-1.05 %d, "
"1.05-1.25 %d, 1.25-2 %d, over 2 %d; %.3f ms from it on average", period / 1e6, rel[0], rel[1], rel[2], rel[3],
rel[4], rel[5], counted ? off_sum / 1e6 / counted : 0.0);
if (lows_n >= 100) { /* (as the performance overlay's rule: no 1% low under 100 frames) */
qsort(lows, (size_t)lows_n, sizeof lows[0], cmp_i64_desc);
const int64_t at = lows[lows_n / 100]; /* (nearest rank: the interval the slowest 1 % reach) */
hos_log("vi: 1%% low %.1f fps over the last %.1f s (%d frames)", at > 0 ? 1e9 / (double)at : 0.0, (now - window_start) / 1e9, lows_n);
}
lows_n = 0;
memset(hist, 0, sizeof hist);
memset(rel, 0, sizeof rel), off_sum = 0;
window_start = now, frames_in_window = 0;

View File

@@ -29,6 +29,7 @@ void rx_option_set(int id, int value); /* rx_backend.c */
#include <stdlib.h>
#include <string.h>
#include "../gpu/vk/vk_api.h" /* (HOS_MOUSE_*) */
#include "hos_bench.h" /* ((Triforce, 11-19) benchmark mode) */
/* A guest read, of the pointers the game's objects hold: inside the guest's space (below 1 MB: a null pointer's), it is
read as the lifted code reads it; a page there not committed yet is committed on the touch (mkw_glue.c
@@ -398,6 +399,7 @@ static void focus_entry(int i, uint64_t entry, uint64_t button, void *arg); /*
static SRWLOCK mouse_lock = SRWLOCK_INIT;
static void mouse_tick_locked(Ctx *c, uint64_t screen);
static int mods_entry_hit(float x, float y); /* ((Triforce) below: the Mods entry under a list's last button) */
static int quit_entry_hit(float x, float y); /* ((Triforce, 11-19) and Quit under it, the System page's only */
/* (mouse_owner: the thread in mouse_tick: the game's focus handler may run inside its setter) */
static void mouse_tick(Ctx *c, uint64_t screen) {
if (!TryAcquireSRWLockExclusive(&mouse_lock)) return;
@@ -763,6 +765,12 @@ static void mouse_tick_locked(Ctx *c, uint64_t screen) {
pressed &= ~(uint32_t)HOS_MOUSE_LEFT;
if (trace) hos_log("menu: the Mods entry clicked (%.0f, %.0f)", hit.x, hit.y);
}
/* ((Triforce, 11-19) a click on Quit under Mods: the renderer opens its dialog (3) */
if ((pressed & HOS_MOUSE_LEFT) && !hit.hit && quit_entry_hit(hit.x, hit.y)) {
rx_option_set(HOS_OPT_MODS_ENTER, 3);
pressed &= ~(uint32_t)HOS_MOUSE_LEFT;
if (trace) hos_log("menu: the Quit entry clicked (%.0f, %.0f)", hit.x, hit.y);
}
/* The "Back" prompt at the bottom right (B), on every screen with one (the title's load list, the pause menu, the
map; in the layout's units, measured from their screens): a click there off the buttons */
if ((pressed & HOS_MOUSE_LEFT) && !hit.hit && hit.y > -1080 && hit.y < -960 && hit.x >= 1600 && hit.x < 1900) {
@@ -821,6 +829,7 @@ static int button_rect(uint64_t button, Rect *r) {
#define TITLE_LIST_VTABLE 0x84c106e8ULL
static volatile LONG64 mods_last_ns; /* (the last frame a list's last button had the game's cursor) */
static Rect mods_entry; /* (the entry's box, as the renderer draws it: under the last button by the pitch) */
static Rect quit_entry; /* ((Triforce, 11-19) Quit's, under Mods by the pitch; empty on the title's list */
static volatile LONG64 mods_entry_ns;
typedef struct { Rect r[16]; uint64_t b[16]; int n, pause; } ModsList;
static void mods_list_entry(int i, uint64_t entry, uint64_t button, void *arg) {
@@ -939,6 +948,7 @@ static void mods_list_tick(uint64_t screen, int title, ModsCall *call) {
const int focused = state == 1 || state == 3 || (mods_held.button && mods_held.button == l.b[last]);
if (focused) InterlockedExchange64(&mods_last_ns, (LONG64)now);
mods_entry = (Rect){r.x0, r.y0 - pitch, r.x1, r.y1 - pitch};
quit_entry = title ? (Rect){0, 0, 0, 0} : (Rect){r.x0, r.y0 - 2 * pitch, r.x1, r.y1 - 2 * pitch};
InterlockedExchange64(&mods_entry_ns, (LONG64)now);
rx_option_set(HOS_OPT_MODS_X0, (int)r.x0), rx_option_set(HOS_OPT_MODS_X1, (int)r.x1);
rx_option_set(HOS_OPT_MODS_Y0, (int)r.y0), rx_option_set(HOS_OPT_MODS_Y1, (int)r.y1);
@@ -954,6 +964,11 @@ int hos_oot_mods_down(void) {
const LONG64 t = InterlockedCompareExchange64(&mods_last_ns, 0, 0);
return t && (LONG64)hos_now_ns() - t < 80000000LL;
}
static int quit_entry_hit(float x, float y) {
const LONG64 t = InterlockedCompareExchange64(&mods_entry_ns, 0, 0);
return t && (LONG64)hos_now_ns() - t < 100000000LL && quit_entry.x1 > quit_entry.x0 && x >= quit_entry.x0 && x <= quit_entry.x1 &&
y >= quit_entry.y0 && y <= quit_entry.y1;
}
static int mods_entry_hit(float x, float y) {
const LONG64 t = InterlockedCompareExchange64(&mods_entry_ns, 0, 0);
return t && (LONG64)hos_now_ns() - t < 100000000LL && x >= mods_entry.x0 && x <= mods_entry.x1 && y >= mods_entry.y0 && y <= mods_entry.y1;
@@ -996,6 +1011,24 @@ static Seen *screen_seen(uint64_t screen, int64_t now) {
return free_one;
}
/* ((Triforce, 11-19) benchmark mode, host/hos_bench.c: the start's screens pressed through as each gets a focused button. The
file select is left on the file it opens on, the newest (its entries are a carousel's places, not files: focusing one by
its place loaded another file in a lab run) */
typedef struct { int index, state; } BenchLook;
static void bench_entry(int i, uint64_t entry, uint64_t button, void *arg) {
(void)entry;
BenchLook *l = (BenchLook *)arg;
uint8_t state = 0;
if (peek(button + 56, &state, 1) && state > l->state) l->index = i, l->state = state;
}
static void bench_menu(Ctx *c, uint64_t screen, uint64_t vt) {
(void)c;
BenchLook l = {-1, 0};
const int n = each_entry(screen, 64, bench_entry, &l);
int entry = -1;
if (hos_bench_menu(screen, vt, 1, l.index, n, &entry) == HOS_BENCH_MENU_PRESS_A) hos_hid_tap("0:A/120");
}
void hos_oot_menu_tick(Ctx *c, uint64_t screen) {
if (!screen) return;
if (trace < 0) trace = getenv("HOS_MENU_TRACE") != NULL;
@@ -1058,7 +1091,10 @@ void hos_oot_menu_tick(Ctx *c, uint64_t screen) {
static int64_t none_since;
const int gone = !front && none_since && now - none_since > 50000000;
none_since = front ? 0 : none_since ? none_since : now;
const int focus_now = me->focus;
const uint64_t vt_now = me->vt;
ReleaseSRWLockExclusive(&seen_lock);
if (focus_now && hos_bench_on()) bench_menu(c, screen, vt_now); /* ((Triforce, 11-19) benchmark mode: the start's screens) */
mods_call(c, &mods_now);
if (gone) hos_mouse_game_menu_gone();
if (mine) mouse_tick(c, screen);

View File

@@ -162,6 +162,8 @@ __attribute__((visibility("default"))) void hos_posix_post_message(uint32_t msg,
if (msg == WM_APP + 9) __atomic_store_n(&restart_asked, 1, __ATOMIC_RELEASE);
if (msg == WM_CLOSE) __atomic_store_n(&close_asked, 1, __ATOMIC_RELEASE);
}
/* ((Triforce, 11-19) benchmark mode's end, host/hos_bench.c: the window closes as at the Insert menu's Quit, on its own thread) */
void hos_window_close(void) { __atomic_store_n(&close_asked, 1, __ATOMIC_RELEASE); }
/* the menu opened: the mouse let go (its capture kept for later); closed: the capture back, if the window still has the focus */
static int captured_before_menu;
static void menu_mouse(int open) {

View File

@@ -207,6 +207,7 @@ int hos_mouse_pointer(MkwVkPointer *out); /* display.c, posix/display_sdl.c */
int hos_sdl_gyro_status(void); /* pad_sdl.c */
extern const char *hos_romfs_dir; /* nn_fs.c, set by hos_main.c */
static const char *host_romfs_dir(void) { return hos_romfs_dir; }
#include "hos_bench.h" /* ((Triforce) MkwVkHost.bench: benchmark mode's panel, hos_bench_state) */
#ifdef _WIN32
static unsigned char menu_key_press[256];
@@ -229,7 +230,7 @@ static const MkwVkHost vk_host = {
hos_gpu_maps_generation, nvn_vmap_generation, hos_reserved_cpus, host_collect_in, host_guest_alloc,
host_watch_guest_writes, hos_pad_raw, hos_binding, hos_bind, host_aspect_ratio, host_take_key_press,
hos_mouse_pointer, hos_mic_count, hos_mic_name, hos_mic_select, hos_sdl_gyro_status, hos_log_flush, hos_prompts_face,
host_romfs_dir, host_wide_menus,
host_romfs_dir, host_wide_menus, hos_bench_state,
};
static const MkwVkRenderer *vk; /* the Vulkan back end, when it was chosen and started */