mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-17 22:19:57 -04:00
Add a floor probe that logs Link on a moving floor each frame on 1.1.1.
Above 60 fps Link stands still on the Deku Tree's floating platform while it moves under him, and the code that carries him is not found yet. With floor_probe set (off by default), each present logs the frame's step, Link's position and how far he moved, and the nearest moving ground group of the engine's ground manager with how far it moved, so one run at 60 and one above it show where the carry is lost. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1011,6 +1011,9 @@
|
||||
# it waits for and what that one is doing (at most 24 lines a run): a game that stops then leaves the chain in its log.
|
||||
# Off by default: its thread takes the game's thread lock every 2 seconds. 10 is a good value for a hang report.
|
||||
# wait_watch_s = 0
|
||||
# Diagnosis: one log line per frame while Link stands near a moving floor (the floating platforms): the frame's step,
|
||||
# how far he moved and how far the floor moved. 1 writes 4000 lines, a larger number that many; 0 is off.
|
||||
# floor_probe = 0
|
||||
# 1: with trace = perf, walks of the process's address space count its private and write-combined memory every 600
|
||||
# frames (the "mem: process" line) and where its committed memory lies every 3600 frames (the "commit census" lines).
|
||||
# Each walk holds the address-space lock for 100-240 ms and delays the next frame by as much, so they are off unless
|
||||
|
||||
@@ -34,7 +34,7 @@ static int save_ok = 1; // the last cfg_save_to wrote (o
|
||||
// Every name the runtime reads (and the patch sets in generated/), without the prefix. A file key outside this list is
|
||||
// logged as unknown. A new variable goes here too, or its ini key logs a harmless "unknown key" line.
|
||||
static const char *const known[] = {
|
||||
"CORES", "TM_DISPATCH", "NVN2_CS_TABLE", "SKIP_SHADERS", "MOVIE_DEBAND", "MOVIE_FPS", "MOVIE_SKIP", "MOVIE_OVERLAY", "MOVIES", "NPLN", "NVN2_PROGRAMS", "NVN_TRAP", "OCARINA_REALTIME", "ONESHOT_BUDGET", "ONESHOT_WAIT_MS", "OCARINA_STEP", "PHYSICS_STEPS", "PICKUP_COUNT", "WATER_STEPS", "MOVIE_PTS", "STEP_STEADY", "VI_HZ", "VI_VRR", "TIME_DUMP", "SHADER_DUMP", "SHOT_AFTER", "SHOT_DIR", "SHOT_EVERY", // Switch 2 port: movie skip (romfs.c), NVN2 proc traps (nvn_procs.c)
|
||||
"CORES", "TM_DISPATCH", "NVN2_CS_TABLE", "SKIP_SHADERS", "MOVIE_DEBAND", "MOVIE_FPS", "MOVIE_SKIP", "MOVIE_OVERLAY", "MOVIES", "NPLN", "NVN2_PROGRAMS", "NVN_TRAP", "OCARINA_REALTIME", "ONESHOT_BUDGET", "ONESHOT_WAIT_MS", "OCARINA_STEP", "PHYSICS_STEPS", "PICKUP_COUNT", "WATER_STEPS", "FLOOR_PROBE", "MOVIE_PTS", "STEP_STEADY", "VI_HZ", "VI_VRR", "TIME_DUMP", "SHADER_DUMP", "SHOT_AFTER", "SHOT_DIR", "SHOT_EVERY", // Switch 2 port: movie skip (romfs.c), NVN2 proc traps (nvn_procs.c)
|
||||
"AA", "AA_LOG", "AB", "AMIIBO_DIR", "ANISO", "APP_POOL", "ASPECT", "ASPECT_PATCH", "ASSUME_FOCUS", "ASTC", "ASTC_BC", "ASTC_TIME", "ASYNC_PREEMPT", "AUDIO", "AUDIO_CATCHUP", "AUDIO_CHANNELS", "AUDIO_DEVICE", "AUDIO_GAME_PRIO", "AUDIO_OFF", "AUDIO_PREFILL_MS", "AUDIO_RAMP", "AUDIO_STATS",
|
||||
"BARRIER_GAME", "MESH_AHEAD", "MESH_FALLBACK", "MESH_FALLBACK_MB", "MESH_FALLBACK_WORKERS", "PROBE_MESHFB_DIR",
|
||||
"BACKGROUND_WINDOW", "BIND_A", "BIND_B", "BIND_DOWN", "BIND_L", "BIND_LCLICK", "BIND_LEFT", "BIND_LSTICK_DOWN", "BIND_LSTICK_LEFT",
|
||||
@@ -100,6 +100,7 @@ static const struct { const char *key, *section; } sections[] = {
|
||||
{"VRAM_HEAP_LIMIT", "performance"}, {"VRAM_RESERVE_MB", "performance"}, {"UPLOAD_BATCH_MB", "performance"}, {"MESH_EMULATION", "performance"},
|
||||
{"MESH_EMU_MB", "performance"}, {"MESH_EMU_TASKS", "performance"}, {"MESH_EMU_BATCH", "performance"}, {"VEC_INDEX_FIX", "performance"},
|
||||
{"GUEST_OPT", "performance"}, {"PASS_TIMES", "diagnostics"}, {"DUMP_KEY", "diagnostics"},
|
||||
{"FLOOR_PROBE", "diagnostics"},
|
||||
{"FPS_LIMIT", "frame rate"}, {"FPS60", "frame rate"}, {"RTSS", "frame rate"},
|
||||
{"REALTIME", "frame rate"}, {"CLOTH_REALTIME", "frame rate"}, {"HIGHFPS_FIX", "frame rate"},
|
||||
{"PHYSICS_STEPS", "frame rate"}, {"PICKUP_COUNT", "frame rate"}, {"WATER_STEPS", "frame rate"},
|
||||
@@ -245,6 +246,8 @@ static const CfgMeta metas[] = {
|
||||
{"HIGHFPS_FIX", "1", "0|1", RESTART},
|
||||
// the set owater of patches-v111.txt (frame_rate.c frame_rate_sim_host): water and floor surfaces' fixed steps
|
||||
{"WATER_STEPS", "1", "0|1", RESTART},
|
||||
// frame_rate.c floor_probe: lines about Link on a moving floor (0 off, 1 = 4000 lines, or a count)
|
||||
{"FLOOR_PROBE", "0", NULL, RESTART},
|
||||
{"LANG", "", "ja|en-US|fr|de|it|es|zh-CN|ko|nl|pt|ru|zh-TW|en-GB|fr-CA|es-419|zh-Hans|zh-Hant|pt-BR|pl", RESTART},
|
||||
{"OPERATION_MODE", "docked", "docked|handheld", LIVE},
|
||||
{"TEXT_SPEED", "normal", "normal|fast|instant", LIVE}, // text_speed.c: the message window's typing
|
||||
|
||||
@@ -751,6 +751,79 @@ static void world_clock(double dt, double step) {
|
||||
atomic_store_explicit(&world_us, w + (int64_t)(step * 1e6 + 0.5), memory_order_relaxed);
|
||||
}
|
||||
|
||||
// ---- NX2NAVI_FLOOR_PROBE (floor_probe in nx2navi.ini, 0 by default): Link on a moving floor, one line per update
|
||||
// (diagnosis, 1.1.1). Above 60 fps Link stands still on the Deku Tree's floating platform while it moves under him, and
|
||||
// the code that carries him has not been found; these lines give what a run needs to find it. The moving floors are
|
||||
// the engine's ground groups: their manager is [[[main+0x4c7df00]] +0xc0] +0x130 (the ground control moves write it,
|
||||
// main+0x3000a90, and its transform setter main+0x386a740 takes it so), the group count at +0x28 and the array of
|
||||
// 32-byte entries at +0x30, each starting with the group; a group's transform is three rows of four floats at +0x88,
|
||||
// +0x98 and +0xa8 (main+0x386a7e8..0x386a800), its translation in their fourth lanes. Each update the probe reads every
|
||||
// group's translation and Link's position (Player +0x31c, player_pos), and logs the step, Link's position and how far
|
||||
// he moved since the last update, and the moving group nearest to him (within FLOOR_PROBE_RADIUS horizontally) with
|
||||
// how far it moved: at 60 fps the two moves match while he stands on it. The value is the number of lines to write
|
||||
// (1 means 4000); off it costs one test per present. The guest memory is read where the host can read it directly.
|
||||
#define FLOOR_PROBE_RADIUS 8.0f
|
||||
#define FLOOR_PROBE_GROUPS 16384
|
||||
static int floor_probe_left = -1; // lines still to write; -1 before the setting was read
|
||||
static float *floor_last; // the groups' translations at the last update (x, y, z each)
|
||||
static uint32_t floor_last_n;
|
||||
static float floor_link[3];
|
||||
static int floor_link_ok;
|
||||
|
||||
static int direct_read(uint64_t a, void *out, size_t n) {
|
||||
if (!a || !mem_host_readable(a, n)) return 0;
|
||||
memcpy(out, (const void *)(uintptr_t)a, n);
|
||||
return 1;
|
||||
}
|
||||
static uint64_t direct_ptr(uint64_t a) {
|
||||
uint64_t v = 0;
|
||||
return direct_read(a, &v, 8) ? v : 0;
|
||||
}
|
||||
|
||||
static void floor_probe(void) {
|
||||
if (floor_probe_left < 0) {
|
||||
const char *e = cfg_get("NX2NAVI_FLOOR_PROBE");
|
||||
int n = e && *e ? atoi(e) : 0;
|
||||
floor_probe_left = !RT_V111 || n <= 0 ? 0 : n == 1 ? 4000 : n;
|
||||
if (floor_probe_left) rt_log("floor probe: on for %d lines", floor_probe_left);
|
||||
}
|
||||
if (!floor_probe_left) return;
|
||||
uint64_t g = direct_ptr(MOD_MAIN_BASE + 0x4c7df00), p = direct_ptr(g), q = p ? direct_ptr(p + 0xc0) : 0,
|
||||
mgr = q ? direct_ptr(q + 0x130) : 0;
|
||||
uint32_t count = 0;
|
||||
uint64_t array = 0;
|
||||
if (!mgr || !direct_read(mgr + 0x28, &count, 4) || !(array = direct_ptr(mgr + 0x30))) return;
|
||||
if (count > FLOOR_PROBE_GROUPS) count = FLOOR_PROBE_GROUPS;
|
||||
if (!floor_last) floor_last = calloc(FLOOR_PROBE_GROUPS * 3, sizeof(float));
|
||||
float link[3];
|
||||
int link_ok = player_pos(link);
|
||||
int best = -1;
|
||||
float best_d2 = FLOOR_PROBE_RADIUS * FLOOR_PROBE_RADIUS, best_t[3] = {0}, best_m[3] = {0};
|
||||
for (uint32_t i = 0; i < count && floor_last; i++) {
|
||||
uint64_t grp = direct_ptr(array + 32ull * i);
|
||||
float t[3], *last = floor_last + 3 * i;
|
||||
if (!grp || !direct_read(grp + 0x88 + 12, &t[0], 4) || !direct_read(grp + 0x98 + 12, &t[1], 4) ||
|
||||
!direct_read(grp + 0xa8 + 12, &t[2], 4) || !isfinite(t[0]) || !isfinite(t[1]) || !isfinite(t[2]))
|
||||
continue;
|
||||
float m[3] = {t[0] - last[0], t[1] - last[1], t[2] - last[2]};
|
||||
int moved = i < floor_last_n && (m[0] != 0 || m[1] != 0 || m[2] != 0);
|
||||
memcpy(last, t, sizeof t);
|
||||
if (!moved || !link_ok) continue;
|
||||
float d2 = (t[0] - link[0]) * (t[0] - link[0]) + (t[2] - link[2]) * (t[2] - link[2]);
|
||||
if (d2 < best_d2) best = (int)i, best_d2 = d2, memcpy(best_t, t, sizeof t), memcpy(best_m, m, sizeof m);
|
||||
}
|
||||
floor_last_n = count;
|
||||
if (link_ok && floor_link_ok && best >= 0) {
|
||||
rt_log("floor probe: step %.4f frames; link %.4f %.4f %.4f moved %.5f %.5f %.5f; "
|
||||
"group %d of %u at %.4f %.4f %.4f moved %.5f %.5f %.5f", (double)frame_step_frames(), link[0], link[1],
|
||||
link[2], link[0] - floor_link[0], link[1] - floor_link[1], link[2] - floor_link[2], best, count,
|
||||
best_t[0], best_t[1], best_t[2], best_m[0], best_m[1], best_m[2]);
|
||||
floor_probe_left--;
|
||||
}
|
||||
if (link_ok) memcpy(floor_link, link, sizeof link);
|
||||
floor_link_ok = link_ok;
|
||||
}
|
||||
|
||||
void frame_step_present(uint64_t display_ns, int interval) {
|
||||
atomic_fetch_add_explicit(&guest_presents, 1, memory_order_relaxed);
|
||||
game_interval = interval > 0 ? interval : 1;
|
||||
@@ -782,6 +855,7 @@ void frame_step_present(uint64_t display_ns, int interval) {
|
||||
atomic_store_explicit(&game_us, atomic_load_explicit(&game_us, memory_order_relaxed) + (uint64_t)(game * 1e6 + 0.5),
|
||||
memory_order_relaxed);
|
||||
world_clock(dt, step);
|
||||
floor_probe();
|
||||
if (rt_trace & RT_TRACE_PERF) {
|
||||
time_dump();
|
||||
if (frame_free_running()) { // the game's own step, as its time manager holds it
|
||||
|
||||
Reference in New Issue
Block a user