upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/test/gameinput_probe.cpp
diff options
context:
space:
mode:
authorkotorvr <332716892+kotorvr@users.noreply.github.com>2026-11-22 01:49:49 +0000
committerkotorvr <332716892+kotorvr@users.noreply.github.com>2026-11-22 02:54:55 +0000
commit0e59c75b7ba15013b5939b9177bfd2aa93c8f155 (patch)
tree545d9b6a58227fe1aa1f69b62e5e1fe5f6efd935 /runtime/test/gameinput_probe.cpp
parent67204bf8c0471335d9046890288b33e8d5e2875b (diff)
Runtime: GameInput shim on SDL3 (any controller; DualSense trigger effects, lightbar)
GameInputCreate and the v0 IGameInput/IGameInputDevice/IGameInputReading/IGameInputDispatcher surface a title uses for gamepads, served from SDL3 gamepads so DualSense, DualShock 4, Switch Pro and Xbox pads all work. Rumble goes to SDL_RumbleGamepad, impulse-trigger rumble to SDL_RumbleGamepadTriggers, and on a DualSense to adaptive-trigger effects through SDL_SendGamepadEffect (LEONIDA_DS_TRIGGERS=off|rumble|resistance). Lightbar via LEONIDA_DS_LIGHTBAR. SDL3 (zlib) comes from an installed package or a pinned, hash-checked release tarball via FetchContent; -DLEONIDA_SDL3=OFF skips the shim. gameinput_test covers the shim on SDL virtual joysticks; gameinput_probe is the manual check on a real pad. docs/gameinput.md has the mapping, settings and VERIFY list. AI-assisted (Claude Code). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'runtime/test/gameinput_probe.cpp')
-rw-r--r--runtime/test/gameinput_probe.cpp104
1 files changed, 104 insertions, 0 deletions
diff --git a/runtime/test/gameinput_probe.cpp b/runtime/test/gameinput_probe.cpp
new file mode 100644
index 000000000..aa077b257
--- /dev/null
+++ b/runtime/test/gameinput_probe.cpp
@@ -0,0 +1,104 @@
1// gameinput_probe: the GameInput shim on a real controller. Not a CTest; run it by hand with a pad connected.
2//
3// gameinput_probe [--seconds N] [--rumble]
4//
5// Lists the gamepads the shim sees, then prints the live gamepad reading of each for N seconds (default 10). With
6// --rumble it first plays, on every pad: the low-frequency motor, the high-frequency motor, the left and the right
7// impulse trigger, one second each. On a DualSense the trigger steps run in the LEONIDA_DS_TRIGGERS mode (rumble by
8// default; set it to resistance to feel that one). Everything goes through GameInputCreate from the shim registry,
9// as a title would call it. No game data.
10#include <windows.h>
11
12#include <cstdio>
13#include <cstdlib>
14#include <cstring>
15#include <vector>
16
17#include "gameinput.h"
18#include "gameinput_abi.h"
19#include "shims.h"
20
21using namespace gi;
22
23namespace {
24
25std::vector<IGameInputDevice*> g_devices;
26
27void CALLBACK on_device(GameInputCallbackToken, void*, IGameInputDevice* device, uint64_t, uint32_t current, uint32_t previous) {
28 const GameInputDeviceInfo* i = device->GetDeviceInfo();
29 std::printf("\n%s %s (%04x:%04x) motors=0x%x\n", (current & GameInputDeviceConnected) ? "connected " : "disconnected",
30 i->displayName ? i->displayName->data : "?", i->vendorId, i->productId, i->supportedRumbleMotors);
31 if ((current & GameInputDeviceConnected) && !(previous & GameInputDeviceConnected)) {
32 device->AddRef();
33 g_devices.push_back(device);
34 }
35}
36
37void play(const char* what, GameInputRumbleParams p) {
38 std::printf("rumble: %s\n", what);
39 for (IGameInputDevice* d : g_devices) d->SetRumbleState(&p);
40 Sleep(1000);
41 for (IGameInputDevice* d : g_devices) d->SetRumbleState(nullptr);
42 Sleep(300);
43}
44
45} // namespace
46
47int main(int argc, char** argv) {
48 int seconds = 10;
49 bool rumble = false;
50 for (int i = 1; i < argc; ++i) {
51 if (!std::strcmp(argv[i], "--seconds") && i + 1 < argc) seconds = std::atoi(argv[++i]);
52 else if (!std::strcmp(argv[i], "--rumble")) rumble = true;
53 else {
54 std::printf("usage: gameinput_probe [--seconds N] [--rumble]\n");
55 return 2;
56 }
57 }
58 auto create = reinterpret_cast<GameInputCreateFn>(rt::shims::find("gameinput.dll", "GameInputCreate"));
59 IGameInput* input = nullptr;
60 if (!create || create(&input) != S_OK) {
61 std::printf("GameInputCreate failed\n");
62 return 1;
63 }
64 Sleep(500); // let the poll thread open what is connected
65 GameInputCallbackToken token = 0;
66 input->RegisterDeviceCallback(nullptr, GameInputKindGamepad, GameInputDeviceAnyStatus, GameInputBlockingEnumeration,
67 nullptr, on_device, &token);
68 if (g_devices.empty()) std::printf("no gamepad connected; plug one in (watching for %d s)\n", seconds);
69
70 if (rumble && !g_devices.empty()) {
71 const auto& c = rt::gameinput::config();
72 std::printf("DualSense trigger mode: %s\n", c.ds_triggers == rt::gameinput::DsTriggerMode::Off ? "off"
73 : c.ds_triggers == rt::gameinput::DsTriggerMode::Resistance ? "resistance"
74 : "rumble");
75 play("low-frequency motor", {1, 0, 0, 0});
76 play("high-frequency motor", {0, 1, 0, 0});
77 play("left trigger", {0, 0, 1, 0});
78 play("right trigger", {0, 0, 0, 1});
79 play("left trigger at 30%", {0, 0, 0.3f, 0});
80 }
81
82 const ULONGLONG end = GetTickCount64() + static_cast<ULONGLONG>(seconds) * 1000;
83 while (GetTickCount64() < end) {
84 IGameInputReading* r = nullptr;
85 if (input->GetCurrentReading(GameInputKindGamepad, nullptr, &r) == S_OK) {
86 GameInputGamepadState s{};
87 GameInputUiNavigationState ui{};
88 r->GetGamepadState(&s);
89 r->GetUiNavigationState(&ui);
90 std::printf("\rbuttons=%04x ui=%06x LT=%.2f RT=%.2f L=(%+.2f,%+.2f) R=(%+.2f,%+.2f) seq=%llu ", s.buttons,
91 ui.buttons, s.leftTrigger, s.rightTrigger, s.leftThumbstickX, s.leftThumbstickY,
92 s.rightThumbstickX, s.rightThumbstickY,
93 static_cast<unsigned long long>(r->GetSequenceNumber(GameInputKindGamepad)));
94 std::fflush(stdout);
95 r->Release();
96 }
97 Sleep(16);
98 }
99 std::printf("\n");
100 input->UnregisterCallback(token, 0);
101 for (IGameInputDevice* d : g_devices) d->Release();
102 input->Release();
103 return 0;
104}