Give game 1.1.1 the direct mouse camera: two sites in the camera's input update take the raw mouse counts after the stick's dead zone and curve, and the Controls tab shows the mouse rows again.

The counts are divided by the frames the game steps and by the camera speed, as the game multiplies the processed stick by both, so a count turns the camera 0.08 degrees on both axes at every frame rate and stick camera speed. The 1.4.3 selectors stay off on 1.1.1. NX2NAVI_MOUSE_TRACE=1 logs the camera input updates and the camera's direction for measurements, and tests/mouse_direct_check.py checks the 1.1.1 hooks.
This commit is contained in:
Gaetarra
2026-11-10 20:47:58 +01:00
parent a7b8810d37
commit ef0b2b49a3
14 changed files with 260 additions and 19 deletions

View File

@@ -48,7 +48,7 @@ static const char *const known[] = {
"HDR_LIVE",
"HDR_PEAK_NITS", "HDR_SATURATION", "HDR_SHADOWS", "HDR_TONEMAP", "HDR_UI_NITS", "HIGHFPS_FIX", "INPUT", "INPUT_RECORD", "INPUT_SCRIPT", "LANG", "LIB_PREBUILD",
"BIG_BUILD_FREE_MB", "BIG_BUILD_MAX_MB", "LIB_PREBUILD_BIG", "LIB_PREBUILD_BIG_BG", "LIB_PREBUILD_KEEP", "LIB_PREBUILD_THREADS", "LIB_WARM", "PIPE_LINK_MS", "FRAME_HOLD_MS", "PACE_SMOOTH", "OQ_BATCH", "GATE_WAIT_MS", "LOCALE", "LOD_GUARD", "LSTICK_DEADZONE", "MEMORY", "MEM_CENSUS", "MENU_LANG", "MENU_SOUND_VOLUME", "MENU_TEST",
"MENU_CURSOR", "MENU_CURSOR_LOG", "MENU_TEST_CLICK", "MENU_TEST_DIR", "MENU_TEST_SET", "MINIMAL_LAYOUT", "MICROPHONE", "MIRROR_GAP", "MODS_DIR", "MODS_DISABLED", "MODS_ORDER", "MODS_REBUILD", "MONITOR", "MOTION", "MOUSE_MODE", "MOUSE_DIRECT_PATCH", "MOUSE_SENS", "MOVIE_HOST", "MOVIE_PACE",
"MENU_CURSOR", "MENU_CURSOR_LOG", "MENU_TEST_CLICK", "MENU_TEST_DIR", "MENU_TEST_SET", "MINIMAL_LAYOUT", "MICROPHONE", "MIRROR_GAP", "MODS_DIR", "MODS_DISABLED", "MODS_ORDER", "MODS_REBUILD", "MONITOR", "MOTION", "MOUSE_MODE", "MOUSE_DIRECT_PATCH", "MOUSE_SENS", "MOUSE_TRACE", "MOVIE_HOST", "MOVIE_PACE",
"MVOBJ_ALL", "MVOBJ_BANKS", "MVOBJ_EQUAL", "MVOBJ_EXACT", "MVOBJ_EXEC", "MVOBJ_NOC4", "MVOBJ_ONLY", "MVOBJ_TIMES", "MVPREV_CHECK", "MVPREV_GROW", "MVPREV_SKIP", "MVPREV_TRUST", "MV_CHECK",
"MV_SURVEY",
"ONE_PER_CORE", "OPERATION_MODE", "OUTPUT_RES", "PAD_LAYOUT", "PACE_HZ", "PASS_CRUMBS", "PATCH_OUTPUT", "PATCH_RES_FIXED", "PATCH_SCENE", "PATCH_WIDE_ASPECT", "PATCH_WIDE_HUD", "PATCH_WIDE_MOVIE", "PATCH_WIDE_OUT", "PATCH_WIDE_SCENE", "PCSS", "PCSS_K", "PERF_OVERLAY", "PERF_SLOW_MS", "PIPELINE_CACHE", "PIPELINE_CACHE_MAX_MB", "PIPE_BINARIES", "PIPE_BINARIES_MAX_MB", "PIPE_FEEDBACK", "PIPE_MEMO", "PIPE_PREBUILD", "PIPE_SKIP", "PIPE_SYNC", "PIPE_WAIT", "POWER_FULL", "TEX_SAME", "PRESENT_HELD", "HELD_SYNC",

View File

@@ -438,6 +438,16 @@ static double ocarina_step(double dt) {
return step;
}
// The 60 Hz frames the game steps at each update where the set ostep gives them (Ocarina); 1 elsewhere, the game's own
// nominal frame. The mouse camera divides by it (mouse_direct.c): the game multiplies camera input by this step.
float frame_step_frames(void) {
if (!ostep_page) return 1.0f;
uint32_t bits = atomic_load_explicit(ostep_page, memory_order_acquire);
float f;
memcpy(&f, &bits, 4);
return f > 0 ? f : 1.0f;
}
static void ocarina_step_write(double dt) {
static int on = -1;
if (on < 0) {

View File

@@ -338,6 +338,7 @@ int frame_free_running(void); // no fps60/realtime p
double frame_step_limit_hz(void); // the frame rate the limit gives (overlay); 0 unknown
double frame_step_game_hz(void); // ... over frame generation's factor: the game's rate
int frame_limit_follows_display(void); // no limit set and frame generation in use: the display's rate
float frame_step_frames(void); // the 60 Hz frames the game steps per update (set ostep), else 1
// rtss_limit.c: RivaTuner Statistics Server takes the frame limit where it runs
void rtss_limit_want(int64_t mhz); // the pacer's limit in millihertz: >0, 0 none, -1 keep RTSS out
int rtss_limit_active(void); // RTSS limits to the wanted rate: the pacer holds no frames

View File

@@ -924,8 +924,12 @@ static void poll_merged(uint64_t *buttons, int32_t *lx, int32_t *ly, int32_t *rx
input_map_stick(down, 1, k);
if (walk) k[0] = (int32_t)(k[0] * walk_scale), k[1] = (int32_t)(k[1] * walk_scale);
pick(&sr[0], &sr[1], k[0], k[1]);
int selector = b & (1ull << B_L) ? 1 : b & (1ull << B_UP) ? 2 :
b & (1ull << B_LEFT) ? 3 : b & (1ull << B_RIGHT) ? 4 : 0;
// The buttons whose selector the right stick picks from. None in Ocarina (1.1.1): its D-pad acts at once
// (ocarina, accessory, Navi, boots), and with L or R held the camera input update goes on taking the
// mouse; where an update stops taking it, the mouse is the right stick again (mouse_camera).
int selector = rt_game_version == 111 ? 0
: b & (1ull << B_L) ? 1 : b & (1ull << B_UP) ? 2 :
b & (1ull << B_LEFT) ? 3 : b & (1ull << B_RIGHT) ? 4 : 0;
mouse_camera(k, selector);
pick(&sr[0], &sr[1], k[0], k[1]);
int32_t shake = shake_stick(input_map_held(down, B_SHAKE));

View File

@@ -14,6 +14,14 @@ int input_kbm_last(void);
// separately: a persistent radial cursor for the ability wheel, discrete steps for horizontal quick lists.
int input_direct_mouse_active(void);
int input_direct_mouse_enabled(void);
int input_direct_mouse_available(void); // the game version has the patch set and it is on: the mode can be chosen
// Ocarina 1.1.1's camera input update (mouse_direct.c camera_input_oot; recomp/patches-v111.txt). Measured with a
// scripted stick, its processed stick at one turns the camera 1 degree up or down and 1.78 degrees sideways
// (StickSensitivityLat2LngRatio) per 60 Hz frame; the game's own camera sensitivity option scales both.
// INPUT_OOT_COUNT_X and _Y, what one mouse count adds to the processed stick per frame at sensitivity 1, make a count
// 0.08 degrees on either axis.
#define INPUT_OOT_COUNT_X (0.08 / 1.78)
#define INPUT_OOT_COUNT_Y 0.08
// A radial selector uses a persistent virtual cursor while its opening button is held.
void input_direct_mouse_radial(int32_t dx, int32_t dy, float sensitivity, float cursor[2], int32_t out[2]);
// Horizontal quick selectors receive short, separated steps instead of a latched radial-cursor direction.

View File

@@ -44,6 +44,8 @@ int input_direct_mouse_active(void) {
int input_direct_mouse_enabled(void) { return direct_mode(); }
int input_direct_mouse_available(void) { return rt_patch_enabled(rt_patch_set("mouse_direct")); }
void input_direct_mouse_radial(int32_t dx, int32_t dy, float sensitivity, float cursor[2], int32_t out[2]) {
if (!(sensitivity > 0)) { cursor[0] = cursor[1] = 0; out[0] = out[1] = 0; return; }
cursor[0] += dx * (double)sensitivity / 200;
@@ -330,7 +332,90 @@ static void camera_activity(Cpu *c) {
c->v[8] = d8;
}
// ---- Ocarina 1.1.1 (recomp/patches-v111.txt, set mouse_direct)
// Its camera input update is main+0x37c300: the same steps as above with other registers and offsets. At the site s1
// and s0 hold the processed x and y (both zero while the camera-reset timer at +0x5e0 runs), x20 the input object and
// x21 the flags (bit 0 camera input off, bit 1 invert x, bit 2 invert y). The two stores, the inversion and the idle
// test that follow read s1 and s0, so the counts added here go through them as the stick's part does.
#define OOT_STICK 0x538 // the processed stick: x, and y at +0x53c
#define OOT_RESET_TIMER 0x5e0 // 60 Hz frames left of the pause after a camera reset (right stick click)
#define OOT_FLAG_IDLE 0x10u // flags (+0x530): the processed stick is under the game's 10% idle threshold
// NX2NAVI_MOUSE_TRACE=1 (test runs): one line per camera input update, with the stick the update made, the counts taken
// and what they added. vk_dlaa.c adds the camera's direction per frame, so a scripted run gives degrees per count.
static int mouse_trace(void) {
static int on = -1;
if (on < 0) {
const char *e = cfg_get("NX2NAVI_MOUSE_TRACE");
on = e && *e && strcmp(e, "0");
}
return on;
}
static void camera_input_oot(Cpu *c) {
mouse_input_object = 0;
uint64_t object = c->x[20], now = plat_now_ns();
uint32_t flags = (uint32_t)c->x[21];
float timer = guest_float(object + OOT_RESET_TIMER);
int accept = !(flags & 1) && !(timer > 0) && !input_direct_mouse_selector_active();
__atomic_store_n(&accepts_mouse, accept, __ATOMIC_RELAXED);
__atomic_store_n(&last_update, now, __ATOMIC_RELEASE);
float x, y, add[2] = {0, 0}, frames = frame_step_frames();
memcpy(&x, &c->v[1], sizeof x);
memcpy(&y, &c->v[0], sizeof y);
int32_t dx = 0, dy = 0;
if (direct_mode()) {
input_direct_mouse_sample(accept, &dx, &dy);
float sensitivity = fminf(10, fmaxf(0, (float)cfg_double("NX2NAVI_MOUSE_SENS")));
// The game multiplies the processed stick by the frames it steps and by its camera speeds, which
// NX2NAVI_STICK_SENS scales (camera_speed.c): divided by both, a count turns the camera by the same angle at
// every frame rate and stick speed. Nothing after the site clamps the sum, so a fast flick is not cut short.
float per = frames * cam_speed_applied();
if (accept && sensitivity > 0 && isfinite(per) && per > 0 && (dx || dy)) {
mouse_input_object = object;
add[0] = dx * (float)INPUT_OOT_COUNT_X * sensitivity / per;
add[1] = -dy * (float)INPUT_OOT_COUNT_Y * sensitivity / per;
float nx = x + add[0], ny = y + add[1];
uint32_t xb, yb;
memcpy(&xb, &nx, sizeof xb);
memcpy(&yb, &ny, sizeof yb);
c->v[1] = xb;
c->v[0] = yb;
static int logged;
if (!logged) {
logged = 1;
rt_log("mouse: direct camera input after the stick dead zone, clamp and exponent (Ocarina 1.1.1)");
}
}
}
if (mouse_trace())
rt_log("mousetrace: in t=%.3f frames=%.4f flags=%x accept=%d timer=%.2f stick=%.5f,%.5f counts=%d,%d add=%.5f,%.5f",
now / 1e6, frames, flags, accept, timer, x, y, dx, dy, add[0], add[1]);
uint32_t original = (uint32_t)c->v[1];
memcpy((void *)(uintptr_t)(object + OOT_STICK), &original, sizeof original); // displaced str s1, [x20, #0x538]
}
// The idle test follows the first site and already counts the mouse's part, but one slow count adds less than the
// game's 10% threshold: an update the mouse moved in is not idle. The site is the displaced ldp d9, d8, [sp, #0x10]
// before the update's last `str w8, [x20, #0x530]`, with the flags in w8.
static void camera_activity_oot(Cpu *c) {
if (mouse_input_object && mouse_input_object == c->x[20]) {
c->x[8] = (uint32_t)c->x[8] & ~OOT_FLAG_IDLE;
mouse_input_object = 0;
}
uint64_t d9, d8;
memcpy(&d9, (const void *)(uintptr_t)(c->sp + 0x10), sizeof d9);
memcpy(&d8, (const void *)(uintptr_t)(c->sp + 0x18), sizeof d8);
c->v[9] = d9;
c->v[8] = d8;
}
__attribute__((constructor)) static void mouse_direct_register(void) {
if (rt_game_version == 111) { // Ocarina: two sites of its own, no orbit or held-object site
rt_register_host(HOST_MOUSE_DIRECT, camera_input_oot);
rt_register_host(HOST_MOUSE_ACTIVITY, camera_activity_oot);
return;
}
rt_register_host(HOST_MOUSE_DIRECT, camera_input);
rt_register_host(HOST_MOUSE_ACTIVITY, camera_activity);
rt_register_host(HOST_MOUSE_ORBIT_BEGIN, orbit_begin);

View File

@@ -1347,6 +1347,15 @@ static void restart_confirm(float scale) {
static void tab_controls(float scale) {
opt_begin("##controls", scale);
// The mouse camera first, where a player on keyboard and mouse looks for it; both rows are live. How the mouse
// reaches the game, where the game version has the direct mode's patch set (mouse_direct.c; the values in their
// cfg.c order, stick then direct), and its sensitivity. The slider stops short of 0, which nx2navi.ini takes to
// switch the mouse camera and the cursor capture off.
if (input_direct_mouse_available()) {
static const UiTextId mouse_mode[] = {UI_MENU_MOUSE_STICK, UI_MENU_MOUSE_DIRECT};
opt_choice("NX2NAVI_MOUSE_MODE", UI_MENU_MOUSE_MODE, mouse_mode, 2, UI_MENU_MOUSE_MODE_DESC);
}
opt_slider("NX2NAVI_MOUSE_SENS", UI_MENU_MOUSE_SENS, 0.05f, 10, UI_MENU_MOUSE_SENS_DESC, 0.05f, "%.2f");
static const UiTextId layout[] = {UI_MENU_PAD_LAYOUT_AUTO, UI_MENU_PAD_LAYOUT_NINTENDO, UI_MENU_PAD_LAYOUT_XBOX,
UI_MENU_PAD_LAYOUT_PLAYSTATION};
opt_choice("NX2NAVI_PAD_LAYOUT", UI_MENU_PAD_LAYOUT, layout, 4, UI_MENU_PAD_LAYOUT_DESC, pad_layout_note());

View File

@@ -289,7 +289,7 @@ static const char *const text_en[UI_TEXT_COUNT] = {
[UI_MENU_STICK_DEADZONE_DESC] = "How far a stick must move to register. Raise it if a stick drifts.",
[UI_MENU_STICK_DEADZONE_NOW] = "stick now: %.0f %%",
[UI_MENU_MOUSE_MODE] = "Mouse camera",
[UI_MENU_MOUSE_MODE_DESC] = "Direct: the camera turns by how far the mouse moves, as in a PC game, with no stick dead zone or curve (game 1.4.3; other versions use stick emulation). Stick emulation: the mouse acts as the right stick.",
[UI_MENU_MOUSE_MODE_DESC] = "Direct: the camera turns by how far the mouse moves, as in a PC game, with no stick dead zone or curve (games 1.1.1 and 1.4.3; other versions use stick emulation). Stick emulation: the mouse acts as the right stick.",
[UI_MENU_MOUSE_STICK] = "Stick emulation",
[UI_MENU_MOUSE_DIRECT] = "Direct",
[UI_MENU_MENU_CURSOR] = "Mouse in the game's menus",
@@ -849,7 +849,7 @@ static const char *const text_ru[UI_TEXT_COUNT] = {
[UI_MENU_STICK_DEADZONE_DESC] = "Насколько нужно сдвинуть стик, чтобы он сработал. Увеличьте при дрейфе.",
[UI_MENU_STICK_DEADZONE_NOW] = "стик сейчас: %.0f %%",
[UI_MENU_MOUSE_MODE] = "Управление мышью",
[UI_MENU_MOUSE_MODE_DESC] = "Прямое: камера поворачивается на столько, на сколько сдвинута мышь, как в играх для ПК, без мёртвой зоны и кривой стика (версия игры 1.4.3; на других версиях эмуляция стика). Эмуляция стика: мышь работает как правый стик.",
[UI_MENU_MOUSE_MODE_DESC] = "Прямое: камера поворачивается на столько, на сколько сдвинута мышь, как в играх для ПК, без мёртвой зоны и кривой стика (версии игры 1.1.1 и 1.4.3; на других версиях эмуляция стика). Эмуляция стика: мышь работает как правый стик.",
[UI_MENU_MOUSE_STICK] = "Эмуляция стика",
[UI_MENU_MOUSE_DIRECT] = "Прямое",
[UI_MENU_MENU_CURSOR] = "Мышь в меню игры",
@@ -1511,7 +1511,7 @@ static const char *const text_pt_br[UI_TEXT_COUNT] = {
[UI_MENU_PROMPTS_PLAYSTATION] = "PlayStation",
[UI_MENU_PROMPTS_PC] = "Teclado e mouse",
[UI_MENU_MOUSE_MODE] = "Câmera com o mouse",
[UI_MENU_MOUSE_MODE_DESC] = "Direta: a câmera gira o quanto o mouse se move, como num jogo de PC, sem zona morta nem curva do analógico (jogo 1.4.3; as outras versões usam a emulação do analógico). Emulação do analógico: o mouse age como o analógico direito.",
[UI_MENU_MOUSE_MODE_DESC] = "Direta: a câmera gira o quanto o mouse se move, como num jogo de PC, sem zona morta nem curva do analógico (jogos 1.1.1 e 1.4.3; as outras versões usam a emulação do analógico). Emulação do analógico: o mouse age como o analógico direito.",
[UI_MENU_MOUSE_STICK] = "Emulação do analógico",
[UI_MENU_MOUSE_DIRECT] = "Direta",
[UI_MENU_MENU_CURSOR] = "Mouse nos menus do jogo",
@@ -2171,7 +2171,7 @@ static const char *const text_zh_hans[UI_TEXT_COUNT] = {
[UI_MENU_PROMPTS_PLAYSTATION] = "PlayStation",
[UI_MENU_PROMPTS_PC] = "键盘和鼠标",
[UI_MENU_MOUSE_MODE] = "鼠标视角",
[UI_MENU_MOUSE_MODE_DESC] = "直接:镜头按鼠标移动的距离转动,与电脑游戏相同,没有摇杆死区和响应曲线(游戏 1.4.3;其他版本使用摇杆模拟)。摇杆模拟:鼠标相当于右摇杆。",
[UI_MENU_MOUSE_MODE_DESC] = "直接:镜头按鼠标移动的距离转动,与电脑游戏相同,没有摇杆死区和响应曲线(游戏 1.1.1 和 1.4.3;其他版本使用摇杆模拟)。摇杆模拟:鼠标相当于右摇杆。",
[UI_MENU_MOUSE_STICK] = "摇杆模拟",
[UI_MENU_MOUSE_DIRECT] = "直接",
[UI_MENU_MENU_CURSOR] = "在游戏菜单中使用鼠标",

View File

@@ -936,6 +936,15 @@ static void fg_camera(const float *v, const double m[16]) {
c->fov_y = P[5] != 0 ? 2.0f * (float)atan(1.0 / fabs(P[5])) : 1.0f;
c->aspect = P[0] != 0 ? (float)fabs(P[5] / P[0]) : 1.777f;
D.fg_cam_ok = 1;
// NX2NAVI_MOUSE_TRACE=1 (test runs, mouse_direct.c): the camera's direction each frame
static int trace = -1;
if (trace < 0) {
const char *e = cfg_get("NX2NAVI_MOUSE_TRACE");
trace = e && *e && strcmp(e, "0");
}
if (trace)
rt_log("mousetrace: cam t=%.3f fwd=%.6f,%.6f,%.6f pos=%.3f,%.3f,%.3f", plat_now_ns() / 1e6, c->fwd[0], c->fwd[1],
c->fwd[2], c->pos[0], c->pos[1], c->pos[2]);
}
// Frames without a camera (dlaa_cam_keep, NX2NAVI_DLAA_CAM_KEEP; 1 by default, 0 restores the old handling). Measured in