upleb.uk

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

summaryrefslogtreecommitdiff
path: root/runtime/test/gameinput_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/test/gameinput_test.cpp')
-rw-r--r--runtime/test/gameinput_test.cpp51
1 files changed, 50 insertions, 1 deletions
diff --git a/runtime/test/gameinput_test.cpp b/runtime/test/gameinput_test.cpp
index bb63e2df9..d34f0b7ce 100644
--- a/runtime/test/gameinput_test.cpp
+++ b/runtime/test/gameinput_test.cpp
@@ -2230,8 +2230,9 @@ int main(int argc, char** argv) {
2230 if (pair_ref) pair_ref->Release(); 2230 if (pair_ref) pair_ref->Release();
2231 2231
2232 // A slow reader: a press that came and went between two reads of a pad is answered once, then the real state. 2232 // A slow reader: a press that came and went between two reads of a pad is answered once, then the real state.
2233 // Sleeps are 150 ms, three times kSlowReaderUs (50 ms), so a loaded CI machine cannot make the reader look fast.
2233 if (IGameInputReading* r = current(input, dev)) r->Release(); 2234 if (IGameInputReading* r = current(input, dev)) r->Release();
2234 Sleep(80); 2235 Sleep(150);
2235 SDL_SetJoystickVirtualButton(xbox2.js, SDL_GAMEPAD_BUTTON_WEST, true); 2236 SDL_SetJoystickVirtualButton(xbox2.js, SDL_GAMEPAD_BUTTON_WEST, true);
2236 rt::gameinput::poll(); 2237 rt::gameinput::poll();
2237 SDL_SetJoystickVirtualButton(xbox2.js, SDL_GAMEPAD_BUTTON_WEST, false); 2238 SDL_SetJoystickVirtualButton(xbox2.js, SDL_GAMEPAD_BUTTON_WEST, false);
@@ -2245,6 +2246,35 @@ int main(int argc, char** argv) {
2245 if (second) second->Release(); 2246 if (second) second->Release();
2246 } 2247 }
2247 2248
2249 // Two slow-read pads: each one's missed press comes back on its own pad only.
2250 if (IGameInputReading* r = current(input, dev)) r->Release();
2251 if (IGameInputReading* r = current(input, dsdev)) r->Release();
2252 Sleep(150);
2253 SDL_SetJoystickVirtualButton(xbox2.js, SDL_GAMEPAD_BUTTON_WEST, true);
2254 rt::gameinput::poll();
2255 SDL_SetJoystickVirtualButton(xbox2.js, SDL_GAMEPAD_BUTTON_WEST, false);
2256 rt::gameinput::poll();
2257 SDL_SetJoystickVirtualButton(ds.js, SDL_GAMEPAD_BUTTON_NORTH, true);
2258 rt::gameinput::poll();
2259 SDL_SetJoystickVirtualButton(ds.js, SDL_GAMEPAD_BUTTON_NORTH, false);
2260 rt::gameinput::poll();
2261 {
2262 IGameInputReading* ds_first = current(input, dsdev);
2263 IGameInputReading* x_first = current(input, dev);
2264 IGameInputReading* ds_second = current(input, dsdev);
2265 IGameInputReading* x_second = current(input, dev);
2266 check(ds_first && device_of(ds_first) == dsdev && (buttons_of(ds_first) & GameInputGamepadY) &&
2267 !(buttons_of(ds_first) & GameInputGamepadX),
2268 "two slow-read pads: the DualSense gets its own missed press, not the Xbox pad's");
2269 check(x_first && device_of(x_first) == dev && (buttons_of(x_first) & GameInputGamepadX) &&
2270 !(buttons_of(x_first) & GameInputGamepadY),
2271 "two slow-read pads: the Xbox pad gets its own missed press, not the DualSense's");
2272 check(ds_second && x_second && !(buttons_of(ds_second) & GameInputGamepadY) && !(buttons_of(x_second) & GameInputGamepadX),
2273 "two slow-read pads: each missed press comes once");
2274 for (IGameInputReading* r : {ds_first, x_first, ds_second, x_second})
2275 if (r) r->Release();
2276 }
2277
2248 // Ageing: a reading leaves the history once the reading after it is more than half a second old. 2278 // Ageing: a reading leaves the history once the reading after it is more than half a second old.
2249 IGameInputReading* aged = current(input, dev); 2279 IGameInputReading* aged = current(input, dev);
2250 SDL_SetJoystickVirtualButton(xbox2.js, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, true); 2280 SDL_SetJoystickVirtualButton(xbox2.js, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, true);
@@ -2294,6 +2324,25 @@ int main(int argc, char** argv) {
2294 check(idle && aged && fresh && idle->Release() == 0 && aged->Release() == 0 && fresh->Release() == 0, 2324 check(idle && aged && fresh && idle->Release() == 0 && aged->Release() == 0 && fresh->Release() == 0,
2295 "history: dropped readings are freed once the title releases them"); 2325 "history: dropped readings are freed once the title releases them");
2296 2326
2327 // Unplugging drops a pending missed press: the first slow read after replugging is the pad's real state.
2328 if (IGameInputReading* r = current(input, dev)) r->Release();
2329 Sleep(150);
2330 SDL_SetJoystickVirtualButton(xbox2.js, SDL_GAMEPAD_BUTTON_WEST, true);
2331 rt::gameinput::poll();
2332 SDL_SetJoystickVirtualButton(xbox2.js, SDL_GAMEPAD_BUTTON_WEST, false);
2333 rt::gameinput::poll();
2334 detach(xbox2);
2335 rt::gameinput::poll();
2336 attach(xbox2, "Leonida virtual Xbox pad", 0x045E, 0x0B12, true);
2337 rt::gameinput::poll();
2338 Sleep(150);
2339 {
2340 IGameInputReading* after = current(input, dev);
2341 check(after && device_of(after) == dev && !(buttons_of(after) & GameInputGamepadX),
2342 "close_pad drops a pending missed press: no stale press after replugging");
2343 if (after) after->Release();
2344 }
2345
2297 if (reading) reading->Release(); 2346 if (reading) reading->Release();
2298 dev->Release(); 2347 dev->Release();
2299 detach(xbox2); 2348 detach(xbox2);