Merge pull request #1301: the mouse turns Autobuild's placement camera and other cameras without a direct hook as the right stick (itaskaev2, #1300)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Valiantsin DzerakhandClaude Opus 5.5 committed 2026-11-19 20:53:20 +03:00
commit 06ebf18f5d
4 files changed
+105 -36

No files matched your search

+22 -1
View File
@@ -364,6 +364,14 @@ static void walk_get(void) {
static int mouse_selector;
int input_direct_mouse_selector_active(void) { return __atomic_load_n(&mouse_selector, __ATOMIC_RELAXED) != 0; }
// A script's MOUSE line within the last 100 ms (under `lock`): mouse_camera then makes a stick of it
static uint64_t script_mouse_at;
static int input_script_mouse_recent(void) {
uint64_t now = plat_now_ns();
if (script_mouse[0] || script_mouse[1]) script_mouse_at = now;
return script_mouse_at && now - script_mouse_at < 100000000ull;
}
// Selector 1 is a radial wheel, 2..4 are distinct horizontal quick lists; only a wheel retains a virtual cursor.
// Under `lock`.
static void mouse_camera(int32_t out[2], int selector) {
@@ -396,7 +404,10 @@ static void mouse_camera(int32_t out[2], int selector) {
frame = ~0ull;
return; // the camera update takes the raw counts itself, once, outside the HID stick path
}
if (!ikb_captured()) {
// A script's MOUSE lines move the stick as the mouse does, captured or not (in direct mode the camera hook takes
// them, input_direct_mouse_sample): for 100 ms after one the stick is the mouse's, as while captured
int scripted = input_script_mouse_recent();
if (!ikb_captured() && !scripted) {
ikb_mouse_take(&dx, &dy);
held[0] = held[1] = 0;
frame = ~0ull;
@@ -406,6 +417,9 @@ static void mouse_camera(int32_t out[2], int selector) {
if (fr != frame) {
double dt = age < 0.004 ? 0.004 : age > 0.1 ? 0.1 : age;
ikb_mouse_take(&dx, &dy);
if (!ikb_captured()) dx = dy = 0;
dx += script_mouse[0], dy += script_mouse[1];
script_mouse[0] = script_mouse[1] = 0;
input_mouse_stick(dx, dy, dt, mouse_sens_get(), held);
frame = fr;
t0 = now;
@@ -907,6 +921,13 @@ static void poll_merged(uint64_t *buttons, int32_t *lx, int32_t *ly, int32_t *rx
if (pad_used) __atomic_store_n(&g_kbm_last, 0, __ATOMIC_RELAXED);
else if (kbm_used) __atomic_store_n(&g_kbm_last, 1, __ATOMIC_RELAXED);
}
// Without the keyboard and mouse poll above (TOTK_INPUT=none in scripted runs, or the window in the background), a
// script's MOUSE lines still move the right stick wherever the mouse would (mouse_camera)
if (!(state > 0 && ikb_foreground()) && input_script_mouse_recent() && !input_direct_mouse_active()) {
int32_t k[2];
mouse_camera(k, 0);
pick(&sr[0], &sr[1], k[0], k[1]);
}
script_apply(&b, sl, sr);
wheel_route(&b, sl, sr);
gameplay_tweaks_apply(__atomic_load_n(&gfx_counters.frames, __ATOMIC_RELAXED), input_gameplay_active(), &b, &sl[0], &sl[1], &sr[0], &sr[1]);
+32 -2
View File
@@ -7,6 +7,7 @@
// raw-count angular deltas at its spherical-angle output instead. The aiming, scope, ability, horse and Purah Pad
// cameras do the same at the angle each integrates from (camera_load). Ultrahand has a separate post-curve hook.
// The other camera modes still take the mouse as stick, linear on both axes (mouse_stick_add).
// A camera that runs none of these hooks gets the mouse as the right stick instead, through input.c (camera_unhooked).
// The ordinary stick's result stays, so a controller still uses the game's own response.
//
// This is deliberately not a render-camera override: the game remains responsible for aiming, camera collision,
@@ -64,10 +65,20 @@ static int hand_active(uint64_t now) {
return last && now - last < 150000000ull;
}
// Cameras no direct hook reaches. The hooks below (the free orbit's orbit_begin, every camera_load site, Ultrahand's
// hand_input) mark each camera step they run in (step_hooked). A camera that runs none of them, such as Autobuild's
// placement camera on games 1.4.3 and 1.2.1, reads its turn from input the hooks never see. After UNHOOKED_STEPS such
// steps in a row the mouse leaves the direct path and acts as the right stick (input.c mouse_camera), as with
// mouse_mode = stick, until a step runs a hook again.
#define UNHOOKED_STEPS 2
static volatile int32_t step_hooked, unhooked_steps;
static void step_mark_hooked(void) { __atomic_store_n(&step_hooked, 1, __ATOMIC_RELAXED); }
static int camera_unhooked(void) { return __atomic_load_n(&unhooked_steps, __ATOMIC_RELAXED) >= UNHOOKED_STEPS; }
int input_direct_mouse_active(void) {
uint64_t last = __atomic_load_n(&last_update, __ATOMIC_ACQUIRE);
return direct_mode() && (__atomic_load_n(&accepts_mouse, __ATOMIC_RELAXED) || hand_active(plat_now_ns())) && last &&
plat_now_ns() - last < 150000000ull;
plat_now_ns() - last < 150000000ull && !camera_unhooked();
}
int input_direct_mouse_enabled(void) { return direct_mode(); }
@@ -373,7 +384,19 @@ static void camera_input(Cpu *c) {
memcpy(&next.pad[1], &c->v[10], sizeof(float));
if (flags & 2) next.pad[0] = -next.pad[0];
if (flags & 4) next.pad[1] = -next.pad[1];
if (direct_mode()) {
// The step before this one ran no direct hook: count it (camera_unhooked)
int hooked = __atomic_exchange_n(&step_hooked, 0, __ATOMIC_RELAXED);
int unhooked = hooked ? 0 : __atomic_load_n(&unhooked_steps, __ATOMIC_RELAXED) + (camera_unhooked() ? 0 : 1);
if (direct_mode() && (unhooked >= UNHOOKED_STEPS) != camera_unhooked()) {
static int lines;
if (lines < 6) {
lines++;
rt_log(unhooked >= UNHOOKED_STEPS ? "mouse: the camera runs no direct hook; the mouse acts as the right stick"
: "mouse: the camera runs a direct hook again; the mouse turns it directly");
}
}
__atomic_store_n(&unhooked_steps, unhooked, __ATOMIC_RELAXED);
if (direct_mode() && !camera_unhooked()) {
int32_t dx, dy;
input_direct_mouse_sample(!input_direct_mouse_selector_active() && (accept || hand_active(plat_now_ns())), &dx, &dy);
float sensitivity = (float)cfg_double("TOTK_MOUSE_SENS");
@@ -432,6 +455,10 @@ static void camera_input(Cpu *c) {
rt_log("mouse: direct camera input after the stick dead zone, clamp and exponent");
}
}
} else {
// Off the direct path (another mouse_mode, or a camera without a direct hook) no step follows a shake: a side
// left set would hold input.c's right stick at full tilt
__atomic_store_n(&shake_side, 0, __ATOMIC_RELAXED);
}
plat_mutex_lock(&sample_lock);
MouseSample last = sample;
@@ -463,6 +490,7 @@ static void orbit_begin(Cpu *c) {
__atomic_store_n(&cam_kind_at, plat_now_ns(), __ATOMIC_RELEASE);
orbit.object = 0;
uint64_t object = c->x[0];
step_mark_hooked();
if (direct_mode()) {
MouseSample m = sample_read();
uint64_t input = guest_pointer(object + 0x20);
@@ -587,6 +615,7 @@ static void orbit_angles(Cpu *c) {
static void hand_input(Cpu *c) {
const MouseLayout *ml = mouse_layout();
__atomic_store_n(&hand_update, plat_now_ns(), __ATOMIC_RELEASE);
step_mark_hooked();
static _Thread_local uint64_t object, generation;
if (direct_mode()) {
MouseSample m = sample_read();
@@ -1039,6 +1068,7 @@ static void camera_load(Cpu *c) {
rt_log("mouse: load hook called from main+%#llx, no such site", (unsigned long long)offset);
abort();
}
step_mark_hooked();
int mapped = INPUT_CAM_UNCLASSIFIED;
switch (s->mode) {
case MODE_AIM: