diff options
| author | Rafael <rafaelalvesp2005@gmail.com> | 2026-11-23 15:36:26 -0300 |
|---|---|---|
| committer | Rafael <rafaelalvesp2005@gmail.com> | 2026-11-23 15:36:26 -0300 |
| commit | 63f0e0dea3a9d44201db408c4e2c3f2f5b2b94d6 (patch) | |
| tree | 86f0dcad8070e2a3a693ef4897aa83950cfeb224 /runtime/test/gameinput_probe.cpp | |
| parent | f78f7d6a2a9364cb128c03ac539fe540d5c70df1 (diff) | |
| parent | 6dda0630bd6fc0514baadb94fb98e36bd7d64c0b (diff) | |
Merge main into fix/walk-bink_names
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.cpp | 63 |
1 files changed, 58 insertions, 5 deletions
diff --git a/runtime/test/gameinput_probe.cpp b/runtime/test/gameinput_probe.cpp index 510194f1d..1d3202cb5 100644 --- a/runtime/test/gameinput_probe.cpp +++ b/runtime/test/gameinput_probe.cpp | |||
| @@ -1,13 +1,15 @@ | |||
| 1 | // gameinput_probe: the GameInput shim on a real controller. Not a CTest; run it by hand with a pad connected. | 1 | // gameinput_probe: the GameInput shim on a real controller. Not a CTest; run it by hand with a pad connected. |
| 2 | // | 2 | // |
| 3 | // gameinput_probe [--seconds N] [--rumble] | 3 | // gameinput_probe [--seconds N] [--rumble] [--force-feedback] |
| 4 | // | 4 | // |
| 5 | // Lists the gamepads the shim sees, with the raw HID report tables of each pad opened through HID, then prints the | 5 | // Lists the gamepads the shim sees, with the raw HID report tables of each pad opened through HID, then prints the |
| 6 | // live gamepad reading (and its newest raw input report, when there is one) for N seconds (default 10). With | 6 | // live gamepad reading (and its newest raw input report, when there is one) for N seconds (default 10). With |
| 7 | // --rumble it first plays, on every pad: the low-frequency motor, the high-frequency motor, the left and the right | 7 | // --rumble it first plays, on every pad: the low-frequency motor, the high-frequency motor, the left and the right |
| 8 | // impulse trigger, one second each. On a DualSense the trigger steps run in the LEONIDA_DS_TRIGGERS mode (rumble by | 8 | // impulse trigger, one second each. On a DualSense the trigger steps run in the LEONIDA_DS_TRIGGERS mode (rumble by |
| 9 | // default; set it to resistance to feel that one). Everything goes through GameInputCreate from the shim registry, | 9 | // default; set it to resistance to feel that one). With --force-feedback it then creates a constant force at |
| 10 | // as a title would call it. No game data. | 10 | // magnitude 1.0 on motor 0 and holds it for a second, which a wheel feels as a steady pull; a pad the shim reports no |
| 11 | // force-feedback motor for is skipped with the reason shown. Everything goes through GameInputCreate from the shim | ||
| 12 | // registry, as a title would call it. No game data. | ||
| 11 | #include <windows.h> | 13 | #include <windows.h> |
| 12 | 14 | ||
| 13 | #include <cstdio> | 15 | #include <cstdio> |
| @@ -61,16 +63,65 @@ void play(const char* what, GameInputRumbleParams p) { | |||
| 61 | Sleep(300); | 63 | Sleep(300); |
| 62 | } | 64 | } |
| 63 | 65 | ||
| 66 | // A constant force at full magnitude on the pad's first motor, held for a second: the effect a wheel feels as a | ||
| 67 | // steady pull. A pad SDL did not open as a haptic device reports no motor, and the step says so and moves on. | ||
| 68 | void constant_force() { | ||
| 69 | // g_devices is in connection order, which is what output_state indexes; the SDL outcome is read back per pad. | ||
| 70 | for (size_t n = 0; n < g_devices.size(); ++n) { | ||
| 71 | IGameInputDevice* d = g_devices[n]; | ||
| 72 | const GameInputDeviceInfo* i = d->GetDeviceInfo(); | ||
| 73 | if (i->forceFeedbackMotorCount == 0) { | ||
| 74 | std::printf("force feedback: %s reports no force-feedback motor; skipped\n", | ||
| 75 | i->displayName ? i->displayName->data : "?"); | ||
| 76 | continue; | ||
| 77 | } | ||
| 78 | const auto* motor = static_cast<const GameInputForceFeedbackMotorInfo*>(i->forceFeedbackMotorInfo); | ||
| 79 | std::printf("force feedback: %u motor(s), motor 0 axes=0x%x constant=%d\n", i->forceFeedbackMotorCount, | ||
| 80 | motor ? static_cast<unsigned>(motor->supportedAxes) : 0u, | ||
| 81 | motor != nullptr && motor->isConstantEffectSupported); | ||
| 82 | GameInputForceFeedbackParams p{}; | ||
| 83 | p.kind = GameInputForceFeedbackConstant; | ||
| 84 | p.data.constant.magnitude.linearX = 1.0f; | ||
| 85 | IGameInputForceFeedbackEffect* e = nullptr; | ||
| 86 | const HRESULT hr = d->CreateForceFeedbackEffect(0, &p, reinterpret_cast<void**>(&e)); | ||
| 87 | if (FAILED(hr) || !e) { | ||
| 88 | std::printf("force feedback: CreateForceFeedbackEffect failed (0x%08lx)\n", static_cast<unsigned long>(hr)); | ||
| 89 | continue; | ||
| 90 | } | ||
| 91 | std::printf("force feedback: constant linearX 1.0 on motor 0, 1 s\n"); | ||
| 92 | e->SetState(GameInputFeedbackRunning); | ||
| 93 | Sleep(1000); // the poll thread creates and runs the effect | ||
| 94 | char seen[256] = "no output state"; | ||
| 95 | rt::gameinput::OutputState out{}; | ||
| 96 | if (rt::gameinput::output_state(static_cast<int>(n), &out)) { | ||
| 97 | if (out.effect_id < 0) { | ||
| 98 | std::snprintf(seen, sizeof seen, "SDL did not create the effect (%s)", | ||
| 99 | out.effect_error[0] ? out.effect_error : "no error text"); | ||
| 100 | } else if (!out.effect_ran) { | ||
| 101 | std::snprintf(seen, sizeof seen, "SDL created effect %d but did not run it (%s)", out.effect_id, | ||
| 102 | out.effect_error[0] ? out.effect_error : "no error text"); | ||
| 103 | } else { | ||
| 104 | std::snprintf(seen, sizeof seen, "SDL created effect %d and is running it", out.effect_id); | ||
| 105 | } | ||
| 106 | } | ||
| 107 | std::printf("force feedback: %s\n", seen); | ||
| 108 | e->SetState(GameInputFeedbackStopped); | ||
| 109 | e->Release(); // the poll thread destroys the SDL effect | ||
| 110 | Sleep(300); | ||
| 111 | } | ||
| 112 | } | ||
| 113 | |||
| 64 | } // namespace | 114 | } // namespace |
| 65 | 115 | ||
| 66 | int main(int argc, char** argv) { | 116 | int main(int argc, char** argv) { |
| 67 | int seconds = 10; | 117 | int seconds = 10; |
| 68 | bool rumble = false; | 118 | bool rumble = false, force_feedback = false; |
| 69 | for (int i = 1; i < argc; ++i) { | 119 | for (int i = 1; i < argc; ++i) { |
| 70 | if (!std::strcmp(argv[i], "--seconds") && i + 1 < argc) seconds = std::atoi(argv[++i]); | 120 | if (!std::strcmp(argv[i], "--seconds") && i + 1 < argc) seconds = std::atoi(argv[++i]); |
| 71 | else if (!std::strcmp(argv[i], "--rumble")) rumble = true; | 121 | else if (!std::strcmp(argv[i], "--rumble")) rumble = true; |
| 122 | else if (!std::strcmp(argv[i], "--force-feedback")) force_feedback = true; | ||
| 72 | else { | 123 | else { |
| 73 | std::printf("usage: gameinput_probe [--seconds N] [--rumble]\n"); | 124 | std::printf("usage: gameinput_probe [--seconds N] [--rumble] [--force-feedback]\n"); |
| 74 | return 2; | 125 | return 2; |
| 75 | } | 126 | } |
| 76 | } | 127 | } |
| @@ -98,6 +149,8 @@ int main(int argc, char** argv) { | |||
| 98 | play("left trigger at 30%", {0, 0, 0.3f, 0}); | 149 | play("left trigger at 30%", {0, 0, 0.3f, 0}); |
| 99 | } | 150 | } |
| 100 | 151 | ||
| 152 | if (force_feedback && !g_devices.empty()) constant_force(); | ||
| 153 | |||
| 101 | const ULONGLONG end = GetTickCount64() + static_cast<ULONGLONG>(seconds) * 1000; | 154 | const ULONGLONG end = GetTickCount64() + static_cast<ULONGLONG>(seconds) * 1000; |
| 102 | while (GetTickCount64() < end) { | 155 | while (GetTickCount64() < end) { |
| 103 | IGameInputReading* r = nullptr; | 156 | IGameInputReading* r = nullptr; |