mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-17 07:09:57 -04:00
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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user