From 3ad253147f54f13a030f986858f953ebe3c32b37 Mon Sep 17 00:00:00 2001 From: SHAURYASANYAL3 Date: Sun, 22 Nov 2026 21:29:03 +0530 Subject: gameinput_test: add assertions for aggregate kind-mismatch and callback E_NOTIMPL guards --- runtime/test/gameinput_test.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'runtime/test/gameinput_test.cpp') diff --git a/runtime/test/gameinput_test.cpp b/runtime/test/gameinput_test.cpp index f525d1cb9..a0a950d9d 100644 --- a/runtime/test/gameinput_test.cpp +++ b/runtime/test/gameinput_test.cpp @@ -608,6 +608,20 @@ void test_aggregate_device(IGameInput* input) { IGameInputReading* r = nullptr; check(input->GetCurrentReading(GameInputKindGamepad, agg, &r) == GAMEINPUT_E_READING_NOT_FOUND && !r, "aggregate device returns READING_NOT_FOUND when no pads are connected"); + check(input->GetCurrentReading(GameInputKindKeyboard, agg, &r) == GAMEINPUT_E_READING_NOT_FOUND && !r, + "aggregate device returns READING_NOT_FOUND for kind mismatch with no pads"); + + // Callback registration guards for aggregate device + GameInputCallbackToken reading_tok = 0xbeef; + check(input->RegisterReadingCallback(agg, GameInputKindGamepad, 0.0f, nullptr, on_reading, &reading_tok) == E_NOTIMPL && + reading_tok == kInvalidCallbackToken, + "RegisterReadingCallback rejects aggregate device with E_NOTIMPL and invalid token"); + + GameInputCallbackToken device_tok = 0xbeef; + check(input->RegisterDeviceCallback(agg, GameInputKindGamepad, GameInputDeviceConnected, + GameInputBlockingEnumeration, nullptr, on_device, &device_tok) == E_NOTIMPL && + device_tok == kInvalidCallbackToken, + "RegisterDeviceCallback rejects aggregate device with E_NOTIMPL and invalid token"); // Attach a virtual pad and verify aggregate device yields readings from it Pad xbox; @@ -624,6 +638,10 @@ void test_aggregate_device(IGameInput* input) { r->Release(); } + IGameInputReading* r_mismatch = nullptr; + check(input->GetCurrentReading(GameInputKindKeyboard, agg, &r_mismatch) == GAMEINPUT_E_READING_NOT_FOUND && !r_mismatch, + "aggregate device rejects kind mismatch even when pad is connected"); + SDL_SetJoystickVirtualButton(xbox.js, SDL_GAMEPAD_BUTTON_SOUTH, false); rt::gameinput::poll(); IGameInputReading* r2 = nullptr; -- cgit v1.2.3 From 3ff74e8d58cb9420e4dae884378b98eb55ce62b2 Mon Sep 17 00:00:00 2001 From: Cozma <65982369+Cozmaaa@users.noreply.github.com> Date: Sun, 22 Nov 2026 18:09:44 +0200 Subject: gameinput: the keyboard pad's right stick reads raw mouse input and keeps the cursor in the window GetCursorPos deltas stop at the screen edge and include pointer acceleration. A message-only window on its own thread now registers for raw mouse input (RIDEV_INPUTSINK) and sums the relative counts; the poll takes the difference of that total. Absolute reports are ignored, and GetCursorPos stays as the fallback if registration fails. With raw input on and a window of this process in the foreground, the cursor is clipped to that window's client area (re-applied every 100 ms), and released on focus loss or when the pad is turned off. LEONIDA_MOUSE_SENSITIVITY (0.1..10, default 1) scales the axis units per count. --- docs/gameinput.md | 26 ++++++++-- runtime/shims/gameinput.cpp | 111 ++++++++++++++++++++++++++++++++++++++-- runtime/shims/gameinput.h | 1 + runtime/test/gameinput_test.cpp | 27 ++++++++++ 4 files changed, 156 insertions(+), 9 deletions(-) (limited to 'runtime/test/gameinput_test.cpp') diff --git a/docs/gameinput.md b/docs/gameinput.md index f848ab0d2..6a98ed5a0 100644 --- a/docs/gameinput.md +++ b/docs/gameinput.md @@ -92,11 +92,23 @@ swapped-buttons setting. WASD pushes the left stick to full deflection. Opposite keys cancel (W+S is centered on Y), and a diagonal sits on the round gate as a real stick reports it: about 0.707 on each axis, not 1. -The right stick follows the cursor's movement (`GetCursorPos`), not its position. Each poll (2 ms with the -background thread) the stick keeps 7/8 of its value and adds 1024 axis units (of 32767) per pixel the cursor moved -since the last poll, clamped to full. Steady movement of 4 pixels a poll (2000 pixels a second) is full deflection; -when the mouse stops, the stick falls back from full to exactly 0 in 67 polls (134 ms). Moving the mouse down pushes -the stick down. The cursor is not captured, so movement stops counting when it reaches the edge of the screen. +The right stick follows the mouse's movement, not the cursor's position. Each poll (2 ms with the background thread) +the stick keeps 7/8 of its value and adds 1024 axis units (of 32767, times `LEONIDA_MOUSE_SENSITIVITY`) per count the mouse moved since the last poll, +clamped to full. Steady movement of 4 counts a poll (2000 a second) is full deflection; when the mouse stops, the +stick falls back from full to exactly 0 in 67 polls (134 ms). Moving the mouse down pushes the stick down. + +The movement comes from raw input (`WM_INPUT`): what the mouse itself reports, so it does not stop at the edge of the +screen and Windows' pointer acceleration does not change it. When the keyboard pad attaches, the shim starts one +thread with a message-only window (never shown) registered for raw mouse input (`RIDEV_INPUTSINK`), which adds each +relative movement to a running total; the poll takes the difference of that total between polls. Absolute reports +(remote desktop, some virtual machines, pen tablets) are ignored. If the window or the registration fails, the shim +logs it and falls back to `GetCursorPos` deltas, which stop at the screen edge. A count is one step of the mouse's +sensor, about a pixel at Windows' default pointer speed without acceleration, so the feel depends on the mouse's DPI. + +With raw input on and a window of this process in the foreground, the cursor is kept inside that window's client +area (`ClipCursor`, re-applied every 100 ms) so that a click cannot land on another window; it is released when focus +moves away or the keyboard pad is turned off. The cursor stays visible: hiding it has to happen on the thread that +owns the game's window, which is the title's, not the shim's. Keys are read with `GetAsyncKeyState`, which needs no window or message loop (SDL's keyboard is part of its video subsystem, which this build leaves out) and works under Wine. With `LEONIDA_KEYBOARD_PAD=1` keys count only while a @@ -170,6 +182,7 @@ sensors are enabled when the pad is opened, at SDL's requested rate, and every p | `LEONIDA_RUMBLE` | `1` | `0` turns all rumble and trigger output off | | `LEONIDA_GAMEINPUT_THREAD` | `1` | `0` stops the background poll thread; only `rt::gameinput::poll()` then reads the pads (tests) | | `LEONIDA_KEYBOARD_PAD` | `off` | `1` adds the [keyboard pad](#keyboard-pad), read while this process has focus; `always` reads keys whatever has focus | +| `LEONIDA_MOUSE_SENSITIVITY` | `1` | scales how far the mouse moves the keyboard pad's right stick, 0.1..10 | SDL's own hints (`SDL_JOYSTICK_*`, see SDL's `SDL_hints.h`) also apply, for example `SDL_JOYSTICK_HIDAPI_PS5=0` to leave a DualSense to the generic driver, or `SDL_GAMECONTROLLERCONFIG` to add a mapping for an unknown pad. @@ -295,6 +308,9 @@ These need the game executable or a test on hardware: - **Identical pads at start**: twins are numbered in the order the shim opens them. For pads already connected when it starts, that is SDL's enumeration order, not measured on Windows for identical pads; if it varies between runs, so does which pad gets which id. +- **Raw mouse registration**: Windows keeps one raw-input target window per device type and process, so if the title + registers raw mouse input itself (a console title is not expected to), it replaces the shim's registration and the + right stick falls back to nothing. The shim does not detect that yet. - **Keyboard pad as a second pad**: it is one more connected gamepad, so with a controller plugged in the title sees two. A title that follows only the first pad it saw, or asks the player to press a button to pick the active pad, may ignore one of them; whether the game does either is unknown. diff --git a/runtime/shims/gameinput.cpp b/runtime/shims/gameinput.cpp index 3b66e2ab9..355ed6d65 100644 --- a/runtime/shims/gameinput.cpp +++ b/runtime/shims/gameinput.cpp @@ -106,6 +106,8 @@ rt::gameinput::Config read_config() { else if (!t.empty() && t != "rumble") std::fprintf(stderr, "[rt] gameinput: LEONIDA_DS_TRIGGERS=%s unknown, using rumble\n", t.c_str()); if (const std::string g = env("LEONIDA_DS_TRIGGER_GAIN"); !g.empty()) c.ds_trigger_gain = std::clamp(static_cast(std::atof(g.c_str())), 0.0f, 4.0f); + if (const std::string g = env("LEONIDA_MOUSE_SENSITIVITY"); !g.empty()) + c.mouse_sensitivity = std::clamp(static_cast(std::atof(g.c_str())), 0.1f, 10.0f); if (const std::string f = env("LEONIDA_DS_TRIGGER_FREQ"); !f.empty()) c.ds_trigger_frequency = static_cast(std::clamp(std::atoi(f.c_str()), 1, 255)); if (const std::string l = env("LEONIDA_DS_LIGHTBAR"); !l.empty()) { @@ -875,8 +877,76 @@ constexpr int kMouseDecayNum = 7, kMouseDecayDen = 8; bool async_key_down(int vk) { return (GetAsyncKeyState(vk) & 0x8000) != 0; } -// shortcut: plain cursor deltas stop at the screen edge; capture or recenter the cursor if that matters in game. +// ---- raw mouse input (its own thread) ---- +// +// The cursor stops at the edge of the screen, so cursor deltas stop too. Raw input reports what the mouse itself +// moved, with no edge and no pointer acceleration. A message-only window (never shown) on its own thread receives +// WM_INPUT and adds each movement to a running total; system_cursor_pos then returns that total as an edgeless +// "cursor", and update_keyboard_pad takes the difference between polls exactly as it did with the real cursor. +std::atomic g_raw_x{0}, g_raw_y{0}; // total raw movement since the thread started, mouse counts +std::atomic g_raw_ready{false}; // registration worked; system_cursor_pos uses the totals +std::atomic g_raw_started{false}; // the thread is started once per process + +LRESULT CALLBACK raw_mouse_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) { + if (msg == WM_INPUT) { + RAWINPUT raw{}; + UINT size = sizeof(raw); + if (GetRawInputData(reinterpret_cast(lp), RID_INPUT, &raw, &size, sizeof(RAWINPUTHEADER)) != + static_cast(-1) && + raw.header.dwType == RIM_TYPEMOUSE && !(raw.data.mouse.usFlags & MOUSE_MOVE_ABSOLUTE)) { + // Relative movement only: absolute reports (remote desktop, some VMs, tablets) are positions, not + // movement, and would make the stick jump. + g_raw_x += raw.data.mouse.lLastX; + g_raw_y += raw.data.mouse.lLastY; // +Y is down, as for the cursor + } + } + return DefWindowProcW(hwnd, msg, wp, lp); // also for WM_INPUT, which lets Windows clean up the input +} + +void raw_mouse_thread() { + const HINSTANCE inst = GetModuleHandleW(nullptr); + WNDCLASSEXW wc{}; + wc.cbSize = sizeof(wc); + wc.lpfnWndProc = raw_mouse_proc; + wc.hInstance = inst; + wc.lpszClassName = L"LeonidaRawMouse"; + RegisterClassExW(&wc); + // HWND_MESSAGE: a window that is never shown and only receives messages. It must be created on the thread that + // runs the message loop below, because a window's messages go to the thread that created it. + HWND hwnd = CreateWindowExW(0, L"LeonidaRawMouse", L"", 0, 0, 0, 0, 0, + HWND_MESSAGE, nullptr, inst, nullptr); + if (!hwnd) { + std::fprintf(stderr, "[rt] gameinput: no raw mouse input (window: error %lu); using the cursor position\n", + GetLastError()); + return; + } + RAWINPUTDEVICE dev{}; + dev.usUsagePage = 0x01; // HID generic desktop + dev.usUsage = 0x02; // mouse + dev.dwFlags = RIDEV_INPUTSINK; // also while this (invisible) window has no focus; focus is checked per poll + dev.hwndTarget = hwnd; + if (!RegisterRawInputDevices(&dev, 1, sizeof(dev))) { + std::fprintf(stderr, "[rt] gameinput: no raw mouse input (register: error %lu); using the cursor position\n", + GetLastError()); + DestroyWindow(hwnd); + return; + } + g_raw_ready = true; + std::fprintf(stderr, "[rt] gameinput: raw mouse input on (the right stick does not stop at the screen edge)\n"); + MSG m; + while (GetMessageW(&m, nullptr, 0, 0) > 0) DispatchMessageW(&m); +} + +void start_raw_mouse() { + if (!g_raw_started.exchange(true)) std::thread(raw_mouse_thread).detach(); +} + bool system_cursor_pos(int* x, int* y) { + if (g_raw_ready) { // the edgeless total; it wraps only after ±2^31 counts, and the poll uses differences + *x = static_cast(g_raw_x.load()); + *y = static_cast(g_raw_y.load()); + return true; + } POINT p; if (!GetCursorPos(&p)) return false; *x = p.x; @@ -911,6 +981,33 @@ void detach_keyboard_pad() { g_keyboard = {}; } +// Keeps the cursor inside the game window while it has focus, so a click cannot land on another window, and releases +// it on focus loss. Only with raw input (a clipped plain cursor would stop the stick at the window edge) and only for +// a real foreground window of this process: not KeyboardPadMode::Always over a terminal, nor a test's fake focus. +// Re-applied every 100 ms, because Windows drops the clip on some focus and resize changes. +bool g_clipped = false; +uint64_t g_clip_at = 0; + +void clip_cursor(bool want) { + if (!want) { + if (g_clipped) ClipCursor(nullptr); + g_clipped = false; + return; + } + const uint64_t now = now_us(); + if (g_clipped && now - g_clip_at < 100'000) return; + const HWND w = GetForegroundWindow(); + RECT r; + if (!w || !GetClientRect(w, &r)) return; + POINT top_left{r.left, r.top}, bottom_right{r.right, r.bottom}; + if (!ClientToScreen(w, &top_left) || !ClientToScreen(w, &bottom_right)) return; + const RECT screen{top_left.x, top_left.y, bottom_right.x, bottom_right.y}; + if (screen.right > screen.left && screen.bottom > screen.top && ClipCursor(&screen)) { + g_clipped = true; + g_clip_at = now; + } +} + bool attach_keyboard_pad() { SDL_VirtualJoystickDesc d; SDL_INIT_INTERFACE(&d); @@ -931,17 +1028,21 @@ bool attach_keyboard_pad() { std::fprintf(stderr, "[rt] gameinput: keyboard pad attached (arrows d-pad, Enter A, Backspace B, X X, Y Y, " "Q/E shoulders, Esc Menu, Tab View, WASD left stick, mouse right stick, right/left " "button LT/RT)\n"); + start_raw_mouse(); return true; } // Before SDL_UpdateGamepads, so the buttons set here are in this poll's reading. void update_keyboard_pad() { + float sens; rt::gameinput::KeyboardPadMode mode; { std::lock_guard lock(g().mu); mode = g().config.keyboard_pad; + sens = g().config.mouse_sensitivity; } if (mode == rt::gameinput::KeyboardPadMode::Off) { + clip_cursor(false); if (g_keyboard.id) detach_keyboard_pad(); g_keyboard.failed = false; return; @@ -953,7 +1054,8 @@ void update_keyboard_pad() { bool aim = false, fire = false; // Out of focus every button, stick and trigger is released, so a key held while switching windows does not stay // pressed, and the cursor is read afresh on return, so moving it in another window does not swing the stick. - if (mode == rt::gameinput::KeyboardPadMode::Always || g_has_focus.load()()) { + const bool active = mode == rt::gameinput::KeyboardPadMode::Always || g_has_focus.load()(); + if (active) { const rt::gameinput::KeyDownFn key_down = g_key_down.load(); for (const auto& b : kKeyBindings) down[b.sdl_button] |= key_down(b.virtual_key); lx = key_down('D') - key_down('A'); // opposite keys cancel @@ -964,9 +1066,9 @@ void update_keyboard_pad() { int x = 0, y = 0; const bool have = g_cursor_pos.load()(&x, &y); const bool moved = have && g_keyboard.have_cursor; - auto step = [](int v, int pixels) { + auto step = [sens](int v, int pixels) { const long long n = static_cast(v) * kMouseDecayNum / kMouseDecayDen + - static_cast(pixels) * kMouseAxisPerPixel; + std::lround(static_cast(pixels) * kMouseAxisPerPixel * sens); return static_cast(std::clamp(n, -kStickFull, kStickFull)); }; g_keyboard.right_x = step(g_keyboard.right_x, moved ? x - g_keyboard.cursor_x : 0); @@ -977,6 +1079,7 @@ void update_keyboard_pad() { g_keyboard.right_x = g_keyboard.right_y = 0; g_keyboard.have_cursor = false; } + clip_cursor(active && g_raw_ready && g_cursor_pos.load() == system_cursor_pos && foreground_is_ours()); for (const auto& b : kKeyBindings) SDL_SetJoystickVirtualButton(g_keyboard.js, b.sdl_button, down[b.sdl_button]); const int reach = lx && ly ? kStickDiagonal : kStickFull; SDL_SetJoystickVirtualAxis(g_keyboard.js, SDL_GAMEPAD_AXIS_LEFTX, static_cast(lx * reach)); diff --git a/runtime/shims/gameinput.h b/runtime/shims/gameinput.h index c78cea16e..0aa3cf38d 100644 --- a/runtime/shims/gameinput.h +++ b/runtime/shims/gameinput.h @@ -15,6 +15,7 @@ enum class KeyboardPadMode { Off, Focused, Always }; struct Config { DsTriggerMode ds_triggers = DsTriggerMode::Rumble; // LEONIDA_DS_TRIGGERS=off|rumble|resistance float ds_trigger_gain = 1.0f; // LEONIDA_DS_TRIGGER_GAIN, 0..4, scales the effect strength + float mouse_sensitivity = 1.0f; // LEONIDA_MOUSE_SENSITIVITY, 0.1..10, scales mouse movement uint8_t ds_trigger_frequency = 30; // LEONIDA_DS_TRIGGER_FREQ, Hz for the rumble mode, 1..255 bool lightbar_set = false; // LEONIDA_DS_LIGHTBAR=RRGGBB|off; unset keeps SDL's uint8_t lightbar[3] = {0, 0, 0}; // player colour diff --git a/runtime/test/gameinput_test.cpp b/runtime/test/gameinput_test.cpp index d1923ceaf..d57b5a0d7 100644 --- a/runtime/test/gameinput_test.cpp +++ b/runtime/test/gameinput_test.cpp @@ -393,6 +393,33 @@ void test_keyboard_pad_sticks(IGameInput* input, IGameInputDevice* kb) { } check(monotonic && polls < 100 && sticks_at_rest(st), "keyboard pad: right stick decays to 0 when the mouse stops"); + // LEONIDA_MOUSE_SENSITIVITY scales the axis units per count: 2 doubles, 0.5 halves; out of range clamps. + auto settle = [&] { + for (int i = 0; i < 200 && !sticks_at_rest(pad_state(input, kb)); ++i) rt::gameinput::poll(); + }; + set_env("LEONIDA_MOUSE_SENSITIVITY", "2"); + rt::gameinput::reload_config(); + g_cursor_x += 10; + rt::gameinput::poll(); + check(approx(pad_state(input, kb).rightThumbstickX, 20480 / 32767.0f), "keyboard pad: mouse sensitivity 2 doubles the stick"); + settle(); + set_env("LEONIDA_MOUSE_SENSITIVITY", "0.5"); + rt::gameinput::reload_config(); + g_cursor_x -= 10; + rt::gameinput::poll(); + check(approx(pad_state(input, kb).rightThumbstickX, -5120 / 32767.0f), "keyboard pad: mouse sensitivity 0.5 halves the stick"); + settle(); + set_env("LEONIDA_MOUSE_SENSITIVITY", "100"); + rt::gameinput::reload_config(); + check(rt::gameinput::config().mouse_sensitivity == 10.0f, "keyboard pad: mouse sensitivity clamps to 10"); + set_env("LEONIDA_MOUSE_SENSITIVITY", "0"); + rt::gameinput::reload_config(); + check(approx(rt::gameinput::config().mouse_sensitivity, 0.1f), "keyboard pad: mouse sensitivity clamps to 0.1"); + set_env("LEONIDA_MOUSE_SENSITIVITY", nullptr); + rt::gameinput::reload_config(); + check(rt::gameinput::config().mouse_sensitivity == 1.0f && rt::gameinput::config().ds_trigger_gain == 1.0f, + "keyboard pad: mouse sensitivity defaults to 1 and leaves the trigger gain alone"); + g_keys[VK_RBUTTON] = true; rt::gameinput::poll(); st = pad_state(input, kb); -- cgit v1.2.3 From b9a3cbcfc006c8fb957f7dc7cbe8cb450adabb51 Mon Sep 17 00:00:00 2001 From: itsRevela Date: Sun, 22 Nov 2026 10:26:34 -0600 Subject: gameinput: GetTemporalReading stays E_NOTIMPL, as in GameInput v0 (RT-147) Microsoft's reference page says IGameInput::GetTemporalReading "was never implemented in v0" and returns E_NOTIMPL, and v1 removed it, so the shim's E_NOTIMPL already matches the API the title was built against. A history lookup would answer what no GameInput runtime does. The v0 header (NuGet Microsoft.GameInput 0.2303.22621.3038) declares (timestamp, device, reading), the shim's layout; the page's five-parameter form doesn't match it. Pin the behaviour in gameinput_test (E_NOTIMPL with the reading cleared, for past, present and current timestamps, with and without a device filter; E_POINTER for a null output) and say so in docs/gameinput.md instead of listing the method as a gap. --- docs/gameinput.md | 10 +++++++--- runtime/shims/gameinput.cpp | 2 ++ runtime/test/gameinput_test.cpp | 11 +++++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) (limited to 'runtime/test/gameinput_test.cpp') diff --git a/docs/gameinput.md b/docs/gameinput.md index f848ab0d2..49e1331cc 100644 --- a/docs/gameinput.md +++ b/docs/gameinput.md @@ -187,7 +187,7 @@ The API surface: | interface | implemented | not implemented | |---|---|---| -| `IGameInput` | `GetCurrentTimestamp` (µs), `GetCurrentReading`, `GetNextReading`, `GetPreviousReading`, `RegisterReadingCallback`, `RegisterDeviceCallback` (blocking and async enumeration), `RegisterGuideButtonCallback`, `RegisterKeyboardLayoutCallback` (never fires), `StopCallback`, `UnregisterCallback`, `CreateDispatcher`, `FindDeviceFromId`, `EnableOemDeviceSupport` (no-op), `SetFocusPolicy` (no-op) | `GetTemporalReading`, `CreateAggregateDevice`, `FindDeviceFromObject/PlatformHandle/PlatformString` | +| `IGameInput` | `GetCurrentTimestamp` (µs), `GetCurrentReading`, `GetNextReading`, `GetPreviousReading`, `RegisterReadingCallback`, `RegisterDeviceCallback` (blocking and async enumeration), `RegisterGuideButtonCallback`, `RegisterKeyboardLayoutCallback` (never fires), `StopCallback`, `UnregisterCallback`, `CreateDispatcher`, `FindDeviceFromId`, `EnableOemDeviceSupport` (no-op), `SetFocusPolicy` (no-op) | `GetTemporalReading` (`E_NOTIMPL`, as in GameInput v0 itself; see below), `CreateAggregateDevice`, `FindDeviceFromObject/PlatformHandle/PlatformString` | | `IGameInputReading` | kind, sequence number, timestamp, device, gamepad state, UI navigation state, controller axes and buttons, motion state | raw report, keyboard, mouse, touch, arcade/flight stick, racing wheel (all return nothing) | | `IGameInputDevice` | device info, status, battery, `SetRumbleState` | force feedback and haptic motors (none reported), raw device I/O, power off, input synchronization (no-ops) | | `IGameInputDispatcher` | `Dispatch`, `OpenWaitHandle` | the quota (the queue is short) | @@ -279,8 +279,12 @@ These need the game executable or a test on hardware: built against one of those, the vtables need a second set. - **IIDs.** `QueryInterface` answers the v0 IIDs from the public header. - **Reading history.** Microsoft's [next reading](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/input/gameinput/interfaces/igameinput/methods/igameinput_getnextreading) - and [previous reading](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/input/gameinput/interfaces/igameinput/methods/igameinput_getpreviousreading) pages describe half a second of readings per device and failure when old readings leave the stream. The table above records the shim's HRESULT choices. Changes faster than the poll are not seen, and - `GetTemporalReading` is not implemented. + and [previous reading](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/input/gameinput/interfaces/igameinput/methods/igameinput_getpreviousreading) pages describe half a second of readings per device and failure when old readings leave the stream. The table above records the shim's HRESULT choices. Changes faster than the poll are not seen. + `GetTemporalReading` returns `E_NOTIMPL` with a null reading on purpose: Microsoft's + [reference page](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/input/gameinput/deprecated/interfaces/igameinput/methods/igameinput_gettemporalreading) + says it "was never implemented in v0" and returns `E_NOTIMPL`, and v1 removed it. The v0 header (NuGet + `Microsoft.GameInput` 0.2303.22621.3038) declares it as `(timestamp, device, reading)`, the layout the shim has; + the page's five-parameter form does not match that header. - **UI navigation mapping** and the **controller-axis convention** (0..1 with sticks at 0.5) are this shim's choice, not measured from a console. - **Battery capacity** is reported as a fraction (remaining 0..1 of full 1), not in device units. diff --git a/runtime/shims/gameinput.cpp b/runtime/shims/gameinput.cpp index 3b66e2ab9..84807f084 100644 --- a/runtime/shims/gameinput.cpp +++ b/runtime/shims/gameinput.cpp @@ -1256,6 +1256,8 @@ public: IGameInputReading** out) override { return find_reading(ref, kind, device, out, false); } + // E_NOTIMPL is GameInput v0's own answer: Microsoft's reference page says the method "was never implemented in + // v0" and returns E_NOTIMPL, and v1 removed it. A history lookup here would give a title what no GameInput does. HRESULT STDMETHODCALLTYPE GetTemporalReading(uint64_t, IGameInputDevice*, IGameInputReading** out) override { if (!out) return E_POINTER; *out = nullptr; diff --git a/runtime/test/gameinput_test.cpp b/runtime/test/gameinput_test.cpp index d1923ceaf..ba2a21f0e 100644 --- a/runtime/test/gameinput_test.cpp +++ b/runtime/test/gameinput_test.cpp @@ -992,6 +992,17 @@ int main() { check(input->GetPreviousReading(idle, GameInputKindGamepad, dev, nullptr) == E_POINTER && input->GetPreviousReading(nullptr, GameInputKindGamepad, dev, &hit) == E_INVALIDARG && !hit, "history: a null output is E_POINTER, a null reference E_INVALIDARG"); + // GetTemporalReading: E_NOTIMPL with a null reading, as GameInput v0 itself, for a timestamp in the history, one + // before it and the current time, with and without a device filter. + const uint64_t idle_us = idle->GetTimestamp(); + bool temporal_notimpl = true; + for (const uint64_t at : {idle_us, idle_us - 1'000'000, input->GetCurrentTimestamp()}) + for (IGameInputDevice* filter : {dev, static_cast(nullptr)}) { + IGameInputReading* temporal = idle; // a stale value the call must clear + temporal_notimpl &= input->GetTemporalReading(at, filter, &temporal) == E_NOTIMPL && !temporal; + } + check(temporal_notimpl && input->GetTemporalReading(idle_us, dev, nullptr) == E_POINTER, + "history: GetTemporalReading is E_NOTIMPL with a null reading, as in GameInput v0"); // Two pads in one stream, one poll each: A on the Xbox pad, B on the DualSense, Y on the Xbox pad. IGameInputReading* start = current(input, dev); -- cgit v1.2.3