Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
736ed3f
feat(timer): opt in high-resolution 16ms smoothing only for A/B
quasistatic-setup Oct 27, 2026
e1e603e
feat(timer): opt in high-resolution 16ms smoothing only for A/B
quasistatic-setup Oct 27, 2026
2946375
feat(timer): opt in high-resolution 16ms smoothing only for A/B
quasistatic-setup Oct 27, 2026
3f54c97
perf(timer): opt-in high resolution waitable clock, coalesced ticks a…
quasistatic-setup Oct 27, 2026
97d5727
docs(timer): explain opt-in highres smoothing test and safety fallback
quasistatic-setup Oct 27, 2026
92eb8f0
docs(timer): explain opt-in highres smoothing test and safety fallback
quasistatic-setup Oct 27, 2026
6f0360d
docs(timer): explain opt-in highres smoothing test and safety fallback
quasistatic-setup Oct 27, 2026
1a6fdcb
fix(anchor): exclude OWN cursor destinations in high-res timer branch
quasistatic-setup Oct 27, 2026
dc0e64f
fix(anchor): exclude OWN cursor destinations in high-res timer branch
quasistatic-setup Oct 27, 2026
ade5443
fix(anchor): carry OWN quarantine and safe hold-release behavior into…
quasistatic-setup Oct 27, 2026
af629c4
docs(anchor): include synthetic-event guard in combined fix
quasistatic-setup Oct 27, 2026
70d2869
merge: integrate hardened anchor relearning into high-resolution time…
quasistatic-setup Oct 27, 2026
d3fea43
ci: upgrade checkout and artifact upload to Node.js 24 actions
quasistatic-setup Oct 27, 2026
a5cb6d0
feat(playing): enable measured 16ms smoothing and document WM_TIMER f…
quasistatic-setup Oct 27, 2026
897a91e
feat(playing): enable measured 16ms smoothing and document WM_TIMER f…
quasistatic-setup Oct 27, 2026
4298c29
feat(playing): enable measured 16ms smoothing and document WM_TIMER f…
quasistatic-setup Oct 27, 2026
ee01aa2
feat(playing): enable measured 16ms smoothing and document WM_TIMER f…
quasistatic-setup Oct 27, 2026
32f857c
feat(playing): enable measured 16ms smoothing and document WM_TIMER f…
quasistatic-setup Oct 27, 2026
3cfabd9
feat(safety): add warp evidence and regressions to timer branch
quasistatic-setup Oct 27, 2026
0ff0089
feat(safety): add warp evidence and regressions to timer branch
quasistatic-setup Oct 27, 2026
8f059e3
fix(hook): bring warp-verification gate into high-res timer branch
quasistatic-setup Oct 27, 2026
57cd66e
fix(hook): bring warp-verification gate into high-res timer branch
quasistatic-setup Oct 27, 2026
e4bf9ad
fix(hook): bring warp-verification gate into high-res timer branch
quasistatic-setup Oct 27, 2026
21ac3e8
fix(anchor): fail-open correction unless genuine warp evidence observed
quasistatic-setup Oct 27, 2026
92cb98b
docs(safety): document external warp proof and no-warp regression
quasistatic-setup Oct 27, 2026
92ec716
docs(safety): document external warp proof and no-warp regression
quasistatic-setup Oct 27, 2026
e9fbb88
merge: require proven recenter before high-resolution correction
quasistatic-setup Oct 27, 2026
f16535f
docs: replace obsolete anchor heuristics with verified-recenter recovery
quasistatic-setup Oct 27, 2026
49dfc62
fix(safety): revoke stale warp gate and discard pending movement on f…
quasistatic-setup Oct 27, 2026
5afc0c2
docs: clarify verified warp detection and fail-open timeout
quasistatic-setup Oct 27, 2026
0a9b1d1
docs: clarify verified warp detection and fail-open timeout
quasistatic-setup Oct 27, 2026
b4256a1
docs: clarify verified warp detection and fail-open timeout
quasistatic-setup Oct 27, 2026
c83fc31
merge: synchronize recenter-proof fail-open safety into high-resoluti…
quasistatic-setup Oct 27, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ correction is still experimental.

## [Unreleased]

### Performance

- A/B-only opt-in high-resolution 16 ms waitable timer replaces the low-priority
WM_TIMER smoothing cadence. A worker coalesces notifications; SendInput remains
exclusively on the original message-loop thread. Falls back to WM_TIMER when
unavailable; a runtime timer/post failure stops correction safely.
- After A/B test measurements (~16.2 ms vs ~26.7 ms per tick), normal Playing
now enables the high-resolution timer by default, while remaining switchable
back to WM_TIMER through `high_res_smoothing_timer=false`. Playing runtime
smoke test is required before merging.

### Fixed

- Require repeated, observed game recenter events before intercepting hidden-cursor
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ Keys beginning with `_` in the supplied configuration files are explanatory comm
| `watchdog_max_output_failures` | `5` | consecutive failed output calls before the watchdog trips |
| `log_mouse_moves` | `true` | `false` records buttons, wheel and state only |
| `trace_correction_timing` | `false` | opt-in 250 ms timer/anchor/pending-delta summaries; enabled in A/B profile |
| `high_res_smoothing_timer` | `false` | high-resolution waitable clock for 16 ms smoothing; enabled in both A/B and Playing profiles after successful A/B field tests; optional to disable |
| `log_directory` | `logs` | relative paths resolve beside the EXE |
| `log_file_prefix` | `remotemousefix` | log filename prefix |
| `max_log_bytes` | `8388608` | rotate after this size |
Expand Down
3 changes: 3 additions & 0 deletions config/config-ab-test.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
"_trace_correction_timing": "Log 250 ms timing/anchor-gate summaries while absolute correction is active and the target holds the cursor.",
"trace_correction_timing": true,

"_high_res_smoothing_timer": "Use the high-resolution 16ms waitable timer; fall back to WM_TIMER if unavailable. Also enabled in Playing after successful A/B measurements.",
"high_res_smoothing_timer": true,

"_console_status_interval_ms": "Live counter refresh in the console. 0 disables it.",
"console_status_interval_ms": 2000,

Expand Down
4 changes: 4 additions & 0 deletions config/config-play.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
"anchor_tolerance_px": 3,
"state_poll_interval_ms": 10,
"log_state_changes": true,

"_high_res_smoothing_timer": "Use 16ms high-resolution waitable timer, with WM_TIMER fallback if unsupported. Validated in A/B profile, enabled for Playing trial.",
"high_res_smoothing_timer": true,

"console_status_interval_ms": 2000,
"heartbeat_interval_ms": 10000
}
28 changes: 28 additions & 0 deletions docs/diagnostics.md
Original file line number Diff line number Diff line change
Expand Up @@ -362,3 +362,31 @@ through again (`## STATE warp-evidence revoked`). Runtime verification must incl
window before the next hold, all Probe A/B/C modes, loss of target focus,
the OFF/relative modes and emergency-off.

## High-resolution smoothing A/B experiment (follow-up PR)

The original `SetTimer(..., 16, ...)` often delivered a 27 ms average tick in
the WoW capture. With `high_res_smoothing_timer=true`, the A/B profile instead
uses a high-resolution Windows waitable timer and a dedicated waiter thread
which posts at most one outstanding `WM_APP` timer notification to the main
message loop. The mouse hook and all `SendInput` calls remain on the original
thread. No process-wide timer-resolution changes, DLL injection or game hooks.

A startup line identifies `## SMOOTH TIMER source=high-res-waitable` or
`source=wm-timer`. If Windows cannot create or arm the high-resolution timer,
the tool logs a warning and uses `WM_TIMER`. If an active high-resolution
timer fails or cannot post to the original thread, the application shuts down
without silently leaving suppressed movements uncorrected.

In the same WoW/TeamViewer scenario, compare `## TIMING` tick counts,
`max_timer_gap_ms`, pending age and perceived camera smoothness with
`high_res_smoothing_timer=true` versus `false`. Especially verify
`Ctrl+Alt+C`, focus loss, multiple modes, `own==applied`, no `queue drops`
or watchdog trips. Hardware, scheduling and game frame rate can still impose
limits: a 16 ms requested timer does not guarantee 16 ms output or cure
the input-side 500 ms pauses. The A/B tests of 27 October 2026 showed a
measured interval of about 16.2 ms versus 26.7 ms with WM_TIMER, with subjective
improvement and no failed or missing SendInput echoes. Therefore the Playing
profile also enables this timer by default; disable
`high_res_smoothing_timer` in `config-play.json` to revert to WM_TIMER.
The new Playing default still requires an ordinary-playing smoke test on
Windows/TeamViewer before merging this PR.
1 change: 1 addition & 0 deletions include/rmf/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ struct Config {
unsigned statePollIntervalMs = 10; // cursor visibility / clip / anchor sampling period
bool logStateChanges = true;
bool traceCorrectionTiming = false; // opt-in timing trace for A/B tests
bool highResSmoothingTimer = false; // opt-in; default Windows WM_TIMER clock
unsigned consoleStatusIntervalMs = 2000; // 0 disables the live console status line
unsigned heartbeatIntervalMs = 10000; // periodic liveness line, 0 disables it

Expand Down
3 changes: 3 additions & 0 deletions src/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,9 @@ bool LoadConfig(const std::wstring& path, Config& cfg) {
} else if (key == L"trace_correction_timing") {
if (ParseBool(value, b)) cfg.traceCorrectionTiming = b;
else cfg.warnings.push_back(L"trace_correction_timing is not a boolean: " + value);
} else if (key == L"high_res_smoothing_timer") {
if (ParseBool(value, b)) cfg.highResSmoothingTimer = b;
else cfg.warnings.push_back(L"high_res_smoothing_timer is not a boolean: " + value);
} else if (key == L"console_status_interval_ms") {
if (ParseU64(value, u) && u <= 60000) cfg.consoleStatusIntervalMs = static_cast<unsigned>(u);
else cfg.warnings.push_back(L"console_status_interval_ms must be 0..60000: " + value);
Expand Down
87 changes: 81 additions & 6 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include <cwchar>
#include <memory>
#include <mutex>
#include <system_error>
#include <string>
#include <thread>
#include <vector>
Expand Down Expand Up @@ -75,6 +76,7 @@ constexpr HotkeySpec kHotkeys[] = {

constexpr UINT kMsgQuitRequested = WM_APP + 1;
constexpr UINT kMsgApplyDelta = WM_APP + 2; // posted by the hook: wParam = dx, lParam = dy
constexpr UINT kMsgSmoothTick = WM_APP + 3; // coalesced high-res timer tick, main thread only
constexpr UINT_PTR kSmoothTimer = 1;
constexpr UINT kSmoothIntervalMs = 16;
constexpr long kSmoothMaxStepPx = 20;
Expand Down Expand Up @@ -1075,8 +1077,71 @@ int main() {
}
};

const UINT_PTR smoothTimerId = SetTimer(nullptr, kSmoothTimer, kSmoothIntervalMs, nullptr);
if (smoothTimerId == 0) {
// Windows WM_TIMER is low priority and was measured around 27 ms/tick despite a
// 16 ms requested period. An opt-in high-resolution waitable timer produces at
// most ONE outstanding thread message; the actual cursor output remains here on
// the message-loop/hook thread. Do not change system-wide timer resolution.
HANDLE highResTimer = nullptr;
std::thread highResWorker;
std::atomic<bool> stopHighResWorker {false};
std::atomic<bool> highResTickQueued {false};
std::atomic<bool> highResTimerFailed {false};
if (cfg.highResSmoothingTimer) {
highResTimer = CreateWaitableTimerExW(
nullptr, nullptr, CREATE_WAITABLE_TIMER_HIGH_RESOLUTION,
TIMER_MODIFY_STATE | SYNCHRONIZE);
if (highResTimer) {
LARGE_INTEGER firstDue {};
firstDue.QuadPart = -static_cast<LONGLONG>(kSmoothIntervalMs) * 10000;
if (!SetWaitableTimer(highResTimer, &firstDue,
static_cast<LONG>(kSmoothIntervalMs),
nullptr, nullptr, FALSE)) {
CloseHandle(highResTimer);
highResTimer = nullptr;
}
}
if (highResTimer) {
// Ensure PostThreadMessage always has an existing message queue.
MSG initialQueueMessage {};
PeekMessageW(&initialQueueMessage, nullptr, WM_USER, WM_USER, PM_NOREMOVE);
try {
highResWorker = std::thread([&] {
while (!stopHighResWorker.load(std::memory_order_acquire) &&
g_running.load(std::memory_order_relaxed)) {
const DWORD waited = WaitForSingleObject(highResTimer, 100);
if (stopHighResWorker.load(std::memory_order_acquire)) break;
if (waited == WAIT_TIMEOUT) continue;
if (waited != WAIT_OBJECT_0) {
highResTimerFailed.store(true, std::memory_order_release);
RequestStop(); // fail closed if the timer breaks during a hold
break;
}
if (!highResTickQueued.exchange(true, std::memory_order_acq_rel) &&
!PostThreadMessageW(g_mainThreadId, kMsgSmoothTick, 0, 0)) {
highResTickQueued.store(false, std::memory_order_release);
highResTimerFailed.store(true, std::memory_order_release);
RequestStop();
break;
}
}
});
} catch (const std::system_error&) {
CancelWaitableTimer(highResTimer);
CloseHandle(highResTimer);
highResTimer = nullptr;
}
}
if (!highResTimer) {
LogLine(L"# CONFIG WARNING : high-resolution smoothing timer unavailable; "
L"falling back to WM_TIMER");
}
}
const UINT_PTR smoothTimerId = highResTimer ? 0 :
SetTimer(nullptr, kSmoothTimer, kSmoothIntervalMs, nullptr);
const bool smoothTimerAvailable = highResTimer || smoothTimerId != 0;
LogLine(highResTimer ? L"## SMOOTH TIMER source=high-res-waitable period_ms=16" :
L"## SMOOTH TIMER source=wm-timer period_ms=16");
if (!smoothTimerAvailable) {
LogLine(L"# CONFIG WARNING : smoothing timer unavailable; absolute mode uses immediate output");
}
MSG msg {};
Expand Down Expand Up @@ -1116,7 +1181,7 @@ int main() {
++timing.incoming;
timingLastInputMs = qpcNowMs();
}
if (mode == rmf::CorrectionMode::Absolute && smoothTimerId != 0) {
if (mode == rmf::CorrectionMode::Absolute && smoothTimerAvailable) {
if (cfg.traceCorrectionTiming && smoothPendingX == 0 && smoothPendingY == 0) {
timingPendingSinceMs = qpcNowMs();
}
Expand Down Expand Up @@ -1145,7 +1210,12 @@ int main() {
continue;
}

if (msg.message == WM_TIMER && msg.wParam == smoothTimerId) {
if ((smoothTimerId != 0 && msg.message == WM_TIMER &&
msg.wParam == smoothTimerId) ||
(highResTimer && msg.message == kMsgSmoothTick)) {
if (msg.message == kMsgSmoothTick) {
highResTickQueued.store(false, std::memory_order_release);
}
if (cfg.traceCorrectionTiming) {
const bool active = correction.Mode() == rmf::CorrectionMode::Absolute &&
cursorHeldByTarget.load(std::memory_order_relaxed);
Expand Down Expand Up @@ -1294,8 +1364,13 @@ int main() {
}

// ---- shutdown ------------------------------------------------------------------------
if (smoothTimerId != 0) {
KillTimer(nullptr, smoothTimerId);
if (smoothTimerId != 0) KillTimer(nullptr, smoothTimerId);
stopHighResWorker.store(true, std::memory_order_release);
if (highResTimer) CancelWaitableTimer(highResTimer);
if (highResWorker.joinable()) highResWorker.join();
if (highResTimer) CloseHandle(highResTimer);
if (highResTimerFailed.load(std::memory_order_acquire)) {
LogLine(L"## SMOOTH TIMER FAILED: stopped correction rather than continuing without ticks");
}
g_running.store(false);
correction.ForceOff();
Expand Down